blob: 63f1daad75581c0b3eb32dd6963ead6d3473bdb3 [file] [log] [blame]
tom3065d122014-09-03 21:56:43 -07001package org.onlab.onos.net;
2
3import com.google.common.testing.EqualsTester;
4import org.junit.Test;
5import org.onlab.onos.net.provider.ProviderId;
alshabib7911a052014-10-16 17:49:37 -07006import org.onlab.packet.ChassisId;
tom3065d122014-09-03 21:56:43 -07007
tom3065d122014-09-03 21:56:43 -07008import static org.junit.Assert.assertEquals;
9import static org.onlab.onos.net.Device.Type.SWITCH;
tomca20e0c2014-09-03 23:22:24 -070010import static org.onlab.onos.net.DeviceId.deviceId;
tom3065d122014-09-03 21:56:43 -070011
12/**
13 * Test of the default device model entity.
14 */
15public class DefaultDeviceTest {
16
tom747a2132014-10-02 08:18:41 -070017 static final ProviderId PID = new ProviderId("of", "foo");
18 static final DeviceId DID1 = deviceId("of:foo");
19 static final DeviceId DID2 = deviceId("of:bar");
20 static final String MFR = "whitebox";
21 static final String HW = "1.1.x";
22 static final String SW = "3.9.1";
23 static final String SN1 = "43311-12345";
24 static final String SN2 = "42346-43512";
alshabib7911a052014-10-16 17:49:37 -070025 static final ChassisId CID = new ChassisId();
tom3065d122014-09-03 21:56:43 -070026
27 @Test
28 public void testEquality() {
alshabib7911a052014-10-16 17:49:37 -070029 Device d1 = new DefaultDevice(PID, DID1, SWITCH, MFR, HW, SW, SN1, CID);
30 Device d2 = new DefaultDevice(PID, DID1, SWITCH, MFR, HW, SW, SN1, CID);
31 Device d3 = new DefaultDevice(PID, DID2, SWITCH, MFR, HW, SW, SN2, CID);
32 Device d4 = new DefaultDevice(PID, DID2, SWITCH, MFR, HW, SW, SN2, CID);
33 Device d5 = new DefaultDevice(PID, DID2, SWITCH, MFR, HW, SW, SN1, CID);
tom3065d122014-09-03 21:56:43 -070034
35 new EqualsTester().addEqualityGroup(d1, d2)
36 .addEqualityGroup(d3, d4)
37 .addEqualityGroup(d5)
38 .testEquals();
39 }
40
41 @Test
42 public void basics() {
alshabib7911a052014-10-16 17:49:37 -070043 Device device = new DefaultDevice(PID, DID1, SWITCH, MFR, HW, SW, SN1, CID);
tom5a9383a2014-10-02 07:33:52 -070044 validate(device);
45 }
46
47 @Test
48 public void annotations() {
alshabib7911a052014-10-16 17:49:37 -070049 Device device = new DefaultDevice(PID, DID1, SWITCH, MFR, HW, SW, SN1, CID,
tom5a9383a2014-10-02 07:33:52 -070050 DefaultAnnotations.builder().set("foo", "bar").build());
51 validate(device);
52 assertEquals("incorrect provider", "bar", device.annotations().value("foo"));
53 }
54
55 private void validate(Device device) {
tom3065d122014-09-03 21:56:43 -070056 assertEquals("incorrect provider", PID, device.providerId());
57 assertEquals("incorrect id", DID1, device.id());
58 assertEquals("incorrect type", SWITCH, device.type());
59 assertEquals("incorrect manufacturer", MFR, device.manufacturer());
60 assertEquals("incorrect hw", HW, device.hwVersion());
61 assertEquals("incorrect sw", SW, device.swVersion());
62 assertEquals("incorrect serial", SN1, device.serialNumber());
tom3065d122014-09-03 21:56:43 -070063 }
Yuta HIGUCHI885be1d2014-10-04 21:47:26 -070064}