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.onap.ccsdk.sli.core.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);
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");
77 String yamlData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/pd.yaml"), Charset.defaultCharset());
78 inParams.put(ParamsHandlerConstant.INPUT_PARAM_PD_CONTENT, yamlData);
80 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
81 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
83 inParams.put(ParamsHandlerConstant.INPUT_PARAM_SYSTEM_NAME, "SOURCE");
85 SvcLogicContext ctx = new SvcLogicContext();
86 propertyDefinitionNode.processExternalSystemParamKeys(inParams, ctx);
87 assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
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");
96 String jsonData = IOUtils.toString(TestPropertyDefinitionNode.class.getClassLoader().getResourceAsStream("parser/request-param.json"), Charset.defaultCharset());
97 inParams.put(ParamsHandlerConstant.INPUT_PARAM_JSON_DATA, jsonData);
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);
102 SvcLogicContext ctx = new SvcLogicContext();
103 propertyDefinitionNode.mergeJsonData(inParams, ctx);
104 assertEquals(ctx.getAttribute("test."+ParamsHandlerConstant.OUTPUT_PARAM_STATUS), ParamsHandlerConstant.OUTPUT_STATUS_SUCCESS);
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());
112 PropertyDefinition propertyDefinition = transformer.convertYAMLToPD(yamlData);
113 String yaml = transformer.convertPDToYaml(propertyDefinition);