blob: 2be0df7a992d32103c0bef51ba7f34da18f77083 [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
18import static org.onosproject.net.Device.Type.SWITCH;
19import static org.onosproject.net.Device.Type.ROADM;
20import static org.junit.Assert.assertEquals;
21
22import java.net.URI;
23
24import org.junit.Before;
25import org.junit.Test;
26import org.onlab.packet.ChassisId;
Ray Milkeya4122362015-08-18 15:19:08 -070027import org.onosproject.net.config.ConfigApplyDelegate;
Thomas Vachuska4998caa2015-08-26 13:28:38 -070028import org.onosproject.net.config.basics.BasicDeviceConfig;
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070029import org.onosproject.net.AnnotationKeys;
30import org.onosproject.net.DefaultAnnotations;
31import org.onosproject.net.DeviceId;
32import org.onosproject.net.SparseAnnotations;
33import org.onosproject.net.device.DefaultDeviceDescription;
34import org.onosproject.net.device.DeviceDescription;
35
36import com.fasterxml.jackson.databind.ObjectMapper;
37import com.fasterxml.jackson.databind.node.JsonNodeFactory;
38
39public 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 SHIMIZU74626412015-09-11 11:46:27 -070057 private final ConfigApplyDelegate delegate = config -> { };
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070058 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}