From 93cb989bb80197a1e6db289d4fc58a7ef6d48216 Mon Sep 17 00:00:00 2001 From: Joss Armstrong Date: Thu, 29 Nov 2018 12:46:23 +0000 Subject: Test case improvements for APPC-1262 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 --- .../params/parser/TestPropertyDefinitionNode.java | 42 +++++++++++++++------- .../transformer/tosca/TestArtifactProcessor.java | 10 ++++++ 2 files changed, 39 insertions(+), 13 deletions(-) (limited to 'appc-config/appc-config-params/provider/src/test/java') diff --git a/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/parser/TestPropertyDefinitionNode.java b/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/parser/TestPropertyDefinitionNode.java index 2a0999783..fe7cb1d7b 100644 --- a/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/parser/TestPropertyDefinitionNode.java +++ b/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/parser/TestPropertyDefinitionNode.java @@ -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 inParams = new HashMap(); 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 inParams = new HashMap(); @@ -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 inParams = new HashMap(); @@ -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 inParams = new HashMap(); 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 inParams = new HashMap(); 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 inParams = new HashMap(); + 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 { diff --git a/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestArtifactProcessor.java b/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestArtifactProcessor.java index a321c686f..d9b31e4bb 100644 --- a/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestArtifactProcessor.java +++ b/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestArtifactProcessor.java @@ -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()); -- cgit 1.2.3-korg