Brian O'Connor | 7cbbbb7 | 2016-04-09 02:13:23 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Brian O'Connor | 7cbbbb7 | 2016-04-09 02:13:23 -0700 | [diff] [blame] | 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 Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 16 | package org.onosproject.provider.lldp.impl; |
| 17 | |
| 18 | import static org.junit.Assert.*; |
| 19 | |
| 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 21 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 22 | import org.junit.Before; |
| 23 | import org.junit.Test; |
| 24 | import org.onosproject.TestApplicationId; |
| 25 | import org.onosproject.net.Device; |
| 26 | import org.onosproject.net.DeviceId; |
| 27 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 28 | |
| 29 | import java.util.HashMap; |
| 30 | import java.util.HashSet; |
| 31 | import java.util.Map; |
| 32 | import java.util.Set; |
| 33 | |
| 34 | public 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 Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 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 | } |