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