2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.seqgen;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import org.junit.Assert;
29 import org.junit.Test;
30 import org.onap.appc.seqgen.dgplugin.SequenceGeneratorPlugin;
31 import org.onap.appc.seqgen.dgplugin.impl.SequenceGeneratorPluginImpl;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
35 import java.io.FileInputStream;
36 import java.io.IOException;
37 import java.net.URISyntaxException;
38 import java.util.HashMap;
41 public class TestSequenceGeneratorPlugin {
43 private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestSequenceGeneratorPlugin.class);
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 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
54 plugin.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 = readInput("/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 = readInput("/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 testGenerateSequenceStopWithoutDep() throws URISyntaxException,IOException{
284 String inputJSON = readInput("/input/stop-WithoutDep.json");
286 Map<String,String> params = new HashMap<>();
287 SvcLogicContext context = new SvcLogicContext();
288 context.setAttribute("inputJSON",inputJSON);
290 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
291 plugin.generateSequence(params,context);
293 String outputJSON = context.getAttribute("output");
294 String actualOutput = readOutput("/output/stop-WithoutDep.json");
296 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
300 public void testGenerateSequenceVnfcNotPresentInInventory() throws URISyntaxException, IOException {
301 String inputJSON = readInput("/input/CheckVNfcInInventory.json");
303 Map<String,String> params = new HashMap<>();
304 SvcLogicContext context = new SvcLogicContext();
305 context.setAttribute("inputJSON",inputJSON);
306 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
307 plugin.generateSequence(params,context);
309 String outputJSON = context.getAttribute("output");
310 String actualOutput = readOutput("/output/CheckVnfcInInventory.json");
312 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
316 public void testGenerateSequenceCheckMandatoryVnfc() throws URISyntaxException, IOException {
317 String inputJSON = readInput("/input/CheckMandatoryVnfc.json");
319 Map<String,String> params = new HashMap<>();
320 SvcLogicContext context = new SvcLogicContext();
321 context.setAttribute("inputJSON",inputJSON);
323 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
324 plugin.generateSequence(params,context);
326 String errorCode = context.getAttribute("error-code");
327 String errorMessage = context.getAttribute("error-message");
328 logger.debug("errorCode = " + errorCode);
329 Assert.assertEquals(errorCode,"401");
330 Assert.assertEquals(errorMessage,"Error generating sequence VMs missing for the mandatory VNFC : [smp]");
334 public void testGenerateSequenceCheckMissingDependencyInfo() throws URISyntaxException, IOException {
335 String inputJSON = readInput("/input/MissingDependencyInfo.json");
337 Map<String,String> params = new HashMap<>();
338 SvcLogicContext context = new SvcLogicContext();
339 context.setAttribute("inputJSON",inputJSON);
341 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
342 plugin.generateSequence(params,context);
344 String errorCode = context.getAttribute("error-code");
345 String errorMessage = context.getAttribute("error-message");
346 logger.debug("errorCode = " + errorCode);
347 Assert.assertEquals(errorCode,"401");
348 Assert.assertEquals(errorMessage,"Error generating sequence Dependency model is missing following vnfc type(s): [smp]");
352 public void testGenerateSequenceExtraVnfcInDependency() throws URISyntaxException, IOException {
353 String inputJSON = readInput("/input/WrongDependencyModel.json");
355 Map<String,String> params = new HashMap<>();
356 SvcLogicContext context = new SvcLogicContext();
357 context.setAttribute("inputJSON",inputJSON);
359 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
360 plugin.generateSequence(params,context);
362 String errorCode = context.getAttribute("error-code");
363 String errorMessage = context.getAttribute("error-message");
364 logger.debug("errorCode = " + errorCode);
365 Assert.assertEquals(errorCode,"401");
366 Assert.assertEquals(errorMessage,"Error generating sequence Dependency model missing vnfc type SMP");
369 private String readInput(String inputFile) throws URISyntaxException, IOException {
370 File file = new File(this.getClass().getResource(inputFile).toURI());
372 byte[] bFile = new byte[(int) file.length()];
373 FileInputStream fileInputStream = new FileInputStream(file);
374 fileInputStream.read(bFile);
375 fileInputStream.close();
376 return new String(bFile);
378 private String readOutput(String outputFile) throws IOException,URISyntaxException {
379 File file = new File(this.getClass().getResource(outputFile).toURI());
381 byte[] bFile = new byte[(int) file.length()];
382 FileInputStream fileInputStream = new FileInputStream(file);
383 fileInputStream.read(bFile);
384 fileInputStream.close();
385 String output=new String(bFile);
386 int start=output.indexOf("[");
387 return output.substring(start,output.length());