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