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 java.io.StringReader;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 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.Mockito;
37 import org.mockito.runners.MockitoJUnitRunner;
38 import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization;
40 import static org.junit.Assert.*;
43 @RunWith(MockitoJUnitRunner.class)
44 public class CatalogQueryTest {
48 public void catalogQuerySetTemplateImpl_Test(){
49 CatalogQuery mockCatalogQuery = Mockito.mock(CatalogQuery.class);
50 Mockito.doCallRealMethod().when(mockCatalogQuery).setTemplate(Mockito.anyString(), Mockito.anyMapOf(String.class, String.class));
52 Map<String,String> valueMap = new HashMap<String,String>();
53 valueMap.put("somekey", "somevalue");
55 String ret = mockCatalogQuery.setTemplate("<somekey>", valueMap);
57 assertTrue(ret.equalsIgnoreCase("somevalue"));
61 public void smartToJson_Test()
63 List<VnfResourceCustomization> paramList = new ArrayList<VnfResourceCustomization>();
64 VnfResourceCustomization d1 = new VnfResourceCustomization();
65 d1.setModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
66 d1.setModelInstanceName("RG_6-26_mog11 0");
70 QueryServiceVnfs qryResp = new QueryServiceVnfs(paramList);
71 QueryServiceVnfs mockCatalogQuery = Mockito.spy(qryResp);
72 Mockito.doCallRealMethod().when(mockCatalogQuery).smartToJSON();
73 String ret = qryResp.smartToJSON();
74 // System.out.println(ret);
76 JsonReader reader = Json.createReader(new StringReader(ret.replaceAll("\r?\n", "")));
77 JsonObject respObj = reader.readObject();
79 JsonArray jArray = respObj.getJsonArray("serviceVnfs");
80 assertEquals(jArray.size(), 1);
81 assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
85 public void toJsonString_Test()
87 CatalogQueryExtendedTest mockCatalogQuery = Mockito.mock(CatalogQueryExtendedTest.class);
88 Mockito.doCallRealMethod().when(mockCatalogQuery).JSON2(Mockito.anyBoolean(), Mockito.anyBoolean());
89 String ret = mockCatalogQuery.JSON2(true, true);
91 // System.out.println(ret);
93 JsonReader reader = Json.createReader(new StringReader(ret.replaceAll("\r?\n", "")));
94 JsonObject respObj = reader.readObject();
96 JsonArray jArray = respObj.getJsonArray("serviceVnfs");
97 assertEquals(jArray.size(), 1);
98 assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
99 assertEquals(jArray.getJsonObject(0).getString("version"), "v2");
102 class CatalogQueryExtendedTest extends CatalogQuery{
104 public String JSON2(boolean isArray, boolean isEmbed) {
105 return "{\"serviceVnfs\":[{\"version\":\"v2\",\"modelCustomizationUuid\":\"16ea3e56-a8ce-4ad7-8edd-4d2eae095391\",\"modelInstanceName\":\"ciVFOnboarded-FNAT-aab06c41 1\",\"created\":null,\"vnfResourceModelUuid\":null,\"vnfResourceModelUUID\":null,\"minInstances\":null,\"maxInstances\":null,\"availabilityZoneMaxCount\":null,\"vnfResource\":null,\"nfFunction\":null,\"nfType\":null,\"nfRole\":null,\"nfNamingCode\":null,\"multiStageDesign\":null,\"vfModuleCustomizations\":null,\"serviceResourceCustomizations\":null,\"creationTimestamp\":null}]}";