2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.sdnc.config.params.parser;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNotNull;
31 import java.nio.charset.Charset;
32 import java.util.HashMap;
34 import org.apache.commons.io.IOUtils;
35 import org.apache.commons.lang.StringUtils;
36 import org.junit.Ignore;
37 import org.junit.Test;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.onap.sdnc.config.params.ParamsHandlerConstant;
40 import org.onap.sdnc.config.params.data.PropertyDefinition;
41 import org.onap.sdnc.config.params.transformer.ArtificatTransformer;
43 public class TestPropertyDefinitionNode {
46 public void testProcessMissingParamKeys() throws Exception {
47 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
48 Map<String, String> inParams = new HashMap<String, String>();
49 inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
51 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
52 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
53 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
55 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
56 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
57 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
59 SvcLogicContext ctx = new SvcLogicContext();
60 propertyDefinitionNode.processMissingParamKeys(inParams, ctx);
61 assertEquals(ctx.getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_STATUS),
62 ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
67 public void testProcessExternalSystemParamKeys() throws Exception {
68 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
69 Map<String, String> inParams = new HashMap<String, String>();
70 inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
72 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
73 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
74 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
76 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
77 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
78 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
80 inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "SOURCE");
82 SvcLogicContext ctx = new SvcLogicContext();
83 propertyDefinitionNode.processExternalSystemParamKeys(inParams, ctx);
85 for (Object key : ctx.getAttributeKeySet()) {
86 String parmName = (String) key;
87 String parmValue = ctx.getAttribute(parmName);
88 if (StringUtils.contains(parmName, "keys")) {
89 System.out.println("Key: " + parmName + ", Value: " + parmValue);
92 assertEquals(ctx.getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_STATUS),
93 ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
97 public void mergeJsonData() throws Exception {
98 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
99 Map<String, String> inParams = new HashMap<String, String>();
100 inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
102 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
103 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
104 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
106 String mergeJsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
107 .getResourceAsStream("parser/merge-param.json"), Charset.defaultCharset());
108 inParams.put(ParamsHandlerConstant.INPUT_PARAM_MERGE__JSON_DATA, mergeJsonData);
110 SvcLogicContext ctx = new SvcLogicContext();
111 propertyDefinitionNode.mergeJsonData(inParams, ctx);
112 String mergedParams = ctx
113 .getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_CONFIGURATION_PARAMETER);
114 assertNotNull(mergedParams);
115 assertEquals(ctx.getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_STATUS),
116 ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
120 public void testArtificatTransformer() throws Exception {
121 ArtificatTransformer transformer = new ArtificatTransformer();
122 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
123 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
125 PropertyDefinition propertyDefinition = transformer.convertYAMLToPD(yamlData);
126 String yaml = transformer.convertPDToYaml(propertyDefinition);
131 public void testValidationPd() throws Exception {
132 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
133 Map<String, String> inParams = new HashMap<String, String>();
134 SvcLogicContext ctx = new SvcLogicContext();
135 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
136 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
137 String mergeJsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
138 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
139 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, jsonData);
140 inParams.put(ParamsHandlerConstant.OUTPUT_PARAM_CONFIGURATION_PARAMETER, mergeJsonData);
141 inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "INSTAR");
142 propertyDefinitionNode.validateParams(inParams, ctx);