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.params.parser;
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertNotNull;
30 import java.nio.charset.Charset;
31 import java.util.HashMap;
33 import org.apache.commons.io.IOUtils;
34 import org.apache.commons.lang.StringUtils;
35 import org.junit.Ignore;
36 import org.junit.Test;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
38 import org.onap.sdnc.config.params.ParamsHandlerConstant;
39 import org.onap.sdnc.config.params.data.PropertyDefinition;
40 import org.onap.sdnc.config.params.transformer.ArtificatTransformer;
42 public class TestPropertyDefinitionNode {
45 public void testProcessMissingParamKeys() throws Exception {
46 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
47 Map<String, String> inParams = new HashMap<String, String>();
48 inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
50 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
51 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
52 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
54 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
55 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
56 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
58 SvcLogicContext ctx = new SvcLogicContext();
59 propertyDefinitionNode.processMissingParamKeys(inParams, ctx);
60 assertEquals(ctx.getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_STATUS),
61 ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
66 public void testProcessExternalSystemParamKeys() throws Exception {
67 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
68 Map<String, String> inParams = new HashMap<String, String>();
69 inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
71 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
72 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
73 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
75 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
76 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
77 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
79 inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "SOURCE");
81 SvcLogicContext ctx = new SvcLogicContext();
82 propertyDefinitionNode.processExternalSystemParamKeys(inParams, ctx);
84 for (Object key : ctx.getAttributeKeySet()) {
85 String parmName = (String) key;
86 String parmValue = ctx.getAttribute(parmName);
87 if (StringUtils.contains(parmName, "keys")) {
88 System.out.println("Key: " + parmName + ", Value: " + parmValue);
91 assertEquals(ctx.getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_STATUS),
92 ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
96 public void mergeJsonData() throws Exception {
97 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
98 Map<String, String> inParams = new HashMap<String, String>();
99 inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
101 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
102 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
103 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
105 String mergeJsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
106 .getResourceAsStream("parser/merge-param.json"), Charset.defaultCharset());
107 inParams.put(ParamsHandlerConstant.INPUT_PARAM_MERGE__JSON_DATA, mergeJsonData);
109 SvcLogicContext ctx = new SvcLogicContext();
110 propertyDefinitionNode.mergeJsonData(inParams, ctx);
111 String mergedParams = ctx
112 .getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_CONFIGURATION_PARAMETER);
113 assertNotNull(mergedParams);
114 assertEquals(ctx.getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_STATUS),
115 ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
119 public void testArtificatTransformer() throws Exception {
120 ArtificatTransformer transformer = new ArtificatTransformer();
121 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
122 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
124 PropertyDefinition propertyDefinition = transformer.convertYAMLToPD(yamlData);
125 String yaml = transformer.convertPDToYaml(propertyDefinition);
130 public void testValidationPd() throws Exception {
131 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
132 Map<String, String> inParams = new HashMap<String, String>();
133 SvcLogicContext ctx = new SvcLogicContext();
134 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
135 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
136 String mergeJsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
137 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
138 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, jsonData);
139 inParams.put(ParamsHandlerConstant.OUTPUT_PARAM_CONFIGURATION_PARAMETER, mergeJsonData);
140 inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "INSTAR");
141 propertyDefinitionNode.validateParams(inParams, ctx);