blob: 85061ca02d28c8a1980f54a5c5cdda3edbb5a7c9 [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
Naoki Shiota399a0b32015-11-15 20:36:13 -060042 public void testDeviceTypes() {
43 Set<Device.Type> inputTypes = new HashSet<Device.Type>() { {
44 add(DEVICE_TYPE_1);
45 add(DEVICE_TYPE_2);
46 } };
47
48 assertNotNull(cfg.deviceTypes(inputTypes));
49
50 Set<Device.Type> outputTypes = cfg.deviceTypes();
51 assertTrue(outputTypes.contains(DEVICE_TYPE_1));
52 assertTrue(outputTypes.contains(DEVICE_TYPE_2));
53 assertEquals(outputTypes.size(), 2);
54 }
55
56 @Test
57 public void testDeviceAnnotation() {
58 Map<String, String> inputMap = new HashMap<String, String>() { {
59 put(ANNOTATION_KEY_1, ANNOTATION_VALUE_1);
60 put(ANNOTATION_KEY_2, ANNOTATION_VALUE_2);
61 } };
62
63 assertNotNull(cfg.annotation(inputMap));
64
65 Map<String, String> outputMap = cfg.annotation();
66 assertEquals(outputMap.get(ANNOTATION_KEY_1), ANNOTATION_VALUE_1);
67 assertEquals(outputMap.get(ANNOTATION_KEY_2), ANNOTATION_VALUE_2);
68 assertEquals(outputMap.size(), 2);
69 }
70
71}