Unit tests for ofoverlay
[groupbasedpolicy.git] / renderers / ofoverlay / src / test / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / statistics / ReadGbpFlowCacheTaskTest.java
1 /*\r
2  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics;\r
10 \r
11 import static org.mockito.Matchers.any;\r
12 import static org.mockito.Matchers.anyString;\r
13 import static org.mockito.Mockito.doNothing;\r
14 import static org.mockito.Mockito.mock;\r
15 import static org.mockito.Mockito.when;\r
16 \r
17 import javax.ws.rs.core.MultivaluedMap;\r
18 \r
19 import java.util.concurrent.ScheduledExecutorService;\r
20 \r
21 import com.sun.jersey.api.client.ClientResponse;\r
22 import org.junit.Before;\r
23 import org.junit.Test;\r
24 import org.mockito.Mockito;\r
25 import org.opendaylight.groupbasedpolicy.api.StatisticsManager;\r
26 \r
27 public class ReadGbpFlowCacheTaskTest {\r
28 \r
29     ReadGbpFlowCacheTask task;\r
30     private JsonRestClientResponse response;\r
31 \r
32     @Before\r
33     public void init() {\r
34         StatisticsManager statisticsManager = mock(StatisticsManager.class);\r
35         ScheduledExecutorService executor = mock(ScheduledExecutorService.class);\r
36         ClientResponse clientResponse = mock(ClientResponse.class);\r
37         response = mock(JsonRestClientResponse.class);\r
38         when(response.getJsonResponse()).thenReturn("[{\"one\":1, \"two\":2, \"three\":3}]");\r
39         when(response.getStatusCode()).thenReturn(200);\r
40         when(response.getClientResponse()).thenReturn(clientResponse);\r
41         SFlowRTConnection connection = mock(SFlowRTConnection.class);\r
42         when(connection.get(anyString(), Mockito.<MultivaluedMap<String, String>>any())).thenReturn(response);\r
43         when(connection.getExecutor()).thenReturn(executor);\r
44         doNothing().when(executor).execute(any(Runnable.class));\r
45 \r
46         task = new ReadGbpFlowCacheTask("cache1", connection, statisticsManager, 100, 0.1, "sum");\r
47     }\r
48 \r
49     @Test\r
50     public void testRun() {\r
51         task.run();\r
52     }\r
53 \r
54     @Test\r
55     public void testRun_response300() {\r
56         when(response.getStatusCode()).thenReturn(300);\r
57         task.run();\r
58     }\r
59 \r
60     @Test\r
61     public void testRun_response400() {\r
62         when(response.getStatusCode()).thenReturn(400);\r
63         task.run();\r
64     }\r
65 \r
66 }\r