blob: f3f3d154aa5e82941f640a02f7e0882f8e431f58 [file] [log] [blame]
Brian O'Connor7cbbbb72016-04-09 02:13:23 -07001/*
2 * Copyright 2015-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Naoki Shiota399a0b32015-11-15 20:36:13 -060016package org.onosproject.provider.lldp.impl;
17
18import static org.junit.Assert.*;
19
20import com.fasterxml.jackson.databind.ObjectMapper;
21import com.fasterxml.jackson.databind.node.JsonNodeFactory;
22import org.junit.Before;
23import org.junit.Test;
24import org.onosproject.TestApplicationId;
25import org.onosproject.net.Device;
26import org.onosproject.net.DeviceId;
27import org.onosproject.net.config.ConfigApplyDelegate;
28
29import java.util.HashMap;
30import java.util.HashSet;
31import java.util.Map;
32import java.util.Set;
33
34public class SuppressionConfigTest {
35 private static final String APP_NAME = "SuppressionConfigTest";
36 private static final TestApplicationId APP_ID = new TestApplicationId(APP_NAME);
37 private static final DeviceId DEVICE_ID_1 = DeviceId.deviceId("of:1111000000000000");
38 private static final DeviceId DEVICE_ID_2 = DeviceId.deviceId("of:2222000000000000");
39 private static final Device.Type DEVICE_TYPE_1 = Device.Type.ROADM;
40 private static final Device.Type DEVICE_TYPE_2 = Device.Type.FIBER_SWITCH;
41 private static final String ANNOTATION_KEY_1 = "no_lldp";
42 private static final String ANNOTATION_VALUE_1 = "true";
43 private static final String ANNOTATION_KEY_2 = "sendLLDP";
44 private static final String ANNOTATION_VALUE_2 = "false";
45
46 private SuppressionConfig cfg;
47
48 @Before
49 public void setUp() throws Exception {
50 ConfigApplyDelegate delegate = config -> { };
51 ObjectMapper mapper = new ObjectMapper();
52 cfg = new SuppressionConfig();
53 cfg.init(APP_ID, LldpLinkProvider.CONFIG_KEY, JsonNodeFactory.instance.objectNode(), mapper, delegate);
54 }
55
56 @Test
Naoki Shiota399a0b32015-11-15 20:36:13 -060057 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}