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.adapters.catalogdb.catalogrest;
23 import static org.junit.Assert.assertTrue;
25 import java.io.StringReader;
26 import java.util.ArrayList;
28 import javax.json.Json;
29 import javax.json.JsonArray;
30 import javax.json.JsonObject;
31 import javax.json.JsonReader;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.runners.MockitoJUnitRunner;
36 import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
37 import org.openecomp.mso.db.catalog.beans.Service;
38 import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder;
40 @RunWith(MockitoJUnitRunner.class)
41 public class QueryServiceMarcoHolderTest {
44 public void JSON2_Test() {
45 Service svc = new Service();
46 svc.setModelUUID("0cb9b26a-9820-48a7-86e5-16c510e993d9");
47 svc.setModelName("Testing Model One");
48 ArrayList<NetworkResourceCustomization> paramList;
49 paramList = new ArrayList<>();
50 NetworkResourceCustomization d1 = new NetworkResourceCustomization();
51 d1.setNetworkResourceModelUuid("0cb9b26a-9820-48a7-86e5-16c510e993d9");
53 ServiceMacroHolder ret = new ServiceMacroHolder(svc);
54 ret.setNetworkResourceCustomization(paramList);
55 QueryServiceMacroHolder holder = new QueryServiceMacroHolder(ret);
56 String s = holder.JSON2(true, true);
58 // System.out.println(s);
60 // prepare to inspect response
61 JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", "")));
62 JsonObject respObj = reader.readObject();
64 JsonObject obj = respObj.getJsonObject("serviceResources");
65 JsonObject obj2 = obj.getJsonObject("modelInfo");
66 String modelName = obj2.getString("modelName");
67 String modelUuid = obj2.getString("modelUuid");
69 assertTrue(modelName.equals("Testing Model One"));
70 assertTrue(modelUuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9"));