Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
| 17 | package org.onosproject.net.config.basics; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 25 | |
| 26 | import static org.junit.Assert.assertEquals; |
| 27 | import static org.junit.Assert.assertTrue; |
| 28 | import static org.onosproject.net.Device.Type.OTN; |
| 29 | import static org.onosproject.net.Device.Type.SWITCH; |
| 30 | |
| 31 | /** |
| 32 | * Test class for BasicDeviceConfig. |
| 33 | */ |
| 34 | public class BasicDeviceConfigTest { |
| 35 | |
| 36 | private static final String DRIVER = "fooDriver"; |
| 37 | private static final String MANUFACTURER = "fooManufacturer"; |
| 38 | private static final String HW_VERSION = "0.0"; |
| 39 | private static final String SW_VERSION = "0.0"; |
| 40 | private static final String SERIAL = "1234"; |
| 41 | private static final String MANAGEMENT_ADDRESS = "12.34.56.78:99"; |
| 42 | private static final String DRIVER_NEW = "barDriver"; |
| 43 | private static final String MANUFACTURER_NEW = "barManufacturer"; |
| 44 | private static final String HW_VERSION_NEW = "1.1"; |
| 45 | private static final String SW_VERSION_NEW = "1.1"; |
| 46 | private static final String SERIAL_NEW = "5678"; |
| 47 | private static final String MANAGEMENT_ADDRESS_NEW = "99.87.65.43:12"; |
| 48 | |
| 49 | private static final String NAME1 = "fooProtocol:fooIP:fooPort"; |
| 50 | |
| 51 | private final ConfigApplyDelegate delegate = config -> { |
| 52 | }; |
| 53 | private final ObjectMapper mapper = new ObjectMapper(); |
| 54 | |
| 55 | private static final BasicDeviceConfig SW_BDC = new BasicDeviceConfig(); |
| 56 | |
| 57 | @Before |
| 58 | public void setUp() { |
| 59 | SW_BDC.init(DeviceId.deviceId(NAME1), NAME1, JsonNodeFactory.instance.objectNode(), mapper, delegate); |
| 60 | SW_BDC.type(SWITCH).manufacturer(MANUFACTURER).hwVersion(HW_VERSION) |
| 61 | .swVersion(SW_VERSION).serial(SERIAL).managementAddress(MANAGEMENT_ADDRESS).driver(DRIVER); |
| 62 | } |
| 63 | |
| 64 | @Test |
| 65 | public void testCorrectConfiguration() { |
| 66 | assertTrue("Configuration contains not valid fields", SW_BDC.isValid()); |
| 67 | assertEquals("Incorrect type", SWITCH, SW_BDC.type()); |
| 68 | assertEquals("Incorrect driver", DRIVER, SW_BDC.driver()); |
| 69 | assertEquals("Incorrect manufacturer", MANUFACTURER, SW_BDC.manufacturer()); |
| 70 | assertEquals("Incorrect HwVersion", HW_VERSION, SW_BDC.hwVersion()); |
| 71 | assertEquals("Incorrect swVersion", SW_VERSION, SW_BDC.swVersion()); |
| 72 | assertEquals("Incorrect serial", SERIAL, SW_BDC.serial()); |
| 73 | assertEquals("Incorrect management Address", MANAGEMENT_ADDRESS, SW_BDC.managementAddress()); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | @Test |
| 78 | public void testSetType() { |
| 79 | SW_BDC.type(OTN); |
| 80 | assertEquals("Incorrect type", OTN, SW_BDC.type()); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | @Test |
| 85 | public void testSetDriver() { |
| 86 | SW_BDC.driver(DRIVER_NEW); |
| 87 | assertEquals("Incorrect driver", DRIVER_NEW, SW_BDC.driver()); |
| 88 | } |
| 89 | |
| 90 | |
| 91 | @Test |
| 92 | public void testSetManufacturer() { |
| 93 | SW_BDC.manufacturer(MANUFACTURER_NEW); |
| 94 | assertEquals("Incorrect manufacturer", MANUFACTURER_NEW, SW_BDC.manufacturer()); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | @Test |
| 99 | public void testSetHwVersion() { |
| 100 | SW_BDC.hwVersion(HW_VERSION_NEW); |
| 101 | assertEquals("Incorrect HwVersion", HW_VERSION_NEW, SW_BDC.hwVersion()); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | @Test |
| 106 | public void testSetSwVersion() { |
| 107 | SW_BDC.swVersion(SW_VERSION_NEW); |
| 108 | assertEquals("Incorrect swVersion", SW_VERSION_NEW, SW_BDC.swVersion()); |
| 109 | } |
| 110 | |
| 111 | @Test |
| 112 | public void testSetSerial() { |
| 113 | SW_BDC.serial(SERIAL_NEW); |
| 114 | assertEquals("Incorrect serial", SERIAL_NEW, SW_BDC.serial()); |
| 115 | } |
| 116 | |
| 117 | @Test |
| 118 | public void testSetManagementAddress() { |
| 119 | SW_BDC.managementAddress(MANAGEMENT_ADDRESS_NEW); |
| 120 | assertEquals("Incorrect managementAddress", MANAGEMENT_ADDRESS_NEW, SW_BDC.managementAddress()); |
| 121 | } |
| 122 | } |