Initial commit for appc-config-params
[appc.git] / appc-config / appc-config-params / provider / src / test / java / org / openecomp / sdnc / config / params / parser / TestPropertyDefinitionNode.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
10  * 
11  *         http://www.apache.org/licenses/LICENSE-2.0
12  * 
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.
18  * 
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.openecomp.sdnc.config.params.parser;
24
25 import static org.junit.Assert.assertEquals;
26
27 import java.io.File;
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;
34 import java.util.Map;
35 import java.util.concurrent.TimeUnit;
36
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;
44
45 import org.openecomp.sdnc.sli.SvcLogicContext;
46
47 import com.fasterxml.jackson.databind.ObjectMapper;
48
49 public class TestPropertyDefinitionNode {
50
51 @Ignore
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");
56
57                 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
58                 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
59
60                 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
61                 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
62
63                 SvcLogicContext ctx = new SvcLogicContext();
64                 propertyDefinitionNode.processMissingParamKeys(inParams, ctx);
65                 assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
66
67         }
68
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");
73
74                 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
75                 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
76
77                 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
78                 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
79
80                 inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "INSTAR");
81
82                 SvcLogicContext ctx = new SvcLogicContext();
83                 propertyDefinitionNode.processExternalSystemParamKeys(inParams, ctx);
84                 assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
85
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"));
90
91         }
92
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");
97
98                 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
99                 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
100
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);
103
104                 SvcLogicContext ctx = new SvcLogicContext();
105                 propertyDefinitionNode.mergeJsonData(inParams, ctx);
106                 assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
107
108                 System.out.println("Result: " + ctx.getAttributeKeySet()); 
109                 System.out.println("Merged Value : " + ctx.getAttribute("test." +ParamsHandlerConstant.OUTPUT_PARAM_CONFIGURATION_PARAMETER) );
110
111
112         }
113
114 //      @Test
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());
118
119                 PropertyDefinition propertyDefinition = transformer.convertYAMLToPD(yamlData);
120
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);
125
126         }
127         
128         
129
130
131 }