Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Test; |
| 20 | import org.onlab.onos.net.provider.ProviderId; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 21 | import org.onlab.packet.ChassisId; |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 22 | |
| 23 | import static org.junit.Assert.assertEquals; |
| 24 | import static org.onlab.onos.net.Device.Type.SWITCH; |
| 25 | import static org.onlab.onos.net.DeviceId.deviceId; |
| 26 | import static org.onlab.onos.net.PortNumber.portNumber; |
| 27 | |
| 28 | /** |
| 29 | * Test of the default port model entity. |
| 30 | */ |
| 31 | public class DefaultPortTest { |
| 32 | |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 33 | private static final ProviderId PID = new ProviderId("of", "foo"); |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 34 | 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() { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 41 | Device device = new DefaultDevice(PID, DID1, SWITCH, "m", "h", "s", "n", |
| 42 | new ChassisId()); |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 43 | 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() { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 57 | Device device = new DefaultDevice(PID, DID1, SWITCH, "m", "h", "s", "n", |
| 58 | new ChassisId()); |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 59 | 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 | } |