From 781b1a6df324419c846c84ea983c18fc8362bfd3 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:19:06 -0800 Subject: Third part of onap rename This part of the commit changes the folder structure on all other folders of appc. Change-Id: I8acfa11cdfcdcd36be0e137245d1dd7324f1abd3 Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../appc/seqgen/TestSequenceGeneratorPlugin.java | 272 +++++++++++++++++++++ .../appc/seqgen/TestSequenceGeneratorPlugin.java | 272 --------------------- 2 files changed, 272 insertions(+), 272 deletions(-) create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/onap/appc/seqgen/TestSequenceGeneratorPlugin.java delete mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/openecomp/appc/seqgen/TestSequenceGeneratorPlugin.java (limited to 'appc-sequence-generator/appc-sequence-generator-bundle/src/test') diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/onap/appc/seqgen/TestSequenceGeneratorPlugin.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/onap/appc/seqgen/TestSequenceGeneratorPlugin.java new file mode 100644 index 000000000..748773a21 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/onap/appc/seqgen/TestSequenceGeneratorPlugin.java @@ -0,0 +1,272 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.seqgen; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.junit.Assert; +import org.junit.Test; +import org.onap.appc.seqgen.dgplugin.SequenceGeneratorPlugin; +import org.onap.appc.seqgen.dgplugin.impl.SequenceGeneratorPluginImpl; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Map; + +public class TestSequenceGeneratorPlugin { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestSequenceGeneratorPlugin.class); + + @Test + public void testGenerateSequenceStart() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/start.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/start.json"); + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + + + @Test + public void testGenerateSequenceSingleVM()throws URISyntaxException, IOException { + String inputJSON = readInput("/input/start-single-vm.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/start-single-vm.json"); + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + @Test + public void testGenerateSequenceNoStrategy() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/no-strategy.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/start.json"); + + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + @Test + public void testGenerateSequenceStop() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/stop.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/stop.json"); + + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + @Test + public void testGenerateSequenceWrongNumber() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/wrongnumber.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String errorCode = context.getAttribute("error-code"); + String errorMessage = context.getAttribute("error-message"); + logger.debug("errorCode = " + errorCode); + Assert.assertEquals(errorCode,"401"); + Assert.assertEquals(errorMessage,"Error generating sequence Invalid Number for Wait Time 6a"); + } + + + @Test + public void testGenerateSequenceCyclic() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/cyclic.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String errorCode = context.getAttribute("error-code"); + String errorMessage = context.getAttribute("error-message"); + logger.debug("errorCode = " + errorCode); + Assert.assertEquals(errorCode,"401"); + Assert.assertEquals(errorMessage,"Error generating sequence There seems to be no Root/Independent node for Vnfc dependencies"); + } + + + @Test + public void testGenerateSequenceWrongAction() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/wrongaction.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String errorCode = context.getAttribute("error-code"); + String errorMessage = context.getAttribute("error-message"); + logger.debug("errorCode = " + errorCode); + Assert.assertEquals(errorCode,"401"); + Assert.assertEquals(errorMessage,"Error generating sequence Invalid Action start"); + } + + + @Test + public void testGenerateSequenceMissingRequestInfo() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/missingrequestinfo.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String errorCode = context.getAttribute("error-code"); + String errorMessage = context.getAttribute("error-message"); + logger.debug("errorCode = " + errorCode); + Assert.assertEquals(errorCode,"401"); + Assert.assertEquals(errorMessage,"Error generating sequence Request info is not provided in the input"); + } + + @Test + public void testGenerateSequenceStopSingleVM() throws URISyntaxException, IOException{ + String inputJSON = readInput("/input/stop-single-vm.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/stop-single-vm.json"); + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + @Test + public void testGenerateSequenceStopSingleVmPerVnfc() throws URISyntaxException, IOException{ + String inputJSON = readInput("/input/stop-single-vm-per-vnfc.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/stop-single-vm-per-vnfc.json"); + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + @Test + public void testGenerateSequenceStartSingleVmPerVnfc() throws URISyntaxException, IOException{ + String inputJSON = readInput("/input/start-single-vm-per-vnfc.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/start-single-vm-per-vnfc.json"); + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + @Test + public void testGenerateSequenceVnfcNotPresentInInventory() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/CheckVNfcInInventory.json"); + + Map params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/CheckVnfcInInventory.json"); + + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + + private String readInput(String inputFile) throws URISyntaxException, IOException { + File file = new File(this.getClass().getResource(inputFile).toURI()); + + byte[] bFile = new byte[(int) file.length()]; + FileInputStream fileInputStream = new FileInputStream(file); + fileInputStream.read(bFile); + fileInputStream.close(); + return new String(bFile); + } + private String readOutput(String outputFile) throws IOException,URISyntaxException { + File file = new File(this.getClass().getResource(outputFile).toURI()); + + byte[] bFile = new byte[(int) file.length()]; + FileInputStream fileInputStream = new FileInputStream(file); + fileInputStream.read(bFile); + fileInputStream.close(); + + String output=new String(bFile); + int start=output.indexOf("["); + int last=output.length(); + return output.substring(start,last); + + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/openecomp/appc/seqgen/TestSequenceGeneratorPlugin.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/openecomp/appc/seqgen/TestSequenceGeneratorPlugin.java deleted file mode 100644 index 748773a21..000000000 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/openecomp/appc/seqgen/TestSequenceGeneratorPlugin.java +++ /dev/null @@ -1,272 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APP-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.seqgen; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.junit.Assert; -import org.junit.Test; -import org.onap.appc.seqgen.dgplugin.SequenceGeneratorPlugin; -import org.onap.appc.seqgen.dgplugin.impl.SequenceGeneratorPluginImpl; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; - -public class TestSequenceGeneratorPlugin { - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestSequenceGeneratorPlugin.class); - - @Test - public void testGenerateSequenceStart() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/start.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/start.json"); - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - - - @Test - public void testGenerateSequenceSingleVM()throws URISyntaxException, IOException { - String inputJSON = readInput("/input/start-single-vm.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/start-single-vm.json"); - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - @Test - public void testGenerateSequenceNoStrategy() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/no-strategy.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/start.json"); - - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - @Test - public void testGenerateSequenceStop() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/stop.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/stop.json"); - - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - @Test - public void testGenerateSequenceWrongNumber() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/wrongnumber.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String errorCode = context.getAttribute("error-code"); - String errorMessage = context.getAttribute("error-message"); - logger.debug("errorCode = " + errorCode); - Assert.assertEquals(errorCode,"401"); - Assert.assertEquals(errorMessage,"Error generating sequence Invalid Number for Wait Time 6a"); - } - - - @Test - public void testGenerateSequenceCyclic() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/cyclic.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String errorCode = context.getAttribute("error-code"); - String errorMessage = context.getAttribute("error-message"); - logger.debug("errorCode = " + errorCode); - Assert.assertEquals(errorCode,"401"); - Assert.assertEquals(errorMessage,"Error generating sequence There seems to be no Root/Independent node for Vnfc dependencies"); - } - - - @Test - public void testGenerateSequenceWrongAction() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/wrongaction.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String errorCode = context.getAttribute("error-code"); - String errorMessage = context.getAttribute("error-message"); - logger.debug("errorCode = " + errorCode); - Assert.assertEquals(errorCode,"401"); - Assert.assertEquals(errorMessage,"Error generating sequence Invalid Action start"); - } - - - @Test - public void testGenerateSequenceMissingRequestInfo() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/missingrequestinfo.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String errorCode = context.getAttribute("error-code"); - String errorMessage = context.getAttribute("error-message"); - logger.debug("errorCode = " + errorCode); - Assert.assertEquals(errorCode,"401"); - Assert.assertEquals(errorMessage,"Error generating sequence Request info is not provided in the input"); - } - - @Test - public void testGenerateSequenceStopSingleVM() throws URISyntaxException, IOException{ - String inputJSON = readInput("/input/stop-single-vm.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/stop-single-vm.json"); - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - @Test - public void testGenerateSequenceStopSingleVmPerVnfc() throws URISyntaxException, IOException{ - String inputJSON = readInput("/input/stop-single-vm-per-vnfc.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/stop-single-vm-per-vnfc.json"); - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - @Test - public void testGenerateSequenceStartSingleVmPerVnfc() throws URISyntaxException, IOException{ - String inputJSON = readInput("/input/start-single-vm-per-vnfc.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/start-single-vm-per-vnfc.json"); - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - @Test - public void testGenerateSequenceVnfcNotPresentInInventory() throws URISyntaxException, IOException { - String inputJSON = readInput("/input/CheckVNfcInInventory.json"); - - Map params = new HashMap<>(); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("inputJSON",inputJSON); - SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); - plugin.generateSequence(params,context); - - String outputJSON = context.getAttribute("output"); - String actualOutput = readOutput("/output/CheckVnfcInInventory.json"); - - Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); - } - - private String readInput(String inputFile) throws URISyntaxException, IOException { - File file = new File(this.getClass().getResource(inputFile).toURI()); - - byte[] bFile = new byte[(int) file.length()]; - FileInputStream fileInputStream = new FileInputStream(file); - fileInputStream.read(bFile); - fileInputStream.close(); - return new String(bFile); - } - private String readOutput(String outputFile) throws IOException,URISyntaxException { - File file = new File(this.getClass().getResource(outputFile).toURI()); - - byte[] bFile = new byte[(int) file.length()]; - FileInputStream fileInputStream = new FileInputStream(file); - fileInputStream.read(bFile); - fileInputStream.close(); - - String output=new String(bFile); - int start=output.indexOf("["); - int last=output.length(); - return output.substring(start,last); - - } -} -- cgit