2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20 * ============LICENSE_END=========================================================
23 package org.openecomp.sdnc.config.params.parser;
25 import static org.junit.Assert.assertEquals;
28 import java.nio.charset.Charset;
29 import java.nio.file.Files;
30 import java.nio.file.Path;
31 import java.nio.file.Paths;
32 import java.nio.file.attribute.BasicFileAttributes;
33 import java.util.HashMap;
35 import java.util.concurrent.TimeUnit;
37 import org.apache.commons.io.IOUtils;
38 import org.junit.Test;
39 import org.junit.Ignore;
40 import org.openecomp.sdnc.config.params.ParamsHandlerConstant;
41 import org.openecomp.sdnc.config.params.data.PropertyDefinition;
42 import org.openecomp.sdnc.config.params.parser.PropertyDefinitionNode;
43 import org.openecomp.sdnc.config.params.transformer.ArtificatTransformer;
45 import org.openecomp.sdnc.sli.SvcLogicContext;
47 import com.fasterxml.jackson.databind.ObjectMapper;
49 public class TestPropertyDefinitionNode {
52 public void testProcessMissingParamKeys() throws Exception {
53 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
54 Map<String, String> inParams = new HashMap<String, String>();
55 inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
57 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
58 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
60 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
61 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
63 SvcLogicContext ctx = new SvcLogicContext();
64 propertyDefinitionNode.processMissingParamKeys(inParams, ctx);
65 assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
69 public void testProcessExternalSystemParamKeys() throws Exception {
70 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
71 Map<String, String> inParams = new HashMap<String, String>();
72 inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
74 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
75 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
77 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
78 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
80 inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "INSTAR");
82 SvcLogicContext ctx = new SvcLogicContext();
83 propertyDefinitionNode.processExternalSystemParamKeys(inParams, ctx);
84 assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
86 System.out.println("Result: " + ctx.getAttributeKeySet());
87 System.out.println("INSTAR.keys : " + ctx.getAttribute("INSTAR.keys"));
88 System.out.println("INSTAR.LOCAL_CORE_ALT_IP_ADDR.request-logic : " + ctx.getAttribute("INSTAR.LOCAL_ACCESS_IP_ADDR"));
89 System.out.println("INSTAR.LOCAL_CORE_ALT_IP_ADDR.request-logic : " + ctx.getAttribute("INSTAR.LOCAL_CORE_ALT_IP_ADDR"));
93 public void mergeJsonData() throws Exception {
94 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
95 Map<String, String> inParams = new HashMap<String, String>();
96 inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
98 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
99 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
101 String mergeJsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/merge-param.json"), Charset.defaultCharset());
102 inParams.put(ParamsHandlerConstant.INPUT_PARAM_MERGE__JSON_DATA, mergeJsonData);
104 SvcLogicContext ctx = new SvcLogicContext();
105 propertyDefinitionNode.mergeJsonData(inParams, ctx);
106 assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
108 System.out.println("Result: " + ctx.getAttributeKeySet());
109 System.out.println("Merged Value : " + ctx.getAttribute("test." +ParamsHandlerConstant.OUTPUT_PARAM_CONFIGURATION_PARAMETER) );
115 public void testArtificatTransformer() throws Exception {
116 ArtificatTransformer transformer = new ArtificatTransformer();
117 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
119 PropertyDefinition propertyDefinition = transformer.convertYAMLToPD(yamlData);
121 // String json = transformer.transformYamlToJson(yamlData);
122 // System.out.println("TestPropertyDefinitionNode.testArtificatTransformer()" + json);
123 String yaml = transformer.convertPDToYaml(propertyDefinition);
124 System.out.println("TestPropertyDefinitionNode.testArtificatTransformer():\n" + yaml);