Second part of onap rename
[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 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.onap.ccsdk.sli.core.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     @Test
72     public void testProcessExternalSystemParamKeys() throws Exception {
73         PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
74         Map<String, String> inParams = new HashMap<String, String>();
75         inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
76
77         String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
78         inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
79
80         String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
81         inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
82
83         inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "SOURCE");
84
85         SvcLogicContext ctx = new SvcLogicContext();
86         propertyDefinitionNode.processExternalSystemParamKeys(inParams, ctx);
87         assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
88 }
89
90     @Test
91     public void mergeJsonData() throws Exception {
92         PropertyDefinitionNode propertyDefinitionNode = new PropertyDefinitionNode();
93         Map<String, String> inParams = new HashMap<String, String>();
94         inParams.put(ParamsHandlerConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
95
96         String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
97         inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
98
99         String mergeJsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/merge-param.json"), Charset.defaultCharset());
100         inParams.put(ParamsHandlerConstant.INPUT_PARAM_MERGE__JSON_DATA, mergeJsonData);
101
102         SvcLogicContext ctx = new SvcLogicContext();
103         propertyDefinitionNode.mergeJsonData(inParams, ctx);
104         assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
105     }
106
107     @Test
108     public void testArtificatTransformer() throws Exception {
109         ArtificatTransformer transformer = new ArtificatTransformer();
110         String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
111
112         PropertyDefinition propertyDefinition = transformer.convertYAMLToPD(yamlData);
113         String yaml = transformer.convertPDToYaml(propertyDefinition);
114     }
115     
116 }