blob: b96290f73788b50d1c2ddc2e6998c782824ee8fa [file] [log] [blame]
Brian Stanke0e5c94e2016-03-08 11:20:04 -05001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
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;
Brian Stanke0e5c94e2016-03-08 11:20:04 -050023import org.onosproject.net.PortNumber;
Brian Stanke7a81b532016-06-14 15:43:51 -040024import org.onosproject.net.TestDeviceParams;
Brian Stanke0e5c94e2016-03-08 11:20:04 -050025
26import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
27
28/**
29 * Test of the default virtual link model entity.
30 */
Brian Stanke7a81b532016-06-14 15:43:51 -040031public class DefaultVirtualLinkTest extends TestDeviceParams {
Brian Stanke0e5c94e2016-03-08 11:20:04 -050032
33 /**
34 * Checks that the DefaultVirtualLink class is immutable.
35 */
36 @Test
37 public void testImmutability() {
38 assertThatClassIsImmutable(DefaultVirtualLink.class);
39 }
40
Brian Stanke9a108972016-04-11 15:25:17 -040041 /**
42 * Tests the DefaultVirtualLink Builder to ensure that the src cannot be null.
43 */
44 @Test(expected = NullPointerException.class)
45 public void testBuilderNullSrc() {
46 DefaultVirtualDevice device1 =
Brian Stanke7a81b532016-06-14 15:43:51 -040047 new DefaultVirtualDevice(NetworkId.networkId(0), DID1);
Brian Stanke9a108972016-04-11 15:25:17 -040048 DefaultVirtualDevice device2 =
Brian Stanke7a81b532016-06-14 15:43:51 -040049 new DefaultVirtualDevice(NetworkId.networkId(0), DID2);
Brian Stanke9a108972016-04-11 15:25:17 -040050 ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1));
51 ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2));
52
53 DefaultVirtualLink.builder()
54 .src(null)
55 .build();
56 }
57
58 /**
59 * Tests the DefaultVirtualLink Builder to ensure that the dst cannot be null.
60 */
61 @Test(expected = NullPointerException.class)
62 public void testBuilderNullDst() {
63 DefaultVirtualDevice device1 =
Brian Stanke7a81b532016-06-14 15:43:51 -040064 new DefaultVirtualDevice(NetworkId.networkId(0), DID1);
Brian Stanke9a108972016-04-11 15:25:17 -040065 DefaultVirtualDevice device2 =
Brian Stanke7a81b532016-06-14 15:43:51 -040066 new DefaultVirtualDevice(NetworkId.networkId(0), DID2);
Brian Stanke9a108972016-04-11 15:25:17 -040067 ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1));
68 ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2));
69
70 DefaultVirtualLink.builder()
71 .dst(null)
72 .build();
73 }
74
75 /**
76 * Tests the DefaultVirtualLink Builder to ensure that the networkId cannot be null.
77 */
78 @Test(expected = NullPointerException.class)
79 public void testBuilderNullNetworkId() {
80 DefaultVirtualDevice device1 =
Brian Stanke7a81b532016-06-14 15:43:51 -040081 new DefaultVirtualDevice(NetworkId.networkId(0), DID1);
Brian Stanke9a108972016-04-11 15:25:17 -040082 DefaultVirtualDevice device2 =
Brian Stanke7a81b532016-06-14 15:43:51 -040083 new DefaultVirtualDevice(NetworkId.networkId(0), DID2);
Brian Stanke9a108972016-04-11 15:25:17 -040084 ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1));
85 ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2));
86
87 DefaultVirtualLink.builder()
88 .networkId(null)
89 .build();
90 }
91
92 /**
93 * Tests the DefaultVirtualLink equality method.
94 */
Brian Stanke0e5c94e2016-03-08 11:20:04 -050095 @Test
96 public void testEquality() {
97 DefaultVirtualDevice device1 =
Brian Stanke7a81b532016-06-14 15:43:51 -040098 new DefaultVirtualDevice(NetworkId.networkId(0), DID1);
Brian Stanke0e5c94e2016-03-08 11:20:04 -050099 DefaultVirtualDevice device2 =
Brian Stanke7a81b532016-06-14 15:43:51 -0400100 new DefaultVirtualDevice(NetworkId.networkId(0), DID2);
Brian Stanke0e5c94e2016-03-08 11:20:04 -0500101 ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1));
102 ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2));
103
Brian Stanke9a108972016-04-11 15:25:17 -0400104 VirtualLink link1 = DefaultVirtualLink.builder()
105 .networkId(NetworkId.networkId(0))
106 .src(src)
107 .dst(dst)
108 .tunnelId(TunnelId.valueOf("1"))
109 .build();
110 VirtualLink link2 = DefaultVirtualLink.builder()
111 .networkId(NetworkId.networkId(0))
112 .src(src)
113 .dst(dst)
114 .tunnelId(TunnelId.valueOf("1"))
115 .build();
116 VirtualLink link3 = DefaultVirtualLink.builder()
117 .networkId(NetworkId.networkId(0))
118 .src(src)
119 .dst(dst)
120 .tunnelId(TunnelId.valueOf("2"))
121 .build();
122 VirtualLink link4 = DefaultVirtualLink.builder()
123 .networkId(NetworkId.networkId(1))
124 .src(src)
125 .dst(dst)
126 .tunnelId(TunnelId.valueOf("3"))
127 .build();
Brian Stanke0e5c94e2016-03-08 11:20:04 -0500128
129 new EqualsTester().addEqualityGroup(link1, link2).addEqualityGroup(link3)
130 .addEqualityGroup(link4).testEquals();
131 }
132}