2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.fail;
14 import java.util.ArrayList;
15 import java.util.List;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection;
21 public class FlowCacheTest {
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;
34 keysValues = new ArrayList<>();
35 keysValues.add(KEY_1);
36 keysValues.add(KEY_2);
38 FlowCacheDefinition.FlowCacheDefinitionBuilder flowCacheDefinitionBuilder = FlowCacheDefinition.builder();
39 flowCacheDefinitionBuilder.getKeysBuilder().setValues(keysValues);
40 flowCacheDefinition = flowCacheDefinitionBuilder.setValue(VALUE_1).setLog(true).build();
42 json = "{\"keys\":\"" + KEY_1 + "," + KEY_2 + "\"," + "\"value\":\"" + VALUE_1 + "\","
43 + "\"filter\":\"\",\"log\":true}";
47 public void testBuilder() {
48 FlowCache.FlowCacheBuilder builder = null;
50 builder = FlowCache.builder();
51 } catch (Exception e) {
52 fail("Exception thrown: " + e.getMessage());
54 assertNotNull(builder);
58 public void testConstructor_Implicitely() {
60 FlowCache.builder().setDefinition(flowCacheDefinition).setDirection(direction).setName(NAME_1).build();
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());