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.openecomp.sdnc.config.params.parser;
27 import static org.junit.Assert.assertEquals;
30 import java.nio.charset.Charset;
31 import java.nio.file.Files;
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
34 import java.nio.file.attribute.BasicFileAttributes;
35 import java.util.HashMap;
37 import java.util.concurrent.TimeUnit;
39 import org.apache.commons.io.IOUtils;
40 import org.junit.Test;
41 import org.junit.Ignore;
42 import org.openecomp.sdnc.config.params.ParamsHandlerConstant;
43 import org.openecomp.sdnc.config.params.data.PropertyDefinition;
44 import org.openecomp.sdnc.config.params.parser.PropertyDefinitionNode;
45 import org.openecomp.sdnc.config.params.transformer.ArtificatTransformer;
47 import org.openecomp.sdnc.sli.SvcLogicContext;
49 import com.fasterxml.jackson.databind.ObjectMapper;
51 public class TestPropertyDefinitionNode {
54 public void testProcessMissingParamKeys() throws Exception {
55 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
56 Map<String, String> inParams = new HashMap<String, String>();
57 inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
59 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
60 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
62 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
63 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
65 SvcLogicContext ctx = new SvcLogicContext();
66 propertyDefinitionNode.processMissingParamKeys(inParams, ctx);
67 assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
71 public void testProcessExternalSystemParamKeys() throws Exception {
72 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
73 Map<String, String> inParams = new HashMap<String, String>();
74 inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
76 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
77 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
79 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
80 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
82 inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "INSTAR");
84 SvcLogicContext ctx = new SvcLogicContext();
85 propertyDefinitionNode.processExternalSystemParamKeys(inParams, ctx);
86 assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
88 System.out.println("Result: " + ctx.getAttributeKeySet());
89 System.out.println("INSTAR.keys : " + ctx.getAttribute("INSTAR.keys"));
90 System.out.println("INSTAR.LOCAL_CORE_ALT_IP_ADDR.request-logic : " + ctx.getAttribute("INSTAR.LOCAL_ACCESS_IP_ADDR"));
91 System.out.println("INSTAR.LOCAL_CORE_ALT_IP_ADDR.request-logic : " + ctx.getAttribute("INSTAR.LOCAL_CORE_ALT_IP_ADDR"));
95 public void mergeJsonData() throws Exception {
96 PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
97 Map<String, String> inParams = new HashMap<String, String>();
98 inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
100 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
101 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
103 String mergeJsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/merge-param.json"), Charset.defaultCharset());
104 inParams.put(ParamsHandlerConstant.INPUT_PARAM_MERGE__JSON_DATA, mergeJsonData);
106 SvcLogicContext ctx = new SvcLogicContext();
107 propertyDefinitionNode.mergeJsonData(inParams, ctx);
108 assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
110 System.out.println("Result: " + ctx.getAttributeKeySet());
111 System.out.println("Merged Value : " + ctx.getAttribute("test." +ParamsHandlerConstant.OUTPUT_PARAM_CONFIGURATION_PARAMETER) );
117 public void testArtificatTransformer() throws Exception {
118 ArtificatTransformer transformer = new ArtificatTransformer();
119 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
121 PropertyDefinition propertyDefinition = transformer.convertYAMLToPD(yamlData);
123 // String json = transformer.transformYamlToJson(yamlData);
124 // System.out.println("TestPropertyDefinitionNode.testArtificatTransformer()" + json);
125 String yaml = transformer.convertPDToYaml(propertyDefinition);
126 System.out.println("TestPropertyDefinitionNode.testArtificatTransformer():\n" + yaml);