summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test
diff options
context:
space:
mode:
authorBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2019-02-18 10:41:17 +0100
committerBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2019-02-27 16:17:57 +0100
commit58cbfa63f239b22e8feb1440919b5fc2cf0118ce (patch)
tree268a88f08b6975f096b29b14591fe61cf9aa3f3f /vid-app-common/src/test
parent389d728d8d25dc1e44f8d95bb16ce588ea9bba0e (diff)
Increasing test coverage for vid.mso
Change-Id: I71d44c6b36babcc5b8931cda65ab86940062deda Issue-ID: VID-387 Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Diffstat (limited to 'vid-app-common/src/test')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java1237
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java95
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java3
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java102
-rw-r--r--vid-app-common/src/test/resources/WEB-INF/conf/system.properties9
-rw-r--r--vid-app-common/src/test/resources/payload_jsons/manual_tasks_by_requestId_test.json29
-rw-r--r--vid-app-common/src/test/resources/payload_jsons/manual_tasks_by_requestId_wrongJson_test.json29
-rw-r--r--vid-app-common/src/test/resources/payload_jsons/mso_model_info_sample_wrong_response.json108
8 files changed, 1445 insertions, 167 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
index 135f3973d..a5fb1a5f0 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
@@ -23,24 +23,39 @@ package org.onap.vid.mso;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+import io.joshworks.restclient.http.HttpResponse;
import org.apache.commons.io.IOUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.jetbrains.annotations.NotNull;
+import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.vid.changeManagement.ChangeManagementRequest;
+import org.onap.vid.controller.OperationalEnvironmentController;
import org.onap.vid.exceptions.GenericUncheckedException;
+import org.onap.vid.model.RequestReferencesContainer;
+import org.onap.vid.model.SoftDeleteRequest;
+import org.onap.vid.mso.model.CloudConfiguration;
+import org.onap.vid.mso.model.ModelInfo;
+import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo;
+import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo;
+import org.onap.vid.mso.model.RequestInfo;
+import org.onap.vid.mso.model.RequestParameters;
+import org.onap.vid.mso.model.RequestReferences;
+import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails;
import org.onap.vid.mso.rest.Request;
import org.onap.vid.mso.rest.RequestDetails;
import org.onap.vid.mso.rest.RequestDetailsWrapper;
+import org.onap.vid.mso.rest.Task;
import org.onap.vid.properties.Features;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.togglz.core.manager.FeatureManager;
+import javax.ws.rs.BadRequestException;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
@@ -49,16 +64,26 @@ import java.util.List;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
-import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.ArgumentMatchers.endsWith;
import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
+import static org.onap.vid.controller.MsoController.CONFIGURATION_ID;
+import static org.onap.vid.controller.MsoController.REQUEST_TYPE;
+import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
+import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
import static org.onap.vid.mso.MsoBusinessLogicImpl.validateEndpointPath;
@ContextConfiguration(classes = {SystemProperties.class})
-@RunWith(SpringJUnit4ClassRunner.class)
-public class MsoBusinessLogicImplTest {
+public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
private static final ObjectMapper objectMapper = new ObjectMapper();
@@ -68,62 +93,175 @@ public class MsoBusinessLogicImplTest {
@Mock
private MsoInterface msoInterface;
+ @Mock
+ private RequestDetails msoRequest;
+
+
private MsoBusinessLogicImpl msoBusinessLogic;
+ private String userId = "testUserId";
+ private String operationalEnvironmentId = "testOperationalEnvironmentId";
- @Before
+ @BeforeClass
public void setUp() {
MockitoAnnotations.initMocks(this);
msoBusinessLogic = new MsoBusinessLogicImpl(msoInterface, featureManager);
}
@Test
- public void createConfigurationInstance_shouldCallMsoInterface_withCorrectServiceInstanceId() throws Exception {
+ public void shouldProperlyCreateConfigurationInstanceWithCorrectServiceInstanceId() throws Exception {
// given
String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
String endpointTemplate = String.format("/serviceInstances/v6/%s/configurations", serviceInstanceId);
- RequestDetailsWrapper requestDetailsWrapper = createRequestDetails("mso_request_create_configuration.json");
+ RequestDetailsWrapper requestDetailsWrapper = createRequestDetails();
MsoResponseWrapper expectedResponse = createOkResponse();
given(msoInterface.createConfigurationInstance(requestDetailsWrapper, endpointTemplate))
- .willReturn(expectedResponse);
+ .willReturn(expectedResponse);
// when
MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
- .createConfigurationInstance(requestDetailsWrapper, serviceInstanceId);
+ .createConfigurationInstance(requestDetailsWrapper, serviceInstanceId);
// then
assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
}
- private RequestDetailsWrapper createRequestDetails(String bodyFileName) throws Exception {
- final URL resource = this.getClass().getResource("/payload_jsons/" + bodyFileName);
+ private RequestDetailsWrapper createRequestDetails() throws Exception {
+ final URL resource = this.getClass().getResource("/payload_jsons/mso_request_create_configuration.json");
RequestDetails requestDetails = objectMapper.readValue(resource, RequestDetails.class);
return new RequestDetailsWrapper(requestDetails);
}
@Test
- public void validateEndpointPath_endPointIsNotEmptyAndVaild_returnProperty() {
+ public void shouldProperlyValidateEndpointPathWheEendPointIsNotEmptyAndValid() {
System.setProperty("TestEnv", "123");
String foundEndPoint = validateEndpointPath("TestEnv");
assertEquals("123", foundEndPoint);
}
@Test
- public void validateEndpointPath_endPointIsNull_throwRuntimeException() {
+ public void shouldThrowRuntimeExceptionWhenValidateEndpointPathEndPointIsNotEmptyAndValid() {
assertThatExceptionOfType(RuntimeException.class)
- .isThrownBy(() -> validateEndpointPath("NotExists"));
+ .isThrownBy(() -> validateEndpointPath("NotExists"));
}
@Test
- public void validateEndpointPath_endPointIsNotEmptyButDoesntExists_throwRuntimeException() {
+ public void shouldThrowRuntimeExceptionWhenValidateEndpointPathWhenEndPointIsNotEmptyButDoesntExists() {
String endPoint = "EmptyEndPoint";
System.setProperty(endPoint, "");
assertThatExceptionOfType(GenericUncheckedException.class)
- .isThrownBy(() -> validateEndpointPath(endPoint))
- .withMessage(endPoint + " env variable is not defined");
+ .isThrownBy(() -> validateEndpointPath(endPoint))
+ .withMessage(endPoint + " env variable is not defined");
+ }
+
+ @Test
+ public void shouldProperlyCreateSvcInstanceWithProperParameters() {
+
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ String svcEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
+ given(msoInterface.createSvcInstance(msoRequest, svcEndpoint)).willReturn(expectedResponse);
+
+ MsoResponseWrapper response = msoBusinessLogic.createSvcInstance(msoRequest);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test
+ public void shouldProperlyCreateE2eSvcInstanceWithProperParameters() {
+ // given
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ String svcEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_E2E_SVC_INSTANCE);
+ given(msoInterface.createE2eSvcInstance(msoRequest, svcEndpoint)).willReturn(expectedResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.createE2eSvcInstance(msoRequest);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test
+ public void shouldProperlyCreateVnfWithProperParameters() {
+
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ String endpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
+ String vnfInstanceId = "testVnfInstanceTempId";
+ String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, vnfInstanceId);
+
+ given(msoInterface.createVnf(msoRequest, vnfEndpoint)).willReturn(expectedResponse);
+
+ MsoResponseWrapper response = msoBusinessLogic.createVnf(msoRequest, vnfInstanceId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test
+ public void shouldProperlyCreateNwInstanceWithProperParameters() {
+
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ String vnfInstanceId = "testNwInstanceTempId";
+ String nwEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
+ String nw_endpoint = nwEndpoint.replaceFirst(SVC_INSTANCE_ID, vnfInstanceId);
+
+ given(msoInterface.createNwInstance(msoRequest, nw_endpoint)).willReturn(expectedResponse);
+
+ MsoResponseWrapper response = msoBusinessLogic.createNwInstance(msoRequest, vnfInstanceId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test
+ public void shouldProperlyCreateVolumeGroupInstanceWithProperParameters() {
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ String serviceInstanceId = "testServiceInstanceTempId";
+ String vnfInstanceId = "testVnfInstanceTempId";
+ String nwEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
+ String vnfEndpoint = nwEndpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ vnfEndpoint = vnfEndpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
+
+ given(msoInterface.createVolumeGroupInstance(msoRequest, vnfEndpoint)).willReturn(expectedResponse);
+
+ MsoResponseWrapper response = msoBusinessLogic.createVolumeGroupInstance(msoRequest, serviceInstanceId, vnfInstanceId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test
+ public void shouldProperlyCreateVfModuleInstanceWithProperParameters() {
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ String serviceInstanceId = "testServiceInstanceTempId";
+ String vnfInstanceId = "testVnfInstanceTempId";
+ String partial_endpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
+ String vf_module_endpoint = partial_endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ vf_module_endpoint = vf_module_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
+
+ given(msoInterface.createVfModuleInstance(msoRequest, vf_module_endpoint)).willReturn(expectedResponse);
+
+ MsoResponseWrapper response = msoBusinessLogic.createVfModuleInstance(msoRequest, serviceInstanceId, vnfInstanceId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test
+ public void shouldProperlyDeleteE2eSvcInstanceWithProperParameters() {
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ String serviceInstanceId = "testDeleteE2eSvcInstanceTempId";
+ String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_E2E_SVC_INSTANCE) + "/" + serviceInstanceId;
+
+ given(msoInterface.deleteE2eSvcInstance(msoRequest, endpoint)).willReturn(expectedResponse);
+
+ MsoResponseWrapper response = msoBusinessLogic.deleteE2eSvcInstance(msoRequest, serviceInstanceId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
}
@Test
- public void deleteSvcInstance_verifyEndPointPathConstructing_unAssignFeatureOffOrUnAssignFlagIsFalse() {
+ public void shouldProperlyDeleteSvcInstanceWithProperParametersAndFalseFeatureFlag() {
// given
String endpointTemplate = "/serviceInstances/v5/%s";
String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
@@ -135,14 +273,14 @@ public class MsoBusinessLogicImplTest {
// when
MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
- .deleteSvcInstance(requestDetails, serviceInstanceId, "unAssignOrDeleteParams");
+ .deleteSvcInstance(requestDetails, serviceInstanceId, "unAssignOrDeleteParams");
// then
assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
}
@Test
- public void deleteSvcInstance_verifyEndPointPathConstructing_unAssignFeatureOnAndUnAssignFlagIsTrue() {
+ public void shouldProperlyDeleteSvcInstanceWithProperParametersAndTrueFeatureFlag() {
// given
String endpointTemplate = "/serviceInstantiation/v5/serviceInstances/%s/unassign";
String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
@@ -154,14 +292,14 @@ public class MsoBusinessLogicImplTest {
// when
MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
- .deleteSvcInstance(requestDetails, serviceInstanceId, "assigned");
+ .deleteSvcInstance(requestDetails, serviceInstanceId, "assigned");
// then
assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
}
@Test
- public void deleteVnf_verifyEndPointPathConstructing() {
+ public void shouldProperlyDeleteVnfWithProperParameters() {
// when
String endpointTemplate = "/serviceInstances/v5/%s/vnfs/%s";
String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
@@ -173,14 +311,14 @@ public class MsoBusinessLogicImplTest {
// when
MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
- .deleteVnf(requestDetails, serviceInstanceId, vnfInstanceId);
+ .deleteVnf(requestDetails, serviceInstanceId, vnfInstanceId);
// then
assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
}
@Test
- public void deleteVfModule_verifyEndPointPathConstructing() {
+ public void shouldProperlyDeleteVfModuleWithProperParameters() {
// when
String endpointTemplate = "/serviceInstances/v7/%s/vnfs/%s/vfModules/%s";
String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
@@ -193,64 +331,141 @@ public class MsoBusinessLogicImplTest {
// when
MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
- .deleteVfModule(requestDetails, serviceInstanceId, vnfInstanceId, vfModuleId);
+ .deleteVfModule(requestDetails, serviceInstanceId, vnfInstanceId, vfModuleId);
// then
assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
}
@Test
+ public void shouldProperlyDeleteVolumeGroupInstanceWithProperParameters() {
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ String serviceInstanceId = "testServiceInstanceTempId";
+ String vnfInstanceId = "testVnfInstanceTempId";
+ String volumeGroupId = "testvolumeGroupIdTempId";
+
+ String deleteVolumeGroupEndpoint = getDeleteVolumeGroupEndpoint(serviceInstanceId, vnfInstanceId, volumeGroupId);
+
+ given(msoInterface.deleteVolumeGroupInstance(msoRequest, deleteVolumeGroupEndpoint)).willReturn(expectedResponse);
+
+ MsoResponseWrapper response = msoBusinessLogic.deleteVolumeGroupInstance(msoRequest, serviceInstanceId, vnfInstanceId, volumeGroupId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @NotNull
+ private String getDeleteVolumeGroupEndpoint(String serviceInstanceId, String vnfInstanceId, String volumeGroupId) {
+ String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
+ String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ String vnfEndpoint = svc_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
+ return vnfEndpoint + "/" + volumeGroupId;
+ }
+
+ @Test
+ public void shouldProperlyDeleteNwInstanceWithProperParameters() {
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ String serviceInstanceId = "testServiceInstanceTempId";
+ String networkInstanceId = "testNetworkInstanceTempId";
+
+ String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
+ String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ String delete_nw_endpoint = svc_endpoint + "/" + networkInstanceId;
+
+ given(msoInterface.deleteNwInstance(msoRequest, delete_nw_endpoint)).willReturn(expectedResponse);
+
+ MsoResponseWrapper response = msoBusinessLogic.deleteNwInstance(msoRequest, serviceInstanceId, networkInstanceId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test
+ public void shouldProperlyGetOrchestrationRequestWithProperParameters() {
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ String requestId = "testRequestTempId";
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
+ String path = p + "/" + requestId;
+
+ given(msoInterface.getOrchestrationRequest(path)).willReturn(expectedResponse);
+
+ MsoResponseWrapper response = msoBusinessLogic.getOrchestrationRequest(requestId);
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test(expectedExceptions = MsoTestException.class)
+ public void shouldProperlyGetOrchestrationRequestWithWrongParameters() {
+ String requestId = "testWrongRequestTempId";
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
+ String path = p + "/" + requestId;
+
+ given(msoInterface.getOrchestrationRequest(path)).willThrow(new MsoTestException("testException"));
+
+ msoBusinessLogic.getOrchestrationRequest(requestId);
+ }
+
+ @Test
+ public void shouldProperlyGetOrchestrationRequestsWithProperParameters() {
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ String filterString = "testRequestsTempId";
+ String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
+ String path = url + filterString;
+
+ given(msoInterface.getOrchestrationRequest(path)).willReturn(expectedResponse);
+
+ MsoResponseWrapper response = msoBusinessLogic.getOrchestrationRequests(filterString);
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test(expectedExceptions = MsoTestException.class)
+ public void shouldThrowExceptionWhenGetOrchestrationRequestsWithWrongParameters() {
+ String filterString = "testRequestsTempId";
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
+ String path = p + filterString;
+
+ given(msoInterface.getOrchestrationRequest(path)).willThrow(new MsoTestException("testException"));
+
+ msoBusinessLogic.getOrchestrationRequests(filterString);
+ }
+
+ @Test
public void shouldSendProperScaleOutRequest() throws IOException {
// given
String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
String vnfInstanceId = "testVnfInstanceTempId";
String endpointTemplate = "/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s/vfModules/scaleOut";
String vnfEndpoint = String.format(endpointTemplate, serviceInstanceId, vnfInstanceId);
- org.onap.vid.changeManagement.RequestDetails requestDetails = readRequest(
- "scaleOutVfModulePayload.json");
- org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails> expectedRequest = readExpectedRequest(
- "scaleOutVfModulePayloadToMso.json");
+ org.onap.vid.changeManagement.RequestDetails requestDetails = readRequest();
+ org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails> expectedRequest = readExpectedRequest();
MsoResponseWrapper expectedMsoResponseWrapper = createOkResponse();
given(
- msoInterface
- .scaleOutVFModuleInstance(argThat(new MsoRequestWrapperMatcher(expectedRequest)),
- eq(vnfEndpoint)))
- .willReturn(expectedMsoResponseWrapper);
+ msoInterface
+ .scaleOutVFModuleInstance(argThat(new MsoRequestWrapperMatcher(expectedRequest)),
+ eq(vnfEndpoint)))
+ .willReturn(expectedMsoResponseWrapper);
// when
MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
- .scaleOutVfModuleInstance(requestDetails, serviceInstanceId, vnfInstanceId);
+ .scaleOutVfModuleInstance(requestDetails, serviceInstanceId, vnfInstanceId);
// then
assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedMsoResponseWrapper);
}
- private org.onap.vid.changeManagement.RequestDetails readRequest(String requestJsonFilename) throws IOException {
- Path path = Paths.get("payload_jsons", requestJsonFilename);
+ private org.onap.vid.changeManagement.RequestDetails readRequest() throws IOException {
+ Path path = Paths.get("payload_jsons", "scaleOutVfModulePayload.json");
URL url = this.getClass().getClassLoader().getResource(path.toString());
return objectMapper.readValue(url, org.onap.vid.changeManagement.RequestDetails.class);
}
- private org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails> readExpectedRequest(String requestJsonFilename)
- throws IOException {
- Path path = Paths.get("payload_jsons", requestJsonFilename);
+ private org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails> readExpectedRequest()
+ throws IOException {
+ Path path = Paths.get("payload_jsons", "scaleOutVfModulePayloadToMso.json");
URL url = this.getClass().getClassLoader().getResource(path.toString());
return objectMapper.readValue(url,
- new TypeReference<org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails>>() {
- });
+ new TypeReference<org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails>>() {
+ });
}
- private MsoResponseWrapper createOkResponse() {
- HttpStatus expectedStatus = HttpStatus.ACCEPTED;
- String expectedBody = " \"body\": {\n" +
- " \"requestReferences\": {\n" +
- " \"instanceId\": \" 123456 \",\n" +
- " \"requestId\": \"b6dc9806-b094-42f7-9386-a48de8218ce8\"\n" +
- " }";
- MsoResponseWrapper responseWrapper = new MsoResponseWrapper();
- responseWrapper.setEntity(expectedBody);
- responseWrapper.setStatus(expectedStatus.value());
- return responseWrapper;
- }
@Test
public void shouldFilterOutOrchestrationRequestsNotAllowedInDashboard() throws Exception {
@@ -260,39 +475,915 @@ public class MsoBusinessLogicImplTest {
MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
given(msoInterface
- .getOrchestrationRequest(any(String.class), any(String.class), any(String.class),
- any(RestObject.class), anyBoolean()))
- .willReturn(msoResponseWrapperMock);
+ .getOrchestrationRequest(any(String.class), any(String.class), any(String.class),
+ any(RestObject.class), anyBoolean()))
+ .willReturn(msoResponseWrapperMock);
given(msoResponseWrapperMock.getEntity())
- .willReturn(vnfModelTypeOrchestrationRequests, scaleOutActionOrchestrationRequests);
+ .willReturn(vnfModelTypeOrchestrationRequests, scaleOutActionOrchestrationRequests);
//when
List<Request> filteredOrchestrationReqs = msoBusinessLogic.getOrchestrationRequestsForDashboard();
-
//then
assertThat(filteredOrchestrationReqs).hasSize(3);
assertThat(MsoBusinessLogicImpl.DASHBOARD_ALLOWED_TYPES)
- .containsAll(filteredOrchestrationReqs
- .stream()
- .map(el -> el.getRequestType().toUpperCase())
- .collect(Collectors.toList()));
+ .containsAll(filteredOrchestrationReqs
+ .stream()
+ .map(el -> el.getRequestType().toUpperCase())
+ .collect(Collectors.toList()));
assertThat(filteredOrchestrationReqs)
- .extracting(Request::getRequestScope)
- .containsOnly("vnf", "vfModule");
+ .extracting(Request::getRequestScope)
+ .containsOnly("vnf", "vfModule");
+ }
+
+ @Test(expectedExceptions = GenericUncheckedException.class)
+ public void shouldThrowGenericUncheckedExceptionWhenGetOrchestrationRequestsForDashboardWithWrongJsonFile_() throws Exception {
+ //given
+ String vnfModelTypeOrchestrationRequests = getFileContentAsString("mso_model_info_sample_wrong_response.json");
+
+ MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
+ given(msoInterface
+ .getOrchestrationRequest(any(String.class), any(String.class), any(String.class),
+ any(RestObject.class), anyBoolean()))
+ .willReturn(msoResponseWrapperMock);
+ given(msoResponseWrapperMock.getEntity())
+ .willReturn(vnfModelTypeOrchestrationRequests);
+
+ //when
+ msoBusinessLogic.getOrchestrationRequestsForDashboard();
+ }
+
+ @Test
+ public void shouldProperlyGetManualTasksByRequestIdWithProperParameters() throws Exception {
+ //given
+ String manualTasksList = getFileContentAsString("manual_tasks_by_requestId_test.json");
+
+ MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
+ given(msoInterface
+ .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
+ any(RestObject.class)))
+ .willReturn(msoResponseWrapperMock);
+ given(msoResponseWrapperMock.getEntity())
+ .willReturn(manualTasksList);
+
+ //when
+ List<Task> filteredOrchestrationReqs = msoBusinessLogic.getManualTasksByRequestId("TestId");
+
+ //then
+ assertThat(filteredOrchestrationReqs).hasSize(2);
+ assertThat(filteredOrchestrationReqs).extracting("taskId", "type").
+ contains(
+ tuple("123123abc", "testTask"),
+ tuple("321321abc", "testTask")
+ );
+ }
+
+ @Test(expectedExceptions = GenericUncheckedException.class)
+ public void shouldThrowGenericUncheckedExceptionWhenGetManualTasksByRequestIdWithWrongJsonFile() throws Exception {
+ //given
+ String manualTasksList = getFileContentAsString("manual_tasks_by_requestId_wrongJson_test.json");
+
+ MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
+ given(msoInterface
+ .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
+ any(RestObject.class)))
+ .willReturn(msoResponseWrapperMock);
+ given(msoResponseWrapperMock.getEntity())
+ .willReturn(manualTasksList);
+
+ //when
+ msoBusinessLogic.getManualTasksByRequestId("TestId");
+ }
+
+ @Test(expectedExceptions = MsoTestException.class)
+ public void getManualTasksByRequestIdWithArgument_shouldThrowException() {
+ //given
+ given(msoInterface
+ .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
+ any(RestObject.class)))
+ .willThrow(MsoTestException.class);
+
+ //when
+ msoBusinessLogic.getManualTasksByRequestId("TestId");
+ }
+
+ @Test
+ public void shouldProperlyCompleteManualTaskWithProperParameters() {
+ //given
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ RequestDetails requestDetails = new RequestDetails();
+ String taskId = "testTaskId";
+
+ String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
+ String path = url + "/" + taskId + "/complete";
+
+ given(msoInterface.completeManualTask(eq(requestDetails), any(String.class), any(String.class), eq(path), any(RestObject.class))).willReturn(expectedResponse);
+
+ //when
+ MsoResponseWrapper response = msoBusinessLogic.completeManualTask(requestDetails, taskId);
+
+ //then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+
+ }
+
+ @Test
+ public void shouldProperlyActivateServiceInstanceWithProperParameters() {
+ //given
+ RequestDetails detail = new RequestDetails();
+ String taskId = "testTaskId";
+
+ RestObject<String> restObjStr = new RestObject<>();
+ restObjStr.set("");
+ MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
+
+ //when
+ MsoResponseWrapper response = msoBusinessLogic.activateServiceInstance(detail, taskId);
+
+ //then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+
+ }
+
+ @Test(expectedExceptions = MsoTestException.class)
+ public void shouldThrowExceptionWhenActivateServiceInstanceWithWrongParameters() {
+ //given
+ RequestDetails requestDetails = new RequestDetails();
+ String taskId = "testTaskId";
+
+ RestObject<String> restObjStr = new RestObject<>();
+ restObjStr.set("");
+ MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
+
+ doThrow(new MsoTestException("testException")).
+ when(msoInterface).setServiceInstanceStatus(eq(requestDetails), any(String.class), any(String.class), any(String.class), any(RestObject.class));
+
+ //when
+ MsoResponseWrapper response = msoBusinessLogic.activateServiceInstance(requestDetails, taskId);
+
+ //then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test(expectedExceptions = MsoTestException.class)
+ public void shouldThrowExceptionWhenManualTaskWithWrongParameters() {
+ //given
+ RequestDetails requestDetails = new RequestDetails();
+ String taskId = "";
+
+ String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
+ String path = url + "/" + taskId + "/complete";
+
+ given(msoInterface.completeManualTask(eq(requestDetails), any(String.class), any(String.class), eq(path), any(RestObject.class))).willThrow(new MsoTestException("empty path"));
+
+ //when
+ msoBusinessLogic.completeManualTask(requestDetails, taskId);
+ }
+
+ @Test
+ public void shouldProperlyUpdateVnfWithProperParameters() {
+ //given
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ String serviceInstanceId = "testServiceId";
+ String vnfInstanceId = "testVnfInstanceId";
+
+ String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
+ String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ vnfEndpoint = vnfEndpoint + '/' + vnfInstanceId;
+
+ given(msoInterface.updateVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
+
+ //when
+ MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnf(requestDetails, serviceInstanceId, vnfInstanceId);
+
+ //then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test
+ public void shouldProperlyReplaceVnfWithProperParameters() {
+ //given
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ String serviceInstanceId = "testServiceId";
+ String vnfInstanceId = "testVnfInstanceId";
+
+ String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE);
+ String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ vnfEndpoint = vnfEndpoint.replace(VNF_INSTANCE_ID, vnfInstanceId);
+ vnfEndpoint = vnfEndpoint.replace(REQUEST_TYPE, ChangeManagementRequest.MsoChangeManagementRequest.REPLACE);
+
+ given(msoInterface.replaceVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
+
+ //when
+ MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.replaceVnf(requestDetails, serviceInstanceId, vnfInstanceId);
+
+ //then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test
+ public void shouldProperlyGenerateInPlaceMsoRequestWithProperParameters() {
+ //given
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
+ "\"existing_software_version\": \"testExistingSoftwareParam\"," +
+ "\"new_software_version\": \"testNewSoftwareParam\"," +
+ "\"operations_timeout\": \"100\"" +
+ "}");
+
+ RequestDetails inPlaceSoftwareUpdateRequest = new RequestDetails();
+ inPlaceSoftwareUpdateRequest.setCloudConfiguration(requestDetails.getCloudConfiguration());
+ inPlaceSoftwareUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
+ inPlaceSoftwareUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
+ org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.changeManagement.RequestDetailsWrapper();
+ requestDetailsWrapper.requestDetails = inPlaceSoftwareUpdateRequest;
+
+ //when
+ org.onap.vid.changeManagement.RequestDetailsWrapper response = msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
+
+ //then
+ assertThat(response).isEqualToComparingFieldByField(requestDetailsWrapper);
+ }
+
+ @Test(expectedExceptions = BadRequestException.class)
+ public void shouldThrowExceptionWhenGenerateInPlaceMsoRequestWithParametersWithWrongCharacters() {
+ //given
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
+ "\"existing_software_version\": \"#####\"," +
+ "\"new_software_version\": \"testNewSoftwareParam\"" +
+ "}");
+
+ //when
+ msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
+ }
+
+ @Test(expectedExceptions = BadRequestException.class)
+ public void shouldThrowExceptionWhenGenerateInPlaceMsoRequestWithWrongParameters() {
+ //given
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
+ "\"test-wrong-parameter\": \"testParam\"," +
+ "\"new_software_version\": \"testNewSoftwareParam\"" +
+ "}");
+
+ //when
+ msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
+ }
+
+ @Test
+ public void shouldProprleyGenerateConfigMsoRequestWithProperParameters() {
+ //given
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
+ "\"request-parameters\": \"testRequestParam\"," +
+ "\"configuration-parameters\": \"testConfigParams\"" +
+ "}");
+
+ RequestDetails configUpdateRequest = new RequestDetails();
+ configUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
+ configUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
+
+ org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.changeManagement.RequestDetailsWrapper();
+ requestDetailsWrapper.requestDetails = configUpdateRequest;
+
+ //when
+ org.onap.vid.changeManagement.RequestDetailsWrapper response = msoBusinessLogic.generateConfigMsoRequest(requestDetails);
+
+ //then
+ assertThat(response).isEqualToComparingFieldByField(requestDetailsWrapper);
+ }
+
+ @Test(expectedExceptions = BadRequestException.class)
+ public void shouldThrowExceptionGenerateConfigMsoRequestWithoutAdditionalParameters() {
+ //given
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(null);
+
+ //when
+ msoBusinessLogic.generateConfigMsoRequest(requestDetails);
+ }
+
+ @Test(expectedExceptions = BadRequestException.class)
+ public void shouldThrowExceptionWhenGenerateConfigMsoRequestWithWrongPayload() {
+ //given
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", null);
+
+ //when
+ msoBusinessLogic.generateConfigMsoRequest(requestDetails);
+ }
+
+ @Test(expectedExceptions = BadRequestException.class)
+ public void shouldThrowExceptionGenerateConfigMsoRequestWithoutAnyParameter() {
+ //given
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
+ "\"test-wrong-parameter\": \"testParam\"," +
+ "\"configuration-parameters\": \"testConfigParam\"" +
+ "}");
+
+ //when
+ msoBusinessLogic.generateConfigMsoRequest(requestDetails);
+ }
+
+ @Test
+ public void shouldProperlyGetActivateFabricConfigurationPathWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String path = validateEndpointPath(MsoProperties.MSO_REST_API_SERVICE_INSTANCE_CREATE);
+ path += "/" + serviceInstanceId + "/activateFabricConfiguration";
+
+ // when
+ String response = msoBusinessLogic.getActivateFabricConfigurationPath(serviceInstanceId);
+
+ // then
+ assertThat(response).isEqualTo(path);
+ }
+
+ @Test
+ public void shouldProperlyGetDeactivateAndCloudDeletePathWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String vnfInstanceId = "testVnfInstanceId";
+ String vfModuleInstanceId = "testVfModuleInstanceId";
+ String path = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
+ path = path.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
+ path += "/" + vfModuleInstanceId + "/deactivateAndCloudDelete";
+
+ // when
+ String response = msoBusinessLogic.getDeactivateAndCloudDeletePath(serviceInstanceId, vnfInstanceId, vfModuleInstanceId);
+
+ // then
+ assertThat(response).isEqualTo(path);
+ }
+
+ @Test
+ public void shouldProperlyBuildRequestDetailsForSoftDeleteWithProperParameters() {
+ // given
+ SoftDeleteRequest softDeleteRequest = new SoftDeleteRequest();
+ RequestDetails requestDetails = new RequestDetails();
+
+ String userId = "testUserID";
+ String tenantId = "testTenantId ";
+ String cloudRegionId = "testCloudId";
+
+
+ RequestInfo requestInfo = new RequestInfo();
+ requestInfo.setSource("VID");
+ requestInfo.setRequestorId(userId);
+ requestDetails.setRequestInfo(requestInfo);
+
+ CloudConfiguration cloudConfiguration = new CloudConfiguration();
+ cloudConfiguration.setTenantId(tenantId);
+ cloudConfiguration.setLcpCloudRegionId(cloudRegionId);
+ requestDetails.setCloudConfiguration(cloudConfiguration);
+
+ setModelInfoForRequestDetails(requestDetails);
+
+ setRequestParametersForRequestDetails(requestDetails);
+
+ softDeleteRequest.setLcpCloudRegionId(cloudRegionId);
+ softDeleteRequest.setTenantId(tenantId);
+ softDeleteRequest.setUserId(userId);
+
+ // when
+ RequestDetails response = msoBusinessLogic.buildRequestDetailsForSoftDelete(softDeleteRequest);
+
+ // then
+ assertThat(response).isEqualTo(requestDetails);
+ }
+
+ private void setRequestParametersForRequestDetails(RequestDetails requestDetails) {
+ RequestParameters requestParameters = new RequestParameters();
+ requestParameters.setTestApi("GR_API");
+ requestDetails.setRequestParameters(requestParameters);
+ }
+
+ private void setModelInfoForRequestDetails(RequestDetails requestDetails) {
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelType("vfModule");
+ requestDetails.setModelInfo(modelInfo);
+ }
+
+ @Test
+ public void shouldProperlyDeactivateAndCloudDeleteWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String vnfInstanceId = "testVnfInstanceId";
+ String vfModuleInstanceId = "testVfModuleInstanceId";
+ RequestDetails requestDetails = new RequestDetails();
+
+ String path = msoBusinessLogic.getDeactivateAndCloudDeletePath(serviceInstanceId, vnfInstanceId, vfModuleInstanceId);
+
+ RequestReferences requestReferences = new RequestReferences();
+ requestReferences.setInstanceId("testInstance");
+ requestReferences.setRequestId("testRequest");
+
+ HttpResponse<RequestReferencesContainer> expectedResponse = HttpResponse.fallback(new RequestReferencesContainer(requestReferences));
+
+ MsoResponseWrapper2 responseWrapped = new MsoResponseWrapper2<>(expectedResponse);
+
+ given(msoInterface.post(eq(path), any(org.onap.vid.changeManagement.RequestDetailsWrapper.class), eq(RequestReferencesContainer.class))).willReturn(expectedResponse);
+
+ // when
+ MsoResponseWrapper2 response = msoBusinessLogic.deactivateAndCloudDelete(serviceInstanceId, vnfInstanceId, vfModuleInstanceId, requestDetails);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(responseWrapped);
+ }
+
+ @Test
+ public void shouldProperlyActivateFabricConfigurationWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ RequestDetails requestDetails = new RequestDetails();
+
+ String path = msoBusinessLogic.getActivateFabricConfigurationPath(serviceInstanceId);
+
+ RequestReferences requestReferences = new RequestReferences();
+ requestReferences.setInstanceId("testInstance");
+ requestReferences.setRequestId("testRequest");
+
+ HttpResponse<RequestReferencesContainer> expectedResponse = HttpResponse.fallback(new RequestReferencesContainer(requestReferences));
+
+ MsoResponseWrapper2 responseWrapped = new MsoResponseWrapper2<>(expectedResponse);
+
+ given(msoInterface.post(eq(path), any(org.onap.vid.changeManagement.RequestDetailsWrapper.class), eq(RequestReferencesContainer.class))).willReturn(expectedResponse);
+
+ // when
+ MsoResponseWrapper2 response = msoBusinessLogic.activateFabricConfiguration(serviceInstanceId, requestDetails);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(responseWrapped);
+ }
+
+ @Test
+ public void shouldProperlyUpdateVnfSoftwareWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String vnfInstanceId = "testVnfInstanceId";
+
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
+ "\"existing_software_version\": \"testExistingSoftwareParam\"," +
+ "\"new_software_version\": \"testNewSoftwareParam\"," +
+ "\"operations_timeout\": \"100\"" +
+ "}");
+
+ MsoResponseWrapper okResponse = createOkResponse();
+
+ given(msoInterface.changeManagementUpdate(isA(org.onap.vid.changeManagement.RequestDetailsWrapper.class), any(String.class))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnfSoftware(requestDetails, serviceInstanceId, vnfInstanceId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test
+ public void shouldProperlyUpdateVnfConfigWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String vnfInstanceId = "testVnfInstanceId";
+
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
+ "\"request-parameters\": \"testRequestParam\"," +
+ "\"configuration-parameters\": \"testConfigParams\"" +
+ "}");
+
+ MsoResponseWrapper okResponse = createOkResponse();
+
+ given(msoInterface.changeManagementUpdate(isA(org.onap.vid.changeManagement.RequestDetailsWrapper.class), any(String.class))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnfConfig(requestDetails, serviceInstanceId, vnfInstanceId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test
+ public void shouldProperlyDeleteConfigurationWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String configurationId = "testConfigurationId";
+
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+
+ MsoResponseWrapper okResponse = createOkResponse();
+ RequestDetailsWrapper wrappedRequestDetail = new RequestDetailsWrapper(requestDetails);
+
+ given(msoInterface.deleteConfiguration(eq(wrappedRequestDetail), any(String.class))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.deleteConfiguration(wrappedRequestDetail, serviceInstanceId, configurationId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test
+ public void shouldProperlySetConfigurationActiveStatusActiveWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String configurationId = "testConfigurationId";
+
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+
+ MsoResponseWrapper okResponse = createOkResponse();
+
+ String endpoint =
+ validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
+ .replace(SVC_INSTANCE_ID, serviceInstanceId)
+ .replace(CONFIGURATION_ID, configurationId)
+ + "/activate";
+
+ given(msoInterface.setConfigurationActiveStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.setConfigurationActiveStatus(requestDetails, serviceInstanceId, configurationId, true);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test
+ public void shouldProperlySetConfigurationActiveStatusDeactivateWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String configurationId = "testConfigurationId";
+
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+
+ MsoResponseWrapper okResponse = createOkResponse();
+
+ String endpoint =
+ validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
+ .replace(SVC_INSTANCE_ID, serviceInstanceId)
+ .replace(CONFIGURATION_ID, configurationId)
+ + "/deactivate";
+
+ given(msoInterface.setConfigurationActiveStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.setConfigurationActiveStatus(requestDetails, serviceInstanceId, configurationId, false);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test
+ public void shouldProperlySetServiceInstanceStatusActiveWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ RestObject<String> restObjStr = new RestObject<>();
+ restObjStr.set("");
+ MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, true);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+
+ }
+
+ @Test
+ public void shouldProperlySetServiceInstanceStatusDeactivateWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ RestObject<String> restObjStr = new RestObject<>();
+ restObjStr.set("");
+ MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, false);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+
+ }
+
+ @Test(expectedExceptions = MsoTestException.class)
+ public void shouldThrowExceptionWhenSetServiceInstanceStatusWithWrongParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+
+ doThrow(new MsoTestException("testException")).
+ when(msoInterface).setServiceInstanceStatus(eq(null), any(String.class), any(String.class), any(String.class), any(RestObject.class));
+
+ // when
+ msoBusinessLogic.setServiceInstanceStatus(null, serviceInstanceId, true);
+ }
+
+ @Test
+ public void shouldProperlySetPortOnConfigurationStatusEnableWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String configurationId = "testConfigurationId";
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ MsoResponseWrapper okResponse = createOkResponse();
+
+ String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
+ .replace(SVC_INSTANCE_ID, serviceInstanceId)
+ .replace(CONFIGURATION_ID, configurationId)
+ + "/enablePort";
+
+ given(msoInterface.setPortOnConfigurationStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.setPortOnConfigurationStatus(requestDetails, serviceInstanceId, configurationId, true);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test
+ public void shouldProperlySetPortOnConfigurationStatusDisableWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String configurationId = "testConfigurationId";
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ MsoResponseWrapper okResponse = createOkResponse();
+
+ String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
+ .replace(SVC_INSTANCE_ID, serviceInstanceId)
+ .replace(CONFIGURATION_ID, configurationId)
+ + "/disablePort";
+
+ given(msoInterface.setPortOnConfigurationStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.setPortOnConfigurationStatus(requestDetails, serviceInstanceId, configurationId, false);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test
+ public void shouldProperlyCreateOperationalEnvironmentActivationRequestDetailsWithProperParameters() {
+ // given
+ OperationalEnvironmentActivateInfo details = createTestOperationalEnvironmentActivateInfo();
+ // when
+ org.onap.vid.changeManagement.RequestDetailsWrapper<RequestDetails> requestDetails = msoBusinessLogic.createOperationalEnvironmentActivationRequestDetails(details);
+
+ // then
+ assertThat(requestDetails.requestDetails.getRequestParameters().getAdditionalProperties().values()).contains(details.getWorkloadContext(), details.getManifest());
+ assertThat(requestDetails.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
+ }
+
+ @Test
+ public void shouldProperlyGetOperationalEnvironmentActivationPathWithProperParameters() {
+ // given
+ OperationalEnvironmentActivateInfo details = createTestOperationalEnvironmentActivateInfo();
+
+ // when
+ String response = msoBusinessLogic.getOperationalEnvironmentActivationPath(details);
+
+ // then
+ assertThat(response).contains(operationalEnvironmentId);
+ }
+
+ @Test
+ public void shouldProperlyCreateOperationalEnvironmentDeactivationRequestDetailsWithProperParameters() {
+ // given
+ OperationalEnvironmentDeactivateInfo details = createTestOperationalEnvironmentDeactivateInfo();
+
+ // when
+ org.onap.vid.changeManagement.RequestDetailsWrapper<RequestDetails> response;
+ response = msoBusinessLogic.createOperationalEnvironmentDeactivationRequestDetails(details);
+
+ // then
+ assertThat(response.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
+ }
+
+ @Test
+ public void shouldProperlyGetCloudResourcesRequestsStatusPathWithProperParameters() {
+ // given
+ String requestId = "testRequestId";
+
+ // when
+ String response = msoBusinessLogic.getCloudResourcesRequestsStatusPath(requestId);
+
+ // then
+ assertThat(response).contains(requestId);
+ }
+
+ @Test
+ public void shouldProperlyGetOperationalEnvironmentDeactivationPathWithProperParameters() {
+ // given
+ OperationalEnvironmentDeactivateInfo details = createTestOperationalEnvironmentDeactivateInfo();
+
+ // when
+ String response = msoBusinessLogic.getOperationalEnvironmentDeactivationPath(details);
+
+ // then
+ assertThat(response).contains(operationalEnvironmentId);
+ }
+
+ @Test
+ public void shouldProperlyGetOperationalEnvironmentCreationPathWithProperParameters() {
+ // when
+ String response = msoBusinessLogic.getOperationalEnvironmentCreationPath();
+
+ // then
+ assertThat(response).isNotBlank();
+ }
+
+ @Test
+ public void shouldProperlyConvertParametersToRequestDetailsWithProperParameters() {
+ // given
+ OperationalEnvironmentController.OperationalEnvironmentCreateBody input = createTestOperationalEnvironmentCreateBody();
+
+ // when
+ org.onap.vid.changeManagement.RequestDetailsWrapper<OperationEnvironmentRequestDetails> response
+ = msoBusinessLogic.convertParametersToRequestDetails(input, userId);
+
+ // then
+ assertThat(response.requestDetails.getRequestInfo().getInstanceName()).isEqualTo(input.getInstanceName());
+ assertThat(response.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
+ assertThat(response.requestDetails.getRequestParameters().getOperationalEnvironmentType()).isEqualTo(input.getOperationalEnvironmentType());
+ assertThat(response.requestDetails.getRequestParameters().getTenantContext()).isEqualTo(input.getTenantContext());
+ assertThat(response.requestDetails.getRequestParameters().getWorkloadContext()).isEqualTo(input.getWorkloadContext());
+ }
+
+ @Test
+ public void shouldProperlyRemoveRelationshipFromServiceInstanceWithProperParameters() {
+ // given
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ String serviceInstanceId = "testServiceId";
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ given(msoInterface.removeRelationshipFromServiceInstance(eq(requestDetails), endsWith("/" + serviceInstanceId + "/removeRelationships")))
+ .willReturn(expectedResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.removeRelationshipFromServiceInstance(requestDetails, serviceInstanceId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test
+ public void shouldProperlyAddRelationshipToServiceInstanceWithProperParameters() {
+ // given
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ String serviceInstanceId = "testServiceId";
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ given(msoInterface.addRelationshipToServiceInstance(eq(requestDetails), endsWith("/" + serviceInstanceId + "/addRelationships")))
+ .willReturn(expectedResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.addRelationshipToServiceInstance(requestDetails, serviceInstanceId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test
+ public void shouldProperlyRequestTypeFromValueWithValidParameters() {
+ // given
+ String testValue = "createInstance";
+ // when
+ MsoBusinessLogicImpl.RequestType response = MsoBusinessLogicImpl.RequestType.fromValue(testValue);
+
+ // then
+ assertThat(response.toString()).isEqualTo(testValue);
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void shouldThrowExceptionWhenRequestTypeFromValueWithWrongParameter() {
+ // given
+ String testValue = "notExistingParameter";
+ // when
+ MsoBusinessLogicImpl.RequestType.fromValue(testValue);
+ }
+
+
+ private OperationalEnvironmentActivateInfo createTestOperationalEnvironmentActivateInfo() {
+ OperationalEnvironmentController.OperationalEnvironmentActivateBody operationalEnvironmentActivateBody = new OperationalEnvironmentController.OperationalEnvironmentActivateBody(
+ "testRelatedInstanceId",
+ "testRelatedInstanceName",
+ "testWorkloadContext",
+ new OperationalEnvironmentController.OperationalEnvironmentManifest()
+ );
+ return new OperationalEnvironmentActivateInfo(operationalEnvironmentActivateBody, userId, operationalEnvironmentId);
+ }
+
+ private OperationalEnvironmentDeactivateInfo createTestOperationalEnvironmentDeactivateInfo() {
+ return new OperationalEnvironmentDeactivateInfo(userId, operationalEnvironmentId);
+ }
+
+ private OperationalEnvironmentController.OperationalEnvironmentCreateBody createTestOperationalEnvironmentCreateBody() {
+ return new OperationalEnvironmentController.OperationalEnvironmentCreateBody(
+ "testInstanceName",
+ "testEcompInstanceId",
+ "testEcompInstanceName",
+ "testOperationalEnvironmentType",
+ "testTenantContext",
+ "testWorkloadContext"
+ );
+ }
+
+ private MsoResponseWrapper createOkResponse() {
+ HttpStatus expectedStatus = HttpStatus.ACCEPTED;
+ String expectedBody = " \"body\": {\n" +
+ " \"requestReferences\": {\n" +
+ " \"instanceId\": \" 123456 \",\n" +
+ " \"requestId\": \"b6dc9806-b094-42f7-9386-a48de8218ce8\"\n" +
+ " }";
+ MsoResponseWrapper responseWrapper = new MsoResponseWrapper();
+ responseWrapper.setEntity(expectedBody);
+ responseWrapper.setStatus(expectedStatus.value());
+ return responseWrapper;
}
private String getFileContentAsString(String resourceName) throws Exception {
Path path = Paths.get("payload_jsons", resourceName);
URL url = this.getClass().getClassLoader().getResource(path.toString());
- return IOUtils.toString(url.toURI(), "UTF-8");
+ String result = "";
+ if (url != null) {
+ result = IOUtils.toString(url.toURI(), "UTF-8");
+ }
+ return result;
}
private static class MsoRequestWrapperMatcher implements
- ArgumentMatcher<org.onap.vid.changeManagement.RequestDetailsWrapper> {
+ ArgumentMatcher<org.onap.vid.changeManagement.RequestDetailsWrapper> {
private final org.onap.vid.changeManagement.RequestDetailsWrapper expectedRequest;
- public MsoRequestWrapperMatcher(org.onap.vid.changeManagement.RequestDetailsWrapper expectedRequest) {
+ MsoRequestWrapperMatcher(org.onap.vid.changeManagement.RequestDetailsWrapper expectedRequest) {
this.expectedRequest = expectedRequest;
}
@@ -301,5 +1392,11 @@ public class MsoBusinessLogicImplTest {
return expectedRequest.requestDetails.equals(argument.requestDetails);
}
}
+
+ private class MsoTestException extends RuntimeException {
+ MsoTestException(String testException) {
+ super(testException);
+ }
+ }
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java
index d09f4a2c5..6cba339d1 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java
@@ -3,13 +3,14 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
@@ -20,71 +21,81 @@
package org.onap.vid.mso;
-import org.junit.Test;
+import org.mockito.Mock;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import javax.ws.rs.core.Response;
+
public class MsoResponseWrapperTest {
- private MsoResponseWrapper createTestSubject() {
- return new MsoResponseWrapper();
+ private static final String PROPER_RESPONSE = "{ \"status\": 1, \"entity\": testEntity}";
+ private static final String PROPER_RESPONSE_WITH_NO_ENTITY = "{ \"status\": 1, \"entity\": \"\"}";
+ private static final String PROPER_TO_STRING = "[status=1,entity=testEntity]";
+
+ @Mock
+ private Response response;
+
+ private MsoResponseWrapper responseWrapper;
+
+ @BeforeSuite
+ public void setUp() {
+ initMocks(this);
}
@Test
- public void testGetEntity() throws Exception {
- MsoResponseWrapper testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getEntity();
+ public void shouldHaveValidGettersAndSetters(){
+ assertThat(MsoResponseWrapper.class, hasValidGettersAndSettersExcluding("response"));
}
@Test
- public void testGetStatus() throws Exception {
- MsoResponseWrapper testSubject;
- int result;
+ public void shouldProperlyConstructResponseWrapperWithParameters(){
+ responseWrapper = new MsoResponseWrapper(1,"testEntity");
- // default test
- testSubject = createTestSubject();
- result = testSubject.getStatus();
+ assertThat(responseWrapper.getStatus()).isEqualTo(1);
+ assertThat(responseWrapper.getEntity()).isEqualTo("testEntity");
}
@Test
- public void testSetStatus() throws Exception {
- MsoResponseWrapper testSubject;
- int v = 0;
+ public void shouldProperlyConstructResponseWrapperFromResponse(){
+ when(response.getStatus()).thenReturn(1);
+ when(response.readEntity(String.class)).thenReturn("testEntity");
+
+ responseWrapper = new MsoResponseWrapper(response);
- // default test
- testSubject = createTestSubject();
- testSubject.setStatus(v);
+ assertThat(responseWrapper.getStatus()).isEqualTo(1);
+ assertThat(responseWrapper.getEntity()).isEqualTo("testEntity");
}
@Test
- public void testSetEntity() throws Exception {
- MsoResponseWrapper testSubject;
- String v = "";
+ public void shouldProperlyGetResponseWithEmptyEntity(){
+ responseWrapper = new MsoResponseWrapper();
+ responseWrapper.setStatus(1);
- // default test
- testSubject = createTestSubject();
- testSubject.setEntity(v);
+ assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE_WITH_NO_ENTITY);
}
@Test
- public void testToString() throws Exception {
- MsoResponseWrapper testSubject;
- String result;
+ public void shouldProperlyGetResponse(){
+ responseWrapper = new MsoResponseWrapper(1,"testEntity");
- // default test
- testSubject = createTestSubject();
- result = testSubject.toString();
+ assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE);
}
@Test
- public void testGetResponse() throws Exception {
- MsoResponseWrapper testSubject;
- String result;
+ public void shouldProperlyConvertToString(){
+ responseWrapper = new MsoResponseWrapper(1,"testEntity");
- // default test
- testSubject = createTestSubject();
- result = testSubject.getResponse();
+ assertThat(responseWrapper.toString()).endsWith(PROPER_TO_STRING);
}
+
+
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java
index 85c5aa472..650bda13b 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java
@@ -22,12 +22,11 @@
package org.onap.vid.mso;
import io.joshworks.restclient.http.HttpResponse;
-import io.joshworks.restclient.http.mapper.ObjectMapper;
import org.apache.http.HttpResponseFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.DefaultHttpResponseFactory;
import org.apache.http.message.BasicStatusLine;
-import org.junit.Test;
+import org.testng.annotations.Test;
import static org.apache.http.HttpStatus.SC_OK;
import static org.apache.http.HttpVersion.HTTP_1_1;
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java
index c7504bc1a..803083321 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java
@@ -20,79 +20,75 @@
package org.onap.vid.mso;
-import org.junit.Test;
+import org.hamcrest.MatcherAssert;
+import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.Test;
-public class RestObjectTest {
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
+import static org.assertj.core.api.Assertions.assertThat;
- private RestObject createTestSubject() {
- return new RestObject();
- }
+public class RestObjectTest {
- @Test
- public void testSet() throws Exception {
- RestObject testSubject;
+ private RestObject restObject;
- // default test
- testSubject = createTestSubject();
- testSubject.set(null);
+ @BeforeSuite
+ private void setUp() {
+ restObject = new RestObject();
}
@Test
- public void testGet() throws Exception {
- RestObject testSubject;
-
- // default test
- testSubject = createTestSubject();
- testSubject.get();
+ public void shouldHaveValidGettersAndSetters(){
+ MatcherAssert.assertThat(RestObject.class, hasValidGettersAndSettersExcluding("t"));
}
@Test
- public void testSetStatusCode() throws Exception {
- RestObject testSubject;
- int v = 0;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setStatusCode(v);
- }
+ public void shouldHaveValidGetterAndSetterForBody() {
+ // given
+ String testString = "set/get_testString";
- @Test
- public void testGetStatusCode() throws Exception {
- RestObject testSubject;
- int result;
+ // when
+ restObject.set(testString);
- // default test
- testSubject = createTestSubject();
- result = testSubject.getStatusCode();
+ // then
+ assertThat(testString).isSameAs(restObject.get());
}
@Test
- public void testGetRaw() throws Exception {
- RestObject testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getRaw();
+ public void shouldProperlyCopyRestObject() {
+ // given
+ MsoResponseWrapper testResponseWraper = new MsoResponseWrapper();
+ String rawTestString = "rawTestString";
+ int statusCode = 404;
+
+ RestObject restObjectToCopyFrom = new RestObject<>();
+ restObjectToCopyFrom.set(testResponseWraper);
+ restObjectToCopyFrom.setRaw(rawTestString);
+ restObjectToCopyFrom.setStatusCode(statusCode);
+
+ // when
+ restObject.copyFrom(restObjectToCopyFrom);
+
+ // then
+ assertThat(restObject).isEqualToComparingFieldByField(restObjectToCopyFrom);
}
@Test
- public void testSetRaw() throws Exception {
- RestObject testSubject;
- String rawT = "";
+ public void shouldProperlyConvertRestObjectToString() {
+ // given
+ String testString = "testString";
+ String rawTestString = "rawTestString";
+ int statusCode = 202;
- // default test
- testSubject = createTestSubject();
- testSubject.setRaw(rawT);
- }
+ restObject.set(testString);
+ restObject.setRaw(rawTestString);
+ restObject.setStatusCode(statusCode);
- @Test
- public void testToString() throws Exception {
- RestObject testSubject;
- String result;
+ String properString = "RestObject{t=testString, rawT=rawTestString, statusCode=202}";
+
+ // when
+ String toStringResponse = restObject.toString();
- // default test
- testSubject = createTestSubject();
- result = testSubject.toString();
+ // then
+ assertThat(toStringResponse).isEqualTo(properString);
}
}
diff --git a/vid-app-common/src/test/resources/WEB-INF/conf/system.properties b/vid-app-common/src/test/resources/WEB-INF/conf/system.properties
index 268666798..6f19eb31e 100644
--- a/vid-app-common/src/test/resources/WEB-INF/conf/system.properties
+++ b/vid-app-common/src/test/resources/WEB-INF/conf/system.properties
@@ -136,6 +136,7 @@ guard_notebook_url=https://rcloud.research.att.com/mini.html?notebook=a06a9cf142
#dev
#mso.server.url=http://mtanjv9moah10-eth0.aic.cip.att.com:8080/ecomp/mso/infra
#istScrum-Master
+mso.restapi.svc.e2einstance=/e2eServiceInstances/v3
mso.client.type=LOCAL
mso.server.url=http://vm1.mso.simpledemo.openecomp.org:8080
mso.polling.interval.msecs=10000
@@ -157,6 +158,14 @@ mso.restapi.get.man.tasks=/tasks/v1
mso.restapi.configurations=/serviceInstances/v6/<service_instance_id>/configurations
mso.restapi.configuration.instance=${mso.restapi.configurations}<configuration_id>
+mso.restapi.operationalEnvironment.activate=${mso.restapi.operationalEnvironment}/activate
+mso.restapi.operationalEnvironment=${mso.restapi.cloudResourcesApiRoot}/operationalEnvironments/<operational_environment_id>
+mso.restapi.cloudResourcesApiRoot=/cloudResources/v1
+mso.restapi.cloudResourcesRequestsApiRoot=/cloudResourcesRequests/v1
+mso.restapi.operationalEnvironment.cloudResourcesRequests.status=${mso.restapi.cloudResourcesRequestsApiRoot}?requestId=<request_id>
+mso.restapi.operationalEnvironment.deactivate=${mso.restapi.operationalEnvironment}/deactivate
+mso.restapi.operationalEnvironment.create=${mso.restapi.cloudResourcesApiRoot}/operationalEnvironments
+
mso.restapi.serviceInstantiationApiRoot=/serviceInstantiation/v7
mso.restapi.serviceInstanceCreate=${mso.restapi.serviceInstantiationApiRoot}/serviceInstances
mso.restapi.serviceInstanceAssign=${mso.restapi.serviceInstantiationApiRoot}/serviceInstances/assign
diff --git a/vid-app-common/src/test/resources/payload_jsons/manual_tasks_by_requestId_test.json b/vid-app-common/src/test/resources/payload_jsons/manual_tasks_by_requestId_test.json
new file mode 100644
index 000000000..f4ba58d54
--- /dev/null
+++ b/vid-app-common/src/test/resources/payload_jsons/manual_tasks_by_requestId_test.json
@@ -0,0 +1,29 @@
+{
+ "taskList":[{
+ "taskId":"123123abc",
+ "type":"testTask",
+ "nfRole":"testTask",
+ "subscriptionServiceType":"testTask",
+ "originalRequestId":"testTask",
+ "originalRequestorId":"testTask",
+ "errorSource":"testTask",
+ "errorCode":"testTask",
+ "errorMessage":"testTask",
+ "buildingBlockName":"testTask",
+ "buildingBlockStep":"testTask",
+ "validResponses":null
+ },{
+ "taskId":"321321abc",
+ "type":"testTask",
+ "nfRole":"testTask",
+ "subscriptionServiceType":"testTask",
+ "originalRequestId":"testTask",
+ "originalRequestorId":"testTask",
+ "errorSource":"testTask",
+ "errorCode":"testTask",
+ "errorMessage":"testTask",
+ "buildingBlockName":"testTask",
+ "buildingBlockStep":"testTask",
+ "validResponses":null
+ }]
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/resources/payload_jsons/manual_tasks_by_requestId_wrongJson_test.json b/vid-app-common/src/test/resources/payload_jsons/manual_tasks_by_requestId_wrongJson_test.json
new file mode 100644
index 000000000..624d3d24f
--- /dev/null
+++ b/vid-app-common/src/test/resources/payload_jsons/manual_tasks_by_requestId_wrongJson_test.json
@@ -0,0 +1,29 @@
+{
+ "taskList":[{
+ "task":"123123abc",
+ "type":"testTask",
+ "nfRole":"testTask",
+ "subscriptionServiceType":"testTask",
+ "originalRequestId":"testTask",
+ "originalRequestorId":"testTask",
+ "errorSource":"testTask",
+ "errorCode":"testTask",
+ "errorMessage":"testTask",
+ "buildingBlockName":"testTask",
+ "buildingBlockStep":"testTask",
+ "validResponses":null
+ },{
+ "task":"321321abc",
+ "type":"testTask",
+ "nfRole":"testTask",
+ "subscriptionServiceType":"testTask",
+ "originalRequestId":"testTask",
+ "originalRequestorId":"testTask",
+ "errorSource":"testTask",
+ "errorCode":"testTask",
+ "errorMessage":"testTask",
+ "buildingBlockName":"testTask",
+ "buildingBlockStep":"testTask",
+ "validResponses":null
+ }]
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/resources/payload_jsons/mso_model_info_sample_wrong_response.json b/vid-app-common/src/test/resources/payload_jsons/mso_model_info_sample_wrong_response.json
new file mode 100644
index 000000000..c74979d0d
--- /dev/null
+++ b/vid-app-common/src/test/resources/payload_jsons/mso_model_info_sample_wrong_response.json
@@ -0,0 +1,108 @@
+
+ "requestList":
+ {
+ "request": {
+ "requestId": "f8c813a2-b22b-4e3d-9be0-8e2d16b1add3",
+ "startTime": "Wed, 03 Oct 2018 13:13:04 GMT",
+ "requestScope": "vnf",
+ "requestType": "createInstance",
+ "requestDetails": {
+ "modelInfo": {
+ "modelCustomizationName": "ws-sp 0",
+ "modelInvariantId": "734f0952-6678-44e7-8918-f9aa4694b687",
+ "modelType": "vnf",
+ "modelName": "ws-sp",
+ "modelVersion": "1.0",
+ "modelCustomizationUuid": "5815868c-35f8-4c5a-b899-e6eb49f52986",
+ "modelVersionId": "0e0bb964-e687-4439-9a9e-de9cd1ff5367",
+ "modelCustomizationId": "5815868c-35f8-4c5a-b899-e6eb49f52986",
+ "modelUuid": "0e0bb964-e687-4439-9a9e-de9cd1ff5367",
+ "modelInvariantUuid": "734f0952-6678-44e7-8918-f9aa4694b687",
+ "modelInstanceName": "ws-sp 0"
+ },
+ "requestInfo": {
+ "productFamilyId": "61cc3239-5c2e-4762-a281-7422a2e54d5a",
+ "source": "VID",
+ "instanceName": "ws-test-0310-8",
+ "suppressRollback": false,
+ "requestorId": "demo"
+ },
+ "relatedInstanceList": [
+ {
+ "relatedInstance": {
+ "instanceId": "fd84f066-ea75-4b23-acd0-3cf3fce7a99b",
+ "modelInfo": {
+ "modelInvariantId": "c9817f08-07b2-458b-a02f-cd5407ee7a7b",
+ "modelType": "service",
+ "modelName": "ws-service",
+ "modelVersion": "1.0",
+ "modelVersionId": "cd3fbd06-6bc8-43a4-b803-933fc2e3cdf7",
+ "modelUuid": "cd3fbd06-6bc8-43a4-b803-933fc2e3cdf7",
+ "modelInvariantUuid": "c9817f08-07b2-458b-a02f-cd5407ee7a7b"
+ }
+ }
+ }
+ ],
+ "cloudConfiguration": {
+ "tenantId": "1e097c6713e74fd7ac8e4295e605ee1e",
+ "lcpCloudRegionId": "RegionOne"
+ },
+ "requestParameters": {
+ "testApi": "VNF_API"
+ },
+ "platform": {
+ "platformName": "Demo"
+ },
+ "lineOfBusiness": {
+ "lineOfBusinessName": "Demo"
+ }
+ },
+ "instanceReferences": {
+ "serviceInstanceId": "fd84f066-ea75-4b23-acd0-3cf3fce7a99b",
+ "vnfInstanceId": "980fe98e-47f8-4164-862d-4ebb026cec75",
+ "vnfInstanceName": "ws-test-0310-8",
+ "requestorId": "demo"
+ },
+ "requestStatus": {
+ "requestState": "COMPLETE",
+ "statusMessage": "Vnf has been created successfully.",
+ "percentProgress": 100,
+ "finishTime": "Wed, 03 Oct 2018 13:13:09 GMT"
+ }
+ }
+ },
+ {
+ "request": {
+ "requestId": "3447ba35-015d-4d72-9345-d89b1e35b2d6",
+ "startTime": "Thu, 04 Oct 2018 10:35:17 GMT",
+ "requestScope": "vnf",
+ "requestType": "inPlaceSoftwareUpdate",
+ "requestDetails": {
+ "requestInfo": {
+ "source": "VID",
+ "suppressRollback": false,
+ "requestorId": "demo"
+ },
+ "cloudConfiguration": {
+ "tenantId": "1e097c6713e74fd7ac8e4295e605ee1e",
+ "lcpCloudRegionId": "RegionOne"
+ },
+ "requestParameters": {
+ "payload": "{\"existing_software_version\":\"0.7\",\"new_software_version\":\"1.0\",\"operations_timeout\":\"10\"}"
+ }
+ },
+ "instanceReferences": {
+ "serviceInstanceId": "fd84f066-ea75-4b23-acd0-3cf3fce7a99b",
+ "vnfInstanceId": "980fe98e-47f8-4164-862d-4ebb026cec75",
+ "requestorId": "demo"
+ },
+ "requestStatus": {
+ "requestState": "FAILED",
+ "statusMessage": "Cloud Region with cloudRegionId RegionOne does not exist in A&AI",
+ "percentProgress": 100,
+ "finishTime": "Thu, 04 Oct 2018 10:35:21 GMT"
+ }
+ }
+ }
+ ]
+} \ No newline at end of file