Add vm caps fixes to sequence-generator code (vm caps)
[appc.git] / appc-sequence-generator / appc-sequence-generator-bundle / src / test / java / org / onap / appc / seqgen / TestSequenceGeneratorPlugin.java
index 5fddce1..c5d82ba 100644 (file)
@@ -29,7 +29,9 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.junit.Assert;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TestName;
 import org.onap.appc.seqgen.dgplugin.SequenceGeneratorPlugin;
 import org.onap.appc.seqgen.dgplugin.impl.SequenceGeneratorPluginImpl;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
@@ -38,12 +40,16 @@ import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 
 public class TestSequenceGeneratorPlugin {
+    @Rule
+    public final TestName thisTestName = new TestName();
 
     private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestSequenceGeneratorPlugin.class);
     private SequenceGeneratorPlugin seqImpl;
 
     @Test
     public void testGenerateSequenceStart() throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/start.json");
 
         Map<String,String> params = new HashMap<>();
@@ -60,6 +66,8 @@ public class TestSequenceGeneratorPlugin {
 
     @Test
     public void testGenerateSequenceWODependencyInfo()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/start-withoutDependency.json");
 
         Map<String,String> params = new HashMap<>();
@@ -76,6 +84,8 @@ public class TestSequenceGeneratorPlugin {
 
     @Test
     public void testGenerateSequenceSingleVM()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/start-singleVM-.json");
 
         Map<String,String> params = new HashMap<>();
@@ -92,6 +102,8 @@ public class TestSequenceGeneratorPlugin {
 
     @Test
     public void testGenerateSequenceNoStrategy() throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/no-strategy.json");
 
         Map<String,String> params = new HashMap<>();
@@ -109,6 +121,8 @@ public class TestSequenceGeneratorPlugin {
 
     @Test
     public void testGenerateSequenceStop() throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/stop.json");
 
         Map<String,String> params = new HashMap<>();
@@ -126,6 +140,8 @@ public class TestSequenceGeneratorPlugin {
 
     @Test
     public void testGenerateSequenceWrongNumber() throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/wrongnumber.json");
 
         Map<String,String> params = new HashMap<>();
@@ -137,7 +153,7 @@ public class TestSequenceGeneratorPlugin {
 
         String errorCode = context.getAttribute("error-code");
         String errorMessage = context.getAttribute("error-message");
-        logger.debug("errorCode = " + errorCode);
+        logger.info("errorCode = " + errorCode);
         Assert.assertEquals(errorCode,"401");
         Assert.assertEquals(errorMessage,"Error generating sequence Invalid Number for Wait Time 6a");
     }
@@ -145,6 +161,8 @@ public class TestSequenceGeneratorPlugin {
 
     @Test
     public void testGenerateSequenceCyclic() throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/cyclic.json");
 
         Map<String,String> params = new HashMap<>();
@@ -156,13 +174,15 @@ public class TestSequenceGeneratorPlugin {
 
         String errorCode = context.getAttribute("error-code");
         String errorMessage = context.getAttribute("error-message");
-        logger.debug("errorCode = " + errorCode);
+        logger.info("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 {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/wrongaction.json");
 
         Map<String,String> params = new HashMap<>();
@@ -174,7 +194,7 @@ public class TestSequenceGeneratorPlugin {
 
         String errorCode = context.getAttribute("error-code");
         String errorMessage = context.getAttribute("error-message");
-        logger.debug("errorCode = " + errorCode);
+        logger.info("errorCode = " + errorCode);
         Assert.assertEquals(errorCode,"401");
         Assert.assertEquals(errorMessage,"Error generating sequence Invalid Action start");
     }
@@ -182,6 +202,8 @@ public class TestSequenceGeneratorPlugin {
 
     @Test
     public void testGenerateSequenceMissingRequestInfo() throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/missingrequestinfo.json");
 
         Map<String,String> params = new HashMap<>();
@@ -200,6 +222,8 @@ public class TestSequenceGeneratorPlugin {
 
     @Test
     public void testGenerateSequenceStopSingleVM() throws URISyntaxException, IOException{
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/stop-singleVM.json");
 
         Map<String,String> params = new HashMap<>();
@@ -216,6 +240,8 @@ public class TestSequenceGeneratorPlugin {
 
     @Test
     public void testGenerateSequenceStopSingleVmPerVnfc() throws URISyntaxException, IOException{
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/stop-singleVmPerVnfc.json");
 
         Map<String,String> params = new HashMap<>();
@@ -232,6 +258,8 @@ public class TestSequenceGeneratorPlugin {
 
     @Test
     public void testGenerateSequenceRestartNoDep() throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/restartNodep.json");
 
         Map<String,String> params = new HashMap<>();
@@ -241,14 +269,16 @@ public class TestSequenceGeneratorPlugin {
         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
         plugin.generateSequence(params,context);
 
-        String outputJSON = context.getAttribute("output");
-        String actualOutput = readOutput("/output/restart-NoDep.json");
+        String actualOutput = context.getAttribute("output");
+        String outputJSON = readOutput("/output/restart-NoDep.json");
         outputJSON.trim();
         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
     }
 
     @Test
     public void testGenerateSequenceRestartNoDepSingleVM() throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/NoDep-SingleVM.json");
 
         Map<String,String> params = new HashMap<>();
@@ -258,13 +288,15 @@ public class TestSequenceGeneratorPlugin {
         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
         plugin.generateSequence(params,context);
 
-        String outputJSON = context.getAttribute("output");
-        String actualOutput = readOutput("/output/restart-Nodep-SingleVM.json");
+        String actualOutput = context.getAttribute("output");
+        String outputJSON = readOutput("/output/restart-Nodep-SingleVM.json");
         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
     }
 
     @Test
     public void testGenerateSequenceStartSingleVmPerVnfc() throws URISyntaxException, IOException{
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/start-singleVmPerVnfc-.json");
 
         Map<String,String> params = new HashMap<>();
@@ -281,6 +313,8 @@ public class TestSequenceGeneratorPlugin {
 
     @Test
     public void testGenerateSequenceVnfcNotPresentInInventory() throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/CheckVNfcInInventory.json");
 
         Map<String,String> params = new HashMap<>();
@@ -297,6 +331,8 @@ public class TestSequenceGeneratorPlugin {
 
     @Test
     public void testGenerateSequenceCheckMandatoryVnfc() throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/CheckMandatoryVnfc.json");
 
         Map<String,String> params = new HashMap<>();
@@ -315,6 +351,8 @@ public class TestSequenceGeneratorPlugin {
 
     @Test
     public void testGenerateSequenceCheckMissingDependencyInfo() throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/MissingDependencyInfo.json");
 
         Map<String,String> params = new HashMap<>();
@@ -333,6 +371,8 @@ public class TestSequenceGeneratorPlugin {
 
     @Test
     public void testGenerateSequenceExtraVnfcInDependency() throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/WrongDependencyModel.json");
 
         Map<String,String> params = new HashMap<>();
@@ -351,6 +391,8 @@ public class TestSequenceGeneratorPlugin {
 
     @Test
     public void testGenerateSequenceStartWithVmStartCaps()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/StartWithVmStartCaps.json");
 
         Map<String,String> params = new HashMap<>();
@@ -367,6 +409,8 @@ public class TestSequenceGeneratorPlugin {
     
     @Test
     public void testGenerateSequenceRestartWithVmRestartCaps()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/RestartWithVmRestartCaps.json");
 
         Map<String,String> params = new HashMap<>();
@@ -376,13 +420,15 @@ public class TestSequenceGeneratorPlugin {
         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
         plugin.generateSequence(params,context);
 
-        String outputJSON = context.getAttribute("output");
-        String actualOutput = readOutput("/output/RestartWithVmRestartCaps.json");
+        String actualOutput = context.getAttribute("output");
+        String outputJSON = readOutput("/output/RestartWithVmRestartCaps.json");
         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
     }
     
     @Test
     public void testGenerateSequenceStopWithVmStopCaps()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/StopWithVmStopCaps.json");
 
         Map<String,String> params = new HashMap<>();
@@ -399,6 +445,8 @@ public class TestSequenceGeneratorPlugin {
     
     @Test
     public void testGenerateSequenceStartWithoutAnyCaps()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/StartWithoutAnyCaps.json");
 
         Map<String,String> params = new HashMap<>();
@@ -415,6 +463,8 @@ public class TestSequenceGeneratorPlugin {
     
     @Test
     public void testGenerateSequenceRestartWithoutAnyCaps()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/RestartWithoutAnyCaps.json");
 
         Map<String,String> params = new HashMap<>();
@@ -424,13 +474,15 @@ public class TestSequenceGeneratorPlugin {
         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
         plugin.generateSequence(params,context);
 
-        String outputJSON = context.getAttribute("output");
-        String actualOutput = readOutput("/output/RestartWithoutAnyCaps.json");
+        String actualOutput = context.getAttribute("output");
+        String outputJSON = readOutput("/output/RestartWithoutAnyCaps.json");
         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
     }
     
     @Test
     public void testGenerateSequenceStopWithoutAnyCaps()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/StopWithoutAnyCaps.json");
 
         Map<String,String> params = new HashMap<>();
@@ -440,12 +492,15 @@ public class TestSequenceGeneratorPlugin {
         SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
         plugin.generateSequence(params,context);
 
-        String outputJSON = context.getAttribute("output");
-        String actualOutput = readOutput("/output/StopWithoutAnyCaps.json");
+        String actualOutput = context.getAttribute("output");
+        String outputJSON = readOutput("/output/StopWithoutAnyCaps.json");
         Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
     }
+
     @Test
     public void testGenerateSequenceStartWithoutVmStartCaps()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/StartWithoutVmStartCaps.json");
 
         Map<String,String> params = new HashMap<>();
@@ -455,15 +510,14 @@ public class TestSequenceGeneratorPlugin {
         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("450", errorCode);
-        Assert.assertEquals("Request is not supported", errorMessage);
+        String actualOutput = context.getAttribute("output");
+        Assert.assertEquals(null, actualOutput);
     }
     
     @Test
     public void testGenerateSequenceRestartWithoutVmRestartCaps()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/RestartWithoutVmRestartCaps.json");
 
         Map<String,String> params = new HashMap<>();
@@ -473,15 +527,14 @@ public class TestSequenceGeneratorPlugin {
         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("450", errorCode);
-        Assert.assertEquals("Request is not supported", errorMessage);
+        String actualOutput = context.getAttribute("output");
+        Assert.assertEquals(null, actualOutput);
     }
     
     @Test
     public void testGenerateSequenceStopWithoutVmStopCaps()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
         String inputJSON = readInput("/input/StopWithoutVmStopCaps.json");
 
         Map<String,String> params = new HashMap<>();
@@ -491,17 +544,122 @@ public class TestSequenceGeneratorPlugin {
         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("450", errorCode);
-        Assert.assertEquals("Request is not supported", errorMessage);
+        String actualOutput = context.getAttribute("output");
+        Assert.assertEquals(null, actualOutput);
+    }
+
+    @Test
+    public void testGenerateSequenceStartWithEmptyVmCaps()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
+        String inputJSON = readInput("/input/StartWithEmptyVmCaps.json");
+
+        Map<String,String> params = new HashMap<>();
+        SvcLogicContext context = new SvcLogicContext();
+        context.setAttribute("inputJSON",inputJSON);
+
+        SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
+        plugin.generateSequence(params,context);
+
+        String actualOutput = context.getAttribute("output");
+        String outputJSON = readOutput("/output/StartWithoutAnyCaps.json");
+        Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
+    }
+
+    @Test
+    public void testGenerateSequenceRestartWithEmptyVmCaps()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
+        String inputJSON = readInput("/input/RestartWithEmptyVmCaps.json");
+
+        Map<String,String> params = new HashMap<>();
+        SvcLogicContext context = new SvcLogicContext();
+        context.setAttribute("inputJSON",inputJSON);
+
+        SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
+        plugin.generateSequence(params,context);
+
+        String actualOutput = context.getAttribute("output");
+        String outputJSON = readOutput("/output/RestartWithoutAnyCaps.json");
+        Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
+    }
+
+    @Test
+    public void testGenerateSequenceStopWithEmptyVmCaps()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
+        String inputJSON = readInput("/input/StopWithEmptyVmCaps.json");
+
+        Map<String,String> params = new HashMap<>();
+        SvcLogicContext context = new SvcLogicContext();
+        context.setAttribute("inputJSON",inputJSON);
+
+        SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
+        plugin.generateSequence(params,context);
+
+        String actualOutput = context.getAttribute("output");
+        String outputJSON = readOutput("/output/StopWithoutAnyCaps.json");
+        Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
+    }
+
+    @Test
+    public void testGenerateSequenceStartWithVmStartCapsAndMissingVnfcInfo()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
+        String inputJSON = readInput("/input/StartWithVmStartCapsAndMissingVnfcInfo.json");
+
+        Map<String,String> params = new HashMap<>();
+        SvcLogicContext context = new SvcLogicContext();
+        context.setAttribute("inputJSON",inputJSON);
+
+        SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
+        plugin.generateSequence(params,context);
+
+        String actualOutput = context.getAttribute("output");
+        String outputJSON = readOutput("/output/StartWithVmStartCapsAndMissingVnfcInfo.json");
+        Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
+    }
+
+    @Test
+    public void testGenerateSequenceStopWithVmStopCapsAndMissingVnfcInfo()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
+        String inputJSON = readInput("/input/StopWithVmStopCapsAndMissingVnfcInfo.json");
+
+        Map<String,String> params = new HashMap<>();
+        SvcLogicContext context = new SvcLogicContext();
+        context.setAttribute("inputJSON",inputJSON);
+
+        SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
+        plugin.generateSequence(params,context);
+
+        String actualOutput = context.getAttribute("output");
+        String outputJSON = readOutput("/output/StopWithVmStopCapsAndMissingVnfcInfo.json");
+        Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
+    }
+
+    @Test
+    public void testGenerateSequenceRestartWithVmRestartCapsAndMissingVnfcInfo()throws URISyntaxException, IOException {
+        logger.info("****** Running test:  " + thisTestName.getMethodName() + " ******");
+
+        String inputJSON = readInput("/input/RestartWithVmRestartCapsAndMissingVnfcInfo.json");
+
+        Map<String,String> params = new HashMap<>();
+        SvcLogicContext context = new SvcLogicContext();
+        context.setAttribute("inputJSON",inputJSON);
+
+        SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl();
+        plugin.generateSequence(params,context);
+
+        String actualOutput = context.getAttribute("output");
+        String outputJSON = readOutput("/output/RestartWithVmRestartCapsAndMissingVnfcInfo.json");
+        Assert.assertEquals(outputJSON.trim(),actualOutput.trim());
     }
 
     private String readInput(String inputFile) throws URISyntaxException, IOException {
         return new String(Files.readAllBytes(Paths.get(this.getClass().getResource(inputFile).toURI())), "UTF-8");
     }
-    
+
     private String readOutput(String outputFile) throws IOException,URISyntaxException {
         String output = new String(Files.readAllBytes(Paths.get(this.getClass().getResource(outputFile).toURI())), "UTF-8");
         int start=output.indexOf("[");