Committed by
Gerrit Code Review
[ONOS-3163] UT on Port Chain Manager
Change-Id: Iab692a7501adcc0a5c926b17e98362e0cd48a860
Showing
1 changed file
with
155 additions
and
0 deletions
apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/impl/PortChainManagerTest.java
0 → 100644
| 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.portchain.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.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 | +import org.onosproject.vtnrsc.DefaultFlowClassifier; | ||
| 33 | +import org.onosproject.vtnrsc.util.VtnStorageServiceTest; | ||
| 34 | + | ||
| 35 | +/** | ||
| 36 | + * Unit tests for PortChainManager class. | ||
| 37 | + */ | ||
| 38 | +public class PortChainManagerTest { | ||
| 39 | + final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae"); | ||
| 40 | + final TenantId tenantId = TenantId.tenantId("1"); | ||
| 41 | + final String name = "PortChain"; | ||
| 42 | + final String description = "PortChain"; | ||
| 43 | + final List<PortPairGroupId> portPairGroupList = new LinkedList<PortPairGroupId>(); | ||
| 44 | + final List<FlowClassifierId> flowClassifierList = new LinkedList<FlowClassifierId>(); | ||
| 45 | + DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder(); | ||
| 46 | + DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder(); | ||
| 47 | + PortChainManager portChainMgr = new PortChainManager(); | ||
| 48 | + PortChain portChain = null; | ||
| 49 | + private final VtnStorageServiceTest storageService = new VtnStorageServiceTest(); | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * Checks the operation of createPortChain() method. | ||
| 53 | + */ | ||
| 54 | + @Test | ||
| 55 | + public void testCreatePortChain() { | ||
| 56 | + // initialize port chain manager | ||
| 57 | + portChainMgr.storageService = storageService; | ||
| 58 | + portChainMgr.activate(); | ||
| 59 | + | ||
| 60 | + // create list of Port Pair Groups. | ||
| 61 | + PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae"); | ||
| 62 | + portPairGroupList.add(portPairGroupId); | ||
| 63 | + portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af"); | ||
| 64 | + portPairGroupList.add(portPairGroupId); | ||
| 65 | + | ||
| 66 | + // create list of Flow classifiers. | ||
| 67 | + FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae"); | ||
| 68 | + flowClassifierList.add(flowClassifierId); | ||
| 69 | + flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af"); | ||
| 70 | + flowClassifierList.add(flowClassifierId); | ||
| 71 | + | ||
| 72 | + // create port chain | ||
| 73 | + portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name).setDescription(description) | ||
| 74 | + .setPortPairGroups(portPairGroupList).setFlowClassifiers(flowClassifierList).build(); | ||
| 75 | + assertThat(portChainMgr.createPortChain(portChain), is(true)); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * Checks the operation of exists() method. | ||
| 80 | + */ | ||
| 81 | + @Test | ||
| 82 | + public void testExists() { | ||
| 83 | + testCreatePortChain(); | ||
| 84 | + assertThat(portChainMgr.exists(portChainId), is(true)); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * Checks the operation of getPortChainCount() method. | ||
| 89 | + */ | ||
| 90 | + @Test | ||
| 91 | + public void testGetPortChainCount() { | ||
| 92 | + testCreatePortChain(); | ||
| 93 | + assertThat(portChainMgr.getPortChainCount(), is(1)); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + /** | ||
| 97 | + * Checks the operation of getPortChains() method. | ||
| 98 | + */ | ||
| 99 | + @Test | ||
| 100 | + public void testGetPortChains() { | ||
| 101 | + testCreatePortChain(); | ||
| 102 | + final Iterable<PortChain> portChainList = portChainMgr.getPortChains(); | ||
| 103 | + assertThat(portChainList, is(notNullValue())); | ||
| 104 | + assertThat(portChainList.iterator().hasNext(), is(true)); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * Checks the operation of getPortChain() method. | ||
| 109 | + */ | ||
| 110 | + @Test | ||
| 111 | + public void testGetPortChain() { | ||
| 112 | + testCreatePortChain(); | ||
| 113 | + assertThat(portChain, is(notNullValue())); | ||
| 114 | + assertThat(portChainMgr.getPortChain(portChainId), is(portChain)); | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + /** | ||
| 118 | + * Checks the operation of updatePortChain() method. | ||
| 119 | + */ | ||
| 120 | + @Test | ||
| 121 | + public void testUpdatePortChain() { | ||
| 122 | + // create a port chain | ||
| 123 | + testCreatePortChain(); | ||
| 124 | + | ||
| 125 | + // new updates | ||
| 126 | + final TenantId tenantId2 = TenantId.tenantId("2"); | ||
| 127 | + final String name2 = "PortChain2"; | ||
| 128 | + final String description2 = "PortChain2"; | ||
| 129 | + // create list of Port Pair Groups. | ||
| 130 | + final List<PortPairGroupId> portPairGroupList = new LinkedList<PortPairGroupId>(); | ||
| 131 | + PortPairGroupId portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae"); | ||
| 132 | + portPairGroupList.add(portPairGroupId); | ||
| 133 | + portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3af"); | ||
| 134 | + portPairGroupList.add(portPairGroupId); | ||
| 135 | + // create list of Flow classifiers. | ||
| 136 | + final List<FlowClassifierId> flowClassifierList = new LinkedList<FlowClassifierId>(); | ||
| 137 | + FlowClassifierId flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3ae"); | ||
| 138 | + flowClassifierList.add(flowClassifierId); | ||
| 139 | + flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3af"); | ||
| 140 | + flowClassifierList.add(flowClassifierId); | ||
| 141 | + portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId2).setName(name2) | ||
| 142 | + .setDescription(description2).setPortPairGroups(portPairGroupList) | ||
| 143 | + .setFlowClassifiers(flowClassifierList).build(); | ||
| 144 | + assertThat(portChainMgr.updatePortChain(portChain), is(true)); | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + /** | ||
| 148 | + * Checks the operation of removePortChain() method. | ||
| 149 | + */ | ||
| 150 | + @Test | ||
| 151 | + public void testRemovePortChain() { | ||
| 152 | + testCreatePortChain(); | ||
| 153 | + assertThat(portChainMgr.removePortChain(portChainId), is(true)); | ||
| 154 | + } | ||
| 155 | +} |
-
Please register or login to post a comment