Naoki Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 1 | package org.onosproject.provider.lldp.impl; |
| 2 | |
| 3 | import static org.junit.Assert.*; |
| 4 | |
| 5 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 6 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 7 | import org.junit.Before; |
| 8 | import org.junit.Test; |
| 9 | import org.onosproject.TestApplicationId; |
| 10 | import org.onosproject.net.Device; |
| 11 | import org.onosproject.net.DeviceId; |
| 12 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 13 | |
| 14 | import java.util.HashMap; |
| 15 | import java.util.HashSet; |
| 16 | import java.util.Map; |
| 17 | import java.util.Set; |
| 18 | |
| 19 | public 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 Shiota | 399a0b3 | 2015-11-15 20:36:13 -0600 | [diff] [blame] | 42 | 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 | } |