blob: 6d8b2755911babfce6729cc1e84a029cbd7fe943 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 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 */
tom3065d122014-09-03 21:56:43 -070016package org.onlab.onos.net;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Test;
20import org.onlab.onos.net.provider.ProviderId;
alshabib7911a052014-10-16 17:49:37 -070021import org.onlab.packet.ChassisId;
tom3065d122014-09-03 21:56:43 -070022
tom3065d122014-09-03 21:56:43 -070023import static org.junit.Assert.assertEquals;
24import static org.onlab.onos.net.Device.Type.SWITCH;
tomca20e0c2014-09-03 23:22:24 -070025import static org.onlab.onos.net.DeviceId.deviceId;
tom3065d122014-09-03 21:56:43 -070026
27/**
28 * Test of the default device model entity.
29 */
30public class DefaultDeviceTest {
31
tom747a2132014-10-02 08:18:41 -070032 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";
alshabib7911a052014-10-16 17:49:37 -070040 static final ChassisId CID = new ChassisId();
tom3065d122014-09-03 21:56:43 -070041
42 @Test
43 public void testEquality() {
alshabib7911a052014-10-16 17:49:37 -070044 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);
tom3065d122014-09-03 21:56:43 -070049
50 new EqualsTester().addEqualityGroup(d1, d2)
51 .addEqualityGroup(d3, d4)
52 .addEqualityGroup(d5)
53 .testEquals();
54 }
55
56 @Test
57 public void basics() {
alshabib7911a052014-10-16 17:49:37 -070058 Device device = new DefaultDevice(PID, DID1, SWITCH, MFR, HW, SW, SN1, CID);
tom5a9383a2014-10-02 07:33:52 -070059 validate(device);
60 }
61
62 @Test
63 public void annotations() {
alshabib7911a052014-10-16 17:49:37 -070064 Device device = new DefaultDevice(PID, DID1, SWITCH, MFR, HW, SW, SN1, CID,
tom5a9383a2014-10-02 07:33:52 -070065 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) {
tom3065d122014-09-03 21:56:43 -070071 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());
tom3065d122014-09-03 21:56:43 -070078 }
Yuta HIGUCHI885be1d2014-10-04 21:47:26 -070079}