ce6b6c006ca025ecfba71db202c78d7dcb9fe01f
[onosfw.git] /
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.router;
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 java.util.HashSet;
24 import java.util.Set;
25
26 import org.junit.Test;
27 import org.onosproject.vtnrsc.RouterGateway;
28 import org.onosproject.vtnrsc.TenantNetworkId;
29 import org.onosproject.vtnrsc.FixedIp;
30
31 import com.google.common.testing.EqualsTester;
32
33 /**
34  * Unit tests for RouterGateway class.
35  */
36 public class RouterGatewayTest {
37     final TenantNetworkId networkId1 = TenantNetworkId.networkId("1");
38     final TenantNetworkId networkId2 = TenantNetworkId.networkId("2");
39     final Set<FixedIp> fixedIpSet1 = new HashSet<>();
40     final Set<FixedIp> fixedIpSet2 = new HashSet<>();
41
42     /**
43      * Checks that the RouterGateway class is immutable.
44      */
45     @Test
46     public void testImmutability() {
47         assertThatClassIsImmutable(RouterGateway.class);
48     }
49
50     /**
51      * Checks the operation of equals().
52      */
53     @Test
54     public void testEquals() {
55         RouterGateway routerGateway1 = RouterGateway.routerGateway(networkId1,
56                                                                    true,
57                                                                    fixedIpSet1);
58         RouterGateway routerGateway2 = RouterGateway.routerGateway(networkId1,
59                                                                    true,
60                                                                    fixedIpSet1);
61         RouterGateway routerGateway3 = RouterGateway.routerGateway(networkId2,
62                                                                    true,
63                                                                    fixedIpSet2);
64         new EqualsTester().addEqualityGroup(routerGateway1, routerGateway2)
65                 .addEqualityGroup(routerGateway3).testEquals();
66     }
67
68     /**
69      * Checks the construction of a RouterGateway object.
70      */
71     @Test
72     public void testConstruction() {
73         RouterGateway routerGateway = RouterGateway.routerGateway(networkId1,
74                                                                   true,
75                                                                   fixedIpSet1);
76         assertThat(fixedIpSet1, is(notNullValue()));
77         assertThat(fixedIpSet1, is(routerGateway.externalFixedIps()));
78         assertThat(networkId1, is(notNullValue()));
79         assertThat(networkId1, is(routerGateway.networkId()));
80         assertThat(routerGateway.enableSnat(), is(true));
81     }
82 }