Add MsoController deletion tests 99/94099/1
authorkurczews <krzysztof.kurczewski@nokia.com>
Thu, 22 Aug 2019 10:35:04 +0000 (12:35 +0200)
committerkurczews <krzysztof.kurczewski@nokia.com>
Thu, 22 Aug 2019 10:36:01 +0000 (12:36 +0200)
Change-Id: I534fb06e7bf742f2fe6931e5b6f279f499aeed08
Issue-ID: VID-470
Signed-off-by: kurczews <krzysztof.kurczewski@nokia.com>
vid-app-common/src/main/java/org/onap/vid/controller/MsoController.java
vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java

index fc718f0..535c97c 100644 (file)
@@ -302,7 +302,6 @@ public class MsoController extends RestrictedBaseController {
      * @throws Exception the exception
      */
     @RequestMapping(value = "/mso_delete_vnf_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
-
     public ResponseEntity<String> deleteVnf(@PathVariable("serviceInstanceId") String serviceInstanceId,
         @PathVariable("vnfInstanceId") String vnfInstanceId,
         HttpServletRequest request, @RequestBody RequestDetails msoRequest) {
@@ -449,7 +448,6 @@ public class MsoController extends RestrictedBaseController {
      * @return the response entity
      * @throws Exception the exception
      */
-    //mso_delete_vf_module/bc305d54-75b4-431b-adb2-eb6b9e546014/vnfs/fe9000-0009-9999/vfmodules/abeeee-abeeee-abeeee
     @RequestMapping(value = "/mso_delete_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfModuleId}", method = RequestMethod.POST)
     public ResponseEntity<String> deleteVfModule(
         @PathVariable("serviceInstanceId") String serviceInstanceId,
index a1b4559..a2f86f4 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.vid.controller;
 
+import static java.lang.String.format;
 import static org.mockito.ArgumentMatchers.argThat;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.BDDMockito.given;
@@ -44,11 +45,14 @@ import org.jeasy.random.randomizers.misc.BooleanRandomizer;
 import org.jeasy.random.randomizers.text.StringRandomizer;
 import org.junit.Before;
 import org.junit.Test;
+import org.onap.vid.model.RequestReferencesContainer;
 import org.onap.vid.mso.MsoBusinessLogic;
 import org.onap.vid.mso.MsoResponseWrapper;
+import org.onap.vid.mso.RestObject;
 import org.onap.vid.mso.rest.MsoRestClientNew;
 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.services.CloudOwnerService;
 import org.springframework.test.web.servlet.MockMvc;
@@ -79,6 +83,27 @@ public class MsoControllerTest {
         mockMvc = MockMvcBuilders.standaloneSetup(msoController).build();
     }
 
+    @Test
+    public void shouldGetOrchestrationRequest() throws Exception {
+        // given
+        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+        String requestId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+
+        MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
+        given(msoBusinessLogic
+            .getOrchestrationRequest(requestId))
+            .willReturn(expectedResponse);
+
+        // when & then
+        mockMvc.perform(get(format("/mso/mso_get_orch_req/%s", requestId))
+            .content(asJson(requestDetails))
+            .contentType(APPLICATION_JSON))
+            .andExpect(status().isOk())
+            .andExpect(content().json(asJson(expectedResponse)));
+
+        then(cloudService).shouldHaveZeroInteractions();
+    }
+
     @Test
     public void shouldDelegateNewServiceInstantiation() throws Exception {
         // given
@@ -99,6 +124,28 @@ public class MsoControllerTest {
         then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
     }
 
+    @Test
+    public void shouldCreateVolumeInstance() throws Exception {
+        // given
+        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+        String vnfInstanceId = "fe9000-0009-9999";
+
+        MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
+        given(msoBusinessLogic
+            .createVolumeGroupInstance(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(vnfInstanceId)))
+            .willReturn(expectedResponse);
+
+        // when & then
+        mockMvc.perform(post(format("/mso/mso_create_volumegroup_instance/%s/vnfs/%s", serviceInstanceId, vnfInstanceId))
+            .content(asJson(requestDetails))
+            .contentType(APPLICATION_JSON))
+            .andExpect(status().isOk())
+            .andExpect(content().json(asJson(expectedResponse)));
+
+        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
+    }
+
     @Test
     public void shouldReturnOrchestrationRequestsForDashboard() throws Exception {
         // given
@@ -194,6 +241,135 @@ public class MsoControllerTest {
         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
@@ -234,6 +410,32 @@ public class MsoControllerTest {
         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);