Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.net.provider.ProviderId; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 21 | import org.onlab.packet.ChassisId; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 22 | |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 23 | import static org.junit.Assert.assertEquals; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 24 | import static org.onosproject.net.Device.Type.SWITCH; |
| 25 | import static org.onosproject.net.DeviceId.deviceId; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Test of the default device model entity. |
| 29 | */ |
| 30 | public class DefaultDeviceTest { |
| 31 | |
tom | 747a213 | 2014-10-02 08:18:41 -0700 | [diff] [blame] | 32 | static final ProviderId PID = new ProviderId("of", "foo"); |
| 33 | static final DeviceId DID1 = deviceId("of:foo"); |
| 34 | static final DeviceId DID2 = deviceId("of:bar"); |
| 35 | static final String MFR = "whitebox"; |
| 36 | static final String HW = "1.1.x"; |
| 37 | static final String SW = "3.9.1"; |
| 38 | static final String SN1 = "43311-12345"; |
| 39 | static final String SN2 = "42346-43512"; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 40 | static final ChassisId CID = new ChassisId(); |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 41 | |
| 42 | @Test |
| 43 | public void testEquality() { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 44 | Device d1 = new DefaultDevice(PID, DID1, SWITCH, MFR, HW, SW, SN1, CID); |
| 45 | Device d2 = new DefaultDevice(PID, DID1, SWITCH, MFR, HW, SW, SN1, CID); |
| 46 | Device d3 = new DefaultDevice(PID, DID2, SWITCH, MFR, HW, SW, SN2, CID); |
| 47 | Device d4 = new DefaultDevice(PID, DID2, SWITCH, MFR, HW, SW, SN2, CID); |
| 48 | Device d5 = new DefaultDevice(PID, DID2, SWITCH, MFR, HW, SW, SN1, CID); |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 49 | |
| 50 | new EqualsTester().addEqualityGroup(d1, d2) |
| 51 | .addEqualityGroup(d3, d4) |
| 52 | .addEqualityGroup(d5) |
| 53 | .testEquals(); |
| 54 | } |
| 55 | |
| 56 | @Test |
| 57 | public void basics() { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 58 | Device device = new DefaultDevice(PID, DID1, SWITCH, MFR, HW, SW, SN1, CID); |
tom | 5a9383a | 2014-10-02 07:33:52 -0700 | [diff] [blame] | 59 | validate(device); |
| 60 | } |
| 61 | |
| 62 | @Test |
| 63 | public void annotations() { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 64 | Device device = new DefaultDevice(PID, DID1, SWITCH, MFR, HW, SW, SN1, CID, |
tom | 5a9383a | 2014-10-02 07:33:52 -0700 | [diff] [blame] | 65 | DefaultAnnotations.builder().set("foo", "bar").build()); |
| 66 | validate(device); |
| 67 | assertEquals("incorrect provider", "bar", device.annotations().value("foo")); |
| 68 | } |
| 69 | |
| 70 | private void validate(Device device) { |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 71 | assertEquals("incorrect provider", PID, device.providerId()); |
| 72 | assertEquals("incorrect id", DID1, device.id()); |
| 73 | assertEquals("incorrect type", SWITCH, device.type()); |
| 74 | assertEquals("incorrect manufacturer", MFR, device.manufacturer()); |
| 75 | assertEquals("incorrect hw", HW, device.hwVersion()); |
| 76 | assertEquals("incorrect sw", SW, device.swVersion()); |
| 77 | assertEquals("incorrect serial", SN1, device.serialNumber()); |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 78 | } |
Yuta HIGUCHI | 885be1d | 2014-10-04 21:47:26 -0700 | [diff] [blame] | 79 | } |