2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Modification Copyright (C) 2018 IBM.
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.sdnc.config.generator.merge;
28 import static org.junit.Assert.assertEquals;
30 import java.io.IOException;
31 import java.util.HashMap;
33 import org.apache.commons.io.IOUtils;
34 import org.junit.Test;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
37 import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
39 public class TestMergeNode {
41 @Test(expected = Exception.class)
42 public void testMergeJsonDataOnTemplate() throws Exception {
43 MergeNode mergeNode = new MergeNode();
44 Map<String, String> inParams = new HashMap<String, String>();
45 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
46 String jsonData = IOUtils.toString(
47 TestMergeNode.class.getClassLoader().getResourceAsStream("merge/vdbe_data.json"));
48 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
49 String templateData = IOUtils.toString(TestMergeNode.class.getClassLoader()
50 .getResourceAsStream("merge/vdbe_template.xml"));
51 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, templateData);
52 SvcLogicContext ctx = new SvcLogicContext();
53 mergeNode.mergeJsonDataOnTemplate(inParams, ctx);
54 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
55 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
59 @Test(expected = Exception.class)
60 public void testMergeComplexJsonDataOnTemplate() throws Exception {
61 MergeNode mergeNode = new MergeNode();
62 Map<String, String> inParams = new HashMap<String, String>();
63 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
65 String jsonData = IOUtils.toString(TestMergeNode.class.getClassLoader()
66 .getResourceAsStream("merge/complex/vdbe_data.json"));
67 System.out.println("TestMergeNode.testMergeJsonComplexDataOnTemplate()" + jsonData);
68 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
70 String templateData = IOUtils.toString(TestMergeNode.class.getClassLoader()
71 .getResourceAsStream("merge/complex/vdbe_template.xml"));
72 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, templateData);
74 SvcLogicContext ctx = new SvcLogicContext();
75 mergeNode.mergeComplexJsonDataOnTemplate(inParams, ctx);
76 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
77 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
81 @Test(expected = Exception.class)
82 public void testMergeJsonDataOnTemplateFile() throws Exception {
83 MergeNode mergeNode = new MergeNode();
84 Map<String, String> inParams = new HashMap<String, String>();
85 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
87 String jsonData = IOUtils.toString(
88 TestMergeNode.class.getClassLoader().getResourceAsStream("merge/vdbe_data.json"));
89 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
90 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_FILE, "merge/vdbe_template.xml");
92 SvcLogicContext ctx = new SvcLogicContext();
93 mergeNode.mergeJsonDataOnTemplate(inParams, ctx);
94 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
95 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
99 public void testMmergeDataOnTemplate() throws SvcLogicException {
100 MergeNode mergeNode = new MergeNode();
101 SvcLogicContext ctx = new SvcLogicContext();
102 Map<String, String> inParams = new HashMap<String, String>();
103 mergeNode.mergeDataOnTemplate(inParams, ctx);
107 public void testMmergeDataOnTemplateWithTemplateData() throws SvcLogicException, IOException {
108 MergeNode mergeNode = new MergeNode();
109 Map<String, String> inParams = new HashMap<String, String>();
110 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
111 String jsonData = "{name1:value1,name2:value2}";
112 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
113 String templateData = "testTemplateData";
114 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, templateData);
115 SvcLogicContext ctx = new SvcLogicContext();
116 mergeNode.mergeJsonDataOnTemplate(inParams, ctx);
117 assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
122 public void mergeYamlDataOnTemplate() throws SvcLogicException {
123 MergeNode mergeNode = new MergeNode();
124 SvcLogicContext ctx = new SvcLogicContext();
125 Map<String, String> inParams = new HashMap<String, String>();
126 mergeNode.mergeYamlDataOnTemplate(inParams, ctx);