2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.bpmn.core.json;
23 import static org.junit.Assert.assertEquals;
25 import java.io.IOException;
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
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;
36 public class JsonUtilsTest {
38 @Mock public DelegateExecution execution;
39 private final String fileLocation = "src/test/resources/json-examples/";
42 public void jsonStringToMapTest() throws IOException {
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");
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.placement");
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");
62 private String getJson(String filename) throws IOException {
63 return new String(Files.readAllBytes(Paths.get(fileLocation + filename)));