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.assertEquals;
25 import java.io.StringReader;
26 import java.util.ArrayList;
27 import java.util.List;
29 import javax.json.Json;
30 import javax.json.JsonArray;
31 import javax.json.JsonObject;
32 import javax.json.JsonReader;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.runners.MockitoJUnitRunner;
37 import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
39 @RunWith(MockitoJUnitRunner.class)
40 public class QueryAllottedResourceCustomizationTest {
43 public void JSON2_Test()
45 List<AllottedResourceCustomization> paramList;
46 paramList = new ArrayList<>();
47 AllottedResourceCustomization d1 = new AllottedResourceCustomization();
48 d1.setModelInstanceName("0cb9b26a-9820-48a7-86e5-16c510e993d9");
49 d1.setModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
52 QueryAllottedResourceCustomization qarcObj = new QueryAllottedResourceCustomization(paramList);
53 String ret = qarcObj.JSON2(true, true);
54 System.out.println(ret);
55 ret = "{" + ret + "}";
57 JsonReader reader = Json.createReader(new StringReader(ret.replaceAll("\r?\n", "")));
58 JsonObject respObj = reader.readObject();
60 JsonArray jArray = respObj.getJsonArray("serviceAllottedResources");
61 assertEquals(jArray.size(), 1);
63 assertEquals(jArray.getJsonObject(0).getJsonObject("modelInfo").getString("modelInstanceName"), "0cb9b26a-9820-48a7-86e5-16c510e993d9");
64 assertEquals(jArray.getJsonObject(0).getJsonObject("modelInfo").getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");