blob: 27234ac3984161bc56bc0dc5e600f0923bd9a621 [file] [log] [blame]
Mahesh Poojary Huawei04897d52015-11-13 16:45:01 +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 Huawei04897d52015-11-13 16:45:01 +053024
25import static org.hamcrest.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.is;
27import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
28
Mahesh Poojary Huawei04897d52015-11-13 16:45:01 +053029/**
30 * Unit tests for DefaultPortChain class.
31 */
32public class DefaultPortChainTest {
33 /**
34 * Checks that the DefaultPortChain class is immutable.
35 */
36 @Test
37 public void testImmutability() {
38 assertThatClassIsImmutable(DefaultPortChain.class);
39 }
40
41 /**
42 * Checks the operation of equals() methods.
43 */
44 @Test
45 public void testEquals() {
46 // Create same two port chain objects.
47 final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
48 final TenantId tenantId = TenantId.tenantId("1");
49 final String name = "PortChain1";
50 final String description = "PortChain1";
51 // create list of Port Pair Groups.
52 final List<PortPairGroupId> portPairGroups = new LinkedList<PortPairGroupId>();
53 PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
54 portPairGroups.add(portPairGroupId);
55 portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af");
56 portPairGroups.add(portPairGroupId);
57 // create list of Flow classifiers.
58 final List<FlowClassifierId> flowClassifiers = new LinkedList<FlowClassifierId>();
59 FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
60 flowClassifiers.add(flowClassifierId);
61 flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af");
62 flowClassifiers.add(flowClassifierId);
63
64 DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
65 final PortChain portChain1 = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name)
66 .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers)
67 .build();
68
69 portChainBuilder = new DefaultPortChain.Builder();
70 final PortChain samePortChain1 = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name)
71 .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers)
72 .build();
73
74 // Create different port chain object.
75 final PortChainId portChainId2 = PortChainId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae");
76 final TenantId tenantId2 = TenantId.tenantId("2");
77 final String name2 = "PortChain2";
78 final String description2 = "PortChain2";
79 // create list of Port Pair Groups.
80 final List<PortPairGroupId> portPairGroups2 = new LinkedList<PortPairGroupId>();
81 portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
82 portPairGroups2.add(portPairGroupId);
83 portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3af");
84 portPairGroups2.add(portPairGroupId);
85 // create list of Flow classifiers.
86 final List<FlowClassifierId> flowClassifiers2 = new LinkedList<FlowClassifierId>();
87 flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3ae");
88 flowClassifiers2.add(flowClassifierId);
89 flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3af");
90 flowClassifiers2.add(flowClassifierId);
91
92 portChainBuilder = new DefaultPortChain.Builder();
93 final PortChain portChain2 = portChainBuilder.setId(portChainId2).setTenantId(tenantId2).setName(name2)
94 .setDescription(description2).setPortPairGroups(portPairGroups2).setFlowClassifiers(flowClassifiers2)
95 .build();
96
97 new EqualsTester().addEqualityGroup(portChain1, samePortChain1).addEqualityGroup(portChain2).testEquals();
98 }
99
100 /**
101 * Checks the construction of a DefaultPortChain object.
102 */
103 @Test
104 public void testConstruction() {
105 final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
106 final TenantId tenantId = TenantId.tenantId("1");
107 final String name = "PortChain";
108 final String description = "PortChain";
109 // create list of Port Pair Groups.
110 final List<PortPairGroupId> portPairGroups = new LinkedList<PortPairGroupId>();
111 PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
112 portPairGroups.add(portPairGroupId);
113 portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af");
114 portPairGroups.add(portPairGroupId);
115 // create list of Flow classifiers.
116 final List<FlowClassifierId> flowClassifiers = new LinkedList<FlowClassifierId>();
117 FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
118 flowClassifiers.add(flowClassifierId);
119 flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af");
120 flowClassifiers.add(flowClassifierId);
121
122 DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
123 final PortChain portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name)
124 .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers)
125 .build();
126
127 assertThat(portChainId, is(portChain.portChainId()));
128 assertThat(tenantId, is(portChain.tenantId()));
129 assertThat(name, is(portChain.name()));
130 assertThat(description, is(portChain.description()));
131 assertThat(portPairGroups, is(portChain.portPairGroups()));
132 assertThat(flowClassifiers, is(portChain.flowClassifiers()));
133 }
134}