+ // when & then
+ mockMvc.perform(get("/mso/mso_get_orch_reqs/dashboard"))
+ .andExpect(status().isOk())
+ .andExpect(content().json(objectMapper.writeValueAsString(orchestrationRequests)));
+
+ then(cloudService).shouldHaveZeroInteractions();
+ }
+
+ @Test
+ public void shouldReturnManualTasksById() throws Exception {
+ // given
+ List<Task> manualTasks = modelGenerator
+ .objects(Task.class, 2)
+ .collect(Collectors.toList());
+
+ String originalRequestId = "za1234d1-5a33-55df-13ab-12abad84e335";
+ given(msoBusinessLogic.getManualTasksByRequestId(originalRequestId)).willReturn(manualTasks);
+
+ // when & then
+ mockMvc.perform(get("/mso/mso_get_man_task/{id}", originalRequestId))
+ .andExpect(status().isOk())
+ .andExpect(content().json(objectMapper.writeValueAsString(manualTasks)));
+
+ then(cloudService).shouldHaveZeroInteractions();
+ }
+
+ @Test
+ public void shouldDelegateE2EServiceInstantiation() throws Exception {
+ // given
+ String requestDetails = "some request details";
+ Map<String, Object> payload = new LinkedHashMap<>();
+ payload.put("requestDetails", requestDetails);
+
+ MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
+ given(wrapper.getResponse()).willReturn("some response");
+ given(msoBusinessLogic.createE2eSvcInstance(requestDetails)).willReturn(wrapper);
+
+ // when & then
+ mockMvc.perform(post("/mso/mso_create_e2e_svc_instance")
+ .content(asJson(payload))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("some response"));
+
+ then(cloudService).shouldHaveZeroInteractions();
+ }
+
+ @Test
+ public void shouldDelegateServiceInstantiation() throws Exception {
+ // given
+ RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+
+ MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
+ given(wrapper.getResponse()).willReturn("some response");
+ given(msoBusinessLogic.createSvcInstance(objectEqualTo(requestDetails))).willReturn(wrapper);
+
+ // when & then
+ mockMvc.perform(post("/mso/mso_create_svc_instance")
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("some response"));
+
+ then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
+ }
+
+ @Test
+ public void shouldDelegateVnfInstantiation() throws Exception {
+ // given
+ RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+ String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+
+ MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
+ given(wrapper.getResponse()).willReturn("some response");
+ given(msoBusinessLogic.createVnf(objectEqualTo(requestDetails), eq(serviceInstanceId))).willReturn(wrapper);
+
+ // when & then
+ mockMvc.perform(post("/mso/mso_create_vnf_instance/" + serviceInstanceId)
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("some response"));
+
+ then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
+ }
+
+ @Test
+ public void shouldDeleteVfModuleInstance() throws Exception {
+ // given
+ RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+ String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+ String vnfInstanceId = "fe9000-0009-9999";
+ String vfModuleId = "abeeee-abeeee-abeeee";
+
+ MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
+ given(wrapper.getResponse()).willReturn("some response");
+ given(msoBusinessLogic.deleteVfModule(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(vnfInstanceId), eq(vfModuleId))).willReturn(wrapper);
+
+ // when & then
+ mockMvc.perform(post(format("/mso/mso_delete_vfmodule_instance/%s/vnfs/%s/vfModules/%s", serviceInstanceId, vnfInstanceId, vfModuleId))
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("some response"));
+
+ then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
+ }
+
+ @Test
+ public void shouldDeleteVolumeGroup() throws Exception {
+ // given
+ RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+ String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+ String vnfInstanceId = "fe9000-0009-9999";
+ String volumeGroupId = "abeeee-abeeee-abeeee";
+
+ MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
+ given(wrapper.getResponse()).willReturn("some response");
+ given(msoBusinessLogic.deleteVolumeGroupInstance(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(vnfInstanceId), eq(volumeGroupId))).willReturn(wrapper);
+
+ // when & then
+ mockMvc.perform(post(format("/mso/mso_delete_volumegroup_instance/%s/vnfs/%s/volumeGroups/%s", serviceInstanceId, vnfInstanceId, volumeGroupId))
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("some response"));
+
+ then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
+ }
+
+ @Test
+ public void shouldDeleteInstance() throws Exception {
+ // given
+ RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+ String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+ String networkInstanceId = "fe9000-0009-9999";
+
+ MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
+ given(wrapper.getResponse()).willReturn("some response");
+ given(msoBusinessLogic.deleteNwInstance(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(networkInstanceId))).willReturn(wrapper);
+
+ // when & then
+ mockMvc.perform(post(format("/mso/mso_delete_nw_instance/%s/networks/%s", serviceInstanceId, networkInstanceId))
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("some response"));
+
+ then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
+ }
+
+ @Test
+ public void shouldDeleteServiceInstance() throws Exception {
+ // given
+ RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+ String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+ String serviceStatus = "ACTIVE";
+
+ MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
+ given(wrapper.getResponse()).willReturn("some response");
+ given(msoBusinessLogic.deleteSvcInstance(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(serviceStatus))).willReturn(wrapper);
+
+ // when & then
+ mockMvc.perform(post(format("/mso/mso_delete_svc_instance/%s", serviceInstanceId))
+ .param("serviceStatus", serviceStatus)
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("some response"));
+
+ then(cloudService).shouldHaveZeroInteractions();
+ }
+
+ @Test
+ public void shouldDeleteVnf() throws Exception {
+ // given
+ RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+ String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+ String vnfInstanceId = "fe9000-0009-9999";
+
+ MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
+ given(wrapper.getResponse()).willReturn("some response");
+ given(msoBusinessLogic.deleteVnf(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(vnfInstanceId))).willReturn(wrapper);
+
+ // when & then
+ mockMvc.perform(post(format("/mso/mso_delete_vnf_instance/%s/vnfs/%s", serviceInstanceId, vnfInstanceId))
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("some response"));
+
+ then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
+ }
+
+ @Test
+ public void shouldDeleteConfiguration() throws Exception {
+ // given
+ RequestDetailsWrapper requestDetails = modelGenerator.nextObject(RequestDetailsWrapper.class);
+ String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+ String configurationId = "fe9000-0009-9999";
+
+ MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
+ given(wrapper.getResponse()).willReturn("some response");
+ given(msoBusinessLogic.deleteConfiguration(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(configurationId))).willReturn(wrapper);
+
+ // when & then
+ mockMvc.perform(post(format("/mso/mso_delete_configuration/%s/configurations/%s", serviceInstanceId, configurationId))
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("some response"));
+
+ then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails.getRequestDetails()));
+ }
+
+ @Test
+ public void shouldDelegateNewInstanceCreation() throws Exception {
+ // given
+ RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+ String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+
+ MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
+ given(wrapper.getResponse()).willReturn("some response");
+ given(msoBusinessLogic.createNwInstance(objectEqualTo(requestDetails), eq(serviceInstanceId))).willReturn(wrapper);
+
+ // when & then
+ mockMvc.perform(post("/mso/mso_create_nw_instance/" + serviceInstanceId)
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("some response"));
+
+ then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
+ }
+
+ @Test
+ public void shouldCompleteManualTask() throws Exception {
+ // given
+ RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+ String taskId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+
+ MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
+ given(wrapper.getResponse()).willReturn("some response");
+ given(msoBusinessLogic.completeManualTask(objectEqualTo(requestDetails), eq(taskId))).willReturn(wrapper);
+
+ // when & then
+ mockMvc.perform(post("/mso/mso_post_man_task/" + taskId)
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("some response"));
+
+ then(cloudService).shouldHaveZeroInteractions();
+ }
+
+ @Test
+ public void shouldActivateFabricConfiguration() throws Exception {
+ // given
+ RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+ String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+
+ String path = "/mso/path";
+ given(msoBusinessLogic.getActivateFabricConfigurationPath(eq(serviceInstanceId))).willReturn(path);
+
+ RestObject<RequestReferencesContainer> response = new RestObject<>();
+ response.set(mock(RequestReferencesContainer.class));
+ response.setRaw("some response");
+ response.setStatusCode(200);
+
+ given(msoRestClient.PostForObject(objectEqualTo(requestDetails), eq(path), eq(RequestReferencesContainer.class))).willReturn(response);
+
+ // when & then
+ mockMvc.perform(post(format("/mso/mso_activate_fabric_configuration/%s", serviceInstanceId))
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string("{\"status\":200,\"entity\":{}}"));
+
+ then(cloudService).shouldHaveZeroInteractions();
+ }
+
+ private <T> String asJson(T value) {
+ try {
+ return objectMapper.writeValueAsString(value);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private <T> T objectEqualTo(T expected) {
+ return argThat(given -> asJson(given).equals(asJson(expected)));
+ }
+
+ @Test
+ public void testActivateFabricConfiguration() throws Exception {
+
+ String serviceInstanceId = "tempId";
+
+ //define mock response object
+ String responseString = "{" +
+ " \"requestReferences\": {" +
+ " \"instanceId\": \"tempId\"," +
+ " \"requestId\": \"dbe54591-c8ed-46d3-abc7-d3a24873dfbd\"" +
+ " }" +
+ " }";
+ final RestObject<RequestReferencesContainer> restObject = new RestObject<>();
+ restObject.set(objectMapper.readValue(responseString, RequestReferencesContainer.class));
+ restObject.setStatusCode(200);
+
+ //register mock
+ String msoPath = "justAFakePath";
+
+ when(msoBusinessLogic.getActivateFabricConfigurationPath(serviceInstanceId)).thenReturn(msoPath);
+ when(msoRestClient.PostForObject(new RequestDetails(), msoPath, RequestReferencesContainer.class)).thenReturn(restObject);
+
+ //expected response
+ MsoResponseWrapper2<RequestReferencesContainer> expectedResponse = new MsoResponseWrapper2<>(restObject);
+
+ //get response from controller
+ // when & then
+ mockMvc.perform(post(format("/mso/mso_activate_fabric_configuration/%s", serviceInstanceId))
+ .content(asJson(new RequestDetails()))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(asJson(expectedResponse)));
+ }