blob: e79d9dba60600a2e8e3c9477ba56002a67c82624 [file] [log] [blame]
Mahesh Poojary Huawei0ea8c202015-11-27 12:19:32 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Mahesh Poojary Huawei0ea8c202015-11-27 12:19:32 +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 */
16package org.onosproject.vtnrsc.portchain.impl;
17
18import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.is;
20import static org.hamcrest.Matchers.notNullValue;
21
22import org.junit.Test;
23import java.util.List;
24import java.util.LinkedList;
25
26import org.onosproject.vtnrsc.PortChainId;
27import org.onosproject.vtnrsc.PortPairGroupId;
28import org.onosproject.vtnrsc.TenantId;
29import org.onosproject.vtnrsc.FlowClassifierId;
30import org.onosproject.vtnrsc.PortChain;
31import org.onosproject.vtnrsc.DefaultPortChain;
32import org.onosproject.vtnrsc.DefaultFlowClassifier;
33import org.onosproject.vtnrsc.util.VtnStorageServiceTest;
Bharat saraswala3f51b52015-12-11 01:09:02 +053034import org.onosproject.common.event.impl.TestEventDispatcher;
35
36import static org.onosproject.net.NetTestTools.injectEventDispatcher;
Mahesh Poojary Huawei0ea8c202015-11-27 12:19:32 +053037
38/**
39 * Unit tests for PortChainManager class.
40 */
41public class PortChainManagerTest {
42 final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
43 final TenantId tenantId = TenantId.tenantId("1");
44 final String name = "PortChain";
45 final String description = "PortChain";
46 final List<PortPairGroupId> portPairGroupList = new LinkedList<PortPairGroupId>();
47 final List<FlowClassifierId> flowClassifierList = new LinkedList<FlowClassifierId>();
48 DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
49 DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
50 PortChainManager portChainMgr = new PortChainManager();
51 PortChain portChain = null;
52 private final VtnStorageServiceTest storageService = new VtnStorageServiceTest();
53
54 /**
55 * Checks the operation of createPortChain() method.
56 */
57 @Test
58 public void testCreatePortChain() {
59 // initialize port chain manager
60 portChainMgr.storageService = storageService;
Bharat saraswala3f51b52015-12-11 01:09:02 +053061 injectEventDispatcher(portChainMgr, new TestEventDispatcher());
Mahesh Poojary Huawei0ea8c202015-11-27 12:19:32 +053062 portChainMgr.activate();
63
64 // create list of Port Pair Groups.
65 PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
66 portPairGroupList.add(portPairGroupId);
67 portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af");
68 portPairGroupList.add(portPairGroupId);
69
70 // create list of Flow classifiers.
71 FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
72 flowClassifierList.add(flowClassifierId);
73 flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af");
74 flowClassifierList.add(flowClassifierId);
75
76 // create port chain
77 portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name).setDescription(description)
78 .setPortPairGroups(portPairGroupList).setFlowClassifiers(flowClassifierList).build();
79 assertThat(portChainMgr.createPortChain(portChain), is(true));
80 }
81
82 /**
83 * Checks the operation of exists() method.
84 */
85 @Test
86 public void testExists() {
87 testCreatePortChain();
88 assertThat(portChainMgr.exists(portChainId), is(true));
89 }
90
91 /**
92 * Checks the operation of getPortChainCount() method.
93 */
94 @Test
95 public void testGetPortChainCount() {
96 testCreatePortChain();
97 assertThat(portChainMgr.getPortChainCount(), is(1));
98 }
99
100 /**
101 * Checks the operation of getPortChains() method.
102 */
103 @Test
104 public void testGetPortChains() {
105 testCreatePortChain();
106 final Iterable<PortChain> portChainList = portChainMgr.getPortChains();
107 assertThat(portChainList, is(notNullValue()));
108 assertThat(portChainList.iterator().hasNext(), is(true));
109 }
110
111 /**
112 * Checks the operation of getPortChain() method.
113 */
114 @Test
115 public void testGetPortChain() {
116 testCreatePortChain();
117 assertThat(portChain, is(notNullValue()));
118 assertThat(portChainMgr.getPortChain(portChainId), is(portChain));
119 }
120
121 /**
122 * Checks the operation of updatePortChain() method.
123 */
124 @Test
125 public void testUpdatePortChain() {
126 // create a port chain
127 testCreatePortChain();
128
129 // new updates
130 final TenantId tenantId2 = TenantId.tenantId("2");
131 final String name2 = "PortChain2";
132 final String description2 = "PortChain2";
133 // create list of Port Pair Groups.
134 final List<PortPairGroupId> portPairGroupList = new LinkedList<PortPairGroupId>();
135 PortPairGroupId portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
136 portPairGroupList.add(portPairGroupId);
137 portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3af");
138 portPairGroupList.add(portPairGroupId);
139 // create list of Flow classifiers.
140 final List<FlowClassifierId> flowClassifierList = new LinkedList<FlowClassifierId>();
141 FlowClassifierId flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3ae");
142 flowClassifierList.add(flowClassifierId);
143 flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3af");
144 flowClassifierList.add(flowClassifierId);
145 portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId2).setName(name2)
146 .setDescription(description2).setPortPairGroups(portPairGroupList)
147 .setFlowClassifiers(flowClassifierList).build();
148 assertThat(portChainMgr.updatePortChain(portChain), is(true));
149 }
150
151 /**
152 * Checks the operation of removePortChain() method.
153 */
154 @Test
155 public void testRemovePortChain() {
156 testCreatePortChain();
157 assertThat(portChainMgr.removePortChain(portChainId), is(true));
158 }
159}