Mahesh Poojary Huawei
Committed by Gerrit Code Review

[ONOS-3116] DefaultPortChainTest

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