AT&T 1712 and 1802 release code
[so.git] / bpmn / MSOCoreBPMN / src / test / java / org / openecomp / mso / bpmn / core / json / JsonUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.mso.bpmn.core.json;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.io.IOException;
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
28 import java.util.Map;
29
30 import org.camunda.bpm.engine.delegate.DelegateExecution;
31 import org.json.JSONArray;
32 import org.json.JSONObject;
33 import org.junit.Test;
34 import org.mockito.Mock;
35
36 public class JsonUtilsTest {
37
38         @Mock public DelegateExecution execution;
39         private final String fileLocation = "src/test/resources/json-examples/";
40
41         @Test
42         public void jsonStringToMapTest() throws IOException {
43                 
44                 JsonUtils utils = new JsonUtils();
45                 String response = this.getJson("SDNCServiceResponseExample.json");
46                 String entry = utils.getJsonValue(response, "SDNCServiceResponse.params");
47                 Map<String, String> map = utils.jsonStringToMap(execution, entry);
48                 assertEquals(map.get("e2e-vpn-key"), "my-key");
49         }
50         
51         @Test
52         public void entryArrayToMapTest() throws IOException {
53                 JsonUtils utils = new JsonUtils();
54                 String response = this.getJson("SNIROExample.json");
55                 String entry = utils.getJsonValue(response, "solutionInfo.placementInfo");
56                 JSONArray arr = new JSONArray(entry);
57                 JSONObject homingDataJson = arr.getJSONObject(0);
58                 JSONArray assignmentInfo = homingDataJson.getJSONArray("assignmentInfo");
59                 Map<String, String> map = utils.entryArrayToMap(execution, assignmentInfo.toString(), "variableName", "variableValue");
60                 assertEquals(map.get("cloudOwner"), "att-aic");
61         }
62         private String getJson(String filename) throws IOException {
63                 return new String(Files.readAllBytes(Paths.get(fileLocation + filename)));
64         }
65 }