blob: 138283cd1dfe73905cdd1034d612bcf9bbf3c714 [file] [log] [blame]
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -07001/*
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 */
16package org.onosproject.net.device.impl;
17
Andrea Campanellab75b4882016-01-15 15:15:09 -080018import com.fasterxml.jackson.databind.ObjectMapper;
19import com.fasterxml.jackson.databind.node.JsonNodeFactory;
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070020import org.junit.Before;
21import org.junit.Test;
22import org.onlab.packet.ChassisId;
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070023import org.onosproject.net.AnnotationKeys;
24import org.onosproject.net.DefaultAnnotations;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.SparseAnnotations;
Andrea Campanellab75b4882016-01-15 15:15:09 -080027import org.onosproject.net.config.ConfigApplyDelegate;
28import org.onosproject.net.config.basics.BasicDeviceConfig;
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070029import org.onosproject.net.device.DefaultDeviceDescription;
30import org.onosproject.net.device.DeviceDescription;
31
Andrea Campanellab75b4882016-01-15 15:15:09 -080032import java.net.URI;
33
34import static org.junit.Assert.assertEquals;
35import static org.onosproject.net.Device.Type.ROADM;
36import static org.onosproject.net.Device.Type.SWITCH;
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070037
38public class BasicDeviceOperatorTest {
39
40 private static final String NAME1 = "of:foo";
41 private static final String NAME2 = "of:bar";
42 private static final String OWNER = "somebody";
43 private static final URI DURI = URI.create(NAME1);
44 private static final String MFR = "whitebox";
45 private static final String HW = "1.1.x";
46 private static final String SW = "3.9.1";
47 private static final String SN = "43311-12345";
48 private static final ChassisId CID = new ChassisId();
Andrea Campanellab75b4882016-01-15 15:15:09 -080049 private static final String DRIVER = "fooDriver";
50 private static final String MANUFACTURER = "fooManufacturer";
51 private static final String HW_VERSION = "0.0";
52 private static final String SW_VERSION = "0.0";
53 private static final String SERIAL = "1234";
54 private static final String MANAGEMENT_ADDRESS = "12.34.56.78:99";
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070055
56 private static final SparseAnnotations SA = DefaultAnnotations.builder()
57 .set(AnnotationKeys.DRIVER, NAME2).build();
58
59 private static final DeviceDescription DEV1 = new DefaultDeviceDescription(
60 DURI, SWITCH, MFR, HW, SW, SN, CID, SA);
61
Sho SHIMIZU74626412015-09-11 11:46:27 -070062 private final ConfigApplyDelegate delegate = config -> { };
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070063 private final ObjectMapper mapper = new ObjectMapper();
64
65 private static final BasicDeviceConfig SW_BDC = new BasicDeviceConfig();
66 private static final BasicDeviceConfig RD_BDC = new BasicDeviceConfig();
67
68 @Before
69 public void setUp() {
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);
Andrea Campanellab75b4882016-01-15 15:15:09 -080073 RD_BDC.type(ROADM).manufacturer(MANUFACTURER).hwVersion(HW_VERSION)
74 .swVersion(SW_VERSION).serial(SERIAL).managementAddress(MANAGEMENT_ADDRESS).driver(DRIVER).owner(OWNER);
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070075 }
76
77 @Test
78 public void testDescOps() {
79 DeviceDescription desc = BasicDeviceOperator.combine(null, DEV1);
80 assertEquals(desc, DEV1);
81
82 // override driver name
83 desc = BasicDeviceOperator.combine(SW_BDC, DEV1);
84 assertEquals(NAME1, desc.annotations().value(AnnotationKeys.DRIVER));
85
Andrea Campanellab75b4882016-01-15 15:15:09 -080086 // override Device Information
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070087 desc = BasicDeviceOperator.combine(RD_BDC, DEV1);
Andrea Campanellab75b4882016-01-15 15:15:09 -080088 assertEquals("Wrong type", ROADM, desc.type());
89 assertEquals("Wrong manufacturer", MANUFACTURER, desc.manufacturer());
90 assertEquals("Wrong HwVersion", HW_VERSION, desc.hwVersion());
91 assertEquals("Wrong swVersion", SW_VERSION, desc.swVersion());
92 assertEquals("Wrong serial", SERIAL, desc.serialNumber());
93 assertEquals("Wrong management Address", MANAGEMENT_ADDRESS,
94 desc.annotations().value(AnnotationKeys.MANAGEMENT_ADDRESS));
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070095 }
96}