blob: ebc3107aded2b0d570a7a0336ab443d1bfa25967 [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;
Thomas Vachuskad16ce182014-10-29 17:25:29 -070026import static org.onlab.onos.net.Port.Type.COPPER;
27import static org.onlab.onos.net.Port.Type.FIBER;
tom568581d2014-09-08 20:13:36 -070028import static org.onlab.onos.net.PortNumber.portNumber;
29
30/**
31 * Test of the default port model entity.
32 */
33public class DefaultPortTest {
34
tom7e02cda2014-09-18 12:05:46 -070035 private static final ProviderId PID = new ProviderId("of", "foo");
tom568581d2014-09-08 20:13:36 -070036 private static final DeviceId DID1 = deviceId("of:foo");
37 private static final DeviceId DID2 = deviceId("of:bar");
38 private static final PortNumber P1 = portNumber(1);
39 private static final PortNumber P2 = portNumber(2);
Thomas Vachuskad16ce182014-10-29 17:25:29 -070040 private static final long SP1 = 1_000_000;
tom568581d2014-09-08 20:13:36 -070041
42 @Test
43 public void testEquality() {
alshabib7911a052014-10-16 17:49:37 -070044 Device device = new DefaultDevice(PID, DID1, SWITCH, "m", "h", "s", "n",
45 new ChassisId());
Thomas Vachuskad16ce182014-10-29 17:25:29 -070046 Port p1 = new DefaultPort(device, portNumber(1), true, COPPER, SP1);
47 Port p2 = new DefaultPort(device, portNumber(1), true, COPPER, SP1);
48 Port p3 = new DefaultPort(device, portNumber(2), true, FIBER, SP1);
49 Port p4 = new DefaultPort(device, portNumber(2), true, FIBER, SP1);
tom568581d2014-09-08 20:13:36 -070050 Port p5 = new DefaultPort(device, portNumber(1), false);
51
52 new EqualsTester().addEqualityGroup(p1, p2)
53 .addEqualityGroup(p3, p4)
54 .addEqualityGroup(p5)
55 .testEquals();
56 }
57
58 @Test
59 public void basics() {
alshabib7911a052014-10-16 17:49:37 -070060 Device device = new DefaultDevice(PID, DID1, SWITCH, "m", "h", "s", "n",
61 new ChassisId());
Thomas Vachuskad16ce182014-10-29 17:25:29 -070062 Port port = new DefaultPort(device, portNumber(1), true, FIBER, SP1);
tom568581d2014-09-08 20:13:36 -070063 assertEquals("incorrect element", device, port.element());
64 assertEquals("incorrect number", portNumber(1), port.number());
65 assertEquals("incorrect state", true, port.isEnabled());
Thomas Vachuskad16ce182014-10-29 17:25:29 -070066 assertEquals("incorrect speed", SP1, port.portSpeed());
67 assertEquals("incorrect type", FIBER, port.type());
tom568581d2014-09-08 20:13:36 -070068 }
69
70}