blob: 681ca17caae9248b683fecde1848b43b2e2e1dc4 [file] [log] [blame]
Mahesh Poojary Huaweidbd49a02015-11-13 16:51:37 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Mahesh Poojary Huaweidbd49a02015-11-13 16:51:37 +05303 *
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
Phaneendra Manda329a1272016-02-10 22:57:00 +053018import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.is;
20import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
21
Ray Milkey6c1bac32015-11-13 14:40:40 -080022import java.util.LinkedList;
23import java.util.List;
24
25import org.junit.Test;
26
27import com.google.common.testing.EqualsTester;
Mahesh Poojary Huaweidbd49a02015-11-13 16:51:37 +053028
Mahesh Poojary Huaweidbd49a02015-11-13 16:51:37 +053029/**
30 * Unit tests for DefaultPortPairGroup class.
31 */
32public class DefaultPortPairGroupTest {
Phaneendra Manda329a1272016-02-10 22:57:00 +053033
34 final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
35 final TenantId tenantId = TenantId.tenantId("1");
36 final String name = "PortPairGroup1";
37 final String description = "PortPairGroup1";
38 final List<PortPairId> portPairList = new LinkedList<PortPairId>();
39
40 private PortPairGroup getPortPairGroup() {
41
42 portPairList.clear();
43 // Create same two port-pair-group objects.
44 PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
45 portPairList.add(portPairId);
46 portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
47 portPairList.add(portPairId);
48
49 DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
50 PortPairGroup portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId)
51 .setName(name).setDescription(description).setPortPairs(portPairList).build();
52
53 return portPairGroup;
54
55 }
56
Mahesh Poojary Huaweidbd49a02015-11-13 16:51:37 +053057 /**
58 * Checks that the DefaultPortPairGroup class is immutable.
59 */
60 @Test
61 public void testImmutability() {
62 assertThatClassIsImmutable(DefaultPortPairGroup.class);
63 }
64
65 /**
66 * Checks the operation of equals() methods.
67 */
68 @Test
69 public void testEquals() {
Phaneendra Manda329a1272016-02-10 22:57:00 +053070
71 final PortPairGroup portPairGroup1 = getPortPairGroup();
Mahesh Poojary Huaweidbd49a02015-11-13 16:51:37 +053072
73 DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
Phaneendra Manda329a1272016-02-10 22:57:00 +053074 final PortPairGroup samePortPairGroup1 = getPortPairGroup();
Mahesh Poojary Huaweidbd49a02015-11-13 16:51:37 +053075
76 // Create different port-pair-group object.
77 final PortPairGroupId portPairGroupId2 = PortPairGroupId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae");
78 final TenantId tenantId2 = TenantId.tenantId("2");
79 final String name2 = "PortPairGroup2";
80 final String description2 = "PortPairGroup2";
81 // create port-pair-id list
82 final List<PortPairId> portPairList2 = new LinkedList<PortPairId>();
Phaneendra Manda329a1272016-02-10 22:57:00 +053083 PortPairId portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
Mahesh Poojary Huaweidbd49a02015-11-13 16:51:37 +053084 portPairList2.add(portPairId);
85 portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
86 portPairList2.add(portPairId);
87
88 portPairGroupBuilder = new DefaultPortPairGroup.Builder();
89 final PortPairGroup portPairGroup2 = portPairGroupBuilder.setId(portPairGroupId2).setTenantId(tenantId2)
90 .setName(name2).setDescription(description2).setPortPairs(portPairList2).build();
91
92 new EqualsTester().addEqualityGroup(portPairGroup1, samePortPairGroup1).addEqualityGroup(portPairGroup2)
Phaneendra Manda329a1272016-02-10 22:57:00 +053093 .testEquals();
Mahesh Poojary Huaweidbd49a02015-11-13 16:51:37 +053094 }
95
96 /**
97 * Checks the construction of a DefaultPortPairGroup object.
98 */
99 @Test
100 public void testConstruction() {
Mahesh Poojary Huaweidbd49a02015-11-13 16:51:37 +0530101
Phaneendra Manda329a1272016-02-10 22:57:00 +0530102 final PortPairGroup portPairGroup = getPortPairGroup();
Mahesh Poojary Huaweidbd49a02015-11-13 16:51:37 +0530103
104 assertThat(portPairGroupId, is(portPairGroup.portPairGroupId()));
105 assertThat(tenantId, is(portPairGroup.tenantId()));
106 assertThat(name, is(portPairGroup.name()));
107 assertThat(description, is(portPairGroup.description()));
108 assertThat(portPairList, is(portPairGroup.portPairs()));
109 }
Phaneendra Manda329a1272016-02-10 22:57:00 +0530110
111 /**
112 * Checks the port pair load map.
113 */
114 @Test
115 public void testPortPairLod() {
116
117 PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
118 final PortPairGroup portPairGroup = getPortPairGroup();
119 int load1 = portPairGroup.getLoad(portPairId);
120 portPairGroup.addLoad(portPairId);
121 int load2 = portPairGroup.getLoad(portPairId);
122
123 assertThat((load1 + 1), is(load2));
124 }
Mahesh Poojary Huaweidbd49a02015-11-13 16:51:37 +0530125}