samueljcc | a3d9b25 | 2015-10-28 15:58:45 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Foundation |
samueljcc | a3d9b25 | 2015-10-28 15:58:45 -0700 | [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 | |
Ray Milkey | 6c1bac3 | 2015-11-13 14:40:40 -0800 | [diff] [blame] | 17 | package org.onosproject.vtnrsc; |
samueljcc | a3d9b25 | 2015-10-28 15:58:45 -0700 | [diff] [blame] | 18 | |
| 19 | import java.util.Map; |
| 20 | import java.util.Set; |
| 21 | |
| 22 | import org.junit.Test; |
| 23 | import org.onlab.packet.IpAddress; |
| 24 | import org.onlab.packet.MacAddress; |
| 25 | import org.onosproject.net.DeviceId; |
samueljcc | a3d9b25 | 2015-10-28 15:58:45 -0700 | [diff] [blame] | 26 | |
| 27 | import com.google.common.collect.Maps; |
| 28 | import com.google.common.collect.Sets; |
| 29 | import com.google.common.testing.EqualsTester; |
| 30 | |
Ray Milkey | 6c1bac3 | 2015-11-13 14:40:40 -0800 | [diff] [blame] | 31 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 32 | |
samueljcc | a3d9b25 | 2015-10-28 15:58:45 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Unit tests for DefaultVirtualPort class. |
| 35 | */ |
| 36 | public class DefaultVirtualPortTest { |
| 37 | |
| 38 | private Set<FixedIp> fixedIps; |
| 39 | private Map<String, String> propertyMap; |
| 40 | private Set<AllowedAddressPair> allowedAddressPairs; |
| 41 | private Set<SecurityGroup> securityGroups; |
| 42 | private VirtualPortId id1; |
| 43 | private VirtualPortId id2; |
| 44 | private String macAddressStr = "fa:12:3e:56:ee:a2"; |
| 45 | private String ipAddress = "10.1.1.1"; |
| 46 | private String deviceStr = "of:000000000000001"; |
| 47 | private String tenantIdStr = "123"; |
| 48 | private String portId1 = "1241"; |
| 49 | private String portId2 = "1242"; |
| 50 | private String tenantNetworkId = "1234567"; |
| 51 | private String subnet = "1212"; |
| 52 | private String hostIdStr = "fa:e2:3e:56:ee:a2"; |
| 53 | |
| 54 | private void initVirtualPortId() { |
| 55 | id1 = VirtualPortId.portId(portId1); |
| 56 | id2 = VirtualPortId.portId(portId2); |
| 57 | } |
| 58 | |
| 59 | private void initFixedIpSet() { |
| 60 | FixedIp fixedIp = FixedIp.fixedIp(SubnetId.subnetId(subnet), |
| 61 | IpAddress.valueOf(ipAddress)); |
| 62 | fixedIps = Sets.newHashSet(); |
| 63 | fixedIps.add(fixedIp); |
| 64 | } |
| 65 | |
| 66 | private void initPropertyMap() { |
| 67 | String deviceOwner = "james"; |
| 68 | propertyMap = Maps.newHashMap(); |
| 69 | propertyMap.putIfAbsent("deviceOwner", deviceOwner); |
| 70 | } |
| 71 | |
| 72 | private void initAddressPairSet() { |
| 73 | allowedAddressPairs = Sets.newHashSet(); |
| 74 | AllowedAddressPair allowedAddressPair = AllowedAddressPair |
| 75 | .allowedAddressPair(IpAddress.valueOf(ipAddress), |
| 76 | MacAddress.valueOf(macAddressStr)); |
| 77 | allowedAddressPairs.add(allowedAddressPair); |
| 78 | } |
| 79 | |
| 80 | private void initSecurityGroupSet() { |
| 81 | securityGroups = Sets.newHashSet(); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Checks that the DefaultVirtualPort class is immutable. |
| 86 | */ |
| 87 | @Test |
| 88 | public void testImmutability() { |
| 89 | assertThatClassIsImmutable(SecurityGroup.class); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Checks the operation of equals(). |
| 94 | */ |
| 95 | @Test |
| 96 | public void testEquals() { |
| 97 | initVirtualPortId(); |
| 98 | initFixedIpSet(); |
| 99 | initPropertyMap(); |
| 100 | initAddressPairSet(); |
| 101 | initSecurityGroupSet(); |
| 102 | TenantNetworkId networkId = TenantNetworkId.networkId(tenantNetworkId); |
| 103 | MacAddress macAddress = MacAddress.valueOf(macAddressStr); |
| 104 | TenantId tenantId = TenantId.tenantId(tenantIdStr); |
| 105 | DeviceId deviceId = DeviceId.deviceId(deviceStr); |
| 106 | BindingHostId bindingHostId = BindingHostId.bindingHostId(hostIdStr); |
| 107 | |
| 108 | VirtualPort d1 = new DefaultVirtualPort(id1, networkId, true, |
| 109 | propertyMap, |
| 110 | VirtualPort.State.ACTIVE, |
| 111 | macAddress, tenantId, deviceId, |
| 112 | fixedIps, bindingHostId, |
| 113 | allowedAddressPairs, |
| 114 | securityGroups); |
| 115 | VirtualPort d2 = new DefaultVirtualPort(id1, networkId, true, |
| 116 | propertyMap, |
| 117 | VirtualPort.State.ACTIVE, |
| 118 | macAddress, tenantId, deviceId, |
| 119 | fixedIps, bindingHostId, |
| 120 | allowedAddressPairs, |
| 121 | securityGroups); |
| 122 | VirtualPort d3 = new DefaultVirtualPort(id2, networkId, true, |
| 123 | propertyMap, |
| 124 | VirtualPort.State.ACTIVE, |
| 125 | macAddress, tenantId, deviceId, |
| 126 | fixedIps, bindingHostId, |
| 127 | allowedAddressPairs, |
| 128 | securityGroups); |
| 129 | new EqualsTester().addEqualityGroup(d1, d2).addEqualityGroup(d3) |
| 130 | .testEquals(); |
| 131 | } |
| 132 | } |