2528fb2936efd5683499aaa4913ad637c42b644c
[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 import java.util.List;
24 import java.util.LinkedList;
25
26 import org.onosproject.vtnrsc.PortPairGroupId;
27 import org.onosproject.vtnrsc.PortPairId;
28 import org.onosproject.vtnrsc.TenantId;
29 import org.onosproject.vtnrsc.PortPairGroup;
30 import org.onosproject.vtnrsc.DefaultPortPairGroup;
31
32 import com.google.common.testing.EqualsTester;
33
34 /**
35  * Unit tests for DefaultPortPairGroup class.
36  */
37 public class DefaultPortPairGroupTest {
38     /**
39      * Checks that the DefaultPortPairGroup class is immutable.
40      */
41     @Test
42     public void testImmutability() {
43         assertThatClassIsImmutable(DefaultPortPairGroup.class);
44     }
45
46     /**
47      * Checks the operation of equals() methods.
48      */
49     @Test
50     public void testEquals() {
51         // Create same two port-pair-group objects.
52         final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
53         final TenantId tenantId = TenantId.tenantId("1");
54         final String name = "PortPairGroup1";
55         final String description = "PortPairGroup1";
56         // create port-pair-id list
57         final List<PortPairId> portPairList = new LinkedList<PortPairId>();
58         PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
59         portPairList.add(portPairId);
60         portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
61         portPairList.add(portPairId);
62
63         DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
64         final PortPairGroup portPairGroup1 = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId)
65                 .setName(name).setDescription(description).setPortPairs(portPairList).build();
66
67         portPairGroupBuilder = new DefaultPortPairGroup.Builder();
68         final PortPairGroup samePortPairGroup1 = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId)
69                 .setName(name).setDescription(description).setPortPairs(portPairList).build();
70
71         // Create different port-pair-group object.
72         final PortPairGroupId portPairGroupId2 = PortPairGroupId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae");
73         final TenantId tenantId2 = TenantId.tenantId("2");
74         final String name2 = "PortPairGroup2";
75         final String description2 = "PortPairGroup2";
76         // create port-pair-id list
77         final List<PortPairId> portPairList2 = new LinkedList<PortPairId>();
78         portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
79         portPairList2.add(portPairId);
80         portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
81         portPairList2.add(portPairId);
82
83         portPairGroupBuilder = new DefaultPortPairGroup.Builder();
84         final PortPairGroup portPairGroup2 = portPairGroupBuilder.setId(portPairGroupId2).setTenantId(tenantId2)
85                 .setName(name2).setDescription(description2).setPortPairs(portPairList2).build();
86
87         new EqualsTester().addEqualityGroup(portPairGroup1, samePortPairGroup1).addEqualityGroup(portPairGroup2)
88                 .testEquals();
89     }
90
91     /**
92      * Checks the construction of a DefaultPortPairGroup object.
93      */
94     @Test
95     public void testConstruction() {
96         final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
97         final TenantId tenantId = TenantId.tenantId("1");
98         final String name = "PortPairGroup";
99         final String description = "PortPairGroup";
100         // create port-pair-id list
101         final List<PortPairId> portPairList = new LinkedList<PortPairId>();
102         PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
103         portPairList.add(portPairId);
104         portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
105         portPairList.add(portPairId);
106
107         DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
108         final PortPairGroup portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId)
109                 .setName(name).setDescription(description).setPortPairs(portPairList).build();
110
111         assertThat(portPairGroupId, is(portPairGroup.portPairGroupId()));
112         assertThat(tenantId, is(portPairGroup.tenantId()));
113         assertThat(name, is(portPairGroup.name()));
114         assertThat(description, is(portPairGroup.description()));
115         assertThat(portPairList, is(portPairGroup.portPairs()));
116     }
117 }