2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Modifications 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.params.parser;
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertNotNull;
32 import java.nio.charset.Charset;
33 import java.util.HashMap;
35 import org.apache.commons.io.IOUtils;
36 import org.apache.commons.lang.StringUtils;
37 import org.junit.Ignore;
38 import org.junit.Test;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
40 import org.onap.sdnc.config.params.ParamsHandlerConstant;
41 import org.onap.sdnc.config.params.data.PropertyDefinition;
42 import org.onap.sdnc.config.params.transformer.ArtificatTransformer;
44 public class TestPropertyDefinitionNode {
47 public void testProcessMissingParamKeys() throws Exception {
48 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
49 Map<String, String> inParams = new HashMap<String, String>();
50 inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
52 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
53 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
54 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
56 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
57 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
58 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
60 SvcLogicContext ctx = new SvcLogicContext();
61 propertyDefinitionNode.processMissingParamKeys(inParams, ctx);
62 assertEquals(ctx.getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_STATUS),
63 ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
68 public void testProcessExternalSystemParamKeys() throws Exception {
69 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
70 Map<String, String> inParams = new HashMap<String, String>();
71 inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
73 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
74 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
75 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
77 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
78 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
79 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
81 inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "SOURCE");
83 SvcLogicContext ctx = new SvcLogicContext();
84 propertyDefinitionNode.processExternalSystemParamKeys(inParams, ctx);
86 for (Object key : ctx.getAttributeKeySet()) {
87 String parmName = (String) key;
88 String parmValue = ctx.getAttribute(parmName);
89 if (StringUtils.contains(parmName, "keys")) {
90 System.out.println("Key: " + parmName + ", Value: " + parmValue);
93 assertEquals(ctx.getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_STATUS),
94 ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
98 public void mergeJsonData() throws Exception {
99 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
100 Map<String, String> inParams = new HashMap<String, String>();
101 inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
103 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
104 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
105 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
107 String mergeJsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
108 .getResourceAsStream("parser/merge-param.json"), Charset.defaultCharset());
109 inParams.put(ParamsHandlerConstant.INPUT_PARAM_MERGE__JSON_DATA, mergeJsonData);
111 SvcLogicContext ctx = new SvcLogicContext();
112 propertyDefinitionNode.mergeJsonData(inParams, ctx);
113 String mergedParams = ctx
114 .getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_CONFIGURATION_PARAMETER);
115 assertNotNull(mergedParams);
116 assertEquals(ctx.getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_STATUS),
117 ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
121 public void testArtificatTransformer() throws Exception {
122 ArtificatTransformer transformer = new ArtificatTransformer();
123 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
124 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
126 PropertyDefinition propertyDefinition = transformer.convertYAMLToPD(yamlData);
127 String yaml = transformer.convertPDToYaml(propertyDefinition);
132 public void testValidationPd() throws Exception {
133 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
134 Map<String, String> inParams = new HashMap<String, String>();
135 SvcLogicContext ctx = new SvcLogicContext();
136 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
137 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
138 String mergeJsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
139 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
140 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, jsonData);
141 inParams.put(ParamsHandlerConstant.OUTPUT_PARAM_CONFIGURATION_PARAMETER, mergeJsonData);
142 inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "INSTAR");
143 propertyDefinitionNode.validateParams(inParams, ctx);