Refactor and add test flows

Small fix in version state filter

Change-Id: I015cbc52b8620b92ebb4f8f0167711e39d9d30a8
Issue-ID: SDC-1503
Signed-off-by: talig <talig@amdocs.com>
diff --git a/workflow-bdd/features/Version.feature b/workflow-bdd/features/Version.feature
index e43971c..a5327fd 100644
--- a/workflow-bdd/features/Version.feature
+++ b/workflow-bdd/features/Version.feature
@@ -25,15 +25,16 @@
     Then I want to get path "/workflows/{item.id}/versions/{item.versionId}"
     And I want to check that property "id" in the response equals to value of saved property "item.versionId"
     And I want to get path "/workflows/{item.id}/versions"
-    And I want to check that element in the response list with "id" equals to value of saved property "item.versionId" exists
+    And I want to check in the list "items" property "id" with value of saved property "item.versionId" exists
 
   Scenario: Create first version with inputs/outputs
-    When I want to set the input data to file "resources/json/createVersionWithInputsOutputs.json"
+    When I want to set the input data to file "resources/json/versionWith2Inputs2Outputs1.json"
     And I want to create for path "/workflows/{item.id}/versions" with the input data from the context
-    And I want to copy to property "item.versionId" from response data path "id"
 
-    Then I want to check property "inputs[0].name" for value "in1"
-    And I want to check property "outputs[0].name" for value "out1"
+    Then I want to check in the list "inputs" property "name" with value "in1" exists
+    And I want to check in the list "inputs" property "name" with value "in2" exists
+    And I want to check in the list "outputs" property "name" with value "out1" exists
+    And I want to check in the list "outputs" property "name" with value "out2" exists
 
   Scenario: Create second version
     And I want to update the input property "description" with value "first empty version"
@@ -50,7 +51,7 @@
     Then I want to get path "/workflows/{item.id}/versions/{item.versionId}"
     And I want to check that property "id" in the response equals to value of saved property "item.versionId"
     And I want to get path "/workflows/{item.id}/versions"
-    And I want to check that element in the response list with "id" equals to value of saved property "item.versionId" exists
+    And I want to check in the list "items" property "id" with value of saved property "item.versionId" exists
 
   Scenario: Update version
     And I want to create input data
@@ -62,4 +63,21 @@
     And I want to update for path "/workflows/{item.id}/versions/{item.versionId}" with the input data from the context
 
     Then I want to get path "/workflows/{item.id}/versions/{item.versionId}"
-    And I want to check property "description" for value "workflow version description updated"
\ No newline at end of file
+    And I want to check property "description" for value "workflow version description updated"
+
+  Scenario: Update version with inputs/outputs (create/update/delete parameters)
+    And I want to set the input data to file "resources/json/versionWith2Inputs2Outputs1.json"
+    And I want to create for path "/workflows/{item.id}/versions" with the input data from the context
+    And I want to copy to property "item.versionId" from response data path "id"
+
+    When I want to set the input data to file "resources/json/versionWith2Inputs2Outputs2.json"
+    And I want to update for path "/workflows/{item.id}/versions/{item.versionId}" with the input data from the context
+
+    Then I want to get path "/workflows/{item.id}/versions/{item.versionId}"
+    And I want to check in the list "inputs" property "name" with value "in1" exists
+    And I want to check in the list "inputs" property "name" with value "in2" does not exist
+    And I want to check in the list "inputs" property "name" with value "in3" exists
+    And I want to check in the list "outputs" property "name" with value "out1" exists
+    And I want to check in the list "outputs" property "name" with value "out2" does not exist
+    And I want to check in the list "outputs" property "name" with value "out3" exists
+
diff --git a/workflow-bdd/features/WorkflowList.feature b/workflow-bdd/features/WorkflowList.feature
index 5b6941e..3cd27a0 100644
--- a/workflow-bdd/features/WorkflowList.feature
+++ b/workflow-bdd/features/WorkflowList.feature
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-Feature: List Workflows
+Feature: Workflows list
 
   Background: Init - create various workflows in order to test list filter
     Given I want to create a Workflow
@@ -41,36 +41,36 @@
     And I want to create for path "/workflows/{item.id}/versions?baseVersionId={item.versionId}" with the input data from the context
 
   Scenario: List all
-    When I want to get path "/workflows?size=2000"
-    Then I want to check that element in the response list with "id" equals to value of saved property "noVersionsWorkflowId" exists
-    And I want to check that element in the response list with "id" equals to value of saved property "draftVersionWorkflowId" exists
-    And I want to check that element in the response list with "id" equals to value of saved property "certifiedVersionWorkflowId" exists
-    And I want to check that element in the response list with "id" equals to value of saved property "draftAndCertifiedVersionWorkflowId" exists
+    When I want to get path "/workflows?limit=2000"
+    Then I want to check in the list "items" property "id" with value of saved property "noVersionsWorkflowId" exists
+    And I want to check in the list "items" property "id" with value of saved property "draftVersionWorkflowId" exists
+    And I want to check in the list "items" property "id" with value of saved property "certifiedVersionWorkflowId" exists
+    And I want to check in the list "items" property "id" with value of saved property "draftAndCertifiedVersionWorkflowId" exists
 
   Scenario: List ones with DRAFT version(s)
-    When I want to get path "/workflows?versionState=DRAFT&size=2000"
-    Then I want to check that element in the response list with "id" equals to value of saved property "noVersionsWorkflowId" does not exist
-    And I want to check that element in the response list with "id" equals to value of saved property "draftVersionWorkflowId" exists
-    And I want to check that element in the response list with "id" equals to value of saved property "certifiedVersionWorkflowId" does not exist
-    And I want to check that element in the response list with "id" equals to value of saved property "draftAndCertifiedVersionWorkflowId" exists
+    When I want to get path "/workflows?versionState=DRAFT&limit=2000"
+    Then I want to check in the list "items" property "id" with value of saved property "noVersionsWorkflowId" does not exist
+    And I want to check in the list "items" property "id" with value of saved property "draftVersionWorkflowId" exists
+    And I want to check in the list "items" property "id" with value of saved property "certifiedVersionWorkflowId" does not exist
+    And I want to check in the list "items" property "id" with value of saved property "draftAndCertifiedVersionWorkflowId" exists
 
   Scenario: List ones with CERTIFIED version(s)
-    When I want to get path "/workflows?versionState=CERTIFIED&size=2000"
-    Then I want to check that element in the response list with "id" equals to value of saved property "noVersionsWorkflowId" does not exist
-    And I want to check that element in the response list with "id" equals to value of saved property "draftVersionWorkflowId" does not exist
-    And I want to check that element in the response list with "id" equals to value of saved property "certifiedVersionWorkflowId" exists
-    And I want to check that element in the response list with "id" equals to value of saved property "draftAndCertifiedVersionWorkflowId" exists
+    When I want to get path "/workflows?versionState=CERTIFIED&limit=2000"
+    Then I want to check in the list "items" property "id" with value of saved property "noVersionsWorkflowId" does not exist
+    And I want to check in the list "items" property "id" with value of saved property "draftVersionWorkflowId" does not exist
+    And I want to check in the list "items" property "id" with value of saved property "certifiedVersionWorkflowId" exists
+    And I want to check in the list "items" property "id" with value of saved property "draftAndCertifiedVersionWorkflowId" exists
 
   Scenario: List ones with DRAFT/CERTIFIED version(s)
-    When I want to get path "/workflows?versionState=DRAFT,CERTIFIED&size=2000"
-    Then I want to check that element in the response list with "id" equals to value of saved property "noVersionsWorkflowId" does not exist
-    And I want to check that element in the response list with "id" equals to value of saved property "draftVersionWorkflowId" exists
-    And I want to check that element in the response list with "id" equals to value of saved property "certifiedVersionWorkflowId" exists
-    And I want to check that element in the response list with "id" equals to value of saved property "draftAndCertifiedVersionWorkflowId" exists
+    When I want to get path "/workflows?versionState=DRAFT,CERTIFIED&limit=2000"
+    Then I want to check in the list "items" property "id" with value of saved property "noVersionsWorkflowId" does not exist
+    And I want to check in the list "items" property "id" with value of saved property "draftVersionWorkflowId" exists
+    And I want to check in the list "items" property "id" with value of saved property "certifiedVersionWorkflowId" exists
+    And I want to check in the list "items" property "id" with value of saved property "draftAndCertifiedVersionWorkflowId" exists
 
   Scenario: List ones with gibberish version(s) = none
-    When I want to get path "/workflows?versionState=gibberish&size=2000"
-    Then I want to check that element in the response list with "id" equals to value of saved property "noVersionsWorkflowId" does not exist
-    And I want to check that element in the response list with "id" equals to value of saved property "draftVersionWorkflowId" does not exist
-    And I want to check that element in the response list with "id" equals to value of saved property "certifiedVersionWorkflowId" does not exist
-    And I want to check that element in the response list with "id" equals to value of saved property "draftAndCertifiedVersionWorkflowId" does not exist
\ No newline at end of file
+    When I want to get path "/workflows?versionState=gibberish&limit=2000"
+    Then I want to check in the list "items" property "id" with value of saved property "noVersionsWorkflowId" does not exist
+    And I want to check in the list "items" property "id" with value of saved property "draftVersionWorkflowId" does not exist
+    And I want to check in the list "items" property "id" with value of saved property "certifiedVersionWorkflowId" does not exist
+    And I want to check in the list "items" property "id" with value of saved property "draftAndCertifiedVersionWorkflowId" does not exist
\ No newline at end of file
diff --git a/workflow-bdd/features/examples/ResponseDataChecks.feature b/workflow-bdd/features/examples/ResponseDataChecks.feature
new file mode 100644
index 0000000..2f8ff52
--- /dev/null
+++ b/workflow-bdd/features/examples/ResponseDataChecks.feature
@@ -0,0 +1,50 @@
+Feature: Example for checking response data
+  Scenario: Example Checks
+    # setting some data just for testing purposes
+    Given Response Data:
+    """
+    {
+      "field1" : "string field",
+      "field2" : true,
+      "field3": "5",
+      "field4" : [{"entry1":"a"},{"entry2":"b"},{"entry3":"c"}],
+      "inputs": [
+        {
+          "mandatory": true,
+          "name": "in1",
+          "type": "STRING"
+        },
+        {
+          "mandatory": true,
+          "name": "in2",
+          "type": "INTEGER"
+        }
+      ],
+      "outputs": [
+        {
+          "mandatory": true,
+          "name": "workflow",
+          "type": "TIMESTAMP"
+        },
+        {
+          "mandatory": true,
+          "name": "out2",
+          "type": "BOOLEAN"
+        }
+      ]
+    }
+    """
+    # printing out for test purposes
+    Then I want to print the context data
+
+    # running the different options of checking the respone data
+    Then I want to check property "field1" for value "string field"
+    Then I want to check property "field2" to be true
+    Then I want to check property "field3" for value 5
+    Then I want to check property "field4" to have length 3
+    Then I want to check property "field4[0].entry1" exists
+    Then I want to check property "field4[0].no_exist" does not exist
+    Then I want to check property "outputs[0].name" exists
+    Then I want to check property "outputs[0].name" for value "workflow"
+    Then I want to check in the list "outputs" property "name" with value "out2" exists
+    Then I want to check in the list "outputs" property "name" with value "out3" does not exist
diff --git a/workflow-bdd/resources/json/createVersionWithInputsOutputs.json b/workflow-bdd/resources/json/createVersionWithInputsOutputs.json
deleted file mode 100644
index a9b6c3d..0000000
--- a/workflow-bdd/resources/json/createVersionWithInputsOutputs.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
-  "description": "first version - with inputs and outputs",
-  "inputs": [
-    {
-      "mandatory": true,
-      "name": "in1",
-      "type": "STRING"
-    }
-  ],
-  "outputs": [
-    {
-      "mandatory": true,
-      "name": "out1",
-      "type": "TIMESTAMP"
-    }
-  ]
-}
\ No newline at end of file
diff --git a/workflow-bdd/resources/json/versionWith2Inputs2Outputs1.json b/workflow-bdd/resources/json/versionWith2Inputs2Outputs1.json
new file mode 100644
index 0000000..cc0a38e
--- /dev/null
+++ b/workflow-bdd/resources/json/versionWith2Inputs2Outputs1.json
@@ -0,0 +1,27 @@
+{
+  "description": "version with 2 inputs and 2 outputs",
+  "inputs": [
+    {
+      "mandatory": true,
+      "name": "in1",
+      "type": "STRING"
+    },
+    {
+      "mandatory": true,
+      "name": "in2",
+      "type": "INTEGER"
+    }
+  ],
+  "outputs": [
+    {
+      "mandatory": true,
+      "name": "out1",
+      "type": "TIMESTAMP"
+    },
+    {
+      "mandatory": true,
+      "name": "out2",
+      "type": "BOOLEAN"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/workflow-bdd/resources/json/versionWith2Inputs2Outputs2.json b/workflow-bdd/resources/json/versionWith2Inputs2Outputs2.json
new file mode 100644
index 0000000..58f9b2b
--- /dev/null
+++ b/workflow-bdd/resources/json/versionWith2Inputs2Outputs2.json
@@ -0,0 +1,27 @@
+{
+  "description": "version with 2 inputs and 2 outputs",
+  "inputs": [
+    {
+      "mandatory": false,
+      "name": "in1",
+      "type": "STRING"
+    },
+    {
+      "mandatory": true,
+      "name": "in3",
+      "type": "INTEGER"
+    }
+  ],
+  "outputs": [
+    {
+      "mandatory": false,
+      "name": "out1",
+      "type": "TIMESTAMP"
+    },
+    {
+      "mandatory": true,
+      "name": "out3",
+      "type": "BOOLEAN"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/workflow-bdd/stepDefinitions/General_Steps.js b/workflow-bdd/stepDefinitions/General_Steps.js
index 2e74c6e..69a703c 100644
--- a/workflow-bdd/stepDefinitions/General_Steps.js
+++ b/workflow-bdd/stepDefinitions/General_Steps.js
@@ -39,7 +39,7 @@
 });
 /**
  * @module ContextData
- * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+ * @exampleFile ResponseDataChecks.feature
  * @description Response Data::<br>
  *     """<br>
  *         {jsonObject}<br>
@@ -83,7 +83,7 @@
 /**
  * @module ResponseData
  * @description Will check the output data for a property and a value. property can be a path (example: results[0].id)
- * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+ * @exampleFile ResponseDataChecks.feature
  * @step I want to check property {string} for value {string}
  **/
 Then('I want to check property {string} for value {string}', function(string, string2)  {
@@ -103,16 +103,17 @@
 /**
  * @module ResponseData
  * @description Will check the output data for a property and a integer. property can be a path (example: results[0].id)
- * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+ * @exampleFile ResponseDataChecks.feature
  * @step I want to check property {string} for value {int}
  **/
 Then('I want to check property {string} for value {int}', function(string, int)  {
 	assert.equal(_.get(this.context.responseData, string), int);
 });
+
 /**
  * @module ResponseData
  * @description Will check the output data for a property and a boolean. property can be a path (example: results[0].id)
- * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+ * @exampleFile ResponseDataChecks.feature
  * @step I want to check property {string} to be "True/False"
  **/
 Then('I want to check property {string} to be {word}', function(string, string2)  {
@@ -121,7 +122,7 @@
 /**
  * @module ResponseData
  * @description Will check the output data for a property and a boolean. property can be a path (example: results[0].id)
- * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+ * @exampleFile ResponseDataChecks.feature
  * @step I want to check property {string} to have length {int}
  **/
 Then('I want to check property {string} to have length {int}', function(string, intLength)  {
@@ -131,7 +132,7 @@
 /**
  * @module ResponseData
  * @description Will check the output data for a property and make sure it exists
- * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+ * @exampleFile ResponseDataChecks.feature
  * @step I want to check property {string} exists
  **/
 Then('I want to check property {string} exists', function(string)  {
@@ -140,7 +141,7 @@
 /**
  * @module ResponseData
  * @description Will check the output data for a property and make sure it does not exist
- * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+ * @exampleFile ResponseDataChecks.feature
  * @step I want to check property {string} does not exist
  **/
 Then('I want to check property {string} does not exist', function(string)  {
@@ -148,9 +149,55 @@
 });
 
 /**
+ * @module ResponseData
+ * @description Will check the output data for a property and a value. property can be a path (example: results[0].id)
+ * @exampleFile ResponseDataChecks.feature
+ * @step I want to check property {string} for value {string}
+ **/
+Then('I want to check in the list {string} property {string} with value {string} exists', function(listPath, propertyPath, value)  {
+    var list = _.get(this.context.responseData, listPath);
+    assert.notEqual(list.find(element => _.get(element, propertyPath) === value), undefined);
+});
+
+/**
+ * @module ResponseData
+ * @description Will check the output data for a property and a value. property can be a path (example: results[0].id)
+ * @exampleFile ResponseDataChecks.feature
+ * @step I want to check property {string} for value {string}
+ **/
+Then('I want to check in the list {string} property {string} with value {string} does not exist', function(listPath, propertyPath, value)  {
+    var list = _.get(this.context.responseData, listPath);
+    assert.equal(list.find(element => _.get(element, propertyPath) === value), undefined);
+});
+
+/**
+ * @module ResponseData
+ * @description Will check the output data for a property and a value. property can be a path (example: results[0].id)
+ * @exampleFile ResponseDataChecks.feature
+ * @step I want to check property {string} for value {string}
+ **/
+Then('I want to check in the list {string} property {string} with value of saved property {string} exists', function(listPath, propertyPath, valueProperty)  {
+    var list = _.get(this.context.responseData, listPath);
+    var value = _.get(this.context, valueProperty);
+    assert.notEqual(list.find(element => _.get(element, propertyPath) === value), undefined);
+});
+
+/**
+ * @module ResponseData
+ * @description Will check the output data for a property and a value. property can be a path (example: results[0].id)
+ * @exampleFile ResponseDataChecks.feature
+ * @step I want to check property {string} for value {string}
+ **/
+Then('I want to check in the list {string} property {string} with value of saved property {string} does not exist', function(listPath, propertyPath, valueProperty)  {
+    var list = _.get(this.context.responseData, listPath);
+    var value = _.get(this.context, valueProperty);
+    assert.equal(list.find(element => _.get(element, propertyPath) === value), undefined);
+});
+
+/**
 * @module ContextData
 * @description Use during development to see what is on the context
- * @exampleFile Example_ResponseData_CheckAndManipulation.feature
+ * @exampleFile ResponseDataChecks.feature
 * @step I want to print the context data
 **/
 Then('I want to print the context data', function()  {
@@ -247,31 +294,6 @@
 	callback();
 });
 
-/**
- * @module ResponseData
- * @description Check that the result list doesn't contain an element with property x which has value
- * equals to saved property y
- * @exampleFile ListItemsFilters.feature
- * @step I want to check that element in the response list with {string} equals to value of saved property {string} does not exist
- **/
-Then('I want to check that element in the response list with {string} equals to value of saved property {string} does not exist', function (propertyPath, valueProperty) {
-    const results = this.context.responseData.results;
-    assert.equal(results.find(result => this.context[valueProperty] === _.get(result, propertyPath)), undefined);
-});
-
-/**
- * @module ResponseData
- * @description Check that the result list contains an element with property x which has value
- * equals to saved property y
- * @exampleFile ListItemsFilters.feature
- * @step I want to check that element in the response list with {string} equals to value of saved property {string} exists
- **/
-Then('I want to check that element in the response list with {string} equals to value of saved property {string} exists', function(propertyPath, valueProperty) {
-    const results = this.context.responseData.results;
-    assert.notEqual(results.find(result => _.get(this.context, valueProperty) === _.get(result, propertyPath)), undefined);
-});
-
-
 Then('I want to check that property {string} in the response equals to value of saved property {string}', function(propertyPath, valueProperty) {
     const results = this.context.responseData;
     assert.equal(results[propertyPath], _.get(this.context, valueProperty));
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStatesFormatter.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStatesFormatter.java
index 5467dee..c9d3bf1 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStatesFormatter.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStatesFormatter.java
@@ -1,6 +1,7 @@
 package org.onap.sdc.workflow.api.types;
 
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Set;
 import java.util.stream.Collectors;
 import lombok.Getter;
@@ -29,8 +30,8 @@
                                                 .collect(Collectors.toSet());
         } catch (Exception ignore) {
             LOGGER.info(
-                    "value is invalid and cannot be formatted to a set of version states, therefore it set to null");
-            return null;
+                    "value is invalid and cannot be formatted to a set of version states, therefore it set to empty set");
+            return Collections.emptySet();
         }
     }
 }
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/VersionStatesFormatterTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/VersionStatesFormatterTest.java
index c57bd9c..423c5e6 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/VersionStatesFormatterTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/VersionStatesFormatterTest.java
@@ -22,7 +22,7 @@
     @Test
     public void setVersionStateInvalid() {
         versionStateSet.setVersionState("aaa");
-        assertNull(versionStateSet.getVersionStates());
+        assertEquals(Collections.emptySet() ,versionStateSet.getVersionStates());
     }
 
     @Test