aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test
diff options
context:
space:
mode:
authorPiotr Darosz <piotr.darosz@nokia.com>2018-08-24 10:21:03 +0200
committerPiotr Darosz <piotr.darosz@nokia.com>2018-08-24 13:03:56 +0200
commit652faeb8067158ea4726c30ee8b2a902df3ba20a (patch)
tree6c9d88b7df98e510054cf6f5407e683ce3b3c61d /vid-app-common/src/test
parent5adc0b0ee92d1e39ddaacd27e67a327dd5988f11 (diff)
Replace SO client
Make SO client use Generic Rest Client Change-Id: I8d0fdf4683f577e0c968f5175dbf42a42c041357 Issue-ID: VID-267 Signed-off-by: Piotr Darosz <piotr.darosz@nokia.com>
Diffstat (limited to 'vid-app-common/src/test')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java395
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java23
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java108
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceUnitTest.java40
-rw-r--r--vid-app-common/src/test/resources/payload_jsons/mso_service_instantiation.json2
5 files changed, 381 insertions, 187 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java
index 59c2c704..402386a5 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java
@@ -1,88 +1,158 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 Nokia. 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.onap.vid.mso.rest;
+import com.xebialabs.restito.server.StubServer;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Properties;
+import java.util.UUID;
+import org.glassfish.grizzly.http.util.HttpStatus;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.vid.client.SyncRestClient;
+import org.onap.vid.controllers.MsoController;
+import org.onap.vid.mso.MsoInterface;
+import org.onap.vid.mso.MsoProperties;
import org.onap.vid.mso.MsoResponseWrapper;
import org.onap.vid.mso.MsoResponseWrapperInterface;
import org.onap.vid.mso.RestObject;
public class MsoRestClientNewTest {
- private MsoRestClientNew createTestSubject() {
- return new MsoRestClientNew();
+ private static StubServer server;
+ private static StubServer securedServer;
+ private static Properties props = new Properties();
+ private static String msoCreateServiceInstanceJson;
+ private final static String CREATE_INSTANCE_RESPONSE_STR =
+ "{\"requestReferences\":{\"instanceId\":\"baa13544-0e95-4644-9565-9a198a29a294\","
+ + "\"requestId\":\"a42a1a35-3d63-4629-bbe0-4989fa7414cb\"}}";
+ private final static String SERVICE_INSTANCE_ID = "12345";
+ private static final String SAMPLE_VNF_INSTANCE_ID = "111";
+ private static final String SAMPLE_VNF_MODULE_ID = "987";
+ private static final String SAMPLE_NETWORK_INSTANCE_ID = "666";
+ private static final String SAMPLE_CONFIGURATION_ID = "997";
+ private static final String SAMPLE_REQUEST_ID = "7777";
+
+
+ @BeforeClass
+ public static void start() throws IOException {
+ server = new StubServer().run();
+ securedServer = new StubServer().secured().run();
+
+ Path resourceDirectory =
+ Paths.get("src", "test", "resources", "WEB-INF", "conf", "system.properties");
+ try(InputStream is = Files.newInputStream(resourceDirectory)) {
+ props.load(is);
+ }
+
+ Path msoServiceInstantiationJsonFilePath =
+ Paths.get("src", "test", "resources", "payload_jsons", "mso_service_instantiation.json");
+ msoCreateServiceInstanceJson =
+ String.join("\n", Files.readAllLines(msoServiceInstantiationJsonFilePath));
+ }
+
+ @AfterClass
+ public static void stop() {
+ server.stop();
+ securedServer.stop();
+ }
+
+
+ private String baseUrl() {
+ return String.format("http://localhost:%d", server.getPort());
}
@Test
public void testCreateSvcInstance() throws Exception {
- MsoRestClientNew testSubject;
- RequestDetails requestDetails = null;
- String endpoint = "";
- MsoResponseWrapper result;
-
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.createSvcInstance(requestDetails, endpoint);
- } catch (Exception e) {
+ String endpoint = props.getProperty(MsoProperties.MSO_REST_API_CONFIGURATIONS);
+ endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
+ try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
+ server,
+ endpoint,
+ HttpStatus.ACCEPTED_202,
+ CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
+ closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createSvcInstance);
}
}
@Test
public void testCreateVnf() throws Exception {
- MsoRestClientNew testSubject;
- RequestDetails requestDetails = null;
- String endpoint = "";
- MsoResponseWrapper result;
-
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.createVnf(requestDetails, endpoint);
- } catch (Exception e) {
+ String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
+ endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
+ try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
+ server,
+ endpoint,
+ HttpStatus.ACCEPTED_202,
+ CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
+
+ closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVnf);
}
}
@Test
public void testCreateNwInstance() throws Exception {
- MsoRestClientNew testSubject;
- RequestDetails requestDetails = null;
- String endpoint = "";
- MsoResponseWrapper result;
-
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.createNwInstance(requestDetails, endpoint);
- } catch (Exception e) {
+ String endpoint = props.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
+ String nw_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
+ try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
+ server,
+ nw_endpoint,
+ HttpStatus.ACCEPTED_202,
+ CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
+ closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createNwInstance);
}
}
@Test
public void testCreateVolumeGroupInstance() throws Exception {
- MsoRestClientNew testSubject;
- RequestDetails requestDetails = null;
- String endpoint = "";
- MsoResponseWrapper result;
-
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.createVolumeGroupInstance(requestDetails, endpoint);
- } catch (Exception e) {
+ String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
+ String vnf_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
+ vnf_endpoint = vnf_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
+ try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
+ server,
+ vnf_endpoint,
+ HttpStatus.ACCEPTED_202,
+ CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
+ closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVolumeGroupInstance);
}
}
@Test
public void testCreateVfModuleInstance() throws Exception {
- MsoRestClientNew testSubject;
- RequestDetails requestDetails = null;
- String endpoint = "";
- MsoResponseWrapper result;
-
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.createVfModuleInstance(requestDetails, endpoint);
- } catch (Exception e) {
+ String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
+ String partial_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
+ String vf_module_endpoint =
+ partial_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
+
+
+ try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
+ server,
+ vf_module_endpoint,
+ HttpStatus.ACCEPTED_202,
+ CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
+ closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::createVfModuleInstance);
}
}
@@ -103,138 +173,105 @@ public class MsoRestClientNewTest {
@Test
public void testDeleteSvcInstance() throws Exception {
- MsoRestClientNew testSubject;
- RequestDetails requestDetails = null;
- String endpoint = "";
- MsoResponseWrapper result;
+ String endpoint = props.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
+ endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.deleteSvcInstance(requestDetails, endpoint);
- } catch (Exception e) {
+
+ try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
+ server,
+ endpoint,
+ HttpStatus.NO_CONTENT_204,
+ CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
+ closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteSvcInstance);
}
}
@Test
public void testDeleteVnf() throws Exception {
- MsoRestClientNew testSubject;
- RequestDetails requestDetails = null;
- String endpoint = "";
- MsoResponseWrapper result;
-
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.deleteVnf(requestDetails, endpoint);
- } catch (Exception e) {
+ String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
+ endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
+
+ try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
+ server,
+ endpoint,
+ HttpStatus.NO_CONTENT_204,
+ CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
+ closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVnf);
}
}
@Test
public void testDeleteVfModule() throws Exception {
- MsoRestClientNew testSubject;
- RequestDetails requestDetails = null;
- String endpoint = "";
- MsoResponseWrapper result;
-
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.deleteVfModule(requestDetails, endpoint);
- } catch (Exception e) {
+ String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
+ String part_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
+ String vf_modules_endpoint = part_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
+ String delete_vf_endpoint = vf_modules_endpoint + '/' + SAMPLE_VNF_MODULE_ID;
+
+ try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
+ server,
+ delete_vf_endpoint,
+ HttpStatus.NO_CONTENT_204,
+ CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
+ closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVfModule);
}
}
@Test
public void testDeleteVolumeGroupInstance() throws Exception {
- MsoRestClientNew testSubject;
- RequestDetails requestDetails = null;
- String endpoint = "";
- MsoResponseWrapper result;
-
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.deleteVolumeGroupInstance(requestDetails, endpoint);
- } catch (Exception e) {
+ String endpoint = props.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
+ String svc_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
+ String vnf_endpoint = svc_endpoint.replaceFirst(MsoController.VNF_INSTANCE_ID, SAMPLE_VNF_INSTANCE_ID);
+ String delete_volume_group_endpoint = vnf_endpoint + "/" + SAMPLE_VNF_MODULE_ID;
+
+ try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
+ server,
+ delete_volume_group_endpoint,
+ HttpStatus.NO_CONTENT_204,
+ CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
+ closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteVolumeGroupInstance);
}
}
@Test
public void testDeleteNwInstance() throws Exception {
- MsoRestClientNew testSubject;
- RequestDetails requestDetails = null;
- String endpoint = "";
- MsoResponseWrapper result;
-
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.deleteNwInstance(requestDetails, endpoint);
- } catch (Exception e) {
+ String endpoint = props.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
+ String svc_endpoint = endpoint.replaceFirst(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
+ String delete_nw_endpoint = svc_endpoint + "/" + SAMPLE_NETWORK_INSTANCE_ID;
+
+ try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
+ server,
+ delete_nw_endpoint,
+ HttpStatus.NO_CONTENT_204,
+ CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
+ closure.executeDelete(msoCreateServiceInstanceJson, msoRestClient()::deleteNwInstance);
}
}
@Test
- public void testGetOrchestrationRequest() throws Exception {
- MsoRestClientNew testSubject;
- String t = "";
- String sourceId = "";
- String endpoint = "";
- RestObject restObject = null;
-
- // default test
- try {
- testSubject = createTestSubject();
- testSubject.getOrchestrationRequest(t, sourceId, endpoint, restObject);
- } catch (Exception e) {
+ public void testGetOrchestrationRequest() {
+ String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
+ String path = p + "/" + SAMPLE_REQUEST_ID;
+
+ try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
+ server,
+ path,
+ HttpStatus.OK_200,
+ CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
+ closure.executeGet(msoRestClient()::getOrchestrationRequest);
}
}
@Test
- public void testGetManualTasks() throws Exception {
- MsoRestClientNew testSubject;
- String t = "";
- String sourceId = "";
- String endpoint = "";
- RestObject restObject = null;
-
- // default test
- try {
- testSubject = createTestSubject();
- testSubject.getManualTasks(t, sourceId, endpoint, restObject);
- } catch (Exception e) {
- }
- }
-
- @Test
- public void testCreateInstance() throws Exception {
- MsoRestClientNew testSubject;
- RequestDetails request = null;
- String path = "";
- MsoResponseWrapper result;
-
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.createInstance(request, path);
- } catch (Exception e) {
- }
- }
-
- @Test
- public void testDeleteInstance() throws Exception {
- MsoRestClientNew testSubject;
- RequestDetails request = null;
- String path = "";
- MsoResponseWrapper result;
-
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.deleteInstance(request, path);
- } catch (Exception e) {
+ public void testGetManualTasks() {
+ String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
+ String path = p + "/" + UUID.randomUUID();
+
+ try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
+ server,
+ path,
+ HttpStatus.OK_200,
+ CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
+ closure.executeGet(msoRestClient()::getManualTasks);
}
}
@@ -307,16 +344,17 @@ public class MsoRestClientNewTest {
@Test
public void testSetConfigurationActiveStatus() throws Exception {
- MsoRestClientNew testSubject;
- RequestDetails request = null;
- String path = "";
- MsoResponseWrapper result;
-
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.setConfigurationActiveStatus(request, path);
- } catch (Exception e) {
+ String endpoint = "/serviceInstances/v5/<service_instance_id>/configurations/<configuration_id>";
+ endpoint = endpoint.replace(MsoController.SVC_INSTANCE_ID, SERVICE_INSTANCE_ID);
+ endpoint = endpoint.replace(MsoController.CONFIGURATION_ID, SAMPLE_CONFIGURATION_ID);
+ endpoint = endpoint + "/activate";
+
+ try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
+ server,
+ endpoint,
+ HttpStatus.ACCEPTED_202,
+ CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
+ closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::setConfigurationActiveStatus);
}
}
@@ -369,16 +407,15 @@ public class MsoRestClientNewTest {
@Test
public void testRemoveRelationshipFromServiceInstance() throws Exception {
- MsoRestClientNew testSubject;
- RequestDetails requestDetails = null;
- String endpoint = "";
- MsoResponseWrapper result;
-
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.removeRelationshipFromServiceInstance(requestDetails, endpoint);
- } catch (Exception e) {
+ String serviceEndpoint = props.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
+ String removeRelationshipsPath = serviceEndpoint + "/" + SERVICE_INSTANCE_ID + "/removeRelationships";
+
+ try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
+ server,
+ removeRelationshipsPath,
+ HttpStatus.ACCEPTED_202,
+ CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
+ closure.executePost(msoCreateServiceInstanceJson, msoRestClient()::removeRelationshipFromServiceInstance);
}
}
@@ -396,4 +433,12 @@ public class MsoRestClientNewTest {
} catch (Exception e) {
}
}
+
+ private MsoRestClientNew msoRestClient() {
+ return new MsoRestClientNew(new SyncRestClient(MsoInterface.objectMapper()), baseUrl());
+ }
+
+ private MsoRestClientNew createTestSubject() {
+ return new MsoRestClientNew(null, "");
+ }
} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
index 0cfc0be1..2b067b28 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
@@ -1,9 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 Nokia. 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.onap.vid.mso.rest;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.json.JSONObject;
import org.junit.Assert;
import org.onap.vid.changeManagement.RequestDetails;
+import org.onap.vid.client.SyncRestClient;
import org.onap.vid.domain.mso.CloudConfiguration;
import org.onap.vid.domain.mso.ModelInfo;
import org.onap.vid.domain.mso.RequestInfo;
@@ -24,7 +45,7 @@ import org.togglz.core.manager.FeatureManager;
public class MsoRestClientTest {
- private MsoBusinessLogic msoBusinessLogic = new MsoBusinessLogicImpl(new MsoRestClientNew(), null);
+ private MsoBusinessLogic msoBusinessLogic = new MsoBusinessLogicImpl(new MsoRestClientNew(new SyncRestClient(), ""), null);
private ObjectMapper om = new ObjectMapper();
@Test
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java
new file mode 100644
index 00000000..e8f55699
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java
@@ -0,0 +1,108 @@
+package org.onap.vid.mso.rest;
+
+import static com.xebialabs.restito.builder.stub.StubHttp.whenHttp;
+import static com.xebialabs.restito.builder.verify.VerifyHttp.verifyHttp;
+import static com.xebialabs.restito.semantics.Action.contentType;
+import static com.xebialabs.restito.semantics.Action.status;
+import static com.xebialabs.restito.semantics.Action.stringContent;
+import static com.xebialabs.restito.semantics.Condition.delete;
+import static com.xebialabs.restito.semantics.Condition.get;
+import static com.xebialabs.restito.semantics.Condition.method;
+import static com.xebialabs.restito.semantics.Condition.post;
+import static com.xebialabs.restito.semantics.Condition.uri;
+import static com.xebialabs.restito.semantics.Condition.withHeader;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.xebialabs.restito.semantics.Action;
+import com.xebialabs.restito.server.StubServer;
+import java.io.IOException;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import org.glassfish.grizzly.http.Method;
+import org.glassfish.grizzly.http.util.HttpStatus;
+import org.json.JSONObject;
+import org.junit.Assert;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.vid.mso.MsoResponseWrapper;
+
+class MsoRestClientTestUtil implements AutoCloseable {
+ private final StubServer server;
+ private final String endpoint;
+ private final String responsePayload;
+ private final HttpStatus expectedStatus;
+ private final String expectedResponseStr;
+
+ MsoRestClientTestUtil(StubServer server, String endpoint, HttpStatus expectedStatus,
+ String responsePayload,
+ String expectedResponseStr) {
+ this.server = server;
+ this.endpoint = endpoint;
+ this.responsePayload = responsePayload;
+ this.expectedStatus = expectedStatus;
+ this.expectedResponseStr = expectedResponseStr;
+ }
+
+ void executePost(String jsonPayload, BiFunction<RequestDetails, String, MsoResponseWrapper> func) throws IOException {
+ whenHttp(server)
+ .match(post(endpoint))
+ .then(status(expectedStatus), jsonContent(responsePayload), contentType(MediaType.APPLICATION_JSON));
+
+ RequestDetails sampleRequestDetails =
+ new ObjectMapper().readValue(jsonPayload, RequestDetails.class);
+
+ MsoResponseWrapper response = func.apply(sampleRequestDetails, endpoint);
+ JSONObject actualJson = new JSONObject(response.getEntity());
+
+ Assert.assertEquals(expectedStatus.getStatusCode(), response.getStatus());
+ Assert.assertEquals(expectedResponseStr, actualJson.toString());
+ verifyServer(server, endpoint, Method.POST);
+
+ }
+
+ void executeDelete(String jsonPayload, BiFunction<RequestDetails, String, MsoResponseWrapper> func)
+ throws IOException {
+ whenHttp(server)
+ .match(delete(endpoint))
+ .then(status(expectedStatus), jsonContent(responsePayload), contentType(MediaType.APPLICATION_JSON));
+
+ RequestDetails sampleRequestDetails =
+ new ObjectMapper().readValue(jsonPayload, RequestDetails.class);
+ MsoResponseWrapper response = func.apply(sampleRequestDetails, endpoint);
+
+ Assert.assertEquals(expectedStatus.getStatusCode(), response.getStatus());
+ verifyServer(server, endpoint, Method.DELETE);
+ }
+
+ void executeGet(Function<String, MsoResponseWrapper> func) {
+ whenHttp(server)
+ .match(get(endpoint))
+ .then(status(expectedStatus), jsonContent(responsePayload), contentType(MediaType.APPLICATION_JSON));
+
+ MsoResponseWrapper response = func.apply(endpoint);
+
+ Assert.assertEquals(expectedStatus.getStatusCode(), response.getStatus());
+ verifyServer(server, endpoint, Method.GET);
+ }
+
+ private void verifyServer(StubServer server, String endpoint, Method httpMethod) {
+ verifyHttp(server).once(
+ method(httpMethod),
+ uri(endpoint),
+ withHeader(HttpHeaders.AUTHORIZATION),
+ withHeader(HttpHeaders.ACCEPT),
+ withHeader(HttpHeaders.CONTENT_TYPE),
+ withHeader(MsoRestClientNew.X_FROM_APP_ID),
+ withHeader(SystemProperties.ECOMP_REQUEST_ID));
+ }
+
+ private Action jsonContent(String str) {
+ return stringContent(str);
+ }
+
+ @Override
+ public void close() {
+ }
+}
+
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceUnitTest.java b/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceUnitTest.java
index 5a21d8ca..8aafda3f 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceUnitTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceUnitTest.java
@@ -1,20 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 Nokia. 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.onap.vid.services;
import com.fasterxml.jackson.databind.ObjectMapper;
+import io.joshworks.restclient.http.HttpResponse;
import org.apache.commons.io.IOUtils;
import org.mockito.ArgumentCaptor;
import org.onap.vid.changeManagement.ChangeManagementRequest;
+import org.onap.vid.changeManagement.RequestDetailsWrapper;
+import org.onap.vid.client.SyncRestClient;
import org.onap.vid.controllers.MsoConfig;
import org.onap.vid.controllers.WebConfig;
import org.onap.vid.model.RequestReferencesContainer;
import org.onap.vid.mso.MsoBusinessLogic;
-import org.onap.vid.mso.RestObject;
+import org.onap.vid.mso.MsoInterface;
import org.onap.vid.mso.rest.MsoRestClientNew;
import org.onap.vid.mso.rest.RequestDetails;
import org.onap.vid.properties.AsdcClientConfiguration;
import org.onap.vid.scheduler.SchedulerRestInterfaceIfc;
-import org.onap.vid.services.ChangeManagementService;
-import org.onap.vid.services.ChangeManagementServiceImpl;
import org.onap.vid.testUtils.RegExMatcher;
import org.onap.portalsdk.core.service.DataAccessService;
import org.onap.portalsdk.core.util.SystemProperties;
@@ -47,23 +68,22 @@ public class ChangeManagementServiceUnitTest extends AbstractTestNGSpringContext
@Inject
private ChangeManagementService changeManagementService;
@Inject
- private MsoRestClientNew restClientUnderTest;
+ private MsoInterface restClientUnderTest;
// @Test
void testInPlaceSoftwareUpdateRequest() throws Exception {
- doReturn(new RestObject<RequestReferencesContainer>()).when(restClientUnderTest).PostForObject(anyObject(), anyString(), anyString(), anyObject());
+ doReturn(new HttpResponse<>(anyObject(), RequestReferencesContainer.class, anyObject())).when(restClientUnderTest).post(anyString(), anyObject(), anyObject());
URL requestJsonUrl = this.getClass().getResource("/services/change_management_software_update_request.json");
ChangeManagementRequest changeManagementRequest = objectMapper.readValue(requestJsonUrl, ChangeManagementRequest.class);
changeManagementService.doChangeManagement(changeManagementRequest, "vidVnf");
ArgumentCaptor<String> endpointCaptor = ArgumentCaptor.forClass(String.class);
- ArgumentCaptor<String> sourceIdCaptor = ArgumentCaptor.forClass(String.class);
- ArgumentCaptor<Object> requestCaptor = ArgumentCaptor.forClass(Object.class);
+ ArgumentCaptor<RequestDetailsWrapper> requestCaptor = ArgumentCaptor.forClass(RequestDetailsWrapper.class);
ArgumentCaptor<Class> responseTypeCaptor = ArgumentCaptor.forClass(Class.class);
- verify(restClientUnderTest).PostForObject(requestCaptor.capture(), sourceIdCaptor.capture(), endpointCaptor.capture(), responseTypeCaptor.capture());
+ verify(restClientUnderTest).post(endpointCaptor.capture(), requestCaptor.capture(), responseTypeCaptor.capture());
org.onap.vid.changeManagement.RequestDetails expectedRequest = changeManagementRequest.getRequestDetails().get(0);
@@ -73,7 +93,7 @@ public class ChangeManagementServiceUnitTest extends AbstractTestNGSpringContext
String regEx = String.format("/serviceInstances/v[0-9]+/%s/vnfs/%s/inPlaceSoftwareUpdate", serviceInstanceId, vnfInstanceId);
assertThat(endpointCaptor.getValue(), RegExMatcher.matchesRegEx(regEx));
assertThat(requestCaptor.getValue(), instanceOf(RequestDetails.class));
- RequestDetails actualRequest = ((RequestDetails) requestCaptor.getValue());
+ RequestDetails actualRequest = ((RequestDetails) requestCaptor.getValue().requestDetails);
assertThat(actualRequest.getCloudConfiguration().getTenantId(), equalTo(expectedRequest.getCloudConfiguration().getTenantId()));
assertThat(actualRequest.getCloudConfiguration().getLcpCloudRegionId(), equalTo(expectedRequest.getCloudConfiguration().getLcpCloudRegionId()));
@@ -98,7 +118,7 @@ public class ChangeManagementServiceUnitTest extends AbstractTestNGSpringContext
@Override
public MsoRestClientNew getMsoClient() {
- MsoRestClientNew spyClient = spy(new MsoRestClientNew());
+ MsoRestClientNew spyClient = spy(new MsoRestClientNew(new SyncRestClient(), ""));
return spyClient;
}
diff --git a/vid-app-common/src/test/resources/payload_jsons/mso_service_instantiation.json b/vid-app-common/src/test/resources/payload_jsons/mso_service_instantiation.json
index 6c515ec2..537b8d60 100644
--- a/vid-app-common/src/test/resources/payload_jsons/mso_service_instantiation.json
+++ b/vid-app-common/src/test/resources/payload_jsons/mso_service_instantiation.json
@@ -29,7 +29,7 @@
"requestorId": "az2016"
},
"requestParameters": {
- "subscriptionServiceType":"MOG", // "subscriptionServiceType":"VMX",
+ "subscriptionServiceType":"MOG",
"aLaCarte": false,
"userParams": [{
"name": "TODO",