blob: 3d3d3d35e7cee924486db5db7c7a8c9d53963fb8 [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 */
tom568581d2014-09-08 20:13:36 -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;
tom568581d2014-09-08 20:13:36 -070022
23import static org.junit.Assert.assertEquals;
24import static org.onlab.onos.net.Device.Type.SWITCH;
25import static org.onlab.onos.net.DeviceId.deviceId;
26import static org.onlab.onos.net.PortNumber.portNumber;
27
28/**
29 * Test of the default port model entity.
30 */
31public class DefaultPortTest {
32
tom7e02cda2014-09-18 12:05:46 -070033 private static final ProviderId PID = new ProviderId("of", "foo");
tom568581d2014-09-08 20:13:36 -070034 private static final DeviceId DID1 = deviceId("of:foo");
35 private static final DeviceId DID2 = deviceId("of:bar");
36 private static final PortNumber P1 = portNumber(1);
37 private static final PortNumber P2 = portNumber(2);
38
39 @Test
40 public void testEquality() {
alshabib7911a052014-10-16 17:49:37 -070041 Device device = new DefaultDevice(PID, DID1, SWITCH, "m", "h", "s", "n",
42 new ChassisId());
tom568581d2014-09-08 20:13:36 -070043 Port p1 = new DefaultPort(device, portNumber(1), true);
44 Port p2 = new DefaultPort(device, portNumber(1), true);
45 Port p3 = new DefaultPort(device, portNumber(2), true);
46 Port p4 = new DefaultPort(device, portNumber(2), true);
47 Port p5 = new DefaultPort(device, portNumber(1), false);
48
49 new EqualsTester().addEqualityGroup(p1, p2)
50 .addEqualityGroup(p3, p4)
51 .addEqualityGroup(p5)
52 .testEquals();
53 }
54
55 @Test
56 public void basics() {
alshabib7911a052014-10-16 17:49:37 -070057 Device device = new DefaultDevice(PID, DID1, SWITCH, "m", "h", "s", "n",
58 new ChassisId());
tom568581d2014-09-08 20:13:36 -070059 Port port = new DefaultPort(device, portNumber(1), true);
60 assertEquals("incorrect element", device, port.element());
61 assertEquals("incorrect number", portNumber(1), port.number());
62 assertEquals("incorrect state", true, port.isEnabled());
63 }
64
65}