Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [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 | */ |
| 16 | |
| 17 | package org.onosproject.incubator.net.virtual; |
| 18 | |
| 19 | import com.google.common.testing.EqualsTester; |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 22 | import org.onosproject.net.ConnectPoint; |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 23 | import org.onosproject.net.PortNumber; |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 24 | import org.onosproject.net.TestDeviceParams; |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 25 | |
| 26 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 27 | |
| 28 | /** |
| 29 | * Test of the default virtual link model entity. |
| 30 | */ |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 31 | public class DefaultVirtualLinkTest extends TestDeviceParams { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Checks that the DefaultVirtualLink class is immutable. |
| 35 | */ |
| 36 | @Test |
| 37 | public void testImmutability() { |
| 38 | assertThatClassIsImmutable(DefaultVirtualLink.class); |
| 39 | } |
| 40 | |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 41 | /** |
| 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 Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 47 | new DefaultVirtualDevice(NetworkId.networkId(0), DID1); |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 48 | DefaultVirtualDevice device2 = |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 49 | new DefaultVirtualDevice(NetworkId.networkId(0), DID2); |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 50 | 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 Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 64 | new DefaultVirtualDevice(NetworkId.networkId(0), DID1); |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 65 | DefaultVirtualDevice device2 = |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 66 | new DefaultVirtualDevice(NetworkId.networkId(0), DID2); |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 67 | 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 Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 81 | new DefaultVirtualDevice(NetworkId.networkId(0), DID1); |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 82 | DefaultVirtualDevice device2 = |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 83 | new DefaultVirtualDevice(NetworkId.networkId(0), DID2); |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 84 | 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 Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 95 | @Test |
| 96 | public void testEquality() { |
| 97 | DefaultVirtualDevice device1 = |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 98 | new DefaultVirtualDevice(NetworkId.networkId(0), DID1); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 99 | DefaultVirtualDevice device2 = |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 100 | new DefaultVirtualDevice(NetworkId.networkId(0), DID2); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 101 | ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1)); |
| 102 | ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2)); |
| 103 | |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 104 | 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 Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 128 | |
| 129 | new EqualsTester().addEqualityGroup(link1, link2).addEqualityGroup(link3) |
| 130 | .addEqualityGroup(link4).testEquals(); |
| 131 | } |
| 132 | } |