jiangrui | 9c6db86 | 2015-11-27 14:50:46 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | package org.onosproject.vtnrsc.floatingip; |
| 17 | |
| 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.is; |
| 20 | import static org.hamcrest.Matchers.notNullValue; |
| 21 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 22 | |
| 23 | import org.junit.Test; |
| 24 | import org.onlab.packet.IpAddress; |
| 25 | import org.onosproject.vtnrsc.DefaultFloatingIp; |
| 26 | import org.onosproject.vtnrsc.FloatingIp; |
| 27 | import org.onosproject.vtnrsc.FloatingIpId; |
| 28 | import org.onosproject.vtnrsc.RouterId; |
| 29 | import org.onosproject.vtnrsc.TenantId; |
| 30 | import org.onosproject.vtnrsc.TenantNetworkId; |
| 31 | import org.onosproject.vtnrsc.VirtualPortId; |
| 32 | |
| 33 | import com.google.common.testing.EqualsTester; |
| 34 | |
| 35 | /** |
| 36 | * Unit tests for DefaultFloatingIp class. |
| 37 | */ |
| 38 | public class DefaultFloatingIpTest { |
| 39 | |
| 40 | private String floatingIpIdStr1 = "5fb63824-4d5c-4b85-9f2f-ebb93c9ce3df"; |
| 41 | private String floatingIpIdStr2 = "fa44f585-fe02-40d3-afe7-d1d7e5782c99"; |
| 42 | private String floatingIpStr = "10.1.1.2"; |
| 43 | private String fixedIpStr = "192.168.1.2"; |
| 44 | private String tenantIdStr = "123"; |
| 45 | private String tenantNetworkId = "1234567"; |
| 46 | private String virtualPortId = "1212"; |
| 47 | private String routerIdStr = "123"; |
| 48 | |
| 49 | /** |
| 50 | * Checks that the DefaultFloatingIp class is immutable. |
| 51 | */ |
| 52 | @Test |
| 53 | public void testImmutability() { |
| 54 | assertThatClassIsImmutable(DefaultFloatingIp.class); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Checks the operation of equals(). |
| 59 | */ |
| 60 | @Test |
| 61 | public void testEquals() { |
| 62 | final TenantId tenantId = TenantId.tenantId(tenantIdStr); |
| 63 | final TenantNetworkId networkId = TenantNetworkId |
| 64 | .networkId(tenantNetworkId); |
| 65 | final VirtualPortId portId = VirtualPortId.portId(virtualPortId); |
| 66 | final RouterId routerId = RouterId.valueOf(routerIdStr); |
| 67 | final FloatingIpId id1 = FloatingIpId.of(floatingIpIdStr1); |
| 68 | final FloatingIpId id2 = FloatingIpId.of(floatingIpIdStr2); |
| 69 | final IpAddress floatingIpAddress = IpAddress.valueOf(floatingIpStr); |
| 70 | final IpAddress fixedIpAddress = IpAddress.valueOf(fixedIpStr); |
| 71 | |
| 72 | FloatingIp fip1 = new DefaultFloatingIp(id1, tenantId, networkId, |
| 73 | portId, routerId, |
| 74 | floatingIpAddress, |
| 75 | fixedIpAddress, |
| 76 | FloatingIp.Status.ACTIVE); |
| 77 | FloatingIp fip2 = new DefaultFloatingIp(id1, tenantId, networkId, |
| 78 | portId, routerId, |
| 79 | floatingIpAddress, |
| 80 | fixedIpAddress, |
| 81 | FloatingIp.Status.ACTIVE); |
| 82 | FloatingIp fip3 = new DefaultFloatingIp(id2, tenantId, networkId, |
| 83 | portId, routerId, |
| 84 | floatingIpAddress, |
| 85 | fixedIpAddress, |
| 86 | FloatingIp.Status.ACTIVE); |
| 87 | |
| 88 | new EqualsTester().addEqualityGroup(fip1, fip2).addEqualityGroup(fip3) |
| 89 | .testEquals(); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Checks the construction of a DefaultFloatingIp object. |
| 94 | */ |
| 95 | @Test |
| 96 | public void testConstruction() { |
| 97 | final TenantId tenantId = TenantId.tenantId(tenantIdStr); |
| 98 | final TenantNetworkId networkId = TenantNetworkId |
| 99 | .networkId(tenantNetworkId); |
| 100 | final VirtualPortId portId = VirtualPortId.portId(virtualPortId); |
| 101 | final RouterId routerId = RouterId.valueOf(routerIdStr); |
| 102 | final FloatingIpId id = FloatingIpId.of(floatingIpIdStr1); |
| 103 | final IpAddress floatingIpAddress = IpAddress.valueOf(floatingIpStr); |
| 104 | final IpAddress fixedIpAddress = IpAddress.valueOf(fixedIpStr); |
| 105 | |
| 106 | FloatingIp fip = new DefaultFloatingIp(id, tenantId, networkId, portId, |
| 107 | routerId, floatingIpAddress, |
| 108 | fixedIpAddress, |
| 109 | FloatingIp.Status.ACTIVE); |
| 110 | assertThat(id, is(notNullValue())); |
| 111 | assertThat(id, is(fip.id())); |
| 112 | assertThat(tenantId, is(notNullValue())); |
| 113 | assertThat(tenantId, is(fip.tenantId())); |
| 114 | assertThat(networkId, is(notNullValue())); |
| 115 | assertThat(networkId, is(fip.networkId())); |
| 116 | assertThat(portId, is(notNullValue())); |
| 117 | assertThat(portId, is(fip.portId())); |
| 118 | assertThat(routerId, is(notNullValue())); |
| 119 | assertThat(routerId, is(fip.routerId())); |
| 120 | assertThat(floatingIpAddress, is(notNullValue())); |
| 121 | assertThat(floatingIpAddress, is(fip.floatingIp())); |
| 122 | assertThat(fixedIpAddress, is(notNullValue())); |
| 123 | assertThat(fixedIpAddress, is(fip.fixedIp())); |
| 124 | } |
| 125 | } |