import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.only;
+import static org.mockito.Mockito.when;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import org.onap.vid.model.RequestReferencesContainer;
import org.onap.vid.mso.MsoBusinessLogic;
import org.onap.vid.mso.MsoResponseWrapper;
+import org.onap.vid.mso.MsoResponseWrapper2;
+import org.onap.vid.mso.RestMsoImplementation;
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;
private MockMvc mockMvc;
private MsoBusinessLogic msoBusinessLogic;
private CloudOwnerService cloudService;
- private MsoRestClientNew msoRestClient;
+ private RestMsoImplementation msoRestClient;
@Before
public void setUp() {
msoBusinessLogic = mock(MsoBusinessLogic.class);
cloudService = mock(CloudOwnerService.class);
- msoRestClient = mock(MsoRestClientNew.class);
+ msoRestClient = mock(RestMsoImplementation.class);
MsoController msoController = new MsoController(msoBusinessLogic, msoRestClient, cloudService);
mockMvc = MockMvcBuilders.standaloneSetup(msoController).build();
then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
}
+ @Test
+ public void shouldCreateVfModuleInstance() 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
+ .createVfModuleInstance(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(vnfInstanceId)))
+ .willReturn(expectedResponse);
+
+ // when & then
+ mockMvc.perform(post(format("/mso/mso_create_vfmodule_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 shouldCreateConfigurationInstance() throws Exception {
+ // given
+ RequestDetailsWrapper requestDetails = modelGenerator.nextObject(RequestDetailsWrapper.class);
+ String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+
+ MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
+ given(msoBusinessLogic
+ .createConfigurationInstance(objectEqualTo(requestDetails), eq(serviceInstanceId)))
+ .willReturn(expectedResponse);
+
+ // when & then
+ mockMvc.perform(post(format("/mso/mso_create_configuration_instance/%s/configurations/", serviceInstanceId))
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(asJson(expectedResponse)));
+
+ then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails.getRequestDetails()));
+ }
+
+ @Test
+ public void shouldDeleteE2eSvcInstance() throws Exception {
+ // given
+ RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+ String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+ String configurationId = "28630972-d548-4d5f-acc2-ad1d748d023d";
+
+ MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
+ given(msoBusinessLogic
+ .setConfigurationActiveStatus(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(configurationId), eq(true)))
+ .willReturn(expectedResponse);
+
+ // when & then
+ mockMvc.perform(post(format("/mso/mso_activate_configuration/%s/configurations/%s", serviceInstanceId, configurationId))
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(asJson(expectedResponse)));
+
+ then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
+ }
+
+ @Test
+ public void shouldDeactivateConfiguration() throws Exception {
+ // given
+ RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+ String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+ String configurationId = "28630972-d548-4d5f-acc2-ad1d748d023d";
+
+ MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
+ given(msoBusinessLogic
+ .setConfigurationActiveStatus(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(configurationId), eq(false)))
+ .willReturn(expectedResponse);
+
+ // when & then
+ mockMvc.perform(post(format("/mso/mso_deactivate_configuration/%s/configurations/%s", serviceInstanceId, configurationId))
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(asJson(expectedResponse)));
+
+ then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
+ }
+
+ @Test
+ public void shouldDisablePortOnConfiguration() throws Exception {
+ // given
+ RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+ String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+ String configurationId = "28630972-d548-4d5f-acc2-ad1d748d023d";
+
+ MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
+ given(msoBusinessLogic
+ .setPortOnConfigurationStatus(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(configurationId), eq(false)))
+ .willReturn(expectedResponse);
+
+ // when & then
+ mockMvc.perform(post(format("/mso/mso_disable_port_configuration/%s/configurations/%s", serviceInstanceId, configurationId))
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(asJson(expectedResponse)));
+
+ then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
+ }
+
+ @Test
+ public void shouldEnablePortOnConfiguration() throws Exception {
+ // given
+ RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
+ String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
+ String configurationId = "28630972-d548-4d5f-acc2-ad1d748d023d";
+
+ MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
+ given(msoBusinessLogic
+ .setPortOnConfigurationStatus(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(configurationId), eq(true)))
+ .willReturn(expectedResponse);
+
+ // when & then
+ mockMvc.perform(post(format("/mso/mso_enable_port_configuration/%s/configurations/%s", serviceInstanceId, configurationId))
+ .content(asJson(requestDetails))
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(asJson(expectedResponse)));
+
+ then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
+ }
+
@Test
public void shouldCreateVolumeInstance() throws Exception {
// given
private <T> T objectEqualTo(T expected) {
return argThat(given -> asJson(given).equals(asJson(expected)));
}
-}
\ No newline at end of file
+
+ @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)));
+ }
+}