blob: 57855f176bc299a26db5d18513dc186dfdb255d0 [file] [log] [blame]
Mahesh Poojary Huawei540376d2015-11-13 16:48:23 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Mahesh Poojary Huawei540376d2015-11-13 16:48:23 +05303 *
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 Milkey6c1bac32015-11-13 14:40:40 -080016package org.onosproject.vtnrsc;
17
18import org.junit.Test;
19
20import com.google.common.testing.EqualsTester;
Mahesh Poojary Huawei540376d2015-11-13 16:48:23 +053021
22import static org.hamcrest.MatcherAssert.assertThat;
23import static org.hamcrest.Matchers.is;
24import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
25
Mahesh Poojary Huawei540376d2015-11-13 16:48:23 +053026/**
27 * Unit tests for DefaultPortPair class.
28 */
29public class DefaultPortPairTest {
30 /**
31 * Checks that the DefaultPortPair class is immutable.
32 */
33 @Test
34 public void testImmutability() {
35 assertThatClassIsImmutable(DefaultPortPair.class);
36 }
37
38 /**
39 * Checks the operation of equals() methods.
40 */
41 @Test
42 public void testEquals() {
43 // Create same two port pair objects.
44 final PortPairId portPairId = PortPairId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
45 final TenantId tenantId = TenantId.tenantId("1");
46 final String name = "PortPair1";
47 final String description = "PortPair1";
48 final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1";
49 final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345";
50
51 DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder();
52 final PortPair portPair1 = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name)
53 .setDescription(description).setIngress(ingress).setEgress(egress).build();
54
55 portPairBuilder = new DefaultPortPair.Builder();
56 final PortPair samePortPair1 = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name)
57 .setDescription(description).setIngress(ingress).setEgress(egress).build();
58
59 // Create different port pair object.
60 final PortPairId portPairId2 = PortPairId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae");
61 final TenantId tenantId2 = TenantId.tenantId("2");
62 final String name2 = "PortPair2";
63 final String description2 = "PortPair2";
64 final String ingress2 = "d5555555-24fc-4fae-af4b-321c5e2eb3d1";
65 final String egress2 = "a6666666-4a56-2a6e-cd3a-9dee4e2ec345";
66
67 portPairBuilder = new DefaultPortPair.Builder();
68 final PortPair portPair2 = portPairBuilder.setId(portPairId2).setTenantId(tenantId2).setName(name2)
69 .setDescription(description2).setIngress(ingress2).setEgress(egress2).build();
70
71 new EqualsTester().addEqualityGroup(portPair1, samePortPair1).addEqualityGroup(portPair2).testEquals();
72 }
73
74 /**
75 * Checks the construction of a DefaultPortPair object.
76 */
77 @Test
78 public void testConstruction() {
79 final PortPairId portPairId = PortPairId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
80 final TenantId tenantId = TenantId.tenantId("1");
81 final String name = "PortPair";
82 final String description = "PortPair";
83 final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1";
84 final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345";
85
86 DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder();
87 final PortPair portPair = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name)
88 .setDescription(description).setIngress(ingress).setEgress(egress).build();
89
90 assertThat(portPairId, is(portPair.portPairId()));
91 assertThat(tenantId, is(portPair.tenantId()));
92 assertThat(name, is(portPair.name()));
93 assertThat(description, is(portPair.description()));
94 assertThat(ingress, is(portPair.ingress()));
95 assertThat(egress, is(portPair.egress()));
96 }
97}