2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.vtnrsc.flowclassifier;
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.is;
20 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
22 import org.junit.Test;
24 import org.onosproject.vtnrsc.PortPairId;
25 import org.onosproject.vtnrsc.TenantId;
26 import org.onosproject.vtnrsc.PortPair;
27 import org.onosproject.vtnrsc.DefaultPortPair;
29 import com.google.common.testing.EqualsTester;
32 * Unit tests for DefaultPortPair class.
34 public class DefaultPortPairTest {
36 * Checks that the DefaultPortPair class is immutable.
39 public void testImmutability() {
40 assertThatClassIsImmutable(DefaultPortPair.class);
44 * Checks the operation of equals() methods.
47 public void testEquals() {
48 // Create same two port pair objects.
49 final PortPairId portPairId = PortPairId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
50 final TenantId tenantId = TenantId.tenantId("1");
51 final String name = "PortPair1";
52 final String description = "PortPair1";
53 final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1";
54 final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345";
56 DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder();
57 final PortPair portPair1 = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name)
58 .setDescription(description).setIngress(ingress).setEgress(egress).build();
60 portPairBuilder = new DefaultPortPair.Builder();
61 final PortPair samePortPair1 = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name)
62 .setDescription(description).setIngress(ingress).setEgress(egress).build();
64 // Create different port pair object.
65 final PortPairId portPairId2 = PortPairId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae");
66 final TenantId tenantId2 = TenantId.tenantId("2");
67 final String name2 = "PortPair2";
68 final String description2 = "PortPair2";
69 final String ingress2 = "d5555555-24fc-4fae-af4b-321c5e2eb3d1";
70 final String egress2 = "a6666666-4a56-2a6e-cd3a-9dee4e2ec345";
72 portPairBuilder = new DefaultPortPair.Builder();
73 final PortPair portPair2 = portPairBuilder.setId(portPairId2).setTenantId(tenantId2).setName(name2)
74 .setDescription(description2).setIngress(ingress2).setEgress(egress2).build();
76 new EqualsTester().addEqualityGroup(portPair1, samePortPair1).addEqualityGroup(portPair2).testEquals();
80 * Checks the construction of a DefaultPortPair object.
83 public void testConstruction() {
84 final PortPairId portPairId = PortPairId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
85 final TenantId tenantId = TenantId.tenantId("1");
86 final String name = "PortPair";
87 final String description = "PortPair";
88 final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1";
89 final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345";
91 DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder();
92 final PortPair portPair = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name)
93 .setDescription(description).setIngress(ingress).setEgress(egress).build();
95 assertThat(portPairId, is(portPair.portPairId()));
96 assertThat(tenantId, is(portPair.tenantId()));
97 assertThat(name, is(portPair.name()));
98 assertThat(description, is(portPair.description()));
99 assertThat(ingress, is(portPair.ingress()));
100 assertThat(egress, is(portPair.egress()));