a38db69c69bc77da524b970d6624cf5cd2973183
[groupbasedpolicy.git] / renderers / ofoverlay / src / test / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / statistics / flowcache / FlowCacheTest.java
1 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache;\r
2 \r
3 import static org.junit.Assert.assertEquals;\r
4 import static org.junit.Assert.assertNotNull;\r
5 import static org.junit.Assert.fail;\r
6 \r
7 import java.util.ArrayList;\r
8 import java.util.List;\r
9 \r
10 import org.junit.Before;\r
11 import org.junit.Test;\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection;\r
13 \r
14 public class FlowCacheTest {\r
15 \r
16     private static final String KEY_1 = "key_1";\r
17     private static final String KEY_2 = "key_2";\r
18     private static final String NAME_1 = "name_1";\r
19     private static final HasDirection.Direction direction = HasDirection.Direction.Bidirectional;\r
20     private static final String VALUE_1 = "value_1";\r
21     private static FlowCacheDefinition flowCacheDefinition;\r
22     private List<String> keysValues;\r
23     private String json;\r
24 \r
25     @Before\r
26     public void init() {\r
27         keysValues = new ArrayList<>();\r
28         keysValues.add(KEY_1);\r
29         keysValues.add(KEY_2);\r
30 \r
31         FlowCacheDefinition.FlowCacheDefinitionBuilder flowCacheDefinitionBuilder = FlowCacheDefinition.builder();\r
32         flowCacheDefinitionBuilder.getKeysBuilder().setValues(keysValues);\r
33         flowCacheDefinition = flowCacheDefinitionBuilder.setValue(VALUE_1).setLog(true).build();\r
34 \r
35         json = "{\"keys\":\"" + KEY_1 + "," + KEY_2 + "\"," + "\"value\":\"" + VALUE_1 + "\","\r
36                 + "\"filter\":\"\",\"log\":true}";\r
37     }\r
38 \r
39     @Test\r
40     public void testBuilder() {\r
41         FlowCache.FlowCacheBuilder builder = null;\r
42         try {\r
43             builder = FlowCache.builder();\r
44         } catch (Exception e) {\r
45             fail("Exception thrown: " + e.getMessage());\r
46         }\r
47         assertNotNull(builder);\r
48     }\r
49 \r
50     @Test\r
51     public void testConstructor_Implicitely() {\r
52         FlowCache flowCache =\r
53                 FlowCache.builder().setDefinition(flowCacheDefinition).setDirection(direction).setName(NAME_1).build();\r
54 \r
55         assertEquals(keysValues.size(), flowCache.getKeyNum());\r
56         assertEquals(keysValues.get(0), flowCache.getKeyNames()[0]);\r
57         assertEquals(keysValues.get(1), flowCache.getKeyNames()[1]);\r
58         assertEquals(FlowCache.API_FLOW + NAME_1 + FlowCache.SUFFIX_JSON, flowCache.getPath());\r
59         assertEquals(json, flowCache.getJsonDefinition());\r
60 \r
61     }\r
62 }\r