summaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-catalog-db-adapter/pom.xml66
-rw-r--r--adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestClassTest.java380
-rw-r--r--adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestHttpTest.java490
-rw-r--r--adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryTest.java112
-rw-r--r--adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomizationTest.java67
-rw-r--r--adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMarcoHolderTest.java74
-rw-r--r--adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceNetworksTest.java72
-rw-r--r--adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceVnfsTest.java73
8 files changed, 1334 insertions, 0 deletions
diff --git a/adapters/mso-catalog-db-adapter/pom.xml b/adapters/mso-catalog-db-adapter/pom.xml
index 4459660240..752d7f66fa 100644
--- a/adapters/mso-catalog-db-adapter/pom.xml
+++ b/adapters/mso-catalog-db-adapter/pom.xml
@@ -99,6 +99,72 @@
<artifactId>status-control</artifactId>
<version>${project.version}</version>
</dependency>-->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.10.19</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>2.0.5-beta</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>1.6.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.6.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.json</groupId>
+ <artifactId>javax.json-api</artifactId>
+ <version>1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish</groupId>
+ <artifactId>javax.json</artifactId>
+ <version>1.0.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <version>1.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-client</artifactId>
+ <version>3.0.19.Final</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>tjws</artifactId>
+ <version>3.0.19.Final</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project> \ No newline at end of file
diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestClassTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestClassTest.java
new file mode 100644
index 0000000000..31a58329d6
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestClassTest.java
@@ -0,0 +1,380 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.catalogdb;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.http.HttpStatus;
+import javax.json.*;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openecomp.mso.adapters.catalogdb.CatalogDbAdapterRest;
+import org.openecomp.mso.adapters.catalogdb.catalogrest.CatalogQueryException;
+import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceVnfs;
+import org.openecomp.mso.db.catalog.CatalogDatabase;
+import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.junit.Before;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.when;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.verifyStatic;
+import static org.hamcrest.CoreMatchers.instanceOf;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({CatalogDbAdapterRest.class, CatalogDatabase.class})
+public class CatalogDbAdapterRestClassTest {
+ @Mock
+ private static CatalogDatabase dbMock;
+
+ private static List<VnfResourceCustomization> paramList;
+
+ @Before
+ public void prepare () {
+ /*
+ * 1. for non routing related methods/classes, use mockito
+ * 2. for routing methods, use TJWSEmbeddedJaxrsServer
+ */
+
+ /*
+ * in the setup portion, create a mock db object
+ *
+ */
+ // set up mock return value
+ paramList = new ArrayList<VnfResourceCustomization>();
+ VnfResourceCustomization d1 = new VnfResourceCustomization();
+ d1.setModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ d1.setModelInstanceName("ciVFOnboarded-FNAT-aab06c41 1");
+ paramList.add(d1);
+ // end
+
+ PowerMockito.mockStatic(CatalogDatabase.class);
+ dbMock = PowerMockito.mock(CatalogDatabase.class);
+ PowerMockito.when(CatalogDatabase.getInstance()).thenReturn(dbMock);
+ try {
+
+ PowerMockito.whenNew(CatalogDatabase.class).withAnyArguments().thenReturn(dbMock);
+ PowerMockito.spy (dbMock);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void respond_Test(){
+ QueryServiceVnfs qryResp = new QueryServiceVnfs(paramList);
+ CatalogDbAdapterRest adapter = new CatalogDbAdapterRest();
+ CatalogDbAdapterRest spyAdapter = Mockito.spy(adapter);
+
+ Response resp = spyAdapter.respond("v1", HttpStatus.SC_OK, false, qryResp);
+ Mockito.verify(spyAdapter,Mockito.times(1)).respond("v1", HttpStatus.SC_OK, false, qryResp);
+
+ String s = resp.getEntity().toString();
+ // System.out.println(s);
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ // end
+ JsonArray jArray = respObj.getJsonArray("serviceVnfs");
+
+ assertEquals(resp.getStatus(), HttpStatus.SC_OK);
+ assertEquals(jArray.size(), 1);
+ assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ }
+
+
+ @Test
+ public void serviceVnfsImpl_vnfUuid_ver_Test()
+ {
+ PowerMockito.when(dbMock.getAllVnfsByVnfModelCustomizationUuid(Mockito.anyString())).thenReturn (paramList);
+
+ try {
+ CatalogDbAdapterRest adapter = new CatalogDbAdapterRest();
+
+ // Run
+ Response resp = adapter.serviceVnfsImpl("v1", true, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null, null, null);
+ String s = resp.getEntity().toString();
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ // end
+ JsonArray jArray = respObj.getJsonArray("serviceVnfs");
+
+ assertEquals(resp.getStatus(), HttpStatus.SC_OK);
+ assertEquals(jArray.size(), 1);
+ assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ //
+ Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByVnfModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void serviceVnfsImpl_smiUuid_NoVer_Test()
+ {
+ PowerMockito.when(dbMock.getAllVnfsByServiceModelInvariantUuid(Mockito.anyString())).thenReturn (paramList);
+
+ try {
+ CatalogDbAdapterRest adapter = new CatalogDbAdapterRest();
+
+ // Run
+ Response resp = adapter.serviceVnfsImpl("v1", true, null, null, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null);
+ String s = resp.getEntity().toString();
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ // end
+ JsonArray jArray = respObj.getJsonArray("serviceVnfs");
+
+ assertEquals(resp.getStatus(), HttpStatus.SC_OK);
+ assertEquals(jArray.size(), 1);
+ assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByServiceModelInvariantUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void serviceVnfsImpl_smUuid_ver_Test()
+ {
+ PowerMockito.when(dbMock.getAllVnfsByServiceModelUuid(Mockito.anyString())).thenReturn (paramList);
+
+ try {
+ CatalogDbAdapterRest adapter = new CatalogDbAdapterRest();
+
+ // Run
+ Response resp = adapter.serviceVnfsImpl("v1", true, null,"16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null, null);
+ String s = resp.getEntity().toString();
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ // end
+ JsonArray jArray = respObj.getJsonArray("serviceVnfs");
+
+ assertEquals(resp.getStatus(), HttpStatus.SC_OK);
+ assertEquals(jArray.size(), 1);
+ assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByServiceModelUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void serviceVnfsImpl_smiUuid_ver_Test()
+ {
+ PowerMockito.when(dbMock.getAllVnfsByServiceModelInvariantUuid(Mockito.anyString(),Mockito.anyString())).thenReturn (paramList);
+
+ try {
+ CatalogDbAdapterRest adapter = new CatalogDbAdapterRest();
+
+ // Run
+ Response resp = adapter.serviceVnfsImpl("v1", true, null, null, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", "v1", null);
+ String s = resp.getEntity().toString();
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonArray jArray = respObj.getJsonArray("serviceVnfs");
+ // end
+
+ assertEquals(resp.getStatus(), HttpStatus.SC_OK);
+ assertEquals(jArray.size(), 1);
+ assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByServiceModelInvariantUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391","v1");
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void serviceVnfsImpl_smName_ver_Test()
+ {
+ PowerMockito.when(dbMock.getAllVnfsByServiceName(Mockito.anyString(),Mockito.anyString())).thenReturn (paramList);
+
+ try {
+ CatalogDbAdapterRest adapter = new CatalogDbAdapterRest();
+
+ // Run
+ Response resp = adapter.serviceVnfsImpl("v1", true, null, null, null, "v1", "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ String s = resp.getEntity().toString();
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ // end
+ JsonArray jArray = respObj.getJsonArray("serviceVnfs");
+
+ assertEquals(resp.getStatus(), HttpStatus.SC_OK);
+ assertEquals(jArray.size(), 1);
+ assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByServiceName("16ea3e56-a8ce-4ad7-8edd-4d2eae095391","v1");
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void serviceVnfsImpl_smName_NoVer_Test()
+ {
+ PowerMockito.when(dbMock.getAllVnfsByServiceName(Mockito.anyString())).thenReturn (paramList);
+
+ try {
+ CatalogDbAdapterRest adapter = new CatalogDbAdapterRest();
+
+ // Run
+ Response resp = adapter.serviceVnfsImpl("v1", true, null, null, null, null, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ String s = resp.getEntity().toString();
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ // end
+ JsonArray jArray = respObj.getJsonArray("serviceVnfs");
+
+ assertEquals(resp.getStatus(), HttpStatus.SC_OK);
+ assertEquals(jArray.size(), 1);
+ assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByServiceName("16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void serviceVnfsImpl_Exception_Test()
+ {
+ PowerMockito.when(dbMock.getAllVnfsByServiceName(Mockito.anyString())).thenReturn (null);
+
+ try {
+ CatalogDbAdapterRest adapter = new CatalogDbAdapterRest();
+
+ // Run
+ Response resp = adapter.serviceVnfsImpl("v1", true, null, null, null, null, null);
+
+ assertEquals(resp.getStatus(), HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ assertThat(resp.getEntity(), instanceOf(CatalogQueryException.class));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void serviceNetworksImpl_nUuid_ver_Test(){
+ CatalogDbAdapterRest adapter = new CatalogDbAdapterRest();
+ CatalogDbAdapterRest spyAdapter = Mockito.spy(adapter);
+
+ Response resp = Response
+ .status(HttpStatus.SC_OK)
+ .entity("{\"serviceVnfs\":[{\"version\":\"v1\",\"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}]}")
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .build();
+
+ Mockito.doReturn(resp).when(spyAdapter).serviceNetworksImpl(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
+
+ // Run
+
+ Response ret = spyAdapter.serviceNetworksImpl("v1", false, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391",null, null, null, null);
+ Mockito.verify(spyAdapter).serviceNetworksImpl("v1", false, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null, null, null);
+
+ assertTrue(ret.getStatus() == HttpStatus.SC_OK);
+ String s = resp.getEntity().toString();
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ // end
+ JsonArray jArray = respObj.getJsonArray("serviceVnfs");
+
+ assertEquals(resp.getStatus(), HttpStatus.SC_OK);
+ assertEquals(jArray.size(), 1);
+ assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+
+ }
+
+ @Test
+ public void serviceAllottedResourcesImpl_Test()
+ {
+ CatalogDbAdapterRest adapter = new CatalogDbAdapterRest();
+ CatalogDbAdapterRest spyAdapter = Mockito.spy(adapter);
+
+ Response resp = Response
+ .status(HttpStatus.SC_OK)
+ .entity("{\"serviceVnfs\":[{\"version\":\"v1\",\"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}]}")
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .build();
+
+ Mockito.doReturn(resp).when(spyAdapter).serviceAllottedResourcesImpl(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
+
+ // Run
+
+ Response ret = spyAdapter.serviceAllottedResourcesImpl("v1", false, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391",null, null, null);
+ Mockito.verify(spyAdapter).serviceAllottedResourcesImpl("v1", false, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null, null);
+
+ assertTrue(ret.getStatus() == HttpStatus.SC_OK);
+ String s = resp.getEntity().toString();
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ // end
+ JsonArray jArray = respObj.getJsonArray("serviceVnfs");
+
+ assertEquals(resp.getStatus(), HttpStatus.SC_OK);
+ assertEquals(jArray.size(), 1);
+ assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+
+ }
+
+}
diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestHttpTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestHttpTest.java
new file mode 100644
index 0000000000..33f5553115
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestHttpTest.java
@@ -0,0 +1,490 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.catalogdb;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.jboss.resteasy.plugins.server.tjws.TJWSEmbeddedJaxrsServer;
+import static org.junit.Assert.*;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.resteasy.spi.Registry;
+import org.jboss.resteasy.spi.ResteasyProviderFactory;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.openecomp.mso.adapters.catalogdb.CatalogDbAdapterRest;
+import org.openecomp.mso.db.catalog.CatalogDatabase;
+import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
+import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
+import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder;
+import org.openecomp.mso.db.catalog.beans.VfModule;
+import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
+import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.apache.http.HttpStatus;
+import org.jboss.resteasy.client.jaxrs.ResteasyClient;
+import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
+import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({CatalogDatabase.class})
+@PowerMockIgnore("javax.net.ssl.*")
+public class CatalogDbAdapterRestHttpTest {
+ @Mock
+ private static CatalogDatabase dbMock;
+ private static TJWSEmbeddedJaxrsServer server;
+ private static final int PORT = 3099;
+ private static Registry registry;
+ private static ResteasyProviderFactory factory;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ server = new TJWSEmbeddedJaxrsServer();
+ server.setPort(PORT);
+ server.start();
+ registry = server.getDeployment().getRegistry();
+ factory = server.getDeployment().getDispatcher().getProviderFactory();
+ registry.addPerRequestResource(CatalogDbAdapterRest.class);
+ factory.registerProvider(CatalogDbAdapterRest.class);
+ }
+
+ @Before
+ public void before(){
+ PowerMockito.mockStatic(CatalogDatabase.class);
+ dbMock = PowerMockito.mock(CatalogDatabase.class);
+ PowerMockito.when(CatalogDatabase.getInstance()).thenReturn(dbMock);
+
+ try {
+ PowerMockito.whenNew(CatalogDatabase.class).withAnyArguments().thenReturn(dbMock);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void healthCheck_Test(){
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:3099/v1/healthcheck");
+ Response response = target.request().get();
+ String value = response.readEntity(String.class);
+ assertTrue(value.contains("Application v1 ready"));
+ }
+
+ @Test
+ public void vnfResourcesUrl_Test()
+ {
+ try {
+ List<VnfResourceCustomization> paramList;
+ // set up mock return value
+ paramList = new ArrayList<VnfResourceCustomization>();
+ VnfResourceCustomization d1 = new VnfResourceCustomization();
+ d1.setModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ d1.setModelInstanceName("RG_6-26_mog11 0");
+ d1.setVersion("v1");
+ paramList.add(d1);
+ PowerMockito.when(dbMock.getAllVnfsByVnfModelCustomizationUuid(Mockito.anyString())).thenReturn (paramList);
+ // end
+
+ // Run
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:3099/v1/vnfResources/16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ Response response = target.request().get();
+ String value = response.readEntity(String.class);
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonArray jArray = respObj.getJsonArray("serviceVnfs");
+ assertTrue(jArray.size() == 1);
+ if(jArray.size() == 1){
+ JsonObject rec = jArray.getJsonObject(0);
+ String version = rec.getString("version");
+ String uuid = rec.getString("modelCustomizationUuid");
+
+ assertTrue(version.equals("v1"));
+ assertTrue(uuid.equals("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"));
+ }
+ // end
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void serviceVnfsUrl_smiUuid_smVer_Test(){
+ try {
+ List<VnfResourceCustomization> paramList;
+ // set up mock return value
+ paramList = new ArrayList<VnfResourceCustomization>();
+ VnfResourceCustomization d1 = new VnfResourceCustomization();
+ d1.setVnfResourceModelUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ d1.setModelInstanceName("RG_6-26_mog11 0");
+ d1.setVersion("v1");
+ d1.setMaxInstances(50);
+ paramList.add(d1);
+ PowerMockito.when(dbMock.getAllVnfsByServiceModelInvariantUuid(Mockito.anyString(),Mockito.anyString())).thenReturn (paramList);
+ // end
+
+ // Run
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:3099/v1/serviceVnfs?serviceModelInvariantUuid=16ea3e56-a8ce-4ad7-8edd-4d2eae095391&serviceModelVersion=ver1");
+ Response response = target.request().get();
+ String value = response.readEntity(String.class);
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonArray jArray = respObj.getJsonArray("serviceVnfs");
+ assertTrue(jArray.size() == 1);
+ if(jArray.size() == 1){
+ JsonObject rec = jArray.getJsonObject(0);
+ String version = rec.getString("version");
+ String uuid = rec.getString("vnfResourceModelUuid");
+ int maxInstance = rec.getInt("maxInstances");
+
+ assertTrue(version.equals("v1"));
+ assertTrue(uuid.equals("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"));
+ assertTrue(maxInstance == 50);
+ }
+ // end
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void serviceVnfsUrl_vnfUuid_Test(){
+ try {
+ List<VnfResourceCustomization> paramList;
+ // set up mock return value
+ paramList = new ArrayList<VnfResourceCustomization>();
+ VnfResourceCustomization d1 = new VnfResourceCustomization();
+ d1.setModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ d1.setModelInstanceName("RG_6-26_mog11 0");
+ d1.setVersion("v1");
+ paramList.add(d1);
+ PowerMockito.when(dbMock.getAllVnfsByVnfModelCustomizationUuid(Mockito.anyString())).thenReturn (paramList);
+ // end
+
+ // Run
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:3099/v1/serviceVnfs?vnfModelCustomizationUuid=16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ Response response = target.request().get();
+ String value = response.readEntity(String.class);
+
+ // System.out.println(value);
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonArray jArray = respObj.getJsonArray("serviceVnfs");
+ assertTrue(jArray.size() == 1);
+ if(jArray.size() == 1){
+ JsonObject rec = jArray.getJsonObject(0);
+ String version = rec.getString("version");
+ String uuid = rec.getString("modelCustomizationUuid");
+
+ assertTrue(version.equals("v1"));
+ assertTrue(uuid.equals("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"));
+ }
+ // end
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void networkResourcesUrl_nUuid_Ver_Test(){
+ try {
+ List<NetworkResourceCustomization> paramList;
+ // set up mock return value
+ paramList = new ArrayList<NetworkResourceCustomization>();
+ NetworkResourceCustomization d1 = new NetworkResourceCustomization();
+ d1.setNetworkResourceModelUuid("0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ paramList.add(d1);
+ PowerMockito.when(dbMock.getAllNetworksByNetworkModelCustomizationUuid(Mockito.anyString())).thenReturn (paramList);
+ // end
+
+ // Run
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:3099/v1/networkResources/0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ Response response = target.request().get();
+ String value = response.readEntity(String.class);
+
+ // System.out.println(value);
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonArray jArray = respObj.getJsonArray("serviceNetworks");
+ assertTrue(jArray.size() == 1);
+ if(jArray.size() == 1){
+ JsonObject rec = jArray.getJsonObject(0);
+ String uuid = rec.getString("networkResourceModelUuid");
+
+ assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9"));
+ }
+ // end
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void serviceNetworksUrl_nType_Test(){
+ try {
+ List<NetworkResourceCustomization> paramList;
+ // set up mock return value
+ paramList = new ArrayList<NetworkResourceCustomization>();
+ NetworkResourceCustomization d1 = new NetworkResourceCustomization();
+ d1.setNetworkResourceModelUuid("0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ paramList.add(d1);
+ PowerMockito.when(dbMock.getAllNetworksByNetworkType(Mockito.anyString())).thenReturn (paramList);
+ // end
+
+ // Run
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:3099/v1/serviceNetworks?networkModelName=0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ Response response = target.request().get();
+ String value = response.readEntity(String.class);
+
+ // System.out.println(value);
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonArray jArray = respObj.getJsonArray("serviceNetworks");
+ assertTrue(jArray.size() == 1);
+ if(jArray.size() == 1){
+ JsonObject rec = jArray.getJsonObject(0);
+ String uuid = rec.getString("networkResourceModelUuid");
+
+ assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9"));
+ }
+ // end
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void serviceResourcesUrl_smiUuid_Ver_Test(){
+ try {
+ ArrayList<NetworkResourceCustomization> paramList;
+ // set up mock return value
+ paramList = new ArrayList<NetworkResourceCustomization>();
+ NetworkResourceCustomization d1 = new NetworkResourceCustomization();
+ d1.setNetworkResourceModelUuid("0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ paramList.add(d1);
+ ServiceMacroHolder ret = new ServiceMacroHolder();
+ ret.setNetworkResourceCustomization(paramList);
+ PowerMockito.when(dbMock.getAllResourcesByServiceModelInvariantUuid(Mockito.anyString(),Mockito.anyString())).thenReturn (ret);
+ // end
+
+ // Run
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:3099/v1/serviceResources?serviceModelInvariantUuid=0cb9b26a-9820-48a7-86e5-16c510e993d9&serviceModelVersion=ver1");
+ Response response = target.request().get();
+ String value = response.readEntity(String.class);
+
+ // System.out.println(value);
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonObject obj = respObj.getJsonObject("serviceResources");
+ JsonArray jArray = obj.getJsonArray("networkResourceCustomization");
+ assertTrue(jArray.size() == 1);
+
+ if(jArray.size() == 1){
+ JsonObject rec = jArray.getJsonObject(0);
+ String uuid = rec.getString("networkResourceModelUuid");
+
+ assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9"));
+ }
+ // end
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void allottedResourcesUrl_aUuid_Test()
+ {
+ try {
+ List<AllottedResourceCustomization> paramList;
+ // set up mock return value
+ paramList = new ArrayList<AllottedResourceCustomization>();
+ AllottedResourceCustomization d1 = new AllottedResourceCustomization();
+ d1.setArModelUuid("0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ paramList.add(d1);
+ PowerMockito.when(dbMock.getAllAllottedResourcesByArModelCustomizationUuid(Mockito.anyString())).thenReturn (paramList);
+ // end
+
+ // Run
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:3099/v1/allottedResources/0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ Response response = target.request().get();
+ String value = response.readEntity(String.class);
+
+ // System.out.println(value);
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonArray jArray = respObj.getJsonArray("serviceAllottedResources");
+ assertTrue(jArray.size() == 1);
+ if(jArray.size() == 1){
+ JsonObject rec = jArray.getJsonObject(0);
+ String uuid = rec.getString("arModelUuid");
+
+ assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9"));
+ }
+ // end
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+
+ }
+
+ @Test
+ public void serviceAllottedResourcesUrl_smiUuid_Test()
+ {
+ try {
+ List<AllottedResourceCustomization> paramList;
+ // set up mock return value
+ paramList = new ArrayList<AllottedResourceCustomization>();
+ AllottedResourceCustomization d1 = new AllottedResourceCustomization();
+ d1.setArModelUuid("0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ paramList.add(d1);
+ PowerMockito.when(dbMock.getAllAllottedResourcesByServiceModelInvariantUuid(Mockito.anyString(), Mockito.anyString())).thenReturn (paramList);
+ // end
+
+ // Run
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:3099/v1/serviceAllottedResources?serviceModelInvariantUuid=0cb9b26a-9820-48a7-86e5-16c510e993d9&serviceModelVersion=ver1");
+ Response response = target.request().get();
+ String value = response.readEntity(String.class);
+
+ // System.out.println(value);
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonArray jArray = respObj.getJsonArray("serviceAllottedResources");
+ assertTrue(jArray.size() == 1);
+ if(jArray.size() == 1){
+ JsonObject rec = jArray.getJsonObject(0);
+ String uuid = rec.getString("arModelUuid");
+
+ assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9"));
+ }
+ // end
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void vfModulesUrl_modelName_Test()
+ {
+ try {
+ // set up mock return value
+ VfModule vfm = new VfModule();
+ vfm.setModelName("test Model");
+ vfm.setModelUUID("0cb9b26a-9820-48a7-86e5-16c510e993d9");
+
+ VfModuleCustomization ret = new VfModuleCustomization();
+ ret.setVfModule(vfm);
+ PowerMockito.when(dbMock.getVfModuleCustomizationByModelName(Mockito.anyString())).thenReturn (ret);
+ // end
+
+ // Run
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target("http://localhost:3099/v1/vfModules?vfModuleModelName=0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ Response response = target.request().get();
+ String value = response.readEntity(String.class);
+
+ // System.out.println(value);
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonObject jObj = respObj.getJsonObject("modelInfo");
+ String uuid = jObj.getString("modelUuid");
+ String name = jObj.getString("modelName");
+ assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9"));
+ assertTrue(name.equals("test Model"));
+ // end
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ server.stop();
+ }
+}
diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryTest.java
new file mode 100644
index 0000000000..31e828d19a
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryTest.java
@@ -0,0 +1,112 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.catalogdb.catalogrest;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization;
+
+import static org.junit.Assert.*;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class CatalogQueryTest {
+
+
+ @Test
+ public void catalogQuerySetTemplateImpl_Test(){
+ CatalogQuery mockCatalogQuery = Mockito.mock(CatalogQuery.class);
+ Mockito.doCallRealMethod().when(mockCatalogQuery).setTemplate(Mockito.anyString(), Mockito.anyMapOf(String.class, String.class));
+
+ Map<String,String> valueMap = new HashMap<String,String>();
+ valueMap.put("somekey", "somevalue");
+
+ String ret = mockCatalogQuery.setTemplate("<somekey>", valueMap);
+
+ assertTrue(ret.equalsIgnoreCase("somevalue"));
+ }
+
+ @Test
+ public void smartToJson_Test()
+ {
+ List<VnfResourceCustomization> paramList = new ArrayList<VnfResourceCustomization>();
+ VnfResourceCustomization d1 = new VnfResourceCustomization();
+ d1.setModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ d1.setModelInstanceName("RG_6-26_mog11 0");
+ d1.setVersion("v1");
+ paramList.add(d1);
+
+ QueryServiceVnfs qryResp = new QueryServiceVnfs(paramList);
+ QueryServiceVnfs mockCatalogQuery = Mockito.spy(qryResp);
+ Mockito.doCallRealMethod().when(mockCatalogQuery).smartToJSON();
+ String ret = qryResp.smartToJSON();
+ // System.out.println(ret);
+
+ JsonReader reader = Json.createReader(new StringReader(ret.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonArray jArray = respObj.getJsonArray("serviceVnfs");
+ assertEquals(jArray.size(), 1);
+ assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ }
+
+ @Test
+ public void toJsonString_Test()
+ {
+ CatalogQueryExtendedTest mockCatalogQuery = Mockito.mock(CatalogQueryExtendedTest.class);
+ Mockito.doCallRealMethod().when(mockCatalogQuery).JSON2(Mockito.anyBoolean(), Mockito.anyBoolean());
+ String ret = mockCatalogQuery.JSON2(true, true);
+
+ // System.out.println(ret);
+
+ JsonReader reader = Json.createReader(new StringReader(ret.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonArray jArray = respObj.getJsonArray("serviceVnfs");
+ assertEquals(jArray.size(), 1);
+ assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ assertEquals(jArray.getJsonObject(0).getString("version"), "v2");
+ }
+
+ class CatalogQueryExtendedTest extends CatalogQuery{
+ @Override
+ public String JSON2(boolean isArray, boolean isEmbed) {
+ 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}]}";
+ }
+
+ }
+
+}
+
+
diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomizationTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomizationTest.java
new file mode 100644
index 0000000000..71352b5272
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomizationTest.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.catalogdb.catalogrest;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
+
+@RunWith(MockitoJUnitRunner.class)
+public class QueryAllottedResourceCustomizationTest {
+
+ @Test
+ public void JSON2_Test()
+ {
+ List<AllottedResourceCustomization> paramList;
+ paramList = new ArrayList<AllottedResourceCustomization>();
+ AllottedResourceCustomization d1 = new AllottedResourceCustomization();
+ d1.setModelInstanceName("0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ d1.setModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ paramList.add(d1);
+
+ QueryAllottedResourceCustomization qarcObj = new QueryAllottedResourceCustomization(paramList);
+ String ret = qarcObj.JSON2(true, true);
+ System.out.println(ret);
+ ret = "{" + ret + "}";
+
+ JsonReader reader = Json.createReader(new StringReader(ret.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonArray jArray = respObj.getJsonArray("serviceAllottedResources");
+ assertEquals(jArray.size(), 1);
+
+ assertEquals(jArray.getJsonObject(0).getJsonObject("modelInfo").getString("modelInstanceName"), "0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ assertEquals(jArray.getJsonObject(0).getJsonObject("modelInfo").getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
+ }
+
+}
diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMarcoHolderTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMarcoHolderTest.java
new file mode 100644
index 0000000000..dfbc2dc384
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMarcoHolderTest.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.catalogdb.catalogrest;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
+import org.openecomp.mso.db.catalog.beans.Service;
+import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder;
+
+@RunWith(MockitoJUnitRunner.class)
+public class QueryServiceMarcoHolderTest {
+
+ @Test
+ public void JSON2_Test()
+ {
+ Service svc = new Service();
+ svc.setModelUUID("0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ svc.setModelName("Testing Model One");
+ ArrayList<NetworkResourceCustomization> paramList;
+ paramList = new ArrayList<NetworkResourceCustomization>();
+ NetworkResourceCustomization d1 = new NetworkResourceCustomization();
+ d1.setNetworkResourceModelUuid("0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ paramList.add(d1);
+ ServiceMacroHolder ret = new ServiceMacroHolder(svc);
+ ret.setNetworkResourceCustomization(paramList);
+ QueryServiceMacroHolder holder = new QueryServiceMacroHolder(ret);
+ String s = holder.JSON2(true, true);
+
+ // System.out.println(s);
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonObject obj = respObj.getJsonObject("serviceResources");
+ JsonObject obj2 = obj.getJsonObject("modelInfo");
+ String modelName = obj2.getString("modelName");
+ String modelUuid = obj2.getString("modelUuid");
+
+ assertTrue(modelName.equals("Testing Model One"));
+ assertTrue(modelUuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9"));
+ // end
+ }
+}
diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceNetworksTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceNetworksTest.java
new file mode 100644
index 0000000000..b237dbe0a8
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceNetworksTest.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.catalogdb.catalogrest;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
+import org.openecomp.mso.db.catalog.beans.Service;
+import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder;
+
+@RunWith(MockitoJUnitRunner.class)
+public class QueryServiceNetworksTest {
+
+
+ @Test
+ public void JSON2_Test()
+ {
+ ArrayList<NetworkResourceCustomization> paramList;
+ paramList = new ArrayList<NetworkResourceCustomization>();
+ NetworkResourceCustomization d1 = new NetworkResourceCustomization();
+ d1.setModelInstanceName("0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ paramList.add(d1);
+ QueryServiceNetworks qsn = new QueryServiceNetworks(paramList);
+
+ String s = qsn.JSON2(true, true);
+ s = "{" + s + "}";
+ System.out.println(s);
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonArray objArr = respObj.getJsonArray("serviceNetworks");
+
+ assertTrue(objArr.size() == 1);
+
+ JsonObject obj2 = objArr.getJsonObject(0).getJsonObject("modelInfo");
+ String modelName = obj2.getString("modelInstanceName");
+
+ assertTrue(modelName.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9"));
+ // end
+ }
+}
diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceVnfsTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceVnfsTest.java
new file mode 100644
index 0000000000..262fe06988
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceVnfsTest.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.catalogdb.catalogrest;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
+import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization;
+
+@RunWith(MockitoJUnitRunner.class)
+public class QueryServiceVnfsTest {
+
+ @Test
+ public void JSON2_Test()
+ {
+ List<VnfResourceCustomization> paramList;
+ paramList = new ArrayList<VnfResourceCustomization>();
+ VnfResourceCustomization d1 = new VnfResourceCustomization();
+ d1.setModelInstanceName("0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ d1.setVnfResourceModelUuid("0cb9b26a-9820-48a7-86e5-16c510e993d9");
+ paramList.add(d1);
+ QueryServiceVnfs qsn = new QueryServiceVnfs(paramList);
+
+ String s = qsn.JSON2(true, true);
+ s = "{" + s + "}";
+ System.out.println(s);
+
+ // prepare to inspect response
+ JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", "")));
+ JsonObject respObj = reader.readObject();
+ reader.close();
+ JsonArray objArr = respObj.getJsonArray("serviceVnfs");
+
+ assertTrue(objArr.size() == 1);
+
+ JsonObject obj2 = objArr.getJsonObject(0).getJsonObject("modelInfo");
+ String modelName = obj2.getString("modelInstanceName");
+
+ assertTrue(modelName.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9"));
+ // end
+
+ }
+}