91e7ab37612ad330e16e2de6b5a1f53fccd53f79
[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.flowclassifier;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.is;
20 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
21
22 import org.junit.Test;
23
24 import org.onosproject.vtnrsc.PortPairId;
25 import org.onosproject.vtnrsc.TenantId;
26 import org.onosproject.vtnrsc.PortPair;
27 import org.onosproject.vtnrsc.DefaultPortPair;
28
29 import com.google.common.testing.EqualsTester;
30
31 /**
32  * Unit tests for DefaultPortPair class.
33  */
34 public class DefaultPortPairTest {
35     /**
36      * Checks that the DefaultPortPair class is immutable.
37      */
38     @Test
39     public void testImmutability() {
40         assertThatClassIsImmutable(DefaultPortPair.class);
41     }
42
43     /**
44      * Checks the operation of equals() methods.
45      */
46     @Test
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";
55
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();
59
60         portPairBuilder = new DefaultPortPair.Builder();
61         final PortPair samePortPair1 = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name)
62                 .setDescription(description).setIngress(ingress).setEgress(egress).build();
63
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";
71
72         portPairBuilder = new DefaultPortPair.Builder();
73         final PortPair portPair2 = portPairBuilder.setId(portPairId2).setTenantId(tenantId2).setName(name2)
74                 .setDescription(description2).setIngress(ingress2).setEgress(egress2).build();
75
76         new EqualsTester().addEqualityGroup(portPair1, samePortPair1).addEqualityGroup(portPair2).testEquals();
77     }
78
79     /**
80      * Checks the construction of a DefaultPortPair object.
81      */
82     @Test
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";
90
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();
94
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()));
101     }
102 }