2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.seqgen;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.onap.appc.seqgen.dgplugin.SequenceGeneratorPlugin;
32 import org.onap.appc.seqgen.dgplugin.impl.SequenceGeneratorPluginImpl;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
36 import java.io.FileInputStream;
37 import java.io.IOException;
38 import java.net.URISyntaxException;
39 import java.util.HashMap;
42 public class TestSequenceGeneratorPlugin {
44 private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestSequenceGeneratorPlugin.class);
47 public void testGenerateSequenceStart() throws URISyntaxException, IOException {
48 String inputJSON = readInput("/input/start.json");
50 Map<String,String> params = new HashMap<>();
51 SvcLogicContext context = new SvcLogicContext();
52 context.setAttribute("inputJSON",inputJSON);
54 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
55 plugin.generateSequence(params,context);
57 String outputJSON = context.getAttribute("output");
58 String actualOutput = readOutput("/output/Start2.json");
59 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
63 public void testGenerateSequenceWODependencyInfo()throws URISyntaxException, IOException {
64 String inputJSON = readInput("/input/start-withoutDependency.json");
66 Map<String,String> params = new HashMap<>();
67 SvcLogicContext context = new SvcLogicContext();
68 context.setAttribute("inputJSON",inputJSON);
70 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
71 plugin.generateSequence(params,context);
73 String outputJSON = context.getAttribute("output");
74 String actualOutput = readOutput("/output/start-withoutDependency.json");
75 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
79 public void testGenerateSequenceSingleVM()throws URISyntaxException, IOException {
80 String inputJSON = readInput("/input/start-singleVM-.json");
82 Map<String,String> params = new HashMap<>();
83 SvcLogicContext context = new SvcLogicContext();
84 context.setAttribute("inputJSON",inputJSON);
86 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
87 plugin.generateSequence(params,context);
89 String outputJSON = context.getAttribute("output");
90 String actualOutput = readOutput("/output/start-singleVM-.json");
91 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
95 public void testGenerateSequenceNoStrategy() throws URISyntaxException, IOException {
96 String inputJSON = readInput("/input/no-strategy.json");
98 Map<String,String> params = new HashMap<>();
99 SvcLogicContext context = new SvcLogicContext();
100 context.setAttribute("inputJSON",inputJSON);
102 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
103 plugin.generateSequence(params,context);
105 String outputJSON = context.getAttribute("output");
106 String actualOutput = readOutput("/output/Start2.json");
108 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
112 public void testGenerateSequenceStop() throws URISyntaxException, IOException {
113 String inputJSON = readInput("/input/stop.json");
115 Map<String,String> params = new HashMap<>();
116 SvcLogicContext context = new SvcLogicContext();
117 context.setAttribute("inputJSON",inputJSON);
119 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
120 plugin.generateSequence(params,context);
122 String outputJSON = context.getAttribute("output");
123 String actualOutput = readOutput("/output/Output-stop.json");
125 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
129 public void testGenerateSequenceWrongNumber() throws URISyntaxException, IOException {
130 String inputJSON = readInput("/input/wrongnumber.json");
132 Map<String,String> params = new HashMap<>();
133 SvcLogicContext context = new SvcLogicContext();
134 context.setAttribute("inputJSON",inputJSON);
136 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
137 plugin.generateSequence(params,context);
139 String errorCode = context.getAttribute("error-code");
140 String errorMessage = context.getAttribute("error-message");
141 logger.debug("errorCode = " + errorCode);
142 Assert.assertEquals(errorCode,"401");
143 Assert.assertEquals(errorMessage,"Error generating sequence Invalid Number for Wait Time 6a");
148 public void testGenerateSequenceCyclic() throws URISyntaxException, IOException {
149 String inputJSON = readInput("/input/cyclic.json");
151 Map<String,String> params = new HashMap<>();
152 SvcLogicContext context = new SvcLogicContext();
153 context.setAttribute("inputJSON",inputJSON);
155 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
156 plugin.generateSequence(params,context);
158 String errorCode = context.getAttribute("error-code");
159 String errorMessage = context.getAttribute("error-message");
160 logger.debug("errorCode = " + errorCode);
161 Assert.assertEquals(errorCode,"401");
162 Assert.assertEquals(errorMessage,"Error generating sequence There seems to be no Root/Independent node for Vnfc dependencies");
166 public void testGenerateSequenceWrongAction() throws URISyntaxException, IOException {
167 String inputJSON = readInput("/input/wrongaction.json");
169 Map<String,String> params = new HashMap<>();
170 SvcLogicContext context = new SvcLogicContext();
171 context.setAttribute("inputJSON",inputJSON);
173 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
174 plugin.generateSequence(params,context);
176 String errorCode = context.getAttribute("error-code");
177 String errorMessage = context.getAttribute("error-message");
178 logger.debug("errorCode = " + errorCode);
179 Assert.assertEquals(errorCode,"401");
180 Assert.assertEquals(errorMessage,"Error generating sequence Invalid Action start");
185 public void testGenerateSequenceMissingRequestInfo() throws URISyntaxException, IOException {
186 String inputJSON = readInput("/input/missingrequestinfo.json");
188 Map<String,String> params = new HashMap<>();
189 SvcLogicContext context = new SvcLogicContext();
190 context.setAttribute("inputJSON",inputJSON);
192 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
193 plugin.generateSequence(params,context);
195 String errorCode = context.getAttribute("error-code");
196 String errorMessage = context.getAttribute("error-message");
197 logger.debug("errorCode = " + errorCode);
198 Assert.assertEquals(errorCode,"401");
199 Assert.assertEquals(errorMessage,"Error generating sequence Request info is not provided in the input");
203 public void testGenerateSequenceStopSingleVM() throws URISyntaxException, IOException{
204 String inputJSON = readInput("/input/stop-singleVM.json");
206 Map<String,String> params = new HashMap<>();
207 SvcLogicContext context = new SvcLogicContext();
208 context.setAttribute("inputJSON",inputJSON);
210 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
211 plugin.generateSequence(params,context);
213 String outputJSON = context.getAttribute("output");
214 String actualOutput = readOutput("/output/stop-singleVM.json");
215 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
219 public void testGenerateSequenceStopSingleVmPerVnfc() throws URISyntaxException, IOException{
220 String inputJSON = readInput("/input/stop-singleVmPerVnfc.json");
222 Map<String,String> params = new HashMap<>();
223 SvcLogicContext context = new SvcLogicContext();
224 context.setAttribute("inputJSON",inputJSON);
226 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
227 plugin.generateSequence(params,context);
229 String outputJSON = context.getAttribute("output");
230 String actualOutput = readOutput("/output/stop-singleVmPerVnfc.json");
231 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
235 public void testGenerateSequenceRestartNoDep() throws URISyntaxException, IOException {
236 String inputJSON = readInput("/input/restartNodep.json");
238 Map<String,String> params = new HashMap<>();
239 SvcLogicContext context = new SvcLogicContext();
240 context.setAttribute("inputJSON",inputJSON);
242 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
243 plugin.generateSequence(params,context);
245 String outputJSON = context.getAttribute("output");
246 String actualOutput = readInput("/output/restart-NoDep.json");
248 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
252 public void testGenerateSequenceRestartNoDepSingleVM() throws URISyntaxException, IOException {
253 String inputJSON = readInput("/input/NoDep-SingleVM.json");
255 Map<String,String> params = new HashMap<>();
256 SvcLogicContext context = new SvcLogicContext();
257 context.setAttribute("inputJSON",inputJSON);
259 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
260 plugin.generateSequence(params,context);
262 String outputJSON = context.getAttribute("output");
263 String actualOutput = readInput("/output/restart-Nodep-SingleVM.json");
264 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
268 public void testGenerateSequenceStartSingleVmPerVnfc() throws URISyntaxException, IOException{
269 String inputJSON = readInput("/input/start-singleVmPerVnfc-.json");
271 Map<String,String> params = new HashMap<>();
272 SvcLogicContext context = new SvcLogicContext();
273 context.setAttribute("inputJSON",inputJSON);
275 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
276 plugin.generateSequence(params,context);
278 String outputJSON = context.getAttribute("output");
279 String actualOutput = readOutput("/output/start-singleVmPerVnfc.json");
280 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
284 public void testGenerateSequenceStopWithoutDep() throws URISyntaxException,IOException{
285 String inputJSON = readInput("/input/stop-WithoutDep.json");
287 Map<String,String> params = new HashMap<>();
288 SvcLogicContext context = new SvcLogicContext();
289 context.setAttribute("inputJSON",inputJSON);
291 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
292 plugin.generateSequence(params,context);
294 String outputJSON = context.getAttribute("output");
295 String actualOutput = readOutput("/output/stop-WithoutDep.json");
297 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
301 public void testGenerateSequenceVnfcNotPresentInInventory() throws URISyntaxException, IOException {
302 String inputJSON = readInput("/input/CheckVNfcInInventory.json");
304 Map<String,String> params = new HashMap<>();
305 SvcLogicContext context = new SvcLogicContext();
306 context.setAttribute("inputJSON",inputJSON);
307 SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
308 plugin.generateSequence(params,context);
310 String outputJSON = context.getAttribute("output");
311 String actualOutput = readOutput("/output/CheckVnfcInInventory.json");
313 Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
317 public void testGenerateSequenceCheckMandatoryVnfc() throws URISyntaxException, IOException {
318 String inputJSON = readInput("/input/CheckMandatoryVnfc.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 VMs missing for the mandatory VNFC : [smp]");
335 public void testGenerateSequenceCheckMissingDependencyInfo() throws URISyntaxException, IOException {
336 String inputJSON = readInput("/input/MissingDependencyInfo.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 is missing following vnfc type(s): [smp]");
353 public void testGenerateSequenceExtraVnfcInDependency() throws URISyntaxException, IOException {
354 String inputJSON = readInput("/input/WrongDependencyModel.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 errorCode = context.getAttribute("error-code");
364 String errorMessage = context.getAttribute("error-message");
365 logger.debug("errorCode = " + errorCode);
366 Assert.assertEquals(errorCode,"401");
367 Assert.assertEquals(errorMessage,"Error generating sequence Dependency model missing vnfc type SMP");
370 private String readInput(String inputFile) throws URISyntaxException, IOException {
371 File file = new File(this.getClass().getResource(inputFile).toURI());
373 byte[] bFile = new byte[(int) file.length()];
374 FileInputStream fileInputStream = new FileInputStream(file);
375 fileInputStream.read(bFile);
376 fileInputStream.close();
377 return new String(bFile);
379 private String readOutput(String outputFile) throws IOException,URISyntaxException {
380 File file = new File(this.getClass().getResource(outputFile).toURI());
382 byte[] bFile = new byte[(int) file.length()];
383 FileInputStream fileInputStream = new FileInputStream(file);
384 fileInputStream.read(bFile);
385 fileInputStream.close();
386 String output=new String(bFile);
387 int start=output.indexOf("[");
388 return output.substring(start,output.length());