blob: 71e214a4fc71fabc453f598bb5babefdb2805960 [file] [log] [blame]
Brian Stanke0e5c94e2016-03-08 11:20:04 -05001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Brian Stanke0e5c94e2016-03-08 11:20:04 -05003 *
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 */
16
17package org.onosproject.incubator.net.virtual;
18
19import com.google.common.testing.EqualsTester;
20import org.junit.Test;
21import org.onosproject.incubator.net.tunnel.TunnelId;
22import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.PortNumber;
25
26import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
27
28/**
29 * Test of the default virtual link model entity.
30 */
31public class DefaultVirtualLinkTest {
32 final String deviceIdValue1 = "DEVICE_ID1";
33 final String deviceIdValue2 = "DEVICE_ID2";
34
35 /**
36 * Checks that the DefaultVirtualLink class is immutable.
37 */
38 @Test
39 public void testImmutability() {
40 assertThatClassIsImmutable(DefaultVirtualLink.class);
41 }
42
Brian Stanke9a108972016-04-11 15:25:17 -040043 /**
44 * Tests the DefaultVirtualLink Builder to ensure that the src cannot be null.
45 */
46 @Test(expected = NullPointerException.class)
47 public void testBuilderNullSrc() {
48 DefaultVirtualDevice device1 =
49 new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
50 DefaultVirtualDevice device2 =
51 new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
52 ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1));
53 ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2));
54
55 DefaultVirtualLink.builder()
56 .src(null)
57 .build();
58 }
59
60 /**
61 * Tests the DefaultVirtualLink Builder to ensure that the dst cannot be null.
62 */
63 @Test(expected = NullPointerException.class)
64 public void testBuilderNullDst() {
65 DefaultVirtualDevice device1 =
66 new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
67 DefaultVirtualDevice device2 =
68 new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
69 ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1));
70 ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2));
71
72 DefaultVirtualLink.builder()
73 .dst(null)
74 .build();
75 }
76
77 /**
78 * Tests the DefaultVirtualLink Builder to ensure that the networkId cannot be null.
79 */
80 @Test(expected = NullPointerException.class)
81 public void testBuilderNullNetworkId() {
82 DefaultVirtualDevice device1 =
83 new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
84 DefaultVirtualDevice device2 =
85 new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
86 ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1));
87 ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2));
88
89 DefaultVirtualLink.builder()
90 .networkId(null)
91 .build();
92 }
93
94 /**
95 * Tests the DefaultVirtualLink equality method.
96 */
Brian Stanke0e5c94e2016-03-08 11:20:04 -050097 @Test
98 public void testEquality() {
99 DefaultVirtualDevice device1 =
100 new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
101 DefaultVirtualDevice device2 =
102 new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
103 ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1));
104 ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2));
105
Brian Stanke9a108972016-04-11 15:25:17 -0400106 VirtualLink link1 = DefaultVirtualLink.builder()
107 .networkId(NetworkId.networkId(0))
108 .src(src)
109 .dst(dst)
110 .tunnelId(TunnelId.valueOf("1"))
111 .build();
112 VirtualLink link2 = DefaultVirtualLink.builder()
113 .networkId(NetworkId.networkId(0))
114 .src(src)
115 .dst(dst)
116 .tunnelId(TunnelId.valueOf("1"))
117 .build();
118 VirtualLink link3 = DefaultVirtualLink.builder()
119 .networkId(NetworkId.networkId(0))
120 .src(src)
121 .dst(dst)
122 .tunnelId(TunnelId.valueOf("2"))
123 .build();
124 VirtualLink link4 = DefaultVirtualLink.builder()
125 .networkId(NetworkId.networkId(1))
126 .src(src)
127 .dst(dst)
128 .tunnelId(TunnelId.valueOf("3"))
129 .build();
Brian Stanke0e5c94e2016-03-08 11:20:04 -0500130
131 new EqualsTester().addEqualityGroup(link1, link2).addEqualityGroup(link3)
132 .addEqualityGroup(link4).testEquals();
133 }
134}