More license header updates to appc-config files
[appc.git] / appc-config / appc-config-params / provider / src / test / java / org / onap / sdnc / config / params / parser / TestPropertyDefinitionNode.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 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  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.sdnc.config.params.parser;
25
26
27
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertNotNull;
30 import java.nio.charset.Charset;
31 import java.util.HashMap;
32 import java.util.Map;
33 import org.apache.commons.io.IOUtils;
34 import org.apache.commons.lang.StringUtils;
35 import org.junit.Ignore;
36 import org.junit.Test;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
38 import org.onap.sdnc.config.params.ParamsHandlerConstant;
39 import org.onap.sdnc.config.params.data.PropertyDefinition;
40 import org.onap.sdnc.config.params.transformer.ArtificatTransformer;
41
42 public class TestPropertyDefinitionNode {
43
44     @Ignore
45     public void testProcessMissingParamKeys() throws Exception {
46         PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
47         Map<String, String> inParams = new HashMap<String, String>();
48         inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
49
50         String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
51                 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
52         inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
53
54         String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
55                 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
56         inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
57
58         SvcLogicContext ctx = new SvcLogicContext();
59         propertyDefinitionNode.processMissingParamKeys(inParams, ctx);
60         assertEquals(ctx.getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_STATUS),
61                 ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
62
63     }
64
65     @Test
66     public void testProcessExternalSystemParamKeys() throws Exception {
67         PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
68         Map<String, String> inParams = new HashMap<String, String>();
69         inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
70
71         String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
72                 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
73         inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
74
75         String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
76                 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
77         inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
78
79         inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "SOURCE");
80
81         SvcLogicContext ctx = new SvcLogicContext();
82         propertyDefinitionNode.processExternalSystemParamKeys(inParams, ctx);
83
84         for (Object key : ctx.getAttributeKeySet()) {
85             String parmName = (String) key;
86             String parmValue = ctx.getAttribute(parmName);
87             if (StringUtils.contains(parmName, "keys")) {
88                 System.out.println("Key: " + parmName + ",    Value: " + parmValue);
89             }
90         }
91         assertEquals(ctx.getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_STATUS),
92                 ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
93     }
94
95     @Test
96     public void mergeJsonData() throws Exception {
97         PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
98         Map<String, String> inParams = new HashMap<String, String>();
99         inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
100
101         String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
102                 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
103         inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
104
105         String mergeJsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
106                 .getResourceAsStream("parser/merge-param.json"), Charset.defaultCharset());
107         inParams.put(ParamsHandlerConstant.INPUT_PARAM_MERGE__JSON_DATA, mergeJsonData);
108
109         SvcLogicContext ctx = new SvcLogicContext();
110         propertyDefinitionNode.mergeJsonData(inParams, ctx);
111         String mergedParams = ctx
112                 .getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_CONFIGURATION_PARAMETER);
113         assertNotNull(mergedParams);
114         assertEquals(ctx.getAttribute("test." + ParamsHandlerConstant.OUTPUT_PARAM_STATUS),
115                 ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
116     }
117
118     @Test
119     public void testArtificatTransformer() throws Exception {
120         ArtificatTransformer transformer = new ArtificatTransformer();
121         String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
122                 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
123
124         PropertyDefinition propertyDefinition = transformer.convertYAMLToPD(yamlData);
125         String yaml = transformer.convertPDToYaml(propertyDefinition);
126     }
127
128
129     @Test
130     public void testValidationPd() throws Exception {
131         PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
132         Map<String, String> inParams = new HashMap<String, String>();
133         SvcLogicContext ctx = new SvcLogicContext();
134         String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
135                 .getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
136         String mergeJsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader()
137                 .getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
138         inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, jsonData);
139         inParams.put(ParamsHandlerConstant.OUTPUT_PARAM_CONFIGURATION_PARAMETER, mergeJsonData);
140         inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "INSTAR");
141         propertyDefinitionNode.validateParams(inParams, ctx);
142     }
143
144 }