blob: 480060c4deee0f02430d72261204ff9c713d0e32 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.link;
tomc0ccfb22014-09-08 00:41:32 -070017
18import org.junit.Test;
Ray Milkeycd6ab182016-02-03 11:13:09 -080019import org.onosproject.net.ConnectPoint;
Pavel Likin9d49f542015-12-13 15:04:55 +030020import org.onosproject.net.DefaultAnnotations;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.DeviceId;
Ray Milkeycd6ab182016-02-03 11:13:09 -080022import org.onosproject.net.Link;
23import org.onosproject.net.NetTestTools;
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.net.PortNumber;
tomc0ccfb22014-09-08 00:41:32 -070025
Ray Milkeycd6ab182016-02-03 11:13:09 -080026import com.google.common.testing.EqualsTester;
27
tomc0ccfb22014-09-08 00:41:32 -070028import static org.junit.Assert.assertEquals;
Pavel Likin9d49f542015-12-13 15:04:55 +030029import static org.junit.Assert.assertTrue;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import static org.onosproject.net.DefaultLinkTest.cp;
31import static org.onosproject.net.DeviceId.deviceId;
32import static org.onosproject.net.Link.Type.DIRECT;
33import static org.onosproject.net.PortNumber.portNumber;
tomc0ccfb22014-09-08 00:41:32 -070034
35/**
36 * Test of the default link description.
37 */
38public 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 Likin9d49f542015-12-13 15:04:55 +030043 private static final DefaultAnnotations DA =
44 DefaultAnnotations.builder().set("Key", "Value").build();
tomc0ccfb22014-09-08 00:41:32 -070045
46 @Test
47 public void basics() {
Pavel Likin9d49f542015-12-13 15:04:55 +030048 LinkDescription desc = new DefaultLinkDescription(cp(DID1, P1), cp(DID2, P1), DIRECT, DA);
tomc0ccfb22014-09-08 00:41:32 -070049 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 Milkeycd6ab182016-02-03 11:13:09 -080052 assertTrue("incorrect annotations", desc.toString().contains("Key=Value"));
tomc0ccfb22014-09-08 00:41:32 -070053 }
54
Ray Milkeycd6ab182016-02-03 11:13:09 -080055 /**
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 }
tomc0ccfb22014-09-08 00:41:32 -070096}