blob: 109b2fa3d86a49d1aaf56ae9539a16bd46c2956d [file] [log] [blame]
Andrea Campanellab75b4882016-01-15 15:15:09 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Andrea Campanellab75b4882016-01-15 15:15:09 -08003 *
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
17package org.onosproject.net.config.basics;
18
19import com.fasterxml.jackson.databind.ObjectMapper;
20import com.fasterxml.jackson.databind.node.JsonNodeFactory;
21import org.junit.Before;
22import org.junit.Test;
Claudine Chiu5951bda2016-02-19 04:04:52 +000023import org.onosproject.net.key.DeviceKeyId;
Andrea Campanellab75b4882016-01-15 15:15:09 -080024import org.onosproject.net.DeviceId;
25import org.onosproject.net.config.ConfigApplyDelegate;
26
27import static org.junit.Assert.assertEquals;
28import static org.junit.Assert.assertTrue;
29import static org.onosproject.net.Device.Type.OTN;
30import static org.onosproject.net.Device.Type.SWITCH;
31
32/**
33 * Test class for BasicDeviceConfig.
34 */
35public class BasicDeviceConfigTest {
36
37 private static final String DRIVER = "fooDriver";
38 private static final String MANUFACTURER = "fooManufacturer";
39 private static final String HW_VERSION = "0.0";
40 private static final String SW_VERSION = "0.0";
41 private static final String SERIAL = "1234";
42 private static final String MANAGEMENT_ADDRESS = "12.34.56.78:99";
Claudine Chiu5951bda2016-02-19 04:04:52 +000043 private static final DeviceKeyId DEVICE_KEY_ID = DeviceKeyId.deviceKeyId("fooDeviceKeyId");
Andrea Campanellab75b4882016-01-15 15:15:09 -080044 private static final String DRIVER_NEW = "barDriver";
45 private static final String MANUFACTURER_NEW = "barManufacturer";
46 private static final String HW_VERSION_NEW = "1.1";
47 private static final String SW_VERSION_NEW = "1.1";
48 private static final String SERIAL_NEW = "5678";
49 private static final String MANAGEMENT_ADDRESS_NEW = "99.87.65.43:12";
Claudine Chiu5951bda2016-02-19 04:04:52 +000050 private static final DeviceKeyId DEVICE_KEY_ID_NEW = DeviceKeyId.deviceKeyId("barDeviceKeyId");
Andrea Campanellab75b4882016-01-15 15:15:09 -080051
52 private static final String NAME1 = "fooProtocol:fooIP:fooPort";
53
54 private final ConfigApplyDelegate delegate = config -> {
55 };
56 private final ObjectMapper mapper = new ObjectMapper();
57
58 private static final BasicDeviceConfig SW_BDC = new BasicDeviceConfig();
59
60 @Before
61 public void setUp() {
62 SW_BDC.init(DeviceId.deviceId(NAME1), NAME1, JsonNodeFactory.instance.objectNode(), mapper, delegate);
63 SW_BDC.type(SWITCH).manufacturer(MANUFACTURER).hwVersion(HW_VERSION)
Claudine Chiu5951bda2016-02-19 04:04:52 +000064 .swVersion(SW_VERSION).serial(SERIAL).managementAddress(MANAGEMENT_ADDRESS).driver(DRIVER)
65 .deviceKeyId(DEVICE_KEY_ID);
Andrea Campanellab75b4882016-01-15 15:15:09 -080066 }
67
68 @Test
69 public void testCorrectConfiguration() {
70 assertTrue("Configuration contains not valid fields", SW_BDC.isValid());
71 assertEquals("Incorrect type", SWITCH, SW_BDC.type());
72 assertEquals("Incorrect driver", DRIVER, SW_BDC.driver());
73 assertEquals("Incorrect manufacturer", MANUFACTURER, SW_BDC.manufacturer());
74 assertEquals("Incorrect HwVersion", HW_VERSION, SW_BDC.hwVersion());
75 assertEquals("Incorrect swVersion", SW_VERSION, SW_BDC.swVersion());
76 assertEquals("Incorrect serial", SERIAL, SW_BDC.serial());
77 assertEquals("Incorrect management Address", MANAGEMENT_ADDRESS, SW_BDC.managementAddress());
Claudine Chiu5951bda2016-02-19 04:04:52 +000078 assertEquals("Incorrect deviceKeyId", DEVICE_KEY_ID, SW_BDC.deviceKeyId());
Andrea Campanellab75b4882016-01-15 15:15:09 -080079 }
80
81
82 @Test
83 public void testSetType() {
84 SW_BDC.type(OTN);
85 assertEquals("Incorrect type", OTN, SW_BDC.type());
86 }
87
88
89 @Test
90 public void testSetDriver() {
91 SW_BDC.driver(DRIVER_NEW);
92 assertEquals("Incorrect driver", DRIVER_NEW, SW_BDC.driver());
93 }
94
95
96 @Test
97 public void testSetManufacturer() {
98 SW_BDC.manufacturer(MANUFACTURER_NEW);
99 assertEquals("Incorrect manufacturer", MANUFACTURER_NEW, SW_BDC.manufacturer());
100 }
101
102
103 @Test
104 public void testSetHwVersion() {
105 SW_BDC.hwVersion(HW_VERSION_NEW);
106 assertEquals("Incorrect HwVersion", HW_VERSION_NEW, SW_BDC.hwVersion());
107 }
108
109
110 @Test
111 public void testSetSwVersion() {
112 SW_BDC.swVersion(SW_VERSION_NEW);
113 assertEquals("Incorrect swVersion", SW_VERSION_NEW, SW_BDC.swVersion());
114 }
115
116 @Test
117 public void testSetSerial() {
118 SW_BDC.serial(SERIAL_NEW);
119 assertEquals("Incorrect serial", SERIAL_NEW, SW_BDC.serial());
120 }
121
122 @Test
123 public void testSetManagementAddress() {
124 SW_BDC.managementAddress(MANAGEMENT_ADDRESS_NEW);
125 assertEquals("Incorrect managementAddress", MANAGEMENT_ADDRESS_NEW, SW_BDC.managementAddress());
126 }
Claudine Chiu5951bda2016-02-19 04:04:52 +0000127
128 @Test
129 public void testSetDeviceKeyId() {
130 // change device key id
131 SW_BDC.deviceKeyId(DEVICE_KEY_ID_NEW);
132 assertEquals("Incorrect deviceKeyId", DEVICE_KEY_ID_NEW, SW_BDC.deviceKeyId());
133 // clear device key id
134 SW_BDC.deviceKeyId(null);
135 assertEquals("Incorrect deviceKeyId", null, SW_BDC.deviceKeyId());
136 }
Andrea Campanellab75b4882016-01-15 15:15:09 -0800137}