2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.sdnc.config.generator.merge;
26 import static org.junit.Assert.assertEquals;
27 import java.util.HashMap;
29 import org.apache.commons.io.IOUtils;
30 import org.junit.Test;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
33 import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
35 public class TestMergeNode {
37 @Test(expected = Exception.class)
38 public void testMergeJsonDataOnTemplate() throws Exception {
39 MergeNode mergeNode = new MergeNode();
40 Map<String, String> inParams = new HashMap<String, String>();
41 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
42 String jsonData = IOUtils.toString(
43 TestMergeNode.class.getClassLoader().getResourceAsStream("merge/vdbe_data.json"));
44 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
45 String templateData = IOUtils.toString(TestMergeNode.class.getClassLoader()
46 .getResourceAsStream("merge/vdbe_template.xml"));
47 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, templateData);
48 SvcLogicContext ctx = new SvcLogicContext();
49 mergeNode.mergeJsonDataOnTemplate(inParams, ctx);
50 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
51 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
55 @Test(expected = Exception.class)
56 public void testMergeComplexJsonDataOnTemplate() throws Exception {
57 MergeNode mergeNode = new MergeNode();
58 Map<String, String> inParams = new HashMap<String, String>();
59 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
61 String jsonData = IOUtils.toString(TestMergeNode.class.getClassLoader()
62 .getResourceAsStream("merge/complex/vdbe_data.json"));
63 System.out.println("TestMergeNode.testMergeJsonComplexDataOnTemplate()" + jsonData);
64 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
66 String templateData = IOUtils.toString(TestMergeNode.class.getClassLoader()
67 .getResourceAsStream("merge/complex/vdbe_template.xml"));
68 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, templateData);
70 SvcLogicContext ctx = new SvcLogicContext();
71 mergeNode.mergeComplexJsonDataOnTemplate(inParams, ctx);
72 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
73 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
77 @Test(expected = Exception.class)
78 public void testMergeJsonDataOnTemplateFile() throws Exception {
79 MergeNode mergeNode = new MergeNode();
80 Map<String, String> inParams = new HashMap<String, String>();
81 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
83 String jsonData = IOUtils.toString(
84 TestMergeNode.class.getClassLoader().getResourceAsStream("merge/vdbe_data.json"));
85 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
86 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_FILE, "merge/vdbe_template.xml");
88 SvcLogicContext ctx = new SvcLogicContext();
89 mergeNode.mergeJsonDataOnTemplate(inParams, ctx);
90 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
91 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
95 public void testMmergeDataOnTemplate() throws SvcLogicException {
96 MergeNode mergeNode = new MergeNode();
97 SvcLogicContext ctx = new SvcLogicContext();
98 Map<String, String> inParams = new HashMap<String, String>();
99 mergeNode.mergeDataOnTemplate(inParams, ctx);
103 public void mergeYamlDataOnTemplate() throws SvcLogicException {
104 MergeNode mergeNode = new MergeNode();
105 SvcLogicContext ctx = new SvcLogicContext();
106 Map<String, String> inParams = new HashMap<String, String>();
107 mergeNode.mergeYamlDataOnTemplate(inParams, ctx);