Test case improvements for APPC-1262 19/73919/4
authorJoss Armstrong <joss.armstrong@ericsson.com>
Thu, 29 Nov 2018 12:46:23 +0000 (12:46 +0000)
committerTakamune Cho <takamune.cho@att.com>
Thu, 29 Nov 2018 20:56:25 +0000 (20:56 +0000)
Improvements to existing test cases and new test case to
increase coverage of PropertyDefinition code from 84% to 96%
and coverage of ArtifactProcess code to 95%

Issue-ID: APPC-1262
Change-Id: Ibfd46c341e218ffac0505b097770c64aa00a494e
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/parser/TestPropertyDefinitionNode.java
appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestArtifactProcessor.java
appc-config/appc-config-params/provider/src/test/resources/parser/merge-param.json
appc-config/appc-config-params/provider/src/test/resources/parser/pd_with_required_keys.yaml [new file with mode: 0644]
appc-config/appc-config-params/provider/src/test/resources/parser/request-param.json
appc-config/appc-config-params/provider/src/test/resources/parser/request-param_missing_keys.json [new file with mode: 0644]
appc-config/appc-config-params/provider/src/test/resources/parser/system-param.json

index 2a09997..fe7cb1d 100644 (file)
@@ -52,6 +52,9 @@ public class TestPropertyDefinitionNode {
     public void setup() {
         propertyDefinitionNode = new PropertyDefinitionNode();
     }
+    
+    @Rule
+    public ExpectedException expectedEx = ExpectedException.none();
 
     @Test
     public void testProcessMissingParamKeys() throws Exception {
@@ -75,7 +78,7 @@ public class TestPropertyDefinitionNode {
 
     }
 
-    @Test(expected = SvcLogicException.class)
+    @Test
     public void testInProcessMissingParamKeysForEmptyPdContent() throws Exception {
         Map<String, String> inParams = new HashMap<String, String>();
         inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
@@ -83,7 +86,8 @@ public class TestPropertyDefinitionNode {
                 TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"),
                 Charset.defaultCharset());
         inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
-
+        expectedEx.expect(SvcLogicException.class);
+        expectedEx.expectMessage("Request Param (pdContent) is Missing ..");
         SvcLogicContext ctx = new SvcLogicContext();
         propertyDefinitionNode.processMissingParamKeys(inParams, ctx);
     }
@@ -118,7 +122,7 @@ public class TestPropertyDefinitionNode {
         assertEquals(ctx.getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_STATUS),
                 ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
     }
-    
+
     @Test
     public void testProcessExternalSystemParamKeysForEmptyParamData() throws Exception {
         Map<String, String> inParams = new HashMap<String, String>();
@@ -134,13 +138,8 @@ public class TestPropertyDefinitionNode {
         propertyDefinitionNode.processExternalSystemParamKeys(inParams, ctx);
         assertEquals(ctx.getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_STATUS),
                 ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
-
-      
     }
 
-    @Rule
-    public ExpectedException expectedEx = ExpectedException.none();
-
     @Test
     public void testProcessExternalSystemParamKeysForEmptySystemName() throws Exception {
         Map<String, String> inParams = new HashMap<String, String>();
@@ -160,16 +159,16 @@ public class TestPropertyDefinitionNode {
         expectedEx.expect(SvcLogicException.class);
         expectedEx.expectMessage("Request Param (systemName) is Missing ..");
         propertyDefinitionNode.processExternalSystemParamKeys(inParams, ctx);
-
     }
 
-    @Test(expected = SvcLogicException.class)
+    @Test
     public void testProcessExternalSystemParamKeysForEmptyPdContent() throws Exception {
-
         Map<String, String> inParams = new HashMap<String, String>();
         inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
         inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "SOURCE");
         SvcLogicContext ctx = new SvcLogicContext();
+        expectedEx.expect(SvcLogicException.class);
+        expectedEx.expectMessage("Request Param (pdContent) is Missing ..");
         propertyDefinitionNode.processExternalSystemParamKeys(inParams, ctx);
     }
 
@@ -198,7 +197,6 @@ public class TestPropertyDefinitionNode {
 
     @Test
     public void mergeJsonDataForEmptyParams() throws SvcLogicException, IOException {
-
         Map<String, String> inParams = new HashMap<String, String>();
         inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
         String mergeJsonData = IOUtils.toString(
@@ -209,7 +207,6 @@ public class TestPropertyDefinitionNode {
         propertyDefinitionNode.mergeJsonData(inParams, ctx);
         String status = ctx.getAttribute("test.status");
         assertEquals(ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS, status);
-
     }
 
     @Test(expected = SvcLogicException.class)
@@ -247,6 +244,25 @@ public class TestPropertyDefinitionNode {
         propertyDefinitionNode.validateParams(inParams, ctx);
     }
     
+    @Test
+    public void testValidationPdWithMissingKeys() throws Exception {
+        Map<String, String> inParams = new HashMap<String, String>();
+        SvcLogicContext ctx = new SvcLogicContext();
+        String jsonData = IOUtils.toString(
+                TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/pd_with_required_keys.yaml"),
+                Charset.defaultCharset());
+        String mergeJsonData = IOUtils.toString(
+                TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param_missing_keys.json"),
+                Charset.defaultCharset());
+        inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, jsonData);
+        inParams.put(ParamsHandlerConstant.OUTPUT_PARAM_CONFIGURATION_PARAMETER, mergeJsonData);
+        inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "INSTAR");
+        expectedEx.expect(SvcLogicException.class);
+        expectedEx.expectMessage("Missing  Mandatory Keys and source are{\"LOCAL_ACCESS_IP_ADDR\":\"INSTAR\"}");
+        propertyDefinitionNode.validateParams(inParams, ctx);
+        //assertEquals(ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS,ctx.getAttribute(ParamsHandlerConstant.OUTPUT_PARAM_STATUS));
+    }
+    
     @Test(expected=SvcLogicException.class)
     public void testValidateParamsForEmptyParams() throws Exception
     {
index a321c68..d9b31e4 100644 (file)
@@ -36,6 +36,8 @@ import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
+import org.onap.sdnc.config.params.data.PropertyDefinition;
+import org.onap.sdnc.config.params.transformer.ArtificatTransformer;
 import org.onap.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException;
 
 public class TestArtifactProcessor {
@@ -79,6 +81,14 @@ public class TestArtifactProcessor {
         String toscaString = outstream.toString();
     }
 
+    @Test
+    public void testReadArtifact() throws IOException, ArtifactProcessorException {
+        ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
+        String pdString = getFileContent("tosca/ExpectedTosca.yml");
+        PropertyDefinition propertyDefinitionObj = arp.readArtifact(pdString);
+        Assert.assertEquals(7, propertyDefinitionObj.getParameters().size());
+    }
+
     private String getFileContent(String fileName) throws IOException {
         ClassLoader classLoader = new TestArtifactProcessor().getClass().getClassLoader();
         InputStream is = new FileInputStream(classLoader.getResource(fileName).getFile());
index 76aebb0..0c3a023 100644 (file)
@@ -1,6 +1,6 @@
 {
-               "Additional1": "XX.XX.XX",
-               "Additional2": "XXXXXX",
-               "Additiona3": "00",
-               "Additional": "00"
+        "Additional1": "XX.XX.XX",
+        "Additional2": "XXXXXX",
+        "Additiona3": "00",
+        "Additional": "00"
 }
diff --git a/appc-config/appc-config-params/provider/src/test/resources/parser/pd_with_required_keys.yaml b/appc-config/appc-config-params/provider/src/test/resources/parser/pd_with_required_keys.yaml
new file mode 100644 (file)
index 0000000..716766a
--- /dev/null
@@ -0,0 +1,96 @@
+# ============LICENSE_START==========================================
+# ONAP : APPC
+# ===================================================================
+# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# ===================================================================
+#
+# Unless otherwise specified, all software contained herein is licensed
+# under the Apache License, Version 2.0 (the License);
+# you may not use this software 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.
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+# ============LICENSE_END============================================
+---
+kind: "Property Definition"
+version: "V1"
+vnf-parameter-list:
+- name: "LOCAL_ACCESS_IP_ADDR"
+  description: null
+  type: null
+  required: true
+  source: "INSTAR"
+  rule-type: "interface-ip-address"
+  default: "0.0.0.0"
+  request-keys:
+  - key-name: "address_fqdn"
+    key-value: "value"
+  - key-name: "address_type"
+    key-value: "v4"
+  response-keys: null
+- name: "LOCAL_CORE_ALT_IP_ADDR"
+  description: null
+  type: null 
+  required: true
+  source: "A&AI"
+  rule-type: null
+  default: "0:0:0:0"
+  request-keys:
+  - key-name: "address_fqdn"
+    key-value: "value"
+  - key-name: "address_type"
+    key-value: "v4"
+  response-keys: null
+- name: "LOCAL_BILLING_IP_ADDR"
+  description: null
+  type: null 
+  required: false
+  source: null
+  rule-type: null
+  default: "0.0.0.0"
+  request-keys: null
+  response-keys: null
+- name: "REMOTE_ACCESS_IP_ADDR"
+  description: null
+  type: null 
+  required: false
+  source: null
+  rule-type: null
+  default: "0.0.0.0"
+  request-keys: null
+  response-keys: null
+- name: "REMOTE_CORE_ALT_IP_ADDR"
+  description: null
+  type: null 
+  required: false
+  source: null
+  rule-type: null
+  default: "0:0:0:0"
+  request-keys: null
+  response-keys: null
+- name: "REMOTE_BILLING_IP_ADDR"
+  description: null
+  type: null 
+  required: false
+  source: "Manual"
+  rule-type: null
+  default: "0.0.0.0"
+  request-keys: null
+  response-keys: null
+- name: "CORE_NETWORK_PLEN"
+  description: null
+  type: null 
+  required: false
+  source: INSTAR
+  rule-type: null
+  default: "32"
+  request-keys: null
+  response-keys: null
index f4dc6f2..fa141ea 100644 (file)
@@ -1,6 +1,6 @@
-{              
-               "LOCAL_BILLING_IP_ADDR": "0.0.0.0",
-               "REMOTE_CORE_ALT_IP_ADDR": "value",
-               "REMOTE_BILLING_IP_ADDR": "0.0.0.0",
-               "CORE_NETWORK_PLEN": "32"
+{
+        "LOCAL_BILLING_IP_ADDR": "0.0.0.0",
+        "REMOTE_CORE_ALT_IP_ADDR": "value",
+        "REMOTE_BILLING_IP_ADDR": "0.0.0.0",
+        "CORE_NETWORK_PLEN": "32"
 }
diff --git a/appc-config/appc-config-params/provider/src/test/resources/parser/request-param_missing_keys.json b/appc-config/appc-config-params/provider/src/test/resources/parser/request-param_missing_keys.json
new file mode 100644 (file)
index 0000000..94630f8
--- /dev/null
@@ -0,0 +1,6 @@
+{
+        "LOCAL_CORE_ALT_IP_ADDR": "0.0.0.0",
+        "REMOTE_CORE_ALT_IP_ADDR": "value",
+        "REMOTE_BILLING_IP_ADDR": "0.0.0.0",
+        "CORE_NETWORK_PLEN": "32"
+}
index bb3fdfc..3367200 100644 (file)
@@ -1,5 +1,5 @@
 {
-               "LOCAL_ACCESS_IP_ADDR": "XX.XX.XX",
-               "LOCAL_BILLING_IP_ADDR": "XXXXXX",
-               "CORE_NETWORK_PLEN": "00"
+        "LOCAL_ACCESS_IP_ADDR": "XX.XX.XX",
+        "LOCAL_BILLING_IP_ADDR": "XXXXXX",
+        "CORE_NETWORK_PLEN": "00"
 }