2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * ============LICENSE_END=========================================================
22 package org.onap.appc.seqgen;
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;
31 import org.junit.Assert;
32 import org.junit.Test;
33 import org.onap.appc.seqgen.dgplugin.SequenceGeneratorPlugin;
34 import org.onap.appc.seqgen.dgplugin.impl.SequenceGeneratorPluginImpl;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
37 import com.att.eelf.configuration.EELFLogger;
38 import com.att.eelf.configuration.EELFManager;
40 public class TestSequenceGeneratorPlugin {
42 private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestSequenceGeneratorPlugin.class);
43 private SequenceGeneratorPlugin seqImpl;
46 public void testGenerateSequenceStart() throws URISyntaxException, IOException {
47 String inputJSON = readInput("/input/start.json");
49 Map<String,String> params = new HashMap<>();
50 SvcLogicContext context = new SvcLogicContext();
51 context.setAttribute("inputJSON",inputJSON);
53 seqImpl = new SequenceGeneratorPluginImpl();
54 seqImpl.generateSequence(params,context);
56 String outputJSON = context.getAttribute("output");
57 String actualOutput = readOutput("/output/Start2.json");
58 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
62 public void testGenerateSequenceWODependencyInfo()throws URISyntaxException, IOException {
63 String inputJSON = readInput("/input/start-withoutDependency.json");
65 Map<String,String> params = new HashMap<>();
66 SvcLogicContext context = new SvcLogicContext();
67 context.setAttribute("inputJSON",inputJSON);
69 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
70 plugin.generateSequence(params,context);
72 String outputJSON = context.getAttribute("output");
73 String actualOutput = readOutput("/output/start-withoutDependency.json");
74 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
78 public void testGenerateSequenceSingleVM()throws URISyntaxException, IOException {
79 String inputJSON = readInput("/input/start-singleVM-.json");
81 Map<String,String> params = new HashMap<>();
82 SvcLogicContext context = new SvcLogicContext();
83 context.setAttribute("inputJSON",inputJSON);
85 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
86 plugin.generateSequence(params,context);
88 String outputJSON = context.getAttribute("output");
89 String actualOutput = readOutput("/output/start-singleVM-.json");
90 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
94 public void testGenerateSequenceNoStrategy() throws URISyntaxException, IOException {
95 String inputJSON = readInput("/input/no-strategy.json");
97 Map<String,String> params = new HashMap<>();
98 SvcLogicContext context = new SvcLogicContext();
99 context.setAttribute("inputJSON",inputJSON);
101 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
102 plugin.generateSequence(params,context);
104 String outputJSON = context.getAttribute("output");
105 String actualOutput = readOutput("/output/Start2.json");
107 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
111 public void testGenerateSequenceStop() throws URISyntaxException, IOException {
112 String inputJSON = readInput("/input/stop.json");
114 Map<String,String> params = new HashMap<>();
115 SvcLogicContext context = new SvcLogicContext();
116 context.setAttribute("inputJSON",inputJSON);
118 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
119 plugin.generateSequence(params,context);
121 String outputJSON = context.getAttribute("output");
122 String actualOutput = readOutput("/output/Output-stop.json");
124 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
128 public void testGenerateSequenceWrongNumber() throws URISyntaxException, IOException {
129 String inputJSON = readInput("/input/wrongnumber.json");
131 Map<String,String> params = new HashMap<>();
132 SvcLogicContext context = new SvcLogicContext();
133 context.setAttribute("inputJSON",inputJSON);
135 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
136 plugin.generateSequence(params,context);
138 String errorCode = context.getAttribute("error-code");
139 String errorMessage = context.getAttribute("error-message");
140 logger.debug("errorCode = " + errorCode);
141 Assert.assertEquals(errorCode,"401");
142 Assert.assertEquals(errorMessage,"Error generating sequence Invalid Number for Wait Time 6a");
147 public void testGenerateSequenceCyclic() throws URISyntaxException, IOException {
148 String inputJSON = readInput("/input/cyclic.json");
150 Map<String,String> params = new HashMap<>();
151 SvcLogicContext context = new SvcLogicContext();
152 context.setAttribute("inputJSON",inputJSON);
154 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
155 plugin.generateSequence(params,context);
157 String errorCode = context.getAttribute("error-code");
158 String errorMessage = context.getAttribute("error-message");
159 logger.debug("errorCode = " + errorCode);
160 Assert.assertEquals(errorCode,"401");
161 Assert.assertEquals(errorMessage,"Error generating sequence There seems to be no Root/Independent node for Vnfc dependencies");
165 public void testGenerateSequenceWrongAction() throws URISyntaxException, IOException {
166 String inputJSON = readInput("/input/wrongaction.json");
168 Map<String,String> params = new HashMap<>();
169 SvcLogicContext context = new SvcLogicContext();
170 context.setAttribute("inputJSON",inputJSON);
172 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
173 plugin.generateSequence(params,context);
175 String errorCode = context.getAttribute("error-code");
176 String errorMessage = context.getAttribute("error-message");
177 logger.debug("errorCode = " + errorCode);
178 Assert.assertEquals(errorCode,"401");
179 Assert.assertEquals(errorMessage,"Error generating sequence Invalid Action start");
184 public void testGenerateSequenceMissingRequestInfo() throws URISyntaxException, IOException {
185 String inputJSON = readInput("/input/missingrequestinfo.json");
187 Map<String,String> params = new HashMap<>();
188 SvcLogicContext context = new SvcLogicContext();
189 context.setAttribute("inputJSON",inputJSON);
191 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
192 plugin.generateSequence(params,context);
194 String errorCode = context.getAttribute("error-code");
195 String errorMessage = context.getAttribute("error-message");
196 logger.debug("errorCode = " + errorCode);
197 Assert.assertEquals(errorCode,"401");
198 Assert.assertEquals(errorMessage,"Error generating sequence Request info is not provided in the input");
202 public void testGenerateSequenceStopSingleVM() throws URISyntaxException, IOException{
203 String inputJSON = readInput("/input/stop-singleVM.json");
205 Map<String,String> params = new HashMap<>();
206 SvcLogicContext context = new SvcLogicContext();
207 context.setAttribute("inputJSON",inputJSON);
209 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
210 plugin.generateSequence(params,context);
212 String outputJSON = context.getAttribute("output");
213 String actualOutput = readOutput("/output/stop-singleVM.json");
214 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
218 public void testGenerateSequenceStopSingleVmPerVnfc() throws URISyntaxException, IOException{
219 String inputJSON = readInput("/input/stop-singleVmPerVnfc.json");
221 Map<String,String> params = new HashMap<>();
222 SvcLogicContext context = new SvcLogicContext();
223 context.setAttribute("inputJSON",inputJSON);
225 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
226 plugin.generateSequence(params,context);
228 String outputJSON = context.getAttribute("output");
229 String actualOutput = readOutput("/output/stop-singleVmPerVnfc.json");
230 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
234 public void testGenerateSequenceRestartNoDep() throws URISyntaxException, IOException {
235 String inputJSON = readInput("/input/restartNodep.json");
237 Map<String,String> params = new HashMap<>();
238 SvcLogicContext context = new SvcLogicContext();
239 context.setAttribute("inputJSON",inputJSON);
241 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
242 plugin.generateSequence(params,context);
244 String outputJSON = context.getAttribute("output");
245 String actualOutput = readOutput("/output/restart-NoDep.json");
247 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
251 public void testGenerateSequenceRestartNoDepSingleVM() throws URISyntaxException, IOException {
252 String inputJSON = readInput("/input/NoDep-SingleVM.json");
254 Map<String,String> params = new HashMap<>();
255 SvcLogicContext context = new SvcLogicContext();
256 context.setAttribute("inputJSON",inputJSON);
258 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
259 plugin.generateSequence(params,context);
261 String outputJSON = context.getAttribute("output");
262 String actualOutput = readOutput("/output/restart-Nodep-SingleVM.json");
263 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
267 public void testGenerateSequenceStartSingleVmPerVnfc() throws URISyntaxException, IOException{
268 String inputJSON = readInput("/input/start-singleVmPerVnfc-.json");
270 Map<String,String> params = new HashMap<>();
271 SvcLogicContext context = new SvcLogicContext();
272 context.setAttribute("inputJSON",inputJSON);
274 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
275 plugin.generateSequence(params,context);
277 String outputJSON = context.getAttribute("output");
278 String actualOutput = readOutput("/output/start-singleVmPerVnfc.json");
279 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
283 public void testGenerateSequenceVnfcNotPresentInInventory() throws URISyntaxException, IOException {
284 String inputJSON = readInput("/input/CheckVNfcInInventory.json");
286 Map<String,String> params = new HashMap<>();
287 SvcLogicContext context = new SvcLogicContext();
288 context.setAttribute("inputJSON",inputJSON);
289 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
290 plugin.generateSequence(params,context);
292 String outputJSON = context.getAttribute("output");
293 String actualOutput = readOutput("/output/CheckVnfcInInventory.json");
295 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
299 public void testGenerateSequenceCheckMandatoryVnfc() throws URISyntaxException, IOException {
300 String inputJSON = readInput("/input/CheckMandatoryVnfc.json");
302 Map<String,String> params = new HashMap<>();
303 SvcLogicContext context = new SvcLogicContext();
304 context.setAttribute("inputJSON",inputJSON);
306 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
307 plugin.generateSequence(params,context);
309 String errorCode = context.getAttribute("error-code");
310 String errorMessage = context.getAttribute("error-message");
311 logger.debug("errorCode = " + errorCode);
312 Assert.assertEquals(errorCode,"401");
313 Assert.assertEquals(errorMessage,"Error generating sequence VMs missing for the mandatory VNFC : [smp]");
317 public void testGenerateSequenceCheckMissingDependencyInfo() throws URISyntaxException, IOException {
318 String inputJSON = readInput("/input/MissingDependencyInfo.json");
320 Map<String,String> params = new HashMap<>();
321 SvcLogicContext context = new SvcLogicContext();
322 context.setAttribute("inputJSON",inputJSON);
324 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
325 plugin.generateSequence(params,context);
327 String errorCode = context.getAttribute("error-code");
328 String errorMessage = context.getAttribute("error-message");
329 logger.debug("errorCode = " + errorCode);
330 Assert.assertEquals(errorCode,"401");
331 Assert.assertEquals(errorMessage,"Error generating sequence Dependency model is missing following vnfc type(s): [smp]");
335 public void testGenerateSequenceExtraVnfcInDependency() throws URISyntaxException, IOException {
336 String inputJSON = readInput("/input/WrongDependencyModel.json");
338 Map<String,String> params = new HashMap<>();
339 SvcLogicContext context = new SvcLogicContext();
340 context.setAttribute("inputJSON",inputJSON);
342 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
343 plugin.generateSequence(params,context);
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 Dependency model missing vnfc type SMP");
353 public void testGenerateSequenceStartWithVmStartCaps()throws URISyntaxException, IOException {
354 String inputJSON = readInput("/input/StartWithVmStartCaps.json");
356 Map<String,String> params = new HashMap<>();
357 SvcLogicContext context = new SvcLogicContext();
358 context.setAttribute("inputJSON",inputJSON);
360 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
361 plugin.generateSequence(params,context);
363 String actualOutput = context.getAttribute("output");
364 String outputJSON = readOutput("/output/StartWithVmStartCaps.json");
365 Assert.assertEquals(outputJSON.trim(), actualOutput.trim());
369 public void testGenerateSequenceRestartWithVmRestartCaps()throws URISyntaxException, IOException {
370 String inputJSON = readInput("/input/RestartWithVmRestartCaps.json");
372 Map<String,String> params = new HashMap<>();
373 SvcLogicContext context = new SvcLogicContext();
374 context.setAttribute("inputJSON",inputJSON);
376 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
377 plugin.generateSequence(params,context);
379 String outputJSON = context.getAttribute("output");
380 String actualOutput = readOutput("/output/RestartWithVmRestartCaps.json");
381 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
385 public void testGenerateSequenceStopWithVmStopCaps()throws URISyntaxException, IOException {
386 String inputJSON = readInput("/input/StopWithVmStopCaps.json");
388 Map<String,String> params = new HashMap<>();
389 SvcLogicContext context = new SvcLogicContext();
390 context.setAttribute("inputJSON",inputJSON);
392 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
393 plugin.generateSequence(params,context);
395 String actualOutput = context.getAttribute("output");
396 String outputJSON = readOutput("/output/StopWithVmStopCaps.json");
397 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
401 public void testGenerateSequenceStartWithoutAnyCaps()throws URISyntaxException, IOException {
402 String inputJSON = readInput("/input/StartWithoutAnyCaps.json");
404 Map<String,String> params = new HashMap<>();
405 SvcLogicContext context = new SvcLogicContext();
406 context.setAttribute("inputJSON",inputJSON);
408 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
409 plugin.generateSequence(params,context);
411 String actualOutput = context.getAttribute("output");
412 String outputJSON = readOutput("/output/StartWithoutAnyCaps.json");
413 Assert.assertEquals(outputJSON.trim(), actualOutput.trim());
417 public void testGenerateSequenceRestartWithoutAnyCaps()throws URISyntaxException, IOException {
418 String inputJSON = readInput("/input/RestartWithoutAnyCaps.json");
420 Map<String,String> params = new HashMap<>();
421 SvcLogicContext context = new SvcLogicContext();
422 context.setAttribute("inputJSON",inputJSON);
424 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
425 plugin.generateSequence(params,context);
427 String outputJSON = context.getAttribute("output");
428 String actualOutput = readOutput("/output/RestartWithoutAnyCaps.json");
429 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
433 public void testGenerateSequenceStopWithoutAnyCaps()throws URISyntaxException, IOException {
434 String inputJSON = readInput("/input/StopWithoutAnyCaps.json");
436 Map<String,String> params = new HashMap<>();
437 SvcLogicContext context = new SvcLogicContext();
438 context.setAttribute("inputJSON",inputJSON);
440 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
441 plugin.generateSequence(params,context);
443 String outputJSON = context.getAttribute("output");
444 String actualOutput = readOutput("/output/StopWithoutAnyCaps.json");
445 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
448 public void testGenerateSequenceStartWithoutVmStartCaps()throws URISyntaxException, IOException {
449 String inputJSON = readInput("/input/StartWithoutVmStartCaps.json");
451 Map<String,String> params = new HashMap<>();
452 SvcLogicContext context = new SvcLogicContext();
453 context.setAttribute("inputJSON",inputJSON);
455 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
456 plugin.generateSequence(params,context);
458 String errorCode = context.getAttribute("error-code");
459 String errorMessage = context.getAttribute("error-message");
460 logger.debug("errorCode = " + errorCode);
461 Assert.assertEquals("450", errorCode);
462 Assert.assertEquals("Request is not supported", errorMessage);
466 public void testGenerateSequenceRestartWithoutVmRestartCaps()throws URISyntaxException, IOException {
467 String inputJSON = readInput("/input/RestartWithoutVmRestartCaps.json");
469 Map<String,String> params = new HashMap<>();
470 SvcLogicContext context = new SvcLogicContext();
471 context.setAttribute("inputJSON",inputJSON);
473 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
474 plugin.generateSequence(params,context);
476 String errorCode = context.getAttribute("error-code");
477 String errorMessage = context.getAttribute("error-message");
478 logger.debug("errorCode = " + errorCode);
479 Assert.assertEquals("450", errorCode);
480 Assert.assertEquals("Request is not supported", errorMessage);
484 public void testGenerateSequenceStopWithoutVmStopCaps()throws URISyntaxException, IOException {
485 String inputJSON = readInput("/input/StopWithoutVmStopCaps.json");
487 Map<String,String> params = new HashMap<>();
488 SvcLogicContext context = new SvcLogicContext();
489 context.setAttribute("inputJSON",inputJSON);
491 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
492 plugin.generateSequence(params,context);
494 String errorCode = context.getAttribute("error-code");
495 String errorMessage = context.getAttribute("error-message");
496 logger.debug("errorCode = " + errorCode);
497 Assert.assertEquals("450", errorCode);
498 Assert.assertEquals("Request is not supported", errorMessage);
501 private String readInput(String inputFile) throws URISyntaxException, IOException {
502 return new String(Files.readAllBytes(Paths.get(this.getClass().getResource(inputFile).toURI())), "UTF-8");
505 private String readOutput(String outputFile) throws IOException,URISyntaxException {
506 String output = new String(Files.readAllBytes(Paths.get(this.getClass().getResource(outputFile).toURI())), "UTF-8");
507 int start=output.indexOf("[");
508 return output.substring(start,output.length());