Changed to unmaintained
[appc.git] / appc-sequence-generator / appc-sequence-generator-bundle / src / test / java / org / onap / appc / seqgen / TestSequenceGeneratorPlugin.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.appc.seqgen;
23
24 import java.io.IOException;
25 import java.net.URISyntaxException;
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
28 import java.util.HashMap;
29 import java.util.Map;
30
31 import org.junit.Assert;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.TestName;
35 import org.onap.appc.seqgen.dgplugin.SequenceGeneratorPlugin;
36 import org.onap.appc.seqgen.dgplugin.impl.SequenceGeneratorPluginImpl;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
38
39 import com.att.eelf.configuration.EELFLogger;
40 import com.att.eelf.configuration.EELFManager;
41
42 public class TestSequenceGeneratorPlugin {
43     @Rule
44     public final TestName thisTestName = new TestName();
45
46     private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestSequenceGeneratorPlugin.class);
47     private SequenceGeneratorPlugin seqImpl;
48
49     @Test
50     public void testGenerateSequenceStart() throws URISyntaxException, IOException {
51         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
52
53         String inputJSON = readInput("/input/start.json");
54
55         Map<String,String> params = new HashMap<>();
56         SvcLogicContext context = new SvcLogicContext();
57         context.setAttribute("inputJSON",inputJSON);
58
59         seqImpl = new SequenceGeneratorPluginImpl();
60         seqImpl.generateSequence(params,context);
61
62         String outputJSON = context.getAttribute("output");
63         String actualOutput = readOutput("/output/Start2.json");
64         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
65     }
66
67     @Test
68     public void testGenerateSequenceWODependencyInfo()throws URISyntaxException, IOException {
69         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
70
71         String inputJSON = readInput("/input/start-withoutDependency.json");
72
73         Map<String,String> params = new HashMap<>();
74         SvcLogicContext context = new SvcLogicContext();
75         context.setAttribute("inputJSON",inputJSON);
76
77         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
78         plugin.generateSequence(params,context);
79
80         String outputJSON = context.getAttribute("output");
81         String actualOutput = readOutput("/output/start-withoutDependency.json");
82         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
83     }
84
85     @Test
86     public void testGenerateSequenceSingleVM()throws URISyntaxException, IOException {
87         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
88
89         String inputJSON = readInput("/input/start-singleVM-.json");
90
91         Map<String,String> params = new HashMap<>();
92         SvcLogicContext context = new SvcLogicContext();
93         context.setAttribute("inputJSON",inputJSON);
94
95         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
96         plugin.generateSequence(params,context);
97
98         String outputJSON = context.getAttribute("output");
99         String actualOutput = readOutput("/output/start-singleVM-.json");
100         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
101     }
102
103     @Test
104     public void testGenerateSequenceNoStrategy() throws URISyntaxException, IOException {
105         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
106
107         String inputJSON = readInput("/input/no-strategy.json");
108
109         Map<String,String> params = new HashMap<>();
110         SvcLogicContext context = new SvcLogicContext();
111         context.setAttribute("inputJSON",inputJSON);
112
113         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
114         plugin.generateSequence(params,context);
115
116         String outputJSON = context.getAttribute("output");
117         String actualOutput = readOutput("/output/Start2.json");
118
119         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
120     }
121
122     @Test
123     public void testGenerateSequenceStop() throws URISyntaxException, IOException {
124         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
125
126         String inputJSON = readInput("/input/stop.json");
127
128         Map<String,String> params = new HashMap<>();
129         SvcLogicContext context = new SvcLogicContext();
130         context.setAttribute("inputJSON",inputJSON);
131
132         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
133         plugin.generateSequence(params,context);
134
135         String outputJSON = context.getAttribute("output");
136         String actualOutput = readOutput("/output/Output-stop.json");
137
138         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
139     }
140
141     @Test
142     public void testGenerateSequenceWrongNumber() throws URISyntaxException, IOException {
143         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
144
145         String inputJSON = readInput("/input/wrongnumber.json");
146
147         Map<String,String> params = new HashMap<>();
148         SvcLogicContext context = new SvcLogicContext();
149         context.setAttribute("inputJSON",inputJSON);
150
151         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
152         plugin.generateSequence(params,context);
153
154         String errorCode = context.getAttribute("error-code");
155         String errorMessage = context.getAttribute("error-message");
156         logger.info("errorCode = " + errorCode);
157         Assert.assertEquals(errorCode,"401");
158         Assert.assertEquals(errorMessage,"Error generating sequence Invalid Number for Wait Time 6a");
159     }
160
161
162     @Test
163     public void testGenerateSequenceCyclic() throws URISyntaxException, IOException {
164         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
165
166         String inputJSON = readInput("/input/cyclic.json");
167
168         Map<String,String> params = new HashMap<>();
169         SvcLogicContext context = new SvcLogicContext();
170         context.setAttribute("inputJSON",inputJSON);
171
172         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
173         plugin.generateSequence(params,context);
174
175         String errorCode = context.getAttribute("error-code");
176         String errorMessage = context.getAttribute("error-message");
177         logger.info("errorCode = " + errorCode);
178         Assert.assertEquals(errorCode,"401");
179         Assert.assertEquals(errorMessage,"Error generating sequence There seems to be no Root/Independent node for Vnfc dependencies");
180     }
181
182     @Test
183     public void testGenerateSequenceWrongAction() throws URISyntaxException, IOException {
184         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
185
186         String inputJSON = readInput("/input/wrongaction.json");
187
188         Map<String,String> params = new HashMap<>();
189         SvcLogicContext context = new SvcLogicContext();
190         context.setAttribute("inputJSON",inputJSON);
191
192         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
193         plugin.generateSequence(params,context);
194
195         String errorCode = context.getAttribute("error-code");
196         String errorMessage = context.getAttribute("error-message");
197         logger.info("errorCode = " + errorCode);
198         Assert.assertEquals(errorCode,"401");
199         Assert.assertEquals(errorMessage,"Error generating sequence Invalid Action start");
200     }
201
202
203     @Test
204     public void testGenerateSequenceMissingRequestInfo() throws URISyntaxException, IOException {
205         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
206
207         String inputJSON = readInput("/input/missingrequestinfo.json");
208
209         Map<String,String> params = new HashMap<>();
210         SvcLogicContext context = new SvcLogicContext();
211         context.setAttribute("inputJSON",inputJSON);
212
213         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
214         plugin.generateSequence(params,context);
215
216         String errorCode = context.getAttribute("error-code");
217         String errorMessage = context.getAttribute("error-message");
218         logger.debug("errorCode = " + errorCode);
219         Assert.assertEquals(errorCode,"401");
220         Assert.assertEquals(errorMessage,"Error generating sequence Request info is not provided in the input");
221     }
222
223     @Test
224     public void testGenerateSequenceStopSingleVM() throws URISyntaxException, IOException{
225         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
226
227         String inputJSON = readInput("/input/stop-singleVM.json");
228
229         Map<String,String> params = new HashMap<>();
230         SvcLogicContext context = new SvcLogicContext();
231         context.setAttribute("inputJSON",inputJSON);
232
233         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
234         plugin.generateSequence(params,context);
235
236         String outputJSON = context.getAttribute("output");
237         String actualOutput = readOutput("/output/stop-singleVM.json");
238         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
239     }
240
241     @Test
242     public void testGenerateSequenceStopSingleVmPerVnfc() throws URISyntaxException, IOException{
243         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
244
245         String inputJSON = readInput("/input/stop-singleVmPerVnfc.json");
246
247         Map<String,String> params = new HashMap<>();
248         SvcLogicContext context = new SvcLogicContext();
249         context.setAttribute("inputJSON",inputJSON);
250
251         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
252         plugin.generateSequence(params,context);
253
254         String outputJSON = context.getAttribute("output");
255         String actualOutput = readOutput("/output/stop-singleVmPerVnfc.json");
256         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
257     }
258
259     @Test
260     public void testGenerateSequenceRestartNoDep() throws URISyntaxException, IOException {
261         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
262
263         String inputJSON = readInput("/input/restartNodep.json");
264
265         Map<String,String> params = new HashMap<>();
266         SvcLogicContext context = new SvcLogicContext();
267         context.setAttribute("inputJSON",inputJSON);
268
269         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
270         plugin.generateSequence(params,context);
271
272         String actualOutput = context.getAttribute("output");
273         String outputJSON = readOutput("/output/restart-NoDep.json");
274         outputJSON.trim();
275         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
276     }
277
278     @Test
279     public void testGenerateSequenceRestartNoDepSingleVM() throws URISyntaxException, IOException {
280         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
281
282         String inputJSON = readInput("/input/NoDep-SingleVM.json");
283
284         Map<String,String> params = new HashMap<>();
285         SvcLogicContext context = new SvcLogicContext();
286         context.setAttribute("inputJSON",inputJSON);
287
288         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
289         plugin.generateSequence(params,context);
290
291         String actualOutput = context.getAttribute("output");
292         String outputJSON = readOutput("/output/restart-Nodep-SingleVM.json");
293         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
294     }
295
296     @Test
297     public void testGenerateSequenceStartSingleVmPerVnfc() throws URISyntaxException, IOException{
298         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
299
300         String inputJSON = readInput("/input/start-singleVmPerVnfc-.json");
301
302         Map<String,String> params = new HashMap<>();
303         SvcLogicContext context = new SvcLogicContext();
304         context.setAttribute("inputJSON",inputJSON);
305
306         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
307         plugin.generateSequence(params,context);
308
309         String outputJSON = context.getAttribute("output");
310         String actualOutput = readOutput("/output/start-singleVmPerVnfc.json");
311         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
312     }
313
314     @Test
315     public void testGenerateSequenceVnfcNotPresentInInventory() throws URISyntaxException, IOException {
316         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
317
318         String inputJSON = readInput("/input/CheckVNfcInInventory.json");
319
320         Map<String,String> params = new HashMap<>();
321         SvcLogicContext context = new SvcLogicContext();
322         context.setAttribute("inputJSON",inputJSON);
323         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
324         plugin.generateSequence(params,context);
325
326         String outputJSON = context.getAttribute("output");
327         String actualOutput = readOutput("/output/CheckVnfcInInventory.json");
328
329         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
330     }
331
332     @Test
333     public void testGenerateSequenceCheckMandatoryVnfc() throws URISyntaxException, IOException {
334         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
335
336         String inputJSON = readInput("/input/CheckMandatoryVnfc.json");
337
338         Map<String,String> params = new HashMap<>();
339         SvcLogicContext context = new SvcLogicContext();
340         context.setAttribute("inputJSON",inputJSON);
341
342         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
343         plugin.generateSequence(params,context);
344
345         String errorCode = context.getAttribute("error-code");
346         String errorMessage = context.getAttribute("error-message");
347         logger.debug("errorCode = " + errorCode);
348         Assert.assertEquals(errorCode,"401");
349         Assert.assertEquals(errorMessage,"Error generating sequence VMs missing for the mandatory VNFC : [smp]");
350     }
351
352     @Test
353     public void testGenerateSequenceCheckMissingDependencyInfo() throws URISyntaxException, IOException {
354         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
355
356         String inputJSON = readInput("/input/MissingDependencyInfo.json");
357
358         Map<String,String> params = new HashMap<>();
359         SvcLogicContext context = new SvcLogicContext();
360         context.setAttribute("inputJSON",inputJSON);
361
362         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
363         plugin.generateSequence(params,context);
364
365         String errorCode = context.getAttribute("error-code");
366         String errorMessage = context.getAttribute("error-message");
367         logger.debug("errorCode = " + errorCode);
368         Assert.assertEquals(errorCode,"401");
369         Assert.assertEquals(errorMessage,"Error generating sequence Dependency model is missing following vnfc type(s): [smp]");
370     }
371
372     @Test
373     public void testGenerateSequenceExtraVnfcInDependency() throws URISyntaxException, IOException {
374         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
375
376         String inputJSON = readInput("/input/WrongDependencyModel.json");
377
378         Map<String,String> params = new HashMap<>();
379         SvcLogicContext context = new SvcLogicContext();
380         context.setAttribute("inputJSON",inputJSON);
381
382         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
383         plugin.generateSequence(params,context);
384
385         String errorCode = context.getAttribute("error-code");
386         String errorMessage = context.getAttribute("error-message");
387         logger.debug("errorCode = " + errorCode);
388         Assert.assertEquals(errorCode,"401");
389         Assert.assertEquals(errorMessage,"Error generating sequence Dependency model missing vnfc type SMP");
390     }
391
392     @Test
393     public void testGenerateSequenceStartWithVmStartCaps()throws URISyntaxException, IOException {
394         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
395
396         String inputJSON = readInput("/input/StartWithVmStartCaps.json");
397
398         Map<String,String> params = new HashMap<>();
399         SvcLogicContext context = new SvcLogicContext();
400         context.setAttribute("inputJSON",inputJSON);
401
402         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
403         plugin.generateSequence(params,context);
404
405         String actualOutput = context.getAttribute("output");
406         String outputJSON = readOutput("/output/StartWithVmStartCaps.json");
407         Assert.assertEquals(outputJSON.trim(), actualOutput.trim());
408     }
409     
410     @Test
411     public void testGenerateSequenceRestartWithVmRestartCaps()throws URISyntaxException, IOException {
412         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
413
414         String inputJSON = readInput("/input/RestartWithVmRestartCaps.json");
415
416         Map<String,String> params = new HashMap<>();
417         SvcLogicContext context = new SvcLogicContext();
418         context.setAttribute("inputJSON",inputJSON);
419
420         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
421         plugin.generateSequence(params,context);
422
423         String actualOutput = context.getAttribute("output");
424         String outputJSON = readOutput("/output/RestartWithVmRestartCaps.json");
425         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
426     }
427     
428     @Test
429     public void testGenerateSequenceStopWithVmStopCaps()throws URISyntaxException, IOException {
430         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
431
432         String inputJSON = readInput("/input/StopWithVmStopCaps.json");
433
434         Map<String,String> params = new HashMap<>();
435         SvcLogicContext context = new SvcLogicContext();
436         context.setAttribute("inputJSON",inputJSON);
437
438         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
439         plugin.generateSequence(params,context);
440
441         String actualOutput = context.getAttribute("output");
442         String outputJSON = readOutput("/output/StopWithVmStopCaps.json");
443         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
444     }
445     
446     @Test
447     public void testGenerateSequenceStartWithoutAnyCaps()throws URISyntaxException, IOException {
448         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
449
450         String inputJSON = readInput("/input/StartWithoutAnyCaps.json");
451
452         Map<String,String> params = new HashMap<>();
453         SvcLogicContext context = new SvcLogicContext();
454         context.setAttribute("inputJSON",inputJSON);
455
456         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
457         plugin.generateSequence(params,context);
458
459         String actualOutput = context.getAttribute("output");
460         String outputJSON = readOutput("/output/StartWithoutAnyCaps.json");
461         Assert.assertEquals(outputJSON.trim(), actualOutput.trim());
462     }
463     
464     @Test
465     public void testGenerateSequenceRestartWithoutAnyCaps()throws URISyntaxException, IOException {
466         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
467
468         String inputJSON = readInput("/input/RestartWithoutAnyCaps.json");
469
470         Map<String,String> params = new HashMap<>();
471         SvcLogicContext context = new SvcLogicContext();
472         context.setAttribute("inputJSON",inputJSON);
473
474         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
475         plugin.generateSequence(params,context);
476
477         String actualOutput = context.getAttribute("output");
478         String outputJSON = readOutput("/output/RestartWithoutAnyCaps.json");
479         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
480     }
481     
482     @Test
483     public void testGenerateSequenceStopWithoutAnyCaps()throws URISyntaxException, IOException {
484         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
485
486         String inputJSON = readInput("/input/StopWithoutAnyCaps.json");
487
488         Map<String,String> params = new HashMap<>();
489         SvcLogicContext context = new SvcLogicContext();
490         context.setAttribute("inputJSON",inputJSON);
491
492         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
493         plugin.generateSequence(params,context);
494
495         String actualOutput = context.getAttribute("output");
496         String outputJSON = readOutput("/output/StopWithoutAnyCaps.json");
497         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
498     }
499
500     @Test
501     public void testGenerateSequenceStartWithoutVmStartCaps()throws URISyntaxException, IOException {
502         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
503
504         String inputJSON = readInput("/input/StartWithoutVmStartCaps.json");
505
506         Map<String,String> params = new HashMap<>();
507         SvcLogicContext context = new SvcLogicContext();
508         context.setAttribute("inputJSON",inputJSON);
509
510         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
511         plugin.generateSequence(params,context);
512
513         String actualOutput = context.getAttribute("output");
514         Assert.assertEquals(null, actualOutput);
515     }
516     
517     @Test
518     public void testGenerateSequenceRestartWithoutVmRestartCaps()throws URISyntaxException, IOException {
519         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
520
521         String inputJSON = readInput("/input/RestartWithoutVmRestartCaps.json");
522
523         Map<String,String> params = new HashMap<>();
524         SvcLogicContext context = new SvcLogicContext();
525         context.setAttribute("inputJSON",inputJSON);
526
527         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
528         plugin.generateSequence(params,context);
529
530         String actualOutput = context.getAttribute("output");
531         Assert.assertEquals(null, actualOutput);
532     }
533     
534     @Test
535     public void testGenerateSequenceStopWithoutVmStopCaps()throws URISyntaxException, IOException {
536         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
537
538         String inputJSON = readInput("/input/StopWithoutVmStopCaps.json");
539
540         Map<String,String> params = new HashMap<>();
541         SvcLogicContext context = new SvcLogicContext();
542         context.setAttribute("inputJSON",inputJSON);
543
544         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
545         plugin.generateSequence(params,context);
546
547         String actualOutput = context.getAttribute("output");
548         Assert.assertEquals(null, actualOutput);
549     }
550
551     @Test
552     public void testGenerateSequenceStartWithEmptyVmCaps()throws URISyntaxException, IOException {
553         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
554
555         String inputJSON = readInput("/input/StartWithEmptyVmCaps.json");
556
557         Map<String,String> params = new HashMap<>();
558         SvcLogicContext context = new SvcLogicContext();
559         context.setAttribute("inputJSON",inputJSON);
560
561         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
562         plugin.generateSequence(params,context);
563
564         String actualOutput = context.getAttribute("output");
565         String outputJSON = readOutput("/output/StartWithoutAnyCaps.json");
566         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
567     }
568
569     @Test
570     public void testGenerateSequenceRestartWithEmptyVmCaps()throws URISyntaxException, IOException {
571         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
572
573         String inputJSON = readInput("/input/RestartWithEmptyVmCaps.json");
574
575         Map<String,String> params = new HashMap<>();
576         SvcLogicContext context = new SvcLogicContext();
577         context.setAttribute("inputJSON",inputJSON);
578
579         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
580         plugin.generateSequence(params,context);
581
582         String actualOutput = context.getAttribute("output");
583         String outputJSON = readOutput("/output/RestartWithoutAnyCaps.json");
584         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
585     }
586
587     @Test
588     public void testGenerateSequenceStopWithEmptyVmCaps()throws URISyntaxException, IOException {
589         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
590
591         String inputJSON = readInput("/input/StopWithEmptyVmCaps.json");
592
593         Map<String,String> params = new HashMap<>();
594         SvcLogicContext context = new SvcLogicContext();
595         context.setAttribute("inputJSON",inputJSON);
596
597         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
598         plugin.generateSequence(params,context);
599
600         String actualOutput = context.getAttribute("output");
601         String outputJSON = readOutput("/output/StopWithoutAnyCaps.json");
602         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
603     }
604
605     @Test
606     public void testGenerateSequenceStartWithVmStartCapsAndMissingVnfcInfo()throws URISyntaxException, IOException {
607         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
608
609         String inputJSON = readInput("/input/StartWithVmStartCapsAndMissingVnfcInfo.json");
610
611         Map<String,String> params = new HashMap<>();
612         SvcLogicContext context = new SvcLogicContext();
613         context.setAttribute("inputJSON",inputJSON);
614
615         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
616         plugin.generateSequence(params,context);
617
618         String actualOutput = context.getAttribute("output");
619         String outputJSON = readOutput("/output/StartWithVmStartCapsAndMissingVnfcInfo.json");
620         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
621     }
622
623     @Test
624     public void testGenerateSequenceStopWithVmStopCapsAndMissingVnfcInfo()throws URISyntaxException, IOException {
625         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
626
627         String inputJSON = readInput("/input/StopWithVmStopCapsAndMissingVnfcInfo.json");
628
629         Map<String,String> params = new HashMap<>();
630         SvcLogicContext context = new SvcLogicContext();
631         context.setAttribute("inputJSON",inputJSON);
632
633         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
634         plugin.generateSequence(params,context);
635
636         String actualOutput = context.getAttribute("output");
637         String outputJSON = readOutput("/output/StopWithVmStopCapsAndMissingVnfcInfo.json");
638         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
639     }
640
641     @Test
642     public void testGenerateSequenceRestartWithVmRestartCapsAndMissingVnfcInfo()throws URISyntaxException, IOException {
643         logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
644
645         String inputJSON = readInput("/input/RestartWithVmRestartCapsAndMissingVnfcInfo.json");
646
647         Map<String,String> params = new HashMap<>();
648         SvcLogicContext context = new SvcLogicContext();
649         context.setAttribute("inputJSON",inputJSON);
650
651         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
652         plugin.generateSequence(params,context);
653
654         String actualOutput = context.getAttribute("output");
655         String outputJSON = readOutput("/output/RestartWithVmRestartCapsAndMissingVnfcInfo.json");
656         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
657     }
658
659     private String readInput(String inputFile) throws URISyntaxException, IOException {
660         return new String(Files.readAllBytes(Paths.get(this.getClass().getResource(inputFile).toURI())), "UTF-8");
661     }
662
663     private String readOutput(String outputFile) throws IOException,URISyntaxException {
664         String output = new String(Files.readAllBytes(Paths.get(this.getClass().getResource(outputFile).toURI())), "UTF-8");
665         int start=output.indexOf("[");
666         return output.substring(start,output.length());
667     }
668 }