tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net; |
| 2 | |
| 3 | import com.google.common.testing.EqualsTester; |
| 4 | import org.junit.Test; |
| 5 | import org.onlab.onos.net.provider.ProviderId; |
| 6 | |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 7 | import static org.junit.Assert.assertEquals; |
| 8 | import static org.onlab.onos.net.Device.Type.SWITCH; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 9 | import static org.onlab.onos.net.DeviceId.deviceId; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 10 | |
| 11 | /** |
| 12 | * Test of the default device model entity. |
| 13 | */ |
| 14 | public class DefaultDeviceTest { |
| 15 | |
tom | 747a213 | 2014-10-02 08:18:41 -0700 | [diff] [blame] | 16 | static final ProviderId PID = new ProviderId("of", "foo"); |
| 17 | static final DeviceId DID1 = deviceId("of:foo"); |
| 18 | static final DeviceId DID2 = deviceId("of:bar"); |
| 19 | static final String MFR = "whitebox"; |
| 20 | static final String HW = "1.1.x"; |
| 21 | static final String SW = "3.9.1"; |
| 22 | static final String SN1 = "43311-12345"; |
| 23 | static final String SN2 = "42346-43512"; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 24 | |
| 25 | @Test |
| 26 | public void testEquality() { |
| 27 | Device d1 = new DefaultDevice(PID, DID1, SWITCH, MFR, HW, SW, SN1); |
| 28 | Device d2 = new DefaultDevice(PID, DID1, SWITCH, MFR, HW, SW, SN1); |
| 29 | Device d3 = new DefaultDevice(PID, DID2, SWITCH, MFR, HW, SW, SN2); |
| 30 | Device d4 = new DefaultDevice(PID, DID2, SWITCH, MFR, HW, SW, SN2); |
| 31 | Device d5 = new DefaultDevice(PID, DID2, SWITCH, MFR, HW, SW, SN1); |
| 32 | |
| 33 | new EqualsTester().addEqualityGroup(d1, d2) |
| 34 | .addEqualityGroup(d3, d4) |
| 35 | .addEqualityGroup(d5) |
| 36 | .testEquals(); |
| 37 | } |
| 38 | |
| 39 | @Test |
| 40 | public void basics() { |
| 41 | Device device = new DefaultDevice(PID, DID1, SWITCH, MFR, HW, SW, SN1); |
tom | 5a9383a | 2014-10-02 07:33:52 -0700 | [diff] [blame] | 42 | validate(device); |
| 43 | } |
| 44 | |
| 45 | @Test |
| 46 | public void annotations() { |
| 47 | Device device = new DefaultDevice(PID, DID1, SWITCH, MFR, HW, SW, SN1, |
| 48 | DefaultAnnotations.builder().set("foo", "bar").build()); |
| 49 | validate(device); |
| 50 | assertEquals("incorrect provider", "bar", device.annotations().value("foo")); |
| 51 | } |
| 52 | |
| 53 | private void validate(Device device) { |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 54 | assertEquals("incorrect provider", PID, device.providerId()); |
| 55 | assertEquals("incorrect id", DID1, device.id()); |
| 56 | assertEquals("incorrect type", SWITCH, device.type()); |
| 57 | assertEquals("incorrect manufacturer", MFR, device.manufacturer()); |
| 58 | assertEquals("incorrect hw", HW, device.hwVersion()); |
| 59 | assertEquals("incorrect sw", SW, device.swVersion()); |
| 60 | assertEquals("incorrect serial", SN1, device.serialNumber()); |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 61 | } |
Yuta HIGUCHI | 885be1d | 2014-10-04 21:47:26 -0700 | [diff] [blame^] | 62 | } |