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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net; |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.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; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 24 | import static org.onosproject.net.Device.Type.SWITCH; |
| 25 | import static org.onosproject.net.DeviceId.deviceId; |
| 26 | import static org.onosproject.net.Port.Type.COPPER; |
| 27 | import static org.onosproject.net.Port.Type.FIBER; |
| 28 | import static org.onosproject.net.PortNumber.portNumber; |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Test of the default port model entity. |
| 32 | */ |
| 33 | public class DefaultPortTest { |
| 34 | |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 35 | private static final ProviderId PID = new ProviderId("of", "foo"); |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 36 | 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 Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 40 | private static final long SP1 = 1_000_000; |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 41 | |
| 42 | @Test |
| 43 | public void testEquality() { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 44 | Device device = new DefaultDevice(PID, DID1, SWITCH, "m", "h", "s", "n", |
| 45 | new ChassisId()); |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 46 | 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); |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 50 | 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() { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 60 | Device device = new DefaultDevice(PID, DID1, SWITCH, "m", "h", "s", "n", |
| 61 | new ChassisId()); |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 62 | Port port = new DefaultPort(device, portNumber(1), true, FIBER, SP1); |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 63 | assertEquals("incorrect element", device, port.element()); |
| 64 | assertEquals("incorrect number", portNumber(1), port.number()); |
| 65 | assertEquals("incorrect state", true, port.isEnabled()); |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 66 | assertEquals("incorrect speed", SP1, port.portSpeed()); |
| 67 | assertEquals("incorrect type", FIBER, port.type()); |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | } |