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.link; |
tom | c0ccfb2 | 2014-09-08 00:41:32 -0700 | [diff] [blame] | 17 | |
| 18 | import org.junit.Test; |
Ray Milkey | cd6ab18 | 2016-02-03 11:13:09 -0800 | [diff] [blame] | 19 | import org.onosproject.net.ConnectPoint; |
Pavel Likin | 9d49f54 | 2015-12-13 15:04:55 +0300 | [diff] [blame] | 20 | import org.onosproject.net.DefaultAnnotations; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.net.DeviceId; |
Ray Milkey | cd6ab18 | 2016-02-03 11:13:09 -0800 | [diff] [blame] | 22 | import org.onosproject.net.Link; |
| 23 | import org.onosproject.net.NetTestTools; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 24 | import org.onosproject.net.PortNumber; |
tom | c0ccfb2 | 2014-09-08 00:41:32 -0700 | [diff] [blame] | 25 | |
Ray Milkey | cd6ab18 | 2016-02-03 11:13:09 -0800 | [diff] [blame] | 26 | import com.google.common.testing.EqualsTester; |
| 27 | |
tom | c0ccfb2 | 2014-09-08 00:41:32 -0700 | [diff] [blame] | 28 | import static org.junit.Assert.assertEquals; |
Pavel Likin | 9d49f54 | 2015-12-13 15:04:55 +0300 | [diff] [blame] | 29 | import static org.junit.Assert.assertTrue; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import static org.onosproject.net.DefaultLinkTest.cp; |
| 31 | import static org.onosproject.net.DeviceId.deviceId; |
| 32 | import static org.onosproject.net.Link.Type.DIRECT; |
| 33 | import static org.onosproject.net.PortNumber.portNumber; |
tom | c0ccfb2 | 2014-09-08 00:41:32 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Test of the default link description. |
| 37 | */ |
| 38 | public class DefaultLinkDescriptionTest { |
| 39 | |
| 40 | private static final DeviceId DID1 = deviceId("of:foo"); |
| 41 | private static final DeviceId DID2 = deviceId("of:bar"); |
| 42 | private static final PortNumber P1 = portNumber(1); |
Pavel Likin | 9d49f54 | 2015-12-13 15:04:55 +0300 | [diff] [blame] | 43 | private static final DefaultAnnotations DA = |
| 44 | DefaultAnnotations.builder().set("Key", "Value").build(); |
tom | c0ccfb2 | 2014-09-08 00:41:32 -0700 | [diff] [blame] | 45 | |
| 46 | @Test |
| 47 | public void basics() { |
Pavel Likin | 9d49f54 | 2015-12-13 15:04:55 +0300 | [diff] [blame] | 48 | LinkDescription desc = new DefaultLinkDescription(cp(DID1, P1), cp(DID2, P1), DIRECT, DA); |
tom | c0ccfb2 | 2014-09-08 00:41:32 -0700 | [diff] [blame] | 49 | assertEquals("incorrect src", cp(DID1, P1), desc.src()); |
| 50 | assertEquals("incorrect dst", cp(DID2, P1), desc.dst()); |
| 51 | assertEquals("incorrect type", DIRECT, desc.type()); |
Ray Milkey | cd6ab18 | 2016-02-03 11:13:09 -0800 | [diff] [blame] | 52 | assertTrue("incorrect annotations", desc.toString().contains("Key=Value")); |
tom | c0ccfb2 | 2014-09-08 00:41:32 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Ray Milkey | cd6ab18 | 2016-02-03 11:13:09 -0800 | [diff] [blame] | 55 | /** |
| 56 | * Tests the equals(), hashCode() and toString() methods. |
| 57 | */ |
| 58 | @Test |
| 59 | public void testEquals() { |
| 60 | ConnectPoint connectPoint1 = NetTestTools.connectPoint("sw1", 1); |
| 61 | ConnectPoint connectPoint2 = NetTestTools.connectPoint("sw2", 2); |
| 62 | ConnectPoint connectPoint3 = NetTestTools.connectPoint("sw3", 3); |
| 63 | |
| 64 | DefaultLinkDescription link1 = |
| 65 | new DefaultLinkDescription(connectPoint1, connectPoint2, |
| 66 | Link.Type.DIRECT); |
| 67 | DefaultLinkDescription sameAsLink1 = |
| 68 | new DefaultLinkDescription(connectPoint1, connectPoint2, |
| 69 | Link.Type.DIRECT); |
| 70 | DefaultLinkDescription link2 = |
| 71 | new DefaultLinkDescription(connectPoint1, connectPoint2, |
| 72 | Link.Type.INDIRECT); |
| 73 | DefaultLinkDescription link3 = |
| 74 | new DefaultLinkDescription(connectPoint1, connectPoint3, |
| 75 | Link.Type.DIRECT); |
| 76 | DefaultLinkDescription link4 = |
| 77 | new DefaultLinkDescription(connectPoint2, connectPoint3, |
| 78 | Link.Type.DIRECT); |
| 79 | DefaultLinkDescription link5 = |
| 80 | new DefaultLinkDescription(connectPoint1, connectPoint2, |
| 81 | Link.Type.DIRECT, false); |
| 82 | DefaultLinkDescription link6 = |
| 83 | new DefaultLinkDescription(connectPoint2, connectPoint3, |
| 84 | Link.Type.DIRECT, DA); |
| 85 | |
| 86 | new EqualsTester() |
| 87 | .addEqualityGroup(link1, sameAsLink1) |
| 88 | .addEqualityGroup(link2) |
| 89 | .addEqualityGroup(link3) |
| 90 | .addEqualityGroup(link4) |
| 91 | .addEqualityGroup(link5) |
| 92 | .addEqualityGroup(link6) |
| 93 | .testEquals(); |
| 94 | |
| 95 | } |
tom | c0ccfb2 | 2014-09-08 00:41:32 -0700 | [diff] [blame] | 96 | } |