blob: 781ed17623c597fd870e6069e9dd832baae883ea [file] [log] [blame]
Naoki Shiota399a0b32015-11-15 20:36:13 -06001package org.onosproject.provider.lldp.impl;
2
3import static org.junit.Assert.*;
4
5import com.fasterxml.jackson.databind.ObjectMapper;
6import com.fasterxml.jackson.databind.node.JsonNodeFactory;
7import org.junit.Before;
8import org.junit.Test;
9import org.onosproject.TestApplicationId;
10import org.onosproject.net.Device;
11import org.onosproject.net.DeviceId;
12import org.onosproject.net.config.ConfigApplyDelegate;
13
14import java.util.HashMap;
15import java.util.HashSet;
16import java.util.Map;
17import java.util.Set;
18
19public class SuppressionConfigTest {
20 private static final String APP_NAME = "SuppressionConfigTest";
21 private static final TestApplicationId APP_ID = new TestApplicationId(APP_NAME);
22 private static final DeviceId DEVICE_ID_1 = DeviceId.deviceId("of:1111000000000000");
23 private static final DeviceId DEVICE_ID_2 = DeviceId.deviceId("of:2222000000000000");
24 private static final Device.Type DEVICE_TYPE_1 = Device.Type.ROADM;
25 private static final Device.Type DEVICE_TYPE_2 = Device.Type.FIBER_SWITCH;
26 private static final String ANNOTATION_KEY_1 = "no_lldp";
27 private static final String ANNOTATION_VALUE_1 = "true";
28 private static final String ANNOTATION_KEY_2 = "sendLLDP";
29 private static final String ANNOTATION_VALUE_2 = "false";
30
31 private SuppressionConfig cfg;
32
33 @Before
34 public void setUp() throws Exception {
35 ConfigApplyDelegate delegate = config -> { };
36 ObjectMapper mapper = new ObjectMapper();
37 cfg = new SuppressionConfig();
38 cfg.init(APP_ID, LldpLinkProvider.CONFIG_KEY, JsonNodeFactory.instance.objectNode(), mapper, delegate);
39 }
40
41 @Test
42 public void testDeviceIds() {
43 Set<DeviceId> inputIds = new HashSet<DeviceId>() { {
44 add(DEVICE_ID_1);
45 add(DEVICE_ID_2);
46 } };
47
48 assertNotNull(cfg.deviceIds(inputIds));
49
50 Set<DeviceId> outputIds = cfg.deviceIds();
51 assertTrue(outputIds.contains(DEVICE_ID_1));
52 assertTrue(outputIds.contains(DEVICE_ID_2));
53 assertEquals(outputIds.size(), 2);
54 }
55
56 @Test
57 public void testDeviceTypes() {
58 Set<Device.Type> inputTypes = new HashSet<Device.Type>() { {
59 add(DEVICE_TYPE_1);
60 add(DEVICE_TYPE_2);
61 } };
62
63 assertNotNull(cfg.deviceTypes(inputTypes));
64
65 Set<Device.Type> outputTypes = cfg.deviceTypes();
66 assertTrue(outputTypes.contains(DEVICE_TYPE_1));
67 assertTrue(outputTypes.contains(DEVICE_TYPE_2));
68 assertEquals(outputTypes.size(), 2);
69 }
70
71 @Test
72 public void testDeviceAnnotation() {
73 Map<String, String> inputMap = new HashMap<String, String>() { {
74 put(ANNOTATION_KEY_1, ANNOTATION_VALUE_1);
75 put(ANNOTATION_KEY_2, ANNOTATION_VALUE_2);
76 } };
77
78 assertNotNull(cfg.annotation(inputMap));
79
80 Map<String, String> outputMap = cfg.annotation();
81 assertEquals(outputMap.get(ANNOTATION_KEY_1), ANNOTATION_VALUE_1);
82 assertEquals(outputMap.get(ANNOTATION_KEY_2), ANNOTATION_VALUE_2);
83 assertEquals(outputMap.size(), 2);
84 }
85
86}