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