diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java')
-rw-r--r-- | bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java | 333 |
1 files changed, 166 insertions, 167 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java index 4a006f8b66..282d7a04f9 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java @@ -25,10 +25,8 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; - import javax.ws.rs.InternalServerErrorException; import javax.ws.rs.core.UriBuilder; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.MockitoAnnotations; @@ -44,169 +42,170 @@ import org.onap.so.adapters.vnfrest.UpdateVolumeGroupResponse; import org.onap.so.client.adapter.rest.AdapterRestClient; import org.onap.so.BaseIntegrationTest; -public class VnfVolumeAdapterClientIT extends BaseIntegrationTest{ - - private static final String TESTING_ID = "___TESTING___"; - private static final String AAI_VOLUME_GROUP_ID = "test"; - private static final String CLOUD_SITE_ID = "test"; - private static final String TENANT_ID = "test"; - private static final String VOLUME_GROUP_STACK_ID = "test"; - private static final boolean SKIP_AAI = true; - private static final String REQUEST_ID = "test"; - private static final String SERVICE_INSTANCE_ID = "test"; - - @Test - public void createVolumeGroupTest() throws VnfAdapterClientException { - CreateVolumeGroupRequest request = new CreateVolumeGroupRequest(); - request.setCloudSiteId(TESTING_ID); - - CreateVolumeGroupResponse mockResponse = new CreateVolumeGroupResponse(); - mockResponse.setVolumeGroupCreated(true); - - VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); - AdapterRestClient mockClient = mock(AdapterRestClient.class); - - doReturn(mockClient).when(client).getAdapterRestClient(""); - when(mockClient.post(request, CreateVolumeGroupResponse.class)).thenReturn(mockResponse); - - CreateVolumeGroupResponse response = client.createVNFVolumes(request); - assertEquals("Testing CreateVolumeGroup response", mockResponse.getVolumeGroupCreated(), - response.getVolumeGroupCreated()); - } - - @Test(expected = VnfAdapterClientException.class) - public void createVolumeGroupTestThrowException() throws VnfAdapterClientException { - CreateVolumeGroupRequest request = new CreateVolumeGroupRequest(); - request.setCloudSiteId(TESTING_ID); - - CreateVolumeGroupResponse mockResponse = new CreateVolumeGroupResponse(); - mockResponse.setVolumeGroupCreated(true); - - VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); - AdapterRestClient mockClient = mock(AdapterRestClient.class); - - doReturn(mockClient).when(client).getAdapterRestClient(""); - when(mockClient.post(request, CreateVolumeGroupResponse.class)).thenThrow(new InternalServerErrorException("Error in create volume group")); - - client.createVNFVolumes(request); - } - - @Test - public void deleteVolumeGroupTest() throws VnfAdapterClientException { - DeleteVolumeGroupRequest request = new DeleteVolumeGroupRequest(); - request.setCloudSiteId(TESTING_ID); - - DeleteVolumeGroupResponse mockResponse = new DeleteVolumeGroupResponse(); - mockResponse.setVolumeGroupDeleted(true); - - VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); - AdapterRestClient mockClient = mock(AdapterRestClient.class); - doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID); - when(mockClient.delete(request, DeleteVolumeGroupResponse.class)).thenReturn(mockResponse); - MockitoAnnotations.initMocks(this); - - DeleteVolumeGroupResponse response = client.deleteVNFVolumes(AAI_VOLUME_GROUP_ID, request); - assertEquals("Testing DeleteVolumeGroup response", mockResponse.getVolumeGroupDeleted(), - response.getVolumeGroupDeleted()); - } - - @Test(expected = VnfAdapterClientException.class) - public void deleteVolumeGroupTestThrowException() throws VnfAdapterClientException { - DeleteVolumeGroupRequest request = new DeleteVolumeGroupRequest(); - request.setCloudSiteId(TESTING_ID); - - DeleteVolumeGroupResponse mockResponse = new DeleteVolumeGroupResponse(); - mockResponse.setVolumeGroupDeleted(true); - - VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); - AdapterRestClient mockClient = mock(AdapterRestClient.class); - doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID); - when(mockClient.delete(request, DeleteVolumeGroupResponse.class)) - .thenThrow(new InternalServerErrorException("Error in delete volume group")); - MockitoAnnotations.initMocks(this); - - client.deleteVNFVolumes(AAI_VOLUME_GROUP_ID, request); - } - - @Test - public void rollbackVolumeGroupTest() throws VnfAdapterClientException { - RollbackVolumeGroupRequest request = new RollbackVolumeGroupRequest(); - - RollbackVolumeGroupResponse mockResponse = new RollbackVolumeGroupResponse(); - mockResponse.setVolumeGroupRolledBack(true); - - VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); - AdapterRestClient mockClient = mock(AdapterRestClient.class); - doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID + "/rollback"); - when(mockClient.delete(request, RollbackVolumeGroupResponse.class)).thenReturn(mockResponse); - MockitoAnnotations.initMocks(this); - - RollbackVolumeGroupResponse response = client.rollbackVNFVolumes(AAI_VOLUME_GROUP_ID, request); - assertEquals("Testing RollbackVolumeGroup response", mockResponse.getVolumeGroupRolledBack(), - response.getVolumeGroupRolledBack()); - } - - @Test(expected = VnfAdapterClientException.class) - public void rollbackVolumeGroupTestThrowException() throws VnfAdapterClientException { - RollbackVolumeGroupRequest request = new RollbackVolumeGroupRequest(); - - RollbackVolumeGroupResponse mockResponse = new RollbackVolumeGroupResponse(); - mockResponse.setVolumeGroupRolledBack(true); - - VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); - AdapterRestClient mockClient = mock(AdapterRestClient.class); - doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID + "/rollback"); - when(mockClient.delete(request, RollbackVolumeGroupResponse.class)) - .thenThrow(new InternalServerErrorException("Error in rollback volume group")); - MockitoAnnotations.initMocks(this); - - client.rollbackVNFVolumes(AAI_VOLUME_GROUP_ID, request); - } - - @Test - public void updateVolumeGroupTest() throws VnfAdapterClientException { - UpdateVolumeGroupRequest request = new UpdateVolumeGroupRequest(); - - UpdateVolumeGroupResponse mockResponse = new UpdateVolumeGroupResponse(); - mockResponse.setVolumeGroupId(AAI_VOLUME_GROUP_ID); - - VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); - AdapterRestClient mockClient = mock(AdapterRestClient.class); - doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID); - when(mockClient.put(request, UpdateVolumeGroupResponse.class)).thenReturn(mockResponse); - MockitoAnnotations.initMocks(this); - - UpdateVolumeGroupResponse response = client.updateVNFVolumes(AAI_VOLUME_GROUP_ID, request); - assertEquals("Testing DeleteVfModule response", mockResponse.getVolumeGroupId(), response.getVolumeGroupId()); - } - - @Test(expected = VnfAdapterClientException.class) - public void updateVolumeGroupTestThrowException() throws VnfAdapterClientException { - UpdateVolumeGroupRequest request = new UpdateVolumeGroupRequest(); - - UpdateVolumeGroupResponse mockResponse = new UpdateVolumeGroupResponse(); - mockResponse.setVolumeGroupId(AAI_VOLUME_GROUP_ID); - - VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); - AdapterRestClient mockClient = mock(AdapterRestClient.class); - doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID); - when(mockClient.put(request, UpdateVolumeGroupResponse.class)) - .thenThrow(new InternalServerErrorException("Error in update volume group")); - MockitoAnnotations.initMocks(this); - - client.updateVNFVolumes(AAI_VOLUME_GROUP_ID, request); - } - - public void buildQueryPathTest() { - String expectedOutput = "/" + AAI_VOLUME_GROUP_ID + "?cloudSiteId=" + CLOUD_SITE_ID + "&tenantId=" + TENANT_ID - + "&volumeGroupStackId=" + VOLUME_GROUP_STACK_ID + "&skipAAI=" + SKIP_AAI + "&msoRequest.requestId=" - + REQUEST_ID + "&msoRequest.serviceInstanceId=" + SERVICE_INSTANCE_ID; - VnfVolumeAdapterClientImpl client = new VnfVolumeAdapterClientImpl(); - assertEquals("Test build query path", expectedOutput, client.buildQueryPath(AAI_VOLUME_GROUP_ID, CLOUD_SITE_ID, - TENANT_ID, VOLUME_GROUP_STACK_ID, SKIP_AAI, REQUEST_ID, SERVICE_INSTANCE_ID)); - } - - protected UriBuilder getUri(String path) { - return UriBuilder.fromPath(path); - } +public class VnfVolumeAdapterClientIT extends BaseIntegrationTest { + + private static final String TESTING_ID = "___TESTING___"; + private static final String AAI_VOLUME_GROUP_ID = "test"; + private static final String CLOUD_SITE_ID = "test"; + private static final String TENANT_ID = "test"; + private static final String VOLUME_GROUP_STACK_ID = "test"; + private static final boolean SKIP_AAI = true; + private static final String REQUEST_ID = "test"; + private static final String SERVICE_INSTANCE_ID = "test"; + + @Test + public void createVolumeGroupTest() throws VnfAdapterClientException { + CreateVolumeGroupRequest request = new CreateVolumeGroupRequest(); + request.setCloudSiteId(TESTING_ID); + + CreateVolumeGroupResponse mockResponse = new CreateVolumeGroupResponse(); + mockResponse.setVolumeGroupCreated(true); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + + doReturn(mockClient).when(client).getAdapterRestClient(""); + when(mockClient.post(request, CreateVolumeGroupResponse.class)).thenReturn(mockResponse); + + CreateVolumeGroupResponse response = client.createVNFVolumes(request); + assertEquals("Testing CreateVolumeGroup response", mockResponse.getVolumeGroupCreated(), + response.getVolumeGroupCreated()); + } + + @Test(expected = VnfAdapterClientException.class) + public void createVolumeGroupTestThrowException() throws VnfAdapterClientException { + CreateVolumeGroupRequest request = new CreateVolumeGroupRequest(); + request.setCloudSiteId(TESTING_ID); + + CreateVolumeGroupResponse mockResponse = new CreateVolumeGroupResponse(); + mockResponse.setVolumeGroupCreated(true); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + + doReturn(mockClient).when(client).getAdapterRestClient(""); + when(mockClient.post(request, CreateVolumeGroupResponse.class)) + .thenThrow(new InternalServerErrorException("Error in create volume group")); + + client.createVNFVolumes(request); + } + + @Test + public void deleteVolumeGroupTest() throws VnfAdapterClientException { + DeleteVolumeGroupRequest request = new DeleteVolumeGroupRequest(); + request.setCloudSiteId(TESTING_ID); + + DeleteVolumeGroupResponse mockResponse = new DeleteVolumeGroupResponse(); + mockResponse.setVolumeGroupDeleted(true); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID); + when(mockClient.delete(request, DeleteVolumeGroupResponse.class)).thenReturn(mockResponse); + MockitoAnnotations.initMocks(this); + + DeleteVolumeGroupResponse response = client.deleteVNFVolumes(AAI_VOLUME_GROUP_ID, request); + assertEquals("Testing DeleteVolumeGroup response", mockResponse.getVolumeGroupDeleted(), + response.getVolumeGroupDeleted()); + } + + @Test(expected = VnfAdapterClientException.class) + public void deleteVolumeGroupTestThrowException() throws VnfAdapterClientException { + DeleteVolumeGroupRequest request = new DeleteVolumeGroupRequest(); + request.setCloudSiteId(TESTING_ID); + + DeleteVolumeGroupResponse mockResponse = new DeleteVolumeGroupResponse(); + mockResponse.setVolumeGroupDeleted(true); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID); + when(mockClient.delete(request, DeleteVolumeGroupResponse.class)) + .thenThrow(new InternalServerErrorException("Error in delete volume group")); + MockitoAnnotations.initMocks(this); + + client.deleteVNFVolumes(AAI_VOLUME_GROUP_ID, request); + } + + @Test + public void rollbackVolumeGroupTest() throws VnfAdapterClientException { + RollbackVolumeGroupRequest request = new RollbackVolumeGroupRequest(); + + RollbackVolumeGroupResponse mockResponse = new RollbackVolumeGroupResponse(); + mockResponse.setVolumeGroupRolledBack(true); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID + "/rollback"); + when(mockClient.delete(request, RollbackVolumeGroupResponse.class)).thenReturn(mockResponse); + MockitoAnnotations.initMocks(this); + + RollbackVolumeGroupResponse response = client.rollbackVNFVolumes(AAI_VOLUME_GROUP_ID, request); + assertEquals("Testing RollbackVolumeGroup response", mockResponse.getVolumeGroupRolledBack(), + response.getVolumeGroupRolledBack()); + } + + @Test(expected = VnfAdapterClientException.class) + public void rollbackVolumeGroupTestThrowException() throws VnfAdapterClientException { + RollbackVolumeGroupRequest request = new RollbackVolumeGroupRequest(); + + RollbackVolumeGroupResponse mockResponse = new RollbackVolumeGroupResponse(); + mockResponse.setVolumeGroupRolledBack(true); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID + "/rollback"); + when(mockClient.delete(request, RollbackVolumeGroupResponse.class)) + .thenThrow(new InternalServerErrorException("Error in rollback volume group")); + MockitoAnnotations.initMocks(this); + + client.rollbackVNFVolumes(AAI_VOLUME_GROUP_ID, request); + } + + @Test + public void updateVolumeGroupTest() throws VnfAdapterClientException { + UpdateVolumeGroupRequest request = new UpdateVolumeGroupRequest(); + + UpdateVolumeGroupResponse mockResponse = new UpdateVolumeGroupResponse(); + mockResponse.setVolumeGroupId(AAI_VOLUME_GROUP_ID); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID); + when(mockClient.put(request, UpdateVolumeGroupResponse.class)).thenReturn(mockResponse); + MockitoAnnotations.initMocks(this); + + UpdateVolumeGroupResponse response = client.updateVNFVolumes(AAI_VOLUME_GROUP_ID, request); + assertEquals("Testing DeleteVfModule response", mockResponse.getVolumeGroupId(), response.getVolumeGroupId()); + } + + @Test(expected = VnfAdapterClientException.class) + public void updateVolumeGroupTestThrowException() throws VnfAdapterClientException { + UpdateVolumeGroupRequest request = new UpdateVolumeGroupRequest(); + + UpdateVolumeGroupResponse mockResponse = new UpdateVolumeGroupResponse(); + mockResponse.setVolumeGroupId(AAI_VOLUME_GROUP_ID); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID); + when(mockClient.put(request, UpdateVolumeGroupResponse.class)) + .thenThrow(new InternalServerErrorException("Error in update volume group")); + MockitoAnnotations.initMocks(this); + + client.updateVNFVolumes(AAI_VOLUME_GROUP_ID, request); + } + + public void buildQueryPathTest() { + String expectedOutput = "/" + AAI_VOLUME_GROUP_ID + "?cloudSiteId=" + CLOUD_SITE_ID + "&tenantId=" + TENANT_ID + + "&volumeGroupStackId=" + VOLUME_GROUP_STACK_ID + "&skipAAI=" + SKIP_AAI + "&msoRequest.requestId=" + + REQUEST_ID + "&msoRequest.serviceInstanceId=" + SERVICE_INSTANCE_ID; + VnfVolumeAdapterClientImpl client = new VnfVolumeAdapterClientImpl(); + assertEquals("Test build query path", expectedOutput, client.buildQueryPath(AAI_VOLUME_GROUP_ID, CLOUD_SITE_ID, + TENANT_ID, VOLUME_GROUP_STACK_ID, SKIP_AAI, REQUEST_ID, SERVICE_INSTANCE_ID)); + } + + protected UriBuilder getUri(String path) { + return UriBuilder.fromPath(path); + } } |