[CCSDK-6] Populate seed code
[ccsdk/sli/adaptors.git] / resource-assignment / provider / src / test / java / jtest / org / openecomp / sdnc / ra / TestRelease.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 ONAP Intellectual Property. All rights
6  *                                              reserved.
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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=========================================================
20  */
21
22 package jtest.org.openecomp.sdnc.ra;
23
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;
38
39 @RunWith(SpringJUnit4ClassRunner.class)
40 @ContextConfiguration(locations = { "classpath:test-context.xml" })
41 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
42 public class TestRelease {
43
44         private static final Logger log = LoggerFactory.getLogger(TestRelease.class);
45
46         @Autowired(required = true)
47         private ResourceAllocator resourceAllocator;
48
49         @Autowired(required = true)
50         private DataSetup dataSetup;
51
52         @Test
53         public void test001() throws Exception {
54                 String t = "001";
55                 log.info("============== release " + t + " ================================");
56                 log.info("=== Test release - cancel - new start");
57
58                 String service1 = "release" + t + "/service1";
59
60                 dataSetup.cleanup();
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");
64
65                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Pending", 2, 200000));
66
67                 SvcLogicContext ctx = new SvcLogicContext();
68                 ctx.setAttribute("tmp.resource-allocator.request-type", "Cancel");
69                 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
70
71                 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
72
73                 log.info("Result: " + st);
74
75                 Assert.assertTrue(st == QueryStatus.SUCCESS);
76                 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
77         }
78
79         @Test
80         public void test002() throws Exception {
81                 String t = "002";
82                 log.info("============== release " + t + " ================================");
83                 log.info("=== Test release - cancel - change");
84
85                 String service1 = "release" + t + "/service1";
86
87                 dataSetup.cleanup();
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");
92
93                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
94                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Pending", 3, 400000));
95
96                 SvcLogicContext ctx = new SvcLogicContext();
97                 ctx.setAttribute("tmp.resource-allocator.request-type", "Cancel");
98                 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
99
100                 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
101
102                 log.info("Result: " + st);
103
104                 Assert.assertTrue(st == QueryStatus.SUCCESS);
105                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
106                 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, 3));
107         }
108
109         @Test
110         public void test003() throws Exception {
111                 String t = "003";
112                 log.info("============== release " + t + " ================================");
113                 log.info("=== Test release - cancel - active there, but no pending - should do nothing and return success");
114
115                 String service1 = "release" + t + "/service1";
116
117                 dataSetup.cleanup();
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");
121
122                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
123
124                 SvcLogicContext ctx = new SvcLogicContext();
125                 ctx.setAttribute("tmp.resource-allocator.request-type", "Cancel");
126                 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
127
128                 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
129
130                 log.info("Result: " + st);
131
132                 Assert.assertTrue(st == QueryStatus.SUCCESS);
133                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
134         }
135
136         @Test
137         public void test004() throws Exception {
138                 String t = "004";
139                 log.info("============== release " + t + " ================================");
140                 log.info("=== Test release - cancel - nothing in DB - should return success");
141
142                 String service1 = "release" + t + "/service1";
143
144                 dataSetup.cleanup();
145
146                 SvcLogicContext ctx = new SvcLogicContext();
147                 ctx.setAttribute("tmp.resource-allocator.request-type", "Cancel");
148                 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
149
150                 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
151
152                 log.info("Result: " + st);
153
154                 Assert.assertTrue(st == QueryStatus.SUCCESS);
155                 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
156         }
157
158         @Test
159         public void test005() throws Exception {
160                 String t = "005";
161                 log.info("============== release " + t + " ================================");
162                 log.info("=== Test release - activate - new start");
163
164                 String service1 = "release" + t + "/service1";
165
166                 dataSetup.cleanup();
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");
170
171                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Pending", 2, 200000));
172
173                 SvcLogicContext ctx = new SvcLogicContext();
174                 ctx.setAttribute("tmp.resource-allocator.request-type", "Activate");
175                 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
176
177                 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
178
179                 log.info("Result: " + st);
180
181                 Assert.assertTrue(st == QueryStatus.SUCCESS);
182                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
183         }
184
185         @Test
186         public void test006() throws Exception {
187                 String t = "006";
188                 log.info("============== release " + t + " ================================");
189                 log.info("=== Test release - actovate - change");
190
191                 String service1 = "release" + t + "/service1";
192
193                 dataSetup.cleanup();
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");
198
199                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
200                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Pending", 3, 400000));
201
202                 SvcLogicContext ctx = new SvcLogicContext();
203                 ctx.setAttribute("tmp.resource-allocator.request-type", "Activate");
204                 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
205
206                 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
207
208                 log.info("Result: " + st);
209
210                 Assert.assertTrue(st == QueryStatus.SUCCESS);
211                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 3, 400000));
212                 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, 2));
213         }
214
215         @Test
216         public void test007() throws Exception {
217                 String t = "007";
218                 log.info("============== release " + t + " ================================");
219                 log.info("=== Test release - activate - active there, but no pending - should do nothing and return success");
220
221                 String service1 = "release" + t + "/service1";
222
223                 dataSetup.cleanup();
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");
227
228                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
229
230                 SvcLogicContext ctx = new SvcLogicContext();
231                 ctx.setAttribute("tmp.resource-allocator.request-type", "Activate");
232                 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
233
234                 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
235
236                 log.info("Result: " + st);
237
238                 Assert.assertTrue(st == QueryStatus.SUCCESS);
239                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
240         }
241
242         @Test
243         public void test008() throws Exception {
244                 String t = "008";
245                 log.info("============== release " + t + " ================================");
246                 log.info("=== Test release - activate - nothing in DB - should return success");
247
248                 String service1 = "release" + t + "/service1";
249
250                 dataSetup.cleanup();
251
252                 SvcLogicContext ctx = new SvcLogicContext();
253                 ctx.setAttribute("tmp.resource-allocator.request-type", "Activate");
254                 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
255
256                 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
257
258                 log.info("Result: " + st);
259
260                 Assert.assertTrue(st == QueryStatus.SUCCESS);
261                 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
262         }
263
264         @Test
265         public void test009() throws Exception {
266                 String t = "009";
267                 log.info("============== release " + t + " ================================");
268                 log.info("=== Test release - disconnect - only pending in DB");
269
270                 String service1 = "release" + t + "/service1";
271
272                 dataSetup.cleanup();
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");
276
277                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Pending", 2, 200000));
278
279                 SvcLogicContext ctx = new SvcLogicContext();
280                 ctx.setAttribute("tmp.resource-allocator.request-type", "Disconnect");
281                 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
282
283                 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
284
285                 log.info("Result: " + st);
286
287                 Assert.assertTrue(st == QueryStatus.SUCCESS);
288                 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
289         }
290
291         @Test
292         public void test010() throws Exception {
293                 String t = "010";
294                 log.info("============== release " + t + " ================================");
295                 log.info("=== Test release - disconnect - only active in DB");
296
297                 String service1 = "release" + t + "/service1";
298
299                 dataSetup.cleanup();
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");
303
304                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
305
306                 SvcLogicContext ctx = new SvcLogicContext();
307                 ctx.setAttribute("tmp.resource-allocator.request-type", "Disconnect");
308                 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
309
310                 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
311
312                 log.info("Result: " + st);
313
314                 Assert.assertTrue(st == QueryStatus.SUCCESS);
315                 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
316         }
317
318         @Test
319         public void test011() throws Exception {
320                 String t = "011";
321                 log.info("============== release " + t + " ================================");
322                 log.info("=== Test release - disconnect - both active and pending in DB");
323
324                 String service1 = "release" + t + "/service1";
325
326                 dataSetup.cleanup();
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");
331
332                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Active", 2, 200000));
333                 Assert.assertTrue(dataSetup.serviceCorrectInDb(service1, "Pending", 3, 400000));
334
335                 SvcLogicContext ctx = new SvcLogicContext();
336                 ctx.setAttribute("tmp.resource-allocator.request-type", "Disconnect");
337                 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
338
339                 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
340
341                 log.info("Result: " + st);
342
343                 Assert.assertTrue(st == QueryStatus.SUCCESS);
344                 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
345         }
346
347         @Test
348         public void test012() throws Exception {
349                 String t = "012";
350                 log.info("============== release " + t + " ================================");
351                 log.info("=== Test release - disconnect - nothing in DB - should return success");
352
353                 String service1 = "release" + t + "/service1";
354
355                 dataSetup.cleanup();
356
357                 SvcLogicContext ctx = new SvcLogicContext();
358                 ctx.setAttribute("tmp.resource-allocator.request-type", "Disconnect");
359                 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
360
361                 QueryStatus st = resourceAllocator.release("NetworkCapacity", null, ctx);
362
363                 log.info("Result: " + st);
364
365                 Assert.assertTrue(st == QueryStatus.SUCCESS);
366                 Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
367         }
368
369         @Test
370         public void test013() throws Exception {
371                 String t = "013";
372                 log.info("============== release " + t + " ================================");
373                 log.info("=== Test input validations - request-type missing in input");
374
375                 String service1 = "release" + t + "/service1";
376
377                 SvcLogicContext ctx = new SvcLogicContext();
378                 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
379
380                 try {
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"));
385                         return;
386                 }
387                 Assert.fail("SvcLogicException expected");
388         }
389
390         @Test
391         public void test014() throws Exception {
392                 String t = "014";
393                 log.info("============== release " + t + " ================================");
394                 log.info("=== Test input validations - invalid request-type in input");
395
396                 String service1 = "release" + t + "/service1";
397
398                 SvcLogicContext ctx = new SvcLogicContext();
399                 ctx.setAttribute("tmp.resource-allocator.request-type", "xxxxx");
400                 ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
401
402                 try {
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."));
407                         return;
408                 }
409                 Assert.fail("SvcLogicException expected");
410         }
411
412         @Test
413         public void test015() throws Exception {
414                 String t = "015";
415                 log.info("============== release " + t + " ================================");
416                 log.info("=== Test input validations - missing service-instance-id in input");
417
418                 SvcLogicContext ctx = new SvcLogicContext();
419                 ctx.setAttribute("tmp.resource-allocator.request-type", "Cancel");
420
421                 try {
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"));
426                         return;
427                 }
428                 Assert.fail("SvcLogicException expected");
429         }
430 }