Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014-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 | */ |
| 16 | package org.onosproject.net.device.impl; |
| 17 | |
| 18 | import static org.onosproject.net.Device.Type.SWITCH; |
| 19 | import static org.onosproject.net.Device.Type.ROADM; |
| 20 | import static org.junit.Assert.assertEquals; |
| 21 | |
| 22 | import java.net.URI; |
| 23 | |
| 24 | import org.junit.Before; |
| 25 | import org.junit.Test; |
| 26 | import org.onlab.packet.ChassisId; |
Ray Milkey | a412236 | 2015-08-18 15:19:08 -0700 | [diff] [blame] | 27 | import org.onosproject.net.config.ConfigApplyDelegate; |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 28 | import org.onosproject.net.config.basics.BasicDeviceConfig; |
Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 29 | import org.onosproject.net.AnnotationKeys; |
| 30 | import org.onosproject.net.DefaultAnnotations; |
| 31 | import org.onosproject.net.DeviceId; |
| 32 | import org.onosproject.net.SparseAnnotations; |
| 33 | import org.onosproject.net.device.DefaultDeviceDescription; |
| 34 | import org.onosproject.net.device.DeviceDescription; |
| 35 | |
| 36 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 37 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 38 | |
| 39 | public class BasicDeviceOperatorTest { |
| 40 | |
| 41 | private static final String NAME1 = "of:foo"; |
| 42 | private static final String NAME2 = "of:bar"; |
| 43 | private static final String OWNER = "somebody"; |
| 44 | private static final URI DURI = URI.create(NAME1); |
| 45 | private static final String MFR = "whitebox"; |
| 46 | private static final String HW = "1.1.x"; |
| 47 | private static final String SW = "3.9.1"; |
| 48 | private static final String SN = "43311-12345"; |
| 49 | private static final ChassisId CID = new ChassisId(); |
| 50 | |
| 51 | private static final SparseAnnotations SA = DefaultAnnotations.builder() |
| 52 | .set(AnnotationKeys.DRIVER, NAME2).build(); |
| 53 | |
| 54 | private static final DeviceDescription DEV1 = new DefaultDeviceDescription( |
| 55 | DURI, SWITCH, MFR, HW, SW, SN, CID, SA); |
| 56 | |
Sho SHIMIZU | 7462641 | 2015-09-11 11:46:27 -0700 | [diff] [blame] | 57 | private final ConfigApplyDelegate delegate = config -> { }; |
Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 58 | private final ObjectMapper mapper = new ObjectMapper(); |
| 59 | |
| 60 | private static final BasicDeviceConfig SW_BDC = new BasicDeviceConfig(); |
| 61 | private static final BasicDeviceConfig RD_BDC = new BasicDeviceConfig(); |
| 62 | |
| 63 | @Before |
| 64 | public void setUp() { |
| 65 | SW_BDC.init(DeviceId.deviceId(NAME1), NAME1, JsonNodeFactory.instance.objectNode(), mapper, delegate); |
| 66 | SW_BDC.type(SWITCH).driver(NAME1).owner(OWNER); |
| 67 | RD_BDC.init(DeviceId.deviceId(NAME2), NAME2, JsonNodeFactory.instance.objectNode(), mapper, delegate); |
| 68 | RD_BDC.type(ROADM); |
| 69 | } |
| 70 | |
| 71 | @Test |
| 72 | public void testDescOps() { |
| 73 | DeviceDescription desc = BasicDeviceOperator.combine(null, DEV1); |
| 74 | assertEquals(desc, DEV1); |
| 75 | |
| 76 | // override driver name |
| 77 | desc = BasicDeviceOperator.combine(SW_BDC, DEV1); |
| 78 | assertEquals(NAME1, desc.annotations().value(AnnotationKeys.DRIVER)); |
| 79 | |
| 80 | // override Device Type |
| 81 | desc = BasicDeviceOperator.combine(RD_BDC, DEV1); |
| 82 | assertEquals(ROADM, desc.type()); |
| 83 | } |
| 84 | } |