Mahesh Poojary Huawei | dbd49a0 | 2015-11-13 16:51:37 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Mahesh Poojary Huawei | dbd49a0 | 2015-11-13 16:51:37 +0530 | [diff] [blame] | 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 Milkey | 6c1bac3 | 2015-11-13 14:40:40 -0800 | [diff] [blame] | 16 | package org.onosproject.vtnrsc; |
| 17 | |
Phaneendra Manda | 329a127 | 2016-02-10 22:57:00 +0530 | [diff] [blame] | 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.is; |
| 20 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 21 | |
Ray Milkey | 6c1bac3 | 2015-11-13 14:40:40 -0800 | [diff] [blame] | 22 | import java.util.LinkedList; |
| 23 | import java.util.List; |
| 24 | |
| 25 | import org.junit.Test; |
| 26 | |
| 27 | import com.google.common.testing.EqualsTester; |
Mahesh Poojary Huawei | dbd49a0 | 2015-11-13 16:51:37 +0530 | [diff] [blame] | 28 | |
Mahesh Poojary Huawei | dbd49a0 | 2015-11-13 16:51:37 +0530 | [diff] [blame] | 29 | /** |
| 30 | * Unit tests for DefaultPortPairGroup class. |
| 31 | */ |
| 32 | public class DefaultPortPairGroupTest { |
Phaneendra Manda | 329a127 | 2016-02-10 22:57:00 +0530 | [diff] [blame] | 33 | |
| 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 Huawei | dbd49a0 | 2015-11-13 16:51:37 +0530 | [diff] [blame] | 57 | /** |
| 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 Manda | 329a127 | 2016-02-10 22:57:00 +0530 | [diff] [blame] | 70 | |
| 71 | final PortPairGroup portPairGroup1 = getPortPairGroup(); |
Mahesh Poojary Huawei | dbd49a0 | 2015-11-13 16:51:37 +0530 | [diff] [blame] | 72 | |
| 73 | DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder(); |
Phaneendra Manda | 329a127 | 2016-02-10 22:57:00 +0530 | [diff] [blame] | 74 | final PortPairGroup samePortPairGroup1 = getPortPairGroup(); |
Mahesh Poojary Huawei | dbd49a0 | 2015-11-13 16:51:37 +0530 | [diff] [blame] | 75 | |
| 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 Manda | 329a127 | 2016-02-10 22:57:00 +0530 | [diff] [blame] | 83 | PortPairId portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae"); |
Mahesh Poojary Huawei | dbd49a0 | 2015-11-13 16:51:37 +0530 | [diff] [blame] | 84 | 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 Manda | 329a127 | 2016-02-10 22:57:00 +0530 | [diff] [blame] | 93 | .testEquals(); |
Mahesh Poojary Huawei | dbd49a0 | 2015-11-13 16:51:37 +0530 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Checks the construction of a DefaultPortPairGroup object. |
| 98 | */ |
| 99 | @Test |
| 100 | public void testConstruction() { |
Mahesh Poojary Huawei | dbd49a0 | 2015-11-13 16:51:37 +0530 | [diff] [blame] | 101 | |
Phaneendra Manda | 329a127 | 2016-02-10 22:57:00 +0530 | [diff] [blame] | 102 | final PortPairGroup portPairGroup = getPortPairGroup(); |
Mahesh Poojary Huawei | dbd49a0 | 2015-11-13 16:51:37 +0530 | [diff] [blame] | 103 | |
| 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 Manda | 329a127 | 2016-02-10 22:57:00 +0530 | [diff] [blame] | 110 | |
| 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 Huawei | dbd49a0 | 2015-11-13 16:51:37 +0530 | [diff] [blame] | 125 | } |