Ayaka Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 1 | package org.onosproject.net.device.impl; |
| 2 | |
| 3 | import org.junit.Before; |
| 4 | import org.junit.Test; |
Ray Milkey | a412236 | 2015-08-18 15:19:08 -0700 | [diff] [blame^] | 5 | import org.onosproject.net.config.Config; |
| 6 | import org.onosproject.net.config.ConfigApplyDelegate; |
Ayaka Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 7 | import org.onosproject.incubator.net.config.basics.OpticalPortConfig; |
| 8 | import org.onosproject.net.AnnotationKeys; |
| 9 | import org.onosproject.net.ConnectPoint; |
| 10 | import org.onosproject.net.DefaultAnnotations; |
| 11 | import org.onosproject.net.DeviceId; |
| 12 | import org.onosproject.net.OduCltPort; |
| 13 | import org.onosproject.net.Port; |
| 14 | import org.onosproject.net.PortNumber; |
| 15 | import org.onosproject.net.SparseAnnotations; |
| 16 | import org.onosproject.net.device.OduCltPortDescription; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 19 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 20 | |
| 21 | import static org.junit.Assert.assertEquals; |
| 22 | |
| 23 | public class OpticalPortOperatorTest { |
| 24 | private static final DeviceId DID = DeviceId.deviceId("op-test"); |
| 25 | private static final String TPNAME = "test-port-100"; |
| 26 | private static final String SPNAME = "out-port-200"; |
| 27 | private static final String CFGNAME = "cfg-name"; |
| 28 | |
| 29 | private static final PortNumber NAMED = PortNumber.portNumber(100, TPNAME); |
| 30 | private static final PortNumber UNNAMED = PortNumber.portNumber(101); |
| 31 | private static final ConnectPoint NCP = new ConnectPoint(DID, UNNAMED); |
| 32 | |
| 33 | private static final SparseAnnotations SA = DefaultAnnotations.builder() |
| 34 | .set(AnnotationKeys.STATIC_PORT, SPNAME) |
| 35 | .build(); |
| 36 | |
| 37 | private static final OduCltPortDescription N_DESC = new OduCltPortDescription( |
| 38 | NAMED, true, OduCltPort.SignalType.CLT_100GBE, SA); |
| 39 | private static final OduCltPortDescription FAULTY = new OduCltPortDescription( |
| 40 | null, true, OduCltPort.SignalType.CLT_100GBE); |
| 41 | |
| 42 | private final ConfigApplyDelegate delegate = new MockCfgDelegate(); |
| 43 | private final ObjectMapper mapper = new ObjectMapper(); |
| 44 | |
| 45 | private static final OpticalPortConfig N_OPC = new OpticalPortConfig(); |
| 46 | private static final OpticalPortConfig UNN_OPC = new OpticalPortConfig(); |
| 47 | |
| 48 | @Before |
| 49 | public void setUp() { |
| 50 | N_OPC.init(NCP, TPNAME, JsonNodeFactory.instance.objectNode(), mapper, delegate); |
| 51 | UNN_OPC.init(NCP, TPNAME, JsonNodeFactory.instance.objectNode(), mapper, delegate); |
| 52 | |
| 53 | N_OPC.portName(CFGNAME).portNumberName(101L).portType(Port.Type.ODUCLT).staticLambda(300L); |
| 54 | UNN_OPC.portType(Port.Type.ODUCLT); |
| 55 | } |
| 56 | |
| 57 | @Test(expected = RuntimeException.class) |
| 58 | public void testDescOps() { |
| 59 | // port-null desc + opc with port number name |
| 60 | OduCltPortDescription res = (OduCltPortDescription) OpticalPortOperator.combine(N_OPC, FAULTY); |
| 61 | assertEquals(CFGNAME, res.portNumber().name()); |
| 62 | // full desc + opc with name |
| 63 | assertEquals(TPNAME, N_DESC.portNumber().name()); |
| 64 | res = (OduCltPortDescription) OpticalPortOperator.combine(N_OPC, N_DESC); |
| 65 | long sl = Long.valueOf(res.annotations().value(AnnotationKeys.STATIC_LAMBDA)); |
| 66 | assertEquals(CFGNAME, res.portNumber().name()); |
| 67 | assertEquals(300L, sl); |
| 68 | // port-null desc + opc without port number name - throws RE |
| 69 | res = (OduCltPortDescription) OpticalPortOperator.combine(UNN_OPC, FAULTY); |
| 70 | } |
| 71 | |
| 72 | private class MockCfgDelegate implements ConfigApplyDelegate { |
| 73 | |
| 74 | @Override |
| 75 | public void onApply(@SuppressWarnings("rawtypes") Config config) { |
| 76 | config.apply(); |
| 77 | } |
| 78 | |
| 79 | } |
| 80 | } |