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