1f982b8e638f4797da88ef2d9b9b325c35bcb2e6
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.openecomp.sdnc.config.params.parser;
26
27 import static org.junit.Assert.assertEquals;
28
29 import java.io.File;
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;
36 import java.util.Map;
37 import java.util.concurrent.TimeUnit;
38
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;
46
47 import org.openecomp.sdnc.sli.SvcLogicContext;
48
49 import com.fasterxml.jackson.databind.ObjectMapper;
50
51 public class TestPropertyDefinitionNode {
52
53 @Ignore
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");
58
59                 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
60                 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
61
62                 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
63                 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
64
65                 SvcLogicContext ctx = new SvcLogicContext();
66                 propertyDefinitionNode.processMissingParamKeys(inParams, ctx);
67                 assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
68
69         }
70
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");
75
76                 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
77                 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
78
79                 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
80                 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
81
82                 inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "INSTAR");
83
84                 SvcLogicContext ctx = new SvcLogicContext();
85                 propertyDefinitionNode.processExternalSystemParamKeys(inParams, ctx);
86                 assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
87
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"));
92
93         }
94
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");
99
100                 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
101                 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
102
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);
105
106                 SvcLogicContext ctx = new SvcLogicContext();
107                 propertyDefinitionNode.mergeJsonData(inParams, ctx);
108                 assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
109
110                 System.out.println("Result: " + ctx.getAttributeKeySet()); 
111                 System.out.println("Merged Value : " + ctx.getAttribute("test." +ParamsHandlerConstant.OUTPUT_PARAM_CONFIGURATION_PARAMETER) );
112
113
114         }
115
116 //      @Test
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());
120
121                 PropertyDefinition propertyDefinition = transformer.convertYAMLToPD(yamlData);
122
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);
127
128         }
129         
130         
131
132
133 }