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; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.PortNumber; |
| 25 | |
| 26 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 27 | |
| 28 | /** |
| 29 | * Test of the default virtual link model entity. |
| 30 | */ |
| 31 | public 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 Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame^] | 43 | /** |
| 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 Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 97 | @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 Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame^] | 106 | 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 Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 130 | |
| 131 | new EqualsTester().addEqualityGroup(link1, link2).addEqualityGroup(link3) |
| 132 | .addEqualityGroup(link4).testEquals(); |
| 133 | } |
| 134 | } |