diff options
Diffstat (limited to 'appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/merge/TestMergeNode.java')
-rw-r--r-- | appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/merge/TestMergeNode.java | 108 |
1 files changed, 37 insertions, 71 deletions
diff --git a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/merge/TestMergeNode.java b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/merge/TestMergeNode.java index a51c603ff..85f53fb41 100644 --- a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/merge/TestMergeNode.java +++ b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/merge/TestMergeNode.java @@ -8,6 +8,8 @@ * ============================================================================= * Modification Copyright (C) 2018 IBM. * ============================================================================= + * Modification Copyright (C) 2018 Ericsson + * ============================================================================= * 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 @@ -27,67 +29,59 @@ package org.onap.sdnc.config.generator.merge; import static org.junit.Assert.assertEquals; -import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; import org.apache.commons.io.IOUtils; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.onap.sdnc.config.generator.ConfigGeneratorConstant; -import org.powermock.modules.junit4.PowerMockRunner; -import org.mockito.Mock; -import org.mockito.Mockito; -@RunWith(PowerMockRunner.class) public class TestMergeNode { - @Test(expected = Exception.class) + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Test public void testMergeJsonDataOnTemplate() throws Exception { MergeNode mergeNode = new MergeNode(); Map<String, String> inParams = new HashMap<String, String>(); inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test"); String jsonData = IOUtils.toString( - TestMergeNode.class.getClassLoader().getResourceAsStream("merge/vdbe_data.json")); + TestMergeNode.class.getClassLoader().getResourceAsStream("merge/valid.json"), + StandardCharsets.UTF_8); inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData); String templateData = IOUtils.toString(TestMergeNode.class.getClassLoader() - .getResourceAsStream("merge/vdbe_template.xml")); + .getResourceAsStream("merge/valid.xml"), StandardCharsets.UTF_8); inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, templateData); SvcLogicContext ctx = new SvcLogicContext(); mergeNode.mergeJsonDataOnTemplate(inParams, ctx); - assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS), - ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS); - + assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS, + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS)); } - - @Test(expected = Exception.class) + + @Test public void testMergeJsonDataOnTemplateForEmptyParamData() throws Exception { MergeNode mergeNode = new MergeNode(); Map<String, String> inParams = new HashMap<String, String>(); inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test"); - String templateData = IOUtils.toString(TestMergeNode.class.getClassLoader() - .getResourceAsStream("merge/vdbe_template.xml")); - inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, templateData); SvcLogicContext ctx = new SvcLogicContext(); expectedEx.expect(SvcLogicException.class); - expectedEx.expectMessage("Param Data is missing.."); + expectedEx.expectMessage("JSON Data is missing"); mergeNode.mergeJsonDataOnTemplate(inParams, ctx); - } - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - - @Test(expected = Exception.class) + @Test public void testMergeJsonDataOnTemplateForEmptyTemplateData() throws Exception { MergeNode mergeNode = new MergeNode(); Map<String, String> inParams = new HashMap<String, String>(); inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test"); String jsonData = IOUtils.toString( - TestMergeNode.class.getClassLoader().getResourceAsStream("merge/vdbe_data.json")); + TestMergeNode.class.getClassLoader().getResourceAsStream("merge/valid.json"), + StandardCharsets.UTF_8); inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData); SvcLogicContext ctx = new SvcLogicContext(); expectedEx.expect(SvcLogicException.class); @@ -95,74 +89,46 @@ public class TestMergeNode { mergeNode.mergeJsonDataOnTemplate(inParams, ctx); } - - @Test(expected = Exception.class) + @Test public void testMergeComplexJsonDataOnTemplate() throws Exception { MergeNode mergeNode = new MergeNode(); Map<String, String> inParams = new HashMap<String, String>(); inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test"); - String jsonData = IOUtils.toString(TestMergeNode.class.getClassLoader() - .getResourceAsStream("merge/complex/vdbe_data.json")); - System.out.println("TestMergeNode.testMergeJsonComplexDataOnTemplate()" + jsonData); + .getResourceAsStream("merge/valid.json"), StandardCharsets.UTF_8); inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData); - - String templateData = IOUtils.toString(TestMergeNode.class.getClassLoader() - .getResourceAsStream("merge/complex/vdbe_template.xml")); - inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, templateData); - + inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_FILE, "merge/valid.xml"); SvcLogicContext ctx = new SvcLogicContext(); mergeNode.mergeComplexJsonDataOnTemplate(inParams, ctx); - assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS), - ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS); - + assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS, + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS)); } - @Test(expected = Exception.class) - public void testMergeJsonDataOnTemplateFile() throws Exception { + @Test + public void testMergeComplexJsonDataWithMissingJson() throws Exception { MergeNode mergeNode = new MergeNode(); Map<String, String> inParams = new HashMap<String, String>(); - inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test"); - - String jsonData = IOUtils.toString( - TestMergeNode.class.getClassLoader().getResourceAsStream("merge/vdbe_data.json")); + inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, ""); + String jsonData = IOUtils.toString(TestMergeNode.class.getClassLoader() + .getResourceAsStream("merge/blank.json"), StandardCharsets.UTF_8); inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData); - inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_FILE, "merge/vdbe_template.xml"); - SvcLogicContext ctx = new SvcLogicContext(); - mergeNode.mergeJsonDataOnTemplate(inParams, ctx); - assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS), - ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS); + expectedEx.expect(SvcLogicException.class); + expectedEx.expectMessage("JSON Data is missing"); + mergeNode.mergeComplexJsonDataOnTemplate(inParams, ctx); } @Test - public void testMmergeDataOnTemplate() throws SvcLogicException { - MergeNode mergeNode = new MergeNode(); - SvcLogicContext ctx = new SvcLogicContext(); - Map<String, String> inParams = new HashMap<String, String>(); - mergeNode.mergeDataOnTemplate(inParams, ctx); - } - - @Test - public void testMmergeDataOnTemplateWithTemplateData() throws SvcLogicException, IOException { + public void testMergeComplexJsonDataWithMissingTemplateDataAndFile() throws Exception { MergeNode mergeNode = new MergeNode(); Map<String, String> inParams = new HashMap<String, String>(); inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test"); - String jsonData = "{name1:value1,name2:value2}"; + String jsonData = IOUtils.toString(TestMergeNode.class.getClassLoader() + .getResourceAsStream("merge/valid.json"), StandardCharsets.UTF_8); inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData); - String templateData = "testTemplateData"; - inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, templateData); - SvcLogicContext ctx = new SvcLogicContext(); - mergeNode.mergeJsonDataOnTemplate(inParams, ctx); - assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS)); - - } - - @Test - public void mergeYamlDataOnTemplate() throws SvcLogicException { - MergeNode mergeNode = new MergeNode(); SvcLogicContext ctx = new SvcLogicContext(); - Map<String, String> inParams = new HashMap<String, String>(); - mergeNode.mergeYamlDataOnTemplate(inParams, ctx); + expectedEx.expect(SvcLogicException.class); + expectedEx.expectMessage("Template data or Template file is missing"); + mergeNode.mergeComplexJsonDataOnTemplate(inParams, ctx); } } |