diff options
Diffstat (limited to 'dcaedt_be/src/test/java/org/onap/sdc/dcae/composition')
2 files changed, 433 insertions, 0 deletions
diff --git a/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/ReferenceBusinessLogicTest.java b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/ReferenceBusinessLogicTest.java new file mode 100644 index 0000000..c353701 --- /dev/null +++ b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/ReferenceBusinessLogicTest.java @@ -0,0 +1,123 @@ +package org.onap.sdc.dcae.composition.impl; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.sdc.dcae.client.ISdcClient; +import org.onap.sdc.dcae.composition.restmodels.MonitoringComponent; +import org.onap.sdc.dcae.composition.restmodels.sdc.*; +import org.onap.sdc.dcae.errormng.ErrorConfigurationLoader; +import org.onap.sdc.dcae.errormng.ResponseFormat; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.HttpClientErrorException; + +import java.util.*; + +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.*; + +@RunWith(MockitoJUnitRunner.class) +public class ReferenceBusinessLogicTest { + private String userId = "me"; + private String requestId = "1"; + private String monitoringComponentName = "monitoringComponentName"; + private String serviceUuid = "serviceUuid"; + private String vfiName = "vfiName"; + + @Mock + private ISdcClient sdcClientMock; + @Mock + private ResourceDetailed templateMC; + + @InjectMocks + ReferenceBusinessLogic classUnderTest; + + @Before + public void setup(){ + classUnderTest.setSdcRestClient(sdcClientMock); + new ErrorConfigurationLoader(System.getProperty("user.dir")+"/src/main/webapp/WEB-INF"); + } + + @Test + public void successfulFetchMonitoringComponents() throws Exception { + when(sdcClientMock.getResource(anyString(),anyString())).thenReturn(templateMC); + ExternalReferencesMap refs = new ExternalReferencesMap(); + refs.put("vfi1", Arrays.asList("a","b","c","d")); + refs.put("vfi2", Arrays.asList("u","v","w","x","y","z")); + Map<String, List<MonitoringComponent>> result = classUnderTest.fetchMonitoringComponents(refs, requestId); + verify(sdcClientMock,times(10)).getResource(anyString(),anyString()); + Assert.assertEquals(1, result.size()); + Assert.assertEquals(10, result.get("monitoringComponents").size()); + } + + @Test + public void partialSuccessfulFetchMonitoringComponents() throws Exception { + when(sdcClientMock.getResource(anyString(),anyString())).thenReturn(templateMC); + when(sdcClientMock.getResource(eq("no_such_uuid"),anyString())).thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND)); + ExternalReferencesMap refs = new ExternalReferencesMap(); + refs.put("vfi1", Collections.singletonList("abc")); + refs.put("vfi2", Collections.singletonList("xyz")); + refs.put("vfi3", Collections.singletonList("no_such_uuid")); + Map<String, List<MonitoringComponent>> result = classUnderTest.fetchMonitoringComponents(refs, requestId); + verify(sdcClientMock,times(3)).getResource(anyString(),anyString()); + Assert.assertEquals(2, result.size()); + Assert.assertEquals(2, result.get("monitoringComponents").size()); + Assert.assertEquals(1, result.get("unavailable").size()); + } + + @Test(expected=RuntimeException.class) + public void deleteVfcmtReference_deleteFailed() { + doThrow(RuntimeException.class).when(sdcClientMock).deleteExternalMonitoringReference(anyString(), anyString(), anyString(), anyString(), anyString(), anyString()); + classUnderTest.deleteVfcmtReference(userId, "", "", "", "", requestId); + } + @Test + public void deleteVfcmtReference_deleteSuccess() { + classUnderTest.deleteVfcmtReference(userId, "", "", "", "", requestId); + verify(sdcClientMock).deleteExternalMonitoringReference(anyString(), anyString(), anyString(), anyString(), anyString(), anyString()); + } + + private void mockGetService() throws Exception { + ServiceDetailed serviceDetailed = new ServiceDetailed(); + ResourceInstance resourceInstance = new ResourceInstance(); + Artifact artifact = new Artifact(); + artifact.setArtifactName(monitoringComponentName); + resourceInstance.setArtifacts(Collections.singletonList(artifact)); + resourceInstance.setResourceInstanceName(vfiName); + serviceDetailed.setResources(Collections.singletonList(resourceInstance)); + when(sdcClientMock.getService(serviceUuid, requestId)).thenReturn(serviceDetailed); + } + + @Test + public void deleteVfcmtReferenceBlueprint_deleteSuccess() throws Exception { + mockGetService(); + ResponseEntity responseEntity = classUnderTest.deleteVfcmtReferenceBlueprint(userId, "", monitoringComponentName, serviceUuid, vfiName, "", requestId); + verify(sdcClientMock).getService(serviceUuid, requestId); + verify(sdcClientMock).deleteInstanceResourceArtifact(anyString(), anyString(), anyString(), anyString(), anyString(), anyString()); + Assert.assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + } + + @Test + public void deleteVfcmtReferenceBlueprint_exceptionSdcGetService() throws Exception { + when(sdcClientMock.getService(serviceUuid, requestId)).thenThrow(new RuntimeException("")); + + ResponseEntity<ResponseFormat> responseEntity = classUnderTest.deleteVfcmtReferenceBlueprint(userId, "", monitoringComponentName, serviceUuid, vfiName, "", requestId); + + Assert.assertEquals("The request was partially successful. Removing the attached Blueprint from the service has failed. You must manually delete the artifact.", responseEntity.getBody().getRequestError().getServiceException().getFormattedErrorMessage()); + } + + @Test + public void deleteVfcmtReferenceBlueprint_exceptionSdcdeleteInstanceResourceArtifact() throws Exception { + mockGetService(); + doThrow(new RuntimeException("")).when(sdcClientMock).deleteInstanceResourceArtifact(anyString(), anyString(), anyString(), anyString(), anyString(), anyString()); + + ResponseEntity<ResponseFormat> responseEntity = classUnderTest.deleteVfcmtReferenceBlueprint(userId, "", monitoringComponentName, serviceUuid, vfiName, "", requestId); + + Assert.assertEquals("The request was partially successful. Removing the attached Blueprint from the service has failed. You must manually delete the artifact.", responseEntity.getBody().getRequestError().getServiceException().getFormattedErrorMessage()); + } +} diff --git a/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/VfcmtBusinessLogicTest.java b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/VfcmtBusinessLogicTest.java new file mode 100644 index 0000000..12ed040 --- /dev/null +++ b/dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/VfcmtBusinessLogicTest.java @@ -0,0 +1,310 @@ +package org.onap.sdc.dcae.composition.impl; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.sdc.dcae.catalog.asdc.ASDCException; +import org.onap.sdc.dcae.client.ISdcClient; +import org.onap.sdc.dcae.client.SdcRestClient; +import org.onap.sdc.dcae.composition.restmodels.CreateVFCMTRequest; +import org.onap.sdc.dcae.composition.restmodels.ImportVFCMTRequest; +import org.onap.sdc.dcae.composition.restmodels.MonitoringComponent; +import org.onap.sdc.dcae.composition.restmodels.VfcmtData; +import org.onap.sdc.dcae.composition.restmodels.sdc.Artifact; +import org.onap.sdc.dcae.composition.restmodels.sdc.ExternalReferencesMap; +import org.onap.sdc.dcae.composition.restmodels.sdc.Resource; +import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed; +import org.onap.sdc.dcae.composition.util.DcaeBeConstants; +import org.onap.sdc.dcae.errormng.ErrorConfigurationLoader; +import org.onap.sdc.dcae.errormng.PolicyException; +import org.onap.sdc.dcae.errormng.RequestError; +import org.onap.sdc.dcae.errormng.ResponseFormat; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.HttpClientErrorException; + +import java.util.*; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.*; +import static org.onap.sdc.dcae.composition.util.DcaeBeConstants.LifecycleStateEnum.CERTIFIED; +import static org.onap.sdc.dcae.composition.util.DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT; + +public class VfcmtBusinessLogicTest { + + private ISdcClient sdcClientMock = Mockito.mock(SdcRestClient.class); + private ResourceDetailed templateMC = Mockito.mock(ResourceDetailed.class); + + private VfcmtBusinessLogic vfcmtBusinessLogic = new VfcmtBusinessLogic(); + private ImportVFCMTRequest request = new ImportVFCMTRequest(); + + private String userId = "me"; + private String requestId = "1"; + + @Before + public void setup(){ + MockitoAnnotations.initMocks(this); + new ErrorConfigurationLoader(System.getProperty("user.dir")+"/src/main/webapp/WEB-INF"); + vfcmtBusinessLogic.setSdcRestClient(sdcClientMock); + request.setTemplateUuid("577"); + request.setVfiName("vfi_XX"); + request.setDescription("description"); + request.setFlowType("SNMP"); + request.setName("newVfcmt"); + request.setServiceUuid("service99999"); + request.setContextType("services"); + } + + @Test + public void sdcIsDown_creatingVfcmt_gotResponseWithError500() throws Exception{ + RequestError requestError = new RequestError(); + requestError.setPolicyException(new PolicyException("POL5000", "Error: Internal Server Error. Please try again later.", null)); + when(sdcClientMock.createResource(userId,request,requestId)).thenThrow(new ASDCException(HttpStatus.INTERNAL_SERVER_ERROR, requestError)); + + ResponseEntity res = vfcmtBusinessLogic.createMcFromTemplate(userId,request,requestId); + verify(sdcClientMock).getResource("577",requestId); + verify(sdcClientMock,times(0)).getResourceArtifact(anyString(),anyString(),anyString()); + Assert.assertEquals(500, res.getStatusCodeValue()); + } + + @Test + public void uploadCloneCdumpFailed_creatingVfcmt_createVfcmtRolledBack() throws Exception { + RequestError requestError = new RequestError(); + requestError.setPolicyException(new PolicyException("POL5000", "Error: Internal Server Error. Please try again later.", null)); + when(sdcClientMock.createResourceArtifact(anyString(),anyString(),any(),anyString())).thenThrow(new ASDCException(HttpStatus.INTERNAL_SERVER_ERROR, requestError)); + when(sdcClientMock.createResource(userId,request,requestId)).thenReturn(templateMC); + when(sdcClientMock.getResourceArtifact(anyString(), anyString(), anyString())).thenReturn("{\"flowType\":\"don't override\""); + when(templateMC.getUuid()).thenReturn("3"); + when(sdcClientMock.getResource(anyString(),anyString())).thenReturn(templateMC); + emulateListOfArtifactsWithCompositionYml(); + + vfcmtBusinessLogic.createMcFromTemplate(userId, request, requestId); + + // making sure rollback is performed if exception is thrown + verify(sdcClientMock).changeResourceLifecycleState(anyString(),anyString(),anyString(),anyString(),anyString()); + } + + // happy happy joy joy + @Test + public void successfulCreationAndAttachmentOfVfcmt() throws Exception { + when(templateMC.getUuid()).thenReturn("3"); + when(sdcClientMock.getResource(anyString(),anyString())).thenReturn(templateMC); + ResourceDetailed mockedVfcmt = Mockito.mock(ResourceDetailed.class); + when(mockedVfcmt.getUuid()).thenReturn("5"); + when(sdcClientMock.createResource(anyString(),any(),anyString())).thenReturn(mockedVfcmt); + when(sdcClientMock.getResourceArtifact(anyString(),anyString(),anyString())).thenReturn("3243324"); + + emulateListOfArtifactsWithCompositionYml(); + + vfcmtBusinessLogic.createMcFromTemplate(userId, request,requestId); + + verify(sdcClientMock).createResource(userId, request,requestId); + verify(sdcClientMock).getResource(anyString(),anyString()); + verify(sdcClientMock).getResourceArtifact(anyString(),anyString(),anyString()); + verify(sdcClientMock, times(2)).createResourceArtifact(anyString(),anyString(),any(),anyString()); + verify(sdcClientMock).addExternalMonitoringReference(anyString(),any(),any(),anyString()); + verify(sdcClientMock).changeResourceLifecycleState(anyString(),anyString(),anyString(),anyString(),anyString()); + } + + @Test + public void successfulImportAndAttachmentOfVfcmtAlreadyConnectedWithoutEditDoCheckin() throws Exception { + when(sdcClientMock.getResource(anyString(),anyString())).thenReturn(templateMC); + when(sdcClientMock.getResourceArtifact(anyString(),anyString(),anyString())).thenReturn("{\"flowType\":\"don't override\"}"); + when(templateMC.getLifecycleState()).thenReturn("NOT_CERTIFIED_CHECKOUT"); + emulateListOfArtifactsWithCompositionYmlAndSvcRef(); + request.setCloneVFCMT(false); + request.setUpdateFlowType(false); + vfcmtBusinessLogic.importMC(userId, request, requestId); + + verify(sdcClientMock, times(0)).createResource(userId, request, requestId); + verify(sdcClientMock).getResource(anyString(),anyString()); + verify(sdcClientMock).getResourceArtifact(anyString(),anyString(),anyString()); + verify(sdcClientMock, times(0)).createResourceArtifact(anyString(),anyString(),any(),anyString()); + verify(sdcClientMock, times(0)).updateResourceArtifact(anyString(), anyString(), any(), anyString()); + verify(sdcClientMock).addExternalMonitoringReference(anyString(),any(),any(),anyString()); + verify(sdcClientMock).changeResourceLifecycleState(anyString(),anyString(),anyString(),anyString(),anyString()); + } + + + @Test + public void successfulImportAndAttachmentOfVfcmtAlreadyConnectedUpdateFlowTypeCheckoutCheckin() throws Exception { + when(sdcClientMock.getResource(anyString(),anyString())).thenReturn(templateMC); + when(templateMC.getUuid()).thenReturn("3"); + when(sdcClientMock.changeResourceLifecycleState(anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(templateMC); + when(sdcClientMock.updateResourceArtifact(anyString(), anyString(), any(), anyString())).thenReturn(new Artifact()); + when(sdcClientMock.getResourceArtifact(anyString(),anyString(),anyString())).thenReturn("{\"cid\":\"xsssdaerrwr\"}"); + when(templateMC.getLifecycleState()).thenReturn("NOT_CERTIFIED_CHECKIN").thenReturn("NOT_CERTIFIED_CHECKOUT"); + emulateListOfArtifactsWithCompositionYmlAndSvcRef(); + request.setCloneVFCMT(false); + request.setUpdateFlowType(true); + vfcmtBusinessLogic.importMC(userId, request, requestId); + + verify(sdcClientMock, times(0)).createResource(userId, request, requestId); + verify(sdcClientMock).getResource(anyString(),anyString()); + verify(sdcClientMock).getResourceArtifact(anyString(),anyString(),anyString()); + verify(sdcClientMock, times(0)).createResourceArtifact(anyString(),anyString(),any(),anyString()); + verify(sdcClientMock, times(1)).updateResourceArtifact(anyString(), anyString(), any(), anyString()); + verify(sdcClientMock).addExternalMonitoringReference(anyString(),any(),any(),anyString()); + verify(sdcClientMock, times(2)).changeResourceLifecycleState(anyString(),anyString(),anyString(),anyString(),anyString()); + } + + + @Test + public void successfulFetchVfcmtDataFull() throws Exception { + String templateUuid = "3"; + when(templateMC.getUuid()).thenReturn(templateUuid); + when(sdcClientMock.getResource(anyString(),anyString())).thenReturn(templateMC); + emulateListOfArtifactsWithCompositionYmlAndSvcRef(); + when(sdcClientMock.getResourceArtifact(templateUuid, "svcRefArtifactUuid", requestId)).thenReturn("thisIsTheServiceId/resources/thisIsTheVfiName"); + when(sdcClientMock.getResourceArtifact(templateUuid, "compositionArtifactUuid", requestId)).thenReturn("\"flowType\":\"Syslog\""); + ResponseEntity<VfcmtData> result = vfcmtBusinessLogic.getVfcmtReferenceData(templateUuid, requestId); + verify(sdcClientMock).getResource(anyString(),anyString()); + verify(sdcClientMock,times(2)).getResourceArtifact(anyString(),anyString(),anyString()); + Assert.assertEquals(200, result.getStatusCodeValue()); + Assert.assertEquals("Syslog", result.getBody().getFlowType()); + Assert.assertEquals("thisIsTheServiceId", result.getBody().getServiceUuid()); + Assert.assertEquals("thisIsTheVfiName", result.getBody().getVfiName()); + } + + @Test + public void successfulFetchVfcmtDataPartial() throws Exception { + String templateUuid = "3"; + when(templateMC.getUuid()).thenReturn(templateUuid); + when(sdcClientMock.getResource(anyString(),anyString())).thenReturn(templateMC); + emulateListOfArtifactsWithCompositionYml(); + when(sdcClientMock.getResourceArtifact(templateUuid, "compositionArtifactUuid", requestId)).thenReturn("\"flowType\":\"Syslog\""); + ResponseEntity<VfcmtData> result = vfcmtBusinessLogic.getVfcmtReferenceData(templateUuid, requestId); + verify(sdcClientMock).getResource(anyString(),anyString()); + verify(sdcClientMock,times(1)).getResourceArtifact(anyString(),anyString(),anyString()); + Assert.assertEquals(200, result.getStatusCodeValue()); + Assert.assertEquals("Syslog", result.getBody().getFlowType()); + Assert.assertEquals(null, result.getBody().getServiceUuid()); + Assert.assertEquals(null, result.getBody().getVfiName()); + } + + @Test + public void successfulFetchVfcmtDataEmpty() throws Exception { + + String templateUuid = "3"; + when(templateMC.getUuid()).thenReturn(templateUuid); + when(sdcClientMock.getResource(anyString(),anyString())).thenReturn(templateMC); + emulateListOfArtifactsWithCompositionYml(); + when(sdcClientMock.getResourceArtifact(templateUuid, "compositionArtifactUuid", requestId)).thenReturn(""); + ResponseEntity<VfcmtData> result = vfcmtBusinessLogic.getVfcmtReferenceData(templateUuid, requestId); + verify(sdcClientMock).getResource(anyString(),anyString()); + verify(sdcClientMock,times(1)).getResourceArtifact(anyString(),anyString(),anyString()); + Assert.assertEquals(200, result.getStatusCodeValue()); + Assert.assertEquals(null, result.getBody().getFlowType()); + Assert.assertEquals(null, result.getBody().getServiceUuid()); + Assert.assertEquals(null, result.getBody().getVfiName()); + } + + @Test + public void fetchVfcmtDataNoCompositionFound() throws Exception { + + String templateUuid = "3"; + when(templateMC.getUuid()).thenReturn(templateUuid); + when(templateMC.getName()).thenReturn(templateUuid); + when(sdcClientMock.getResource(anyString(),anyString())).thenReturn(templateMC); + ResponseEntity<ResponseFormat> result = vfcmtBusinessLogic.getVfcmtReferenceData(templateUuid, requestId); + verify(sdcClientMock).getResource(anyString(),anyString()); + verify(sdcClientMock,times(0)).getResourceArtifact(anyString(),anyString(),anyString()); + Assert.assertEquals(404, result.getStatusCodeValue()); + Assert.assertEquals("Error – Could not read component 3 details.", result.getBody().getRequestError().getServiceException().getFormattedErrorMessage()); + + } + + @Test + public void getVfcmtsForMigration() throws Exception { + ExternalReferencesMap connectedVfcmts = new ExternalReferencesMap(); + connectedVfcmts.put("11",Arrays.asList("Red", "Blue", "Yellow")); + connectedVfcmts.put("22",Arrays.asList("Ibiza", "Bora Bora", "Mykonos")); + connectedVfcmts.put("33",Arrays.asList("Large", "Medium", "Small")); + connectedVfcmts.put("44",Arrays.asList("Basket", "Foot", "Volley")); + + when(sdcClientMock.getMonitoringReferences(anyString(),anyString(),anyString(),anyString())).thenReturn(connectedVfcmts); + + Resource myRedResource = new Resource(); + myRedResource.setUuid("Red"); + myRedResource.setLastUpdaterUserId("me"); + myRedResource.setLifecycleState(NOT_CERTIFIED_CHECKOUT.name()); + + Resource herRaphaelResource = new Resource(); + herRaphaelResource.setUuid("Raphael"); + herRaphaelResource.setLastUpdaterUserId("her"); + herRaphaelResource.setLifecycleState(NOT_CERTIFIED_CHECKOUT.name()); + + Resource myMediumResource = new Resource(); + myMediumResource.setUuid("Medium"); + myMediumResource.setLastUpdaterUserId("me"); + + Resource herDonateloResource = new Resource(); + herDonateloResource.setUuid("Donatelo"); + herDonateloResource.setLastUpdaterUserId("her"); + herDonateloResource.setVersion("1.0"); + + Resource hisMykonosResource = new Resource(); + hisMykonosResource.setUuid("Mykonos"); + hisMykonosResource.setLastUpdaterUserId("his"); + hisMykonosResource.setLifecycleState(NOT_CERTIFIED_CHECKOUT.name()); + + Resource hisMichaelangeloResource = new Resource(); + hisMichaelangeloResource.setUuid("Michaelangelo"); + hisMichaelangeloResource.setLastUpdaterUserId("his"); + hisMykonosResource.setLifecycleState(CERTIFIED.name()); + hisMykonosResource.setVersion("1.1"); + + // Versions and connectivity to service shouldn't be part of this test as these are passed to SDC to be + // filtered by SDC requests (getMonitoringReference and getResource) + + List<Resource> theVfcmts = Arrays.asList(myRedResource,herRaphaelResource,myMediumResource,herDonateloResource,hisMykonosResource,hisMichaelangeloResource); + + when(sdcClientMock.getResources(anyString(),anyString(),anyString(),anyString())).thenReturn(theVfcmts); + + ResponseEntity<List<Resource>> response = vfcmtBusinessLogic.getVfcmtsForMigration(userId,"service","5544","1.0",requestId); + + Assert.assertEquals(2, response.getBody().size()); + Assert.assertEquals(200, response.getStatusCodeValue()); + } + + private void emulateListOfArtifactsWithCompositionYml() { + List<Artifact> listOfArtifactCompositionYml = new ArrayList<>(); + Artifact compositionArtifact = Mockito.mock(Artifact.class); + when(compositionArtifact.getArtifactName()).thenReturn(DcaeBeConstants.Composition.fileNames.COMPOSITION_YML); + when(compositionArtifact.getArtifactUUID()).thenReturn("compositionArtifactUuid"); + when(compositionArtifact.getPayloadData()).thenReturn("{\"flowType\":\"don't override\"}"); + listOfArtifactCompositionYml.add(compositionArtifact); + when(templateMC.getArtifacts()).thenReturn(listOfArtifactCompositionYml); + } + + private void emulateListOfArtifactsWithCompositionYmlAndSvcRef() { + List<Artifact> listOfArtifactCompositionYml = new ArrayList<>(); + Artifact compositionArtifact = Mockito.mock(Artifact.class); + Artifact svcRefArtifact = Mockito.mock(Artifact.class); + when(compositionArtifact.getArtifactName()).thenReturn(DcaeBeConstants.Composition.fileNames.COMPOSITION_YML); + when(compositionArtifact.getArtifactUUID()).thenReturn("compositionArtifactUuid"); + when(compositionArtifact.getPayloadData()).thenReturn("{\"flowType\":\"don't override\"}"); + when(svcRefArtifact.getArtifactName()).thenReturn(DcaeBeConstants.Composition.fileNames.SVC_REF); + when(svcRefArtifact.getArtifactUUID()).thenReturn("svcRefArtifactUuid"); + listOfArtifactCompositionYml.add(compositionArtifact); + listOfArtifactCompositionYml.add(svcRefArtifact); + when(templateMC.getArtifacts()).thenReturn(listOfArtifactCompositionYml); + } + + @Test + public void uiHasABug_creatingVfcmtWithBadRequestNoServiceUuid_gotResponseWithError400() throws Exception{ + RequestError requestError = new RequestError(); + requestError.setPolicyException(new PolicyException("POL5000", "Error: Internal Server Error. Please try again later.", null)); + when(sdcClientMock.createResource(userId,request,requestId)).thenThrow(new ASDCException(HttpStatus.INTERNAL_SERVER_ERROR, requestError)); + CreateVFCMTRequest req = new CreateVFCMTRequest(); + req.setServiceUuid(null); + ResponseEntity res = vfcmtBusinessLogic.createMcFromTemplate(userId,req,requestId); + verify(sdcClientMock,times(0)).getResource(anyString(),anyString()); + verify(sdcClientMock,times(0)).getResourceArtifact(anyString(),anyString(),anyString()); + Assert.assertEquals(400, res.getStatusCodeValue()); + } +}
\ No newline at end of file |