bobzhou | 3514897 | 2015-10-31 17:39:59 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
bobzhou | 3514897 | 2015-10-31 17:39:59 +0800 | [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 | */ |
Ray Milkey | 6c1bac3 | 2015-11-13 14:40:40 -0800 | [diff] [blame] | 16 | package org.onosproject.vtnrsc; |
bobzhou | 3514897 | 2015-10-31 17:39:59 +0800 | [diff] [blame] | 17 | |
| 18 | import java.util.HashSet; |
| 19 | import java.util.Set; |
| 20 | |
| 21 | import org.junit.Test; |
bobzhou | 3514897 | 2015-10-31 17:39:59 +0800 | [diff] [blame] | 22 | |
| 23 | import com.google.common.testing.EqualsTester; |
| 24 | |
Ray Milkey | 6c1bac3 | 2015-11-13 14:40:40 -0800 | [diff] [blame] | 25 | import static org.hamcrest.MatcherAssert.assertThat; |
| 26 | import static org.hamcrest.Matchers.is; |
| 27 | import static org.hamcrest.Matchers.notNullValue; |
| 28 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 29 | |
bobzhou | 3514897 | 2015-10-31 17:39:59 +0800 | [diff] [blame] | 30 | /** |
| 31 | * Unit tests for RouterGateway class. |
| 32 | */ |
| 33 | public class RouterGatewayTest { |
| 34 | final TenantNetworkId networkId1 = TenantNetworkId.networkId("1"); |
| 35 | final TenantNetworkId networkId2 = TenantNetworkId.networkId("2"); |
| 36 | final Set<FixedIp> fixedIpSet1 = new HashSet<>(); |
| 37 | final Set<FixedIp> fixedIpSet2 = new HashSet<>(); |
| 38 | |
| 39 | /** |
| 40 | * Checks that the RouterGateway class is immutable. |
| 41 | */ |
| 42 | @Test |
| 43 | public void testImmutability() { |
| 44 | assertThatClassIsImmutable(RouterGateway.class); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Checks the operation of equals(). |
| 49 | */ |
| 50 | @Test |
| 51 | public void testEquals() { |
| 52 | RouterGateway routerGateway1 = RouterGateway.routerGateway(networkId1, |
| 53 | true, |
| 54 | fixedIpSet1); |
| 55 | RouterGateway routerGateway2 = RouterGateway.routerGateway(networkId1, |
| 56 | true, |
| 57 | fixedIpSet1); |
| 58 | RouterGateway routerGateway3 = RouterGateway.routerGateway(networkId2, |
| 59 | true, |
| 60 | fixedIpSet2); |
| 61 | new EqualsTester().addEqualityGroup(routerGateway1, routerGateway2) |
| 62 | .addEqualityGroup(routerGateway3).testEquals(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Checks the construction of a RouterGateway object. |
| 67 | */ |
| 68 | @Test |
| 69 | public void testConstruction() { |
| 70 | RouterGateway routerGateway = RouterGateway.routerGateway(networkId1, |
| 71 | true, |
| 72 | fixedIpSet1); |
| 73 | assertThat(fixedIpSet1, is(notNullValue())); |
| 74 | assertThat(fixedIpSet1, is(routerGateway.externalFixedIps())); |
| 75 | assertThat(networkId1, is(notNullValue())); |
| 76 | assertThat(networkId1, is(routerGateway.networkId())); |
| 77 | assertThat(routerGateway.enableSnat(), is(true)); |
| 78 | } |
| 79 | } |