2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package jtest.org.openecomp.sdnc.ra;
24 import org.junit.Assert;
25 import org.junit.FixMethodOrder;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.MethodSorters;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
32 import org.openecomp.sdnc.ra.ResourceAllocator;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.test.context.ContextConfiguration;
37 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
39 @RunWith(SpringJUnit4ClassRunner.class)
40 @ContextConfiguration(locations = { "classpath:test-context.xml" })
41 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
42 public class TestRelease {
44 private static final Logger log = LoggerFactory.getLogger(TestRelease.class);
46 @Autowired(required = true)
47 private ResourceAllocator resourceAllocator;
49 @Autowired(required = true)
50 private DataSetup dataSetup;
53 public void test001() throws Exception {
55 log.info("============== release " + t + " ================================");
56 log.info("=== Test release - cancel - new start");
58 String service1 = "release" + t + "/service1";
61 dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
62 dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
63 dataSetup.setupService(service1, "Pending", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
65 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Pending", 2, 200000));
67 SvcLogicContext ctx = new SvcLogicContext();
68 ctx.setAttribute("tmp.resource-allocator.request-type", "Cancel");
69 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
71 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
73 log.info("Result: " + st);
75 Assert.assertTrue(st == QueryStatus.SUCCESS);
76 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
80 public void test002() throws Exception {
82 log.info("============== release " + t + " ================================");
83 log.info("=== Test release - cancel - change");
85 String service1 = "release" + t + "/service1";
88 dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
89 dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
90 dataSetup.setupService(service1, "Active", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
91 dataSetup.setupService(service1, "Pending", 3, 400000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
93 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
94 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Pending", 3, 400000));
96 SvcLogicContext ctx = new SvcLogicContext();
97 ctx.setAttribute("tmp.resource-allocator.request-type", "Cancel");
98 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
100 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
102 log.info("Result: " + st);
104 Assert.assertTrue(st == QueryStatus.SUCCESS);
105 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
106 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, 3));
110 public void test003() throws Exception {
112 log.info("============== release " + t + " ================================");
113 log.info("=== Test release - cancel - active there, but no pending - should do nothing and return success");
115 String service1 = "release" + t + "/service1";
118 dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
119 dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
120 dataSetup.setupService(service1, "Active", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
122 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
124 SvcLogicContext ctx = new SvcLogicContext();
125 ctx.setAttribute("tmp.resource-allocator.request-type", "Cancel");
126 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
128 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
130 log.info("Result: " + st);
132 Assert.assertTrue(st == QueryStatus.SUCCESS);
133 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
137 public void test004() throws Exception {
139 log.info("============== release " + t + " ================================");
140 log.info("=== Test release - cancel - nothing in DB - should return success");
142 String service1 = "release" + t + "/service1";
146 SvcLogicContext ctx = new SvcLogicContext();
147 ctx.setAttribute("tmp.resource-allocator.request-type", "Cancel");
148 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
150 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
152 log.info("Result: " + st);
154 Assert.assertTrue(st == QueryStatus.SUCCESS);
155 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
159 public void test005() throws Exception {
161 log.info("============== release " + t + " ================================");
162 log.info("=== Test release - activate - new start");
164 String service1 = "release" + t + "/service1";
167 dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
168 dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
169 dataSetup.setupService(service1, "Pending", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
171 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Pending", 2, 200000));
173 SvcLogicContext ctx = new SvcLogicContext();
174 ctx.setAttribute("tmp.resource-allocator.request-type", "Activate");
175 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
177 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
179 log.info("Result: " + st);
181 Assert.assertTrue(st == QueryStatus.SUCCESS);
182 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
186 public void test006() throws Exception {
188 log.info("============== release " + t + " ================================");
189 log.info("=== Test release - actovate - change");
191 String service1 = "release" + t + "/service1";
194 dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
195 dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
196 dataSetup.setupService(service1, "Active", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
197 dataSetup.setupService(service1, "Pending", 3, 400000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
199 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
200 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Pending", 3, 400000));
202 SvcLogicContext ctx = new SvcLogicContext();
203 ctx.setAttribute("tmp.resource-allocator.request-type", "Activate");
204 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
206 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
208 log.info("Result: " + st);
210 Assert.assertTrue(st == QueryStatus.SUCCESS);
211 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 3, 400000));
212 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, 2));
216 public void test007() throws Exception {
218 log.info("============== release " + t + " ================================");
219 log.info("=== Test release - activate - active there, but no pending - should do nothing and return success");
221 String service1 = "release" + t + "/service1";
224 dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
225 dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
226 dataSetup.setupService(service1, "Active", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
228 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
230 SvcLogicContext ctx = new SvcLogicContext();
231 ctx.setAttribute("tmp.resource-allocator.request-type", "Activate");
232 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
234 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
236 log.info("Result: " + st);
238 Assert.assertTrue(st == QueryStatus.SUCCESS);
239 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
243 public void test008() throws Exception {
245 log.info("============== release " + t + " ================================");
246 log.info("=== Test release - activate - nothing in DB - should return success");
248 String service1 = "release" + t + "/service1";
252 SvcLogicContext ctx = new SvcLogicContext();
253 ctx.setAttribute("tmp.resource-allocator.request-type", "Activate");
254 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
256 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
258 log.info("Result: " + st);
260 Assert.assertTrue(st == QueryStatus.SUCCESS);
261 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
265 public void test009() throws Exception {
267 log.info("============== release " + t + " ================================");
268 log.info("=== Test release - disconnect - only pending in DB");
270 String service1 = "release" + t + "/service1";
273 dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
274 dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
275 dataSetup.setupService(service1, "Pending", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
277 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Pending", 2, 200000));
279 SvcLogicContext ctx = new SvcLogicContext();
280 ctx.setAttribute("tmp.resource-allocator.request-type", "Disconnect");
281 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
283 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
285 log.info("Result: " + st);
287 Assert.assertTrue(st == QueryStatus.SUCCESS);
288 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
292 public void test010() throws Exception {
294 log.info("============== release " + t + " ================================");
295 log.info("=== Test release - disconnect - only active in DB");
297 String service1 = "release" + t + "/service1";
300 dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
301 dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
302 dataSetup.setupService(service1, "Active", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
304 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
306 SvcLogicContext ctx = new SvcLogicContext();
307 ctx.setAttribute("tmp.resource-allocator.request-type", "Disconnect");
308 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
310 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
312 log.info("Result: " + st);
314 Assert.assertTrue(st == QueryStatus.SUCCESS);
315 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
319 public void test011() throws Exception {
321 log.info("============== release " + t + " ================================");
322 log.info("=== Test release - disconnect - both active and pending in DB");
324 String service1 = "release" + t + "/service1";
327 dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
328 dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
329 dataSetup.setupService(service1, "Active", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
330 dataSetup.setupService(service1, "Pending", 3, 400000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
332 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
333 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Pending", 3, 400000));
335 SvcLogicContext ctx = new SvcLogicContext();
336 ctx.setAttribute("tmp.resource-allocator.request-type", "Disconnect");
337 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
339 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
341 log.info("Result: " + st);
343 Assert.assertTrue(st == QueryStatus.SUCCESS);
344 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
348 public void test012() throws Exception {
350 log.info("============== release " + t + " ================================");
351 log.info("=== Test release - disconnect - nothing in DB - should return success");
353 String service1 = "release" + t + "/service1";
357 SvcLogicContext ctx = new SvcLogicContext();
358 ctx.setAttribute("tmp.resource-allocator.request-type", "Disconnect");
359 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
361 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
363 log.info("Result: " + st);
365 Assert.assertTrue(st == QueryStatus.SUCCESS);
366 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
370 public void test013() throws Exception {
372 log.info("============== release " + t + " ================================");
373 log.info("=== Test input validations - request-type missing in input");
375 String service1 = "release" + t + "/service1";
377 SvcLogicContext ctx = new SvcLogicContext();
378 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
381 resourceAllocator.release("NetworkCapacity", null, ctx);
382 } catch (SvcLogicException e) {
383 Assert.assertTrue(e.getMessage().equals(
384 "tmp.resource-allocator.request-type is required in ResourceAllocator"));
387 Assert.fail("SvcLogicException expected");
391 public void test014() throws Exception {
393 log.info("============== release " + t + " ================================");
394 log.info("=== Test input validations - invalid request-type in input");
396 String service1 = "release" + t + "/service1";
398 SvcLogicContext ctx = new SvcLogicContext();
399 ctx.setAttribute("tmp.resource-allocator.request-type", "xxxxx");
400 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
403 resourceAllocator.release("NetworkCapacity", null, ctx);
404 } catch (SvcLogicException e) {
405 Assert.assertTrue(e.getMessage().equals(
406 "Invalid tmp.resource-allocator.request-type: xxxxx. Supported values are Cancel, Activate, Disconnect."));
409 Assert.fail("SvcLogicException expected");
413 public void test015() throws Exception {
415 log.info("============== release " + t + " ================================");
416 log.info("=== Test input validations - missing service-instance-id in input");
418 SvcLogicContext ctx = new SvcLogicContext();
419 ctx.setAttribute("tmp.resource-allocator.request-type", "Cancel");
422 resourceAllocator.release("NetworkCapacity", null, ctx);
423 } catch (SvcLogicException e) {
424 Assert.assertTrue(e.getMessage().equals(
425 "tmp.resource-allocator.service-instance-id is required in ResourceAllocator"));
428 Assert.fail("SvcLogicException expected");