2 * Copyright 2014-2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.net.device.impl;
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;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.onlab.packet.ChassisId;
27 import org.onosproject.net.config.Config;
28 import org.onosproject.net.config.ConfigApplyDelegate;
29 import org.onosproject.net.config.basics.BasicDeviceConfig;
30 import org.onosproject.net.AnnotationKeys;
31 import org.onosproject.net.DefaultAnnotations;
32 import org.onosproject.net.DeviceId;
33 import org.onosproject.net.SparseAnnotations;
34 import org.onosproject.net.device.DefaultDeviceDescription;
35 import org.onosproject.net.device.DeviceDescription;
37 import com.fasterxml.jackson.databind.ObjectMapper;
38 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
40 public class BasicDeviceOperatorTest {
42 private static final String NAME1 = "of:foo";
43 private static final String NAME2 = "of:bar";
44 private static final String OWNER = "somebody";
45 private static final URI DURI = URI.create(NAME1);
46 private static final String MFR = "whitebox";
47 private static final String HW = "1.1.x";
48 private static final String SW = "3.9.1";
49 private static final String SN = "43311-12345";
50 private static final ChassisId CID = new ChassisId();
52 private static final SparseAnnotations SA = DefaultAnnotations.builder()
53 .set(AnnotationKeys.DRIVER, NAME2).build();
55 private static final DeviceDescription DEV1 = new DefaultDeviceDescription(
56 DURI, SWITCH, MFR, HW, SW, SN, CID, SA);
58 private final ConfigApplyDelegate delegate = new ConfigApplyDelegate() {
60 public void onApply(Config config) {
63 private final ObjectMapper mapper = new ObjectMapper();
65 private static final BasicDeviceConfig SW_BDC = new BasicDeviceConfig();
66 private static final BasicDeviceConfig RD_BDC = new BasicDeviceConfig();
70 SW_BDC.init(DeviceId.deviceId(NAME1), NAME1, JsonNodeFactory.instance.objectNode(), mapper, delegate);
71 SW_BDC.type(SWITCH).driver(NAME1).owner(OWNER);
72 RD_BDC.init(DeviceId.deviceId(NAME2), NAME2, JsonNodeFactory.instance.objectNode(), mapper, delegate);
77 public void testDescOps() {
78 DeviceDescription desc = BasicDeviceOperator.combine(null, DEV1);
79 assertEquals(desc, DEV1);
81 // override driver name
82 desc = BasicDeviceOperator.combine(SW_BDC, DEV1);
83 assertEquals(NAME1, desc.annotations().value(AnnotationKeys.DRIVER));
85 // override Device Type
86 desc = BasicDeviceOperator.combine(RD_BDC, DEV1);
87 assertEquals(ROADM, desc.type());