blob: c2ebe44100f032cc5a51d696d6747d100c085e19 [file] [log] [blame]
jiangrui181166e2015-11-12 11:34:48 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
jiangrui181166e2015-11-12 11:34:48 +08003 *
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 */
16package org.onosproject.vtnrsc.router;
17
18import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.is;
20import static org.hamcrest.Matchers.notNullValue;
21import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
22
23import java.util.Collections;
24
25import org.junit.Test;
26import org.onosproject.vtnrsc.DefaultRouter;
27import org.onosproject.vtnrsc.Router;
28import org.onosproject.vtnrsc.RouterGateway;
29import org.onosproject.vtnrsc.RouterId;
30import org.onosproject.vtnrsc.TenantId;
31import org.onosproject.vtnrsc.TenantNetworkId;
32import org.onosproject.vtnrsc.VirtualPortId;
33
34import com.google.common.testing.EqualsTester;
35
36/**
37 * Unit tests for DefaultRouter class.
38 */
39public class DefaultRouterTest {
40
41 private String tenantIdStr = "123";
42 private String virtualPortId = "1212";
43 private String routeIdStr1 = "1";
44 private String routeIdStr2 = "2";
45 private String routerName = "router";
46 private String tenantNetworkId = "1234567";
47
48 /**
49 * Checks that the DefaultRouter class is immutable.
50 */
51 @Test
52 public void testImmutability() {
53 assertThatClassIsImmutable(DefaultRouter.class);
54 }
55
56 /**
57 * Checks the operation of equals().
58 */
59 @Test
60 public void testEquals() {
61 final TenantId tenantId = TenantId.tenantId(tenantIdStr);
62 final VirtualPortId portId = VirtualPortId.portId(virtualPortId);
63 final RouterId routerId1 = RouterId.valueOf(routeIdStr1);
64 final RouterId routerId2 = RouterId.valueOf(routeIdStr2);
65 final TenantNetworkId networkId = TenantNetworkId
66 .networkId(tenantNetworkId);
67 final RouterGateway routerGateway = RouterGateway.routerGateway(
68 networkId,
69 true,
70 Collections
71 .emptySet());
72
73 Router r1 = new DefaultRouter(routerId1, routerName, false,
74 Router.Status.ACTIVE, false,
75 routerGateway, portId, tenantId, null);
76 Router r2 = new DefaultRouter(routerId1, routerName, false,
77 Router.Status.ACTIVE, false,
78 routerGateway, portId, tenantId, null);
79 Router r3 = new DefaultRouter(routerId2, routerName, false,
80 Router.Status.ACTIVE, false,
81 routerGateway, portId, tenantId, null);
82
83 new EqualsTester().addEqualityGroup(r1, r2).addEqualityGroup(r3)
84 .testEquals();
85 }
86
87 /**
88 * Checks the construction of a DefaultRouter object.
89 */
90 @Test
91 public void testConstruction() {
92 final TenantId tenantId = TenantId.tenantId(tenantIdStr);
93 final VirtualPortId portId = VirtualPortId.portId(virtualPortId);
94 final RouterId routerId = RouterId.valueOf(routeIdStr1);
95 final TenantNetworkId networkId = TenantNetworkId
96 .networkId(tenantNetworkId);
97 final RouterGateway routerGateway = RouterGateway.routerGateway(
98 networkId,
99 true,
100 Collections
101 .emptySet());
102
103 Router r1 = new DefaultRouter(routerId, routerName, false,
104 Router.Status.ACTIVE, false,
105 routerGateway, portId, tenantId, null);
106 assertThat(routerId, is(notNullValue()));
107 assertThat(routerId, is(r1.id()));
108 assertThat(tenantId, is(notNullValue()));
109 assertThat(tenantId, is(r1.tenantId()));
110 assertThat(routerGateway, is(notNullValue()));
111 assertThat(routerGateway, is(r1.externalGatewayInfo()));
112 }
113
114}