Fix OSGi wiring issues
[ccsdk/features.git] / blueprints-processor / plugin / model-provider / src / test / java / org / onap / ccsdk / features / params / service / ExpressionUtilsTest.java
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  * Modifications Copyright © 2018 IBM.\r
4  * \r
5  * Licensed under the Apache License, Version 2.0 (the "License");\r
6  * you may not use this file except in compliance with the License.\r
7  * You may obtain a copy of the License at\r
8  * \r
9  * http://www.apache.org/licenses/LICENSE-2.0\r
10  * \r
11  * Unless required by applicable law or agreed to in writing, software\r
12  * distributed under the License is distributed on an "AS IS" BASIS,\r
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14  * See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  */\r
17 \r
18 package org.onap.ccsdk.features.params.service;\r
19 \r
20 import java.io.File;\r
21 import java.nio.charset.Charset;\r
22 import java.util.ArrayList;\r
23 import java.util.HashMap;\r
24 import java.util.List;\r
25 import java.util.Map;\r
26 import org.apache.commons.io.FileUtils;\r
27 import org.junit.Test;\r
28 import org.onap.ccsdk.features.model.utils.ExpressionUtils;\r
29 import org.onap.ccsdk.features.model.utils.TransformationUtils;\r
30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
31 import com.att.eelf.configuration.EELFLogger;\r
32 import com.att.eelf.configuration.EELFManager;\r
33 import com.fasterxml.jackson.databind.JsonNode;\r
34 import com.fasterxml.jackson.databind.ObjectMapper;\r
35 \r
36 public class ExpressionUtilsTest {\r
37     private static EELFLogger logger = EELFManager.getInstance().getLogger(ExpressionUtilsTest.class);\r
38 \r
39     @Test\r
40     public void testProcessJsonExpression() throws Exception {\r
41         String fileContent = FileUtils.readFileToString(new File("src/test/resources/properties/default.json"),\r
42                 Charset.defaultCharset());\r
43 \r
44         SvcLogicContext context = new SvcLogicContext();\r
45         context.setAttribute("host-password", "1234");\r
46         context.setAttribute("host-ip-address", "[\"123.23.34.45\", \"123.23.34.45\"]");\r
47         context.setAttribute("loopback-default", "[\"Sample\", \"Brinda\"]");\r
48 \r
49         Map<String, String> inparams = new HashMap<String, String>();\r
50         ExpressionUtils jsonExpressionUtils = new ExpressionUtils(context, inparams);\r
51         ObjectMapper mapper = new ObjectMapper();\r
52         JsonNode rootArray = mapper.readTree(fileContent);\r
53         jsonExpressionUtils.processJsonExpression(rootArray);\r
54 \r
55     }\r
56 \r
57     @Test\r
58     public void testJson2Property() throws Exception {\r
59         String fileContent = FileUtils.readFileToString(new File("src/test/resources/properties/convert.json"),\r
60                 Charset.defaultCharset());\r
61 \r
62         List<String> blockKeys = new ArrayList<String>();\r
63         blockKeys.add(\r
64                 "interfaces.ResourceAssignmentService.operations.getResourceAssignment.inputs.assignment-mappings");\r
65         blockKeys.add("interfaces.ResourceAssignmentService.operations.getResourceAssignment.outputs");\r
66         blockKeys.add("type");\r
67 \r
68         Map<String, String> workflowMap = new HashMap<>();\r
69         Map<String, String> propertyMap =\r
70                 TransformationUtils.convertJson2Properties(workflowMap, fileContent, blockKeys);\r
71 \r
72         TransformationUtils.printMap(propertyMap);\r
73 \r
74     }\r
75 \r
76 }\r