Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | c0ccfb2 | 2014-09-08 00:41:32 -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; |
tom | c0ccfb2 | 2014-09-08 00:41:32 -0700 | [diff] [blame] | 21 | |
| 22 | import static org.junit.Assert.assertEquals; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import static org.onosproject.net.DeviceId.deviceId; |
| 24 | import static org.onosproject.net.Link.Type.DIRECT; |
| 25 | import static org.onosproject.net.Link.Type.INDIRECT; |
| 26 | import static org.onosproject.net.PortNumber.portNumber; |
tom | c0ccfb2 | 2014-09-08 00:41:32 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Test of the default link model entity. |
| 30 | */ |
| 31 | public class DefaultLinkTest { |
| 32 | |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 33 | private static final ProviderId PID = new ProviderId("of", "foo"); |
tom | c0ccfb2 | 2014-09-08 00:41:32 -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 | |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 39 | public static ConnectPoint cp(ElementId id, PortNumber pn) { |
tom | c0ccfb2 | 2014-09-08 00:41:32 -0700 | [diff] [blame] | 40 | return new ConnectPoint(id, pn); |
| 41 | } |
| 42 | |
| 43 | @Test |
| 44 | public void testEquality() { |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 45 | Link l1 = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT, Link.State.ACTIVE); |
| 46 | Link l2 = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT, Link.State.ACTIVE); |
| 47 | Link l3 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), DIRECT, Link.State.ACTIVE); |
| 48 | Link l4 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), DIRECT, Link.State.ACTIVE); |
| 49 | Link l5 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), INDIRECT, Link.State.ACTIVE); |
tom | c0ccfb2 | 2014-09-08 00:41:32 -0700 | [diff] [blame] | 50 | |
| 51 | new EqualsTester().addEqualityGroup(l1, l2) |
| 52 | .addEqualityGroup(l3, l4) |
| 53 | .addEqualityGroup(l5) |
| 54 | .testEquals(); |
| 55 | } |
| 56 | |
| 57 | @Test |
| 58 | public void basics() { |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 59 | Link link = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT, Link.State.ACTIVE); |
tom | c0ccfb2 | 2014-09-08 00:41:32 -0700 | [diff] [blame] | 60 | assertEquals("incorrect src", cp(DID1, P1), link.src()); |
| 61 | assertEquals("incorrect dst", cp(DID2, P2), link.dst()); |
| 62 | assertEquals("incorrect type", DIRECT, link.type()); |
| 63 | } |
| 64 | |
| 65 | } |