Mahesh Poojary Huawei | eafd980 | 2015-11-27 12:14:31 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Foundation |
Mahesh Poojary Huawei | eafd980 | 2015-11-27 12:14:31 +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 | */ |
| 16 | package org.onosproject.vtnrsc.portpairgroup.impl; |
| 17 | |
| 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.is; |
| 20 | import static org.hamcrest.Matchers.notNullValue; |
| 21 | |
| 22 | import org.junit.Test; |
| 23 | import java.util.List; |
| 24 | import java.util.LinkedList; |
| 25 | |
| 26 | import org.onosproject.vtnrsc.PortPairId; |
| 27 | import org.onosproject.vtnrsc.PortPairGroup; |
| 28 | import org.onosproject.vtnrsc.PortPairGroupId; |
| 29 | import org.onosproject.vtnrsc.TenantId; |
| 30 | import org.onosproject.vtnrsc.DefaultPortPairGroup; |
| 31 | import org.onosproject.vtnrsc.util.VtnStorageServiceTest; |
Bharat saraswal | 513e817 | 2015-12-11 01:04:50 +0530 | [diff] [blame] | 32 | import org.onosproject.common.event.impl.TestEventDispatcher; |
| 33 | |
| 34 | import static org.onosproject.net.NetTestTools.injectEventDispatcher; |
Mahesh Poojary Huawei | eafd980 | 2015-11-27 12:14:31 +0530 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Unit tests for PortPairGroupManager class. |
| 38 | */ |
| 39 | public class PortPairGroupManagerTest { |
| 40 | final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae"); |
| 41 | final TenantId tenantId = TenantId.tenantId("1"); |
| 42 | final String name = "PortPairGroup"; |
| 43 | final String description = "PortPairGroup"; |
| 44 | final List<PortPairId> portPairIdList = new LinkedList<PortPairId>(); |
| 45 | DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder(); |
| 46 | PortPairGroupManager portPairGroupMgr = new PortPairGroupManager(); |
| 47 | PortPairGroup portPairGroup = null; |
| 48 | private final VtnStorageServiceTest storageService = new VtnStorageServiceTest(); |
| 49 | |
| 50 | /** |
| 51 | * Checks the operation of createPortPairGroup() method. |
| 52 | */ |
| 53 | @Test |
| 54 | public void testCreatePortPairGroup() { |
| 55 | // initialize port pair group manager |
| 56 | portPairGroupMgr.storageService = storageService; |
Bharat saraswal | 513e817 | 2015-12-11 01:04:50 +0530 | [diff] [blame] | 57 | injectEventDispatcher(portPairGroupMgr, new TestEventDispatcher()); |
Mahesh Poojary Huawei | eafd980 | 2015-11-27 12:14:31 +0530 | [diff] [blame] | 58 | portPairGroupMgr.activate(); |
| 59 | |
| 60 | // create port-pair-id list |
| 61 | PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae"); |
| 62 | portPairIdList.add(portPairId); |
| 63 | portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae"); |
| 64 | portPairIdList.add(portPairId); |
| 65 | |
| 66 | // create port pair |
| 67 | portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId).setName(name) |
| 68 | .setDescription(description).setPortPairs(portPairIdList).build(); |
| 69 | assertThat(portPairGroupMgr.createPortPairGroup(portPairGroup), is(true)); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Checks the operation of exists() method. |
| 74 | */ |
| 75 | @Test |
| 76 | public void testExists() { |
| 77 | testCreatePortPairGroup(); |
| 78 | assertThat(portPairGroupMgr.exists(portPairGroupId), is(true)); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Checks the operation of getPortPairGroupCount() method. |
| 83 | */ |
| 84 | @Test |
| 85 | public void testGetPortPairGroupCount() { |
| 86 | testCreatePortPairGroup(); |
| 87 | assertThat(portPairGroupMgr.getPortPairGroupCount(), is(1)); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Checks the operation of getPortPairGroups() method. |
| 92 | */ |
| 93 | @Test |
| 94 | public void testGetPortPairGroups() { |
| 95 | testCreatePortPairGroup(); |
| 96 | final Iterable<PortPairGroup> portPairGroupList = portPairGroupMgr.getPortPairGroups(); |
| 97 | assertThat(portPairGroupList, is(notNullValue())); |
| 98 | assertThat(portPairGroupList.iterator().hasNext(), is(true)); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Checks the operation of getPortPairGroup() method. |
| 103 | */ |
| 104 | @Test |
| 105 | public void testGetPortPairGroup() { |
| 106 | testCreatePortPairGroup(); |
| 107 | assertThat(portPairGroup, is(notNullValue())); |
| 108 | assertThat(portPairGroupMgr.getPortPairGroup(portPairGroupId), is(portPairGroup)); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Checks the operation of updatePortPairGroup() method. |
| 113 | */ |
| 114 | @Test |
| 115 | public void testUpdatePortPairGroup() { |
| 116 | // create a port pair group |
| 117 | testCreatePortPairGroup(); |
| 118 | |
| 119 | // new updates |
| 120 | // create port-pair-id list |
| 121 | final TenantId tenantId2 = TenantId.tenantId("2"); |
| 122 | final String name2 = "PortPairGroup2"; |
| 123 | final String description2 = "PortPairGroup2"; |
| 124 | final List<PortPairId> portPairIdList = new LinkedList<PortPairId>(); |
| 125 | PortPairId portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae"); |
| 126 | portPairIdList.add(portPairId); |
| 127 | portPairId = PortPairId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3ae"); |
| 128 | portPairIdList.add(portPairId); |
| 129 | |
| 130 | // create port pair |
| 131 | portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId2).setName(name2) |
| 132 | .setDescription(description2).setPortPairs(portPairIdList).build(); |
| 133 | assertThat(portPairGroupMgr.updatePortPairGroup(portPairGroup), is(true)); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Checks the operation of removePortPairGroup() method. |
| 138 | */ |
| 139 | @Test |
| 140 | public void testRemovePortPairGroup() { |
| 141 | testCreatePortPairGroup(); |
| 142 | assertThat(portPairGroupMgr.removePortPairGroup(portPairGroupId), is(true)); |
| 143 | } |
| 144 | } |