diff options
author | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2018-03-23 14:46:56 +0100 |
---|---|---|
committer | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2018-03-23 14:46:56 +0100 |
commit | 378d05bded462b721cd04e7eb5ab06a944da452e (patch) | |
tree | 1469e4d7645cb33c5c86a8c4ecccb63593e50626 /src/test/java/org | |
parent | dc90370d229c69ed6c7ce39993f72a0ea3a314e9 (diff) |
Rework the SDC test
Rework the uni tests so that SDC controller is more tested, also dcae
code has been reworked for improving sonar report
Issue-ID: CLAMP-81
Change-Id: Ia6ec272e1bf86e72d9d7294aeec0695b861f78af
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
Diffstat (limited to 'src/test/java/org')
-rw-r--r-- | src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java | 44 | ||||
-rw-r--r-- | src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java | 61 |
2 files changed, 75 insertions, 30 deletions
diff --git a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java index b64e6a0d0..40dffcd6b 100644 --- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java @@ -25,6 +25,7 @@ package org.onap.clamp.clds.it.sdc.controller.installer; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.att.aft.dme2.internal.apache.commons.io.IOUtils; @@ -47,28 +48,22 @@ import org.onap.clamp.clds.util.ResourceFileUtil; import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.openecomp.sdc.toscaparser.api.elements.Metadata; -import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.util.ReflectionTestUtils; @RunWith(SpringRunner.class) @SpringBootTest public class CsarInstallerItCase { - private static final String sdcFolder = "/tmp/csar-handler-tests"; - private static final String csarArtifactName = "testArtifact.csar"; + private static final String CSAR_ARTIFACT_NAME = "testArtifact.csar"; + private static final String SERVICE_UUID = "serviceUUID"; + private static final String RESOURCE1_UUID = "resource1UUID"; @Autowired private CsarInstaller csarInstaller; @Autowired private CldsDao cldsDao; - private void loadFile(String fileName) throws IOException { - ReflectionTestUtils.setField(csarInstaller, "blueprintMappingFile", fileName); - ((CsarInstallerImpl) csarInstaller).loadConfiguration(); - } - @Test(expected = SdcArtifactInstallerException.class) public void testInstallTheCsarFail() throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { @@ -79,10 +74,7 @@ public class CsarInstallerItCase { fail("Should have raised an SdcArtifactInstallerException"); } - @Test(expected = SdcArtifactInstallerException.class) - public void testInstallTheCsarTca() - throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { - String generatedName = RandomStringUtils.randomAlphanumeric(5); + private CsarHandler buildFakeCsarHandler(String generatedName) throws IOException { CsarHandler csarHandler = Mockito.mock(CsarHandler.class); Mockito.when(csarHandler.getDcaeBlueprint()) .thenReturn(ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca.yaml")); @@ -91,7 +83,26 @@ public class CsarInstallerItCase { Mockito.when(data.getValue("name")).thenReturn(generatedName); Mockito.when(csarHelper.getServiceMetadata()).thenReturn(data); Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(csarHelper); + Mockito.when(csarHandler.getBlueprintArtifactName()).thenReturn(CSAR_ARTIFACT_NAME); + Mockito.when(csarHandler.getBlueprintInvariantServiceUuid()).thenReturn(SERVICE_UUID); + Mockito.when(csarHandler.getBlueprintInvariantResourceUuid()).thenReturn(RESOURCE1_UUID); + return csarHandler; + } + + @Test + public void testIsCsarAlreadyDeployedTca() + throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { + String generatedName = RandomStringUtils.randomAlphanumeric(5); + CsarHandler csarHandler = buildFakeCsarHandler(generatedName); csarInstaller.installTheCsar(csarHandler); + assertTrue(csarInstaller.isCsarAlreadyDeployed(csarHandler)); + } + + @Test + public void testInstallTheCsarTca() + throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { + String generatedName = RandomStringUtils.randomAlphanumeric(5); + csarInstaller.installTheCsar(buildFakeCsarHandler(generatedName)); // Get the template back from DB CldsTemplate templateFromDB = CldsTemplate.retrieve(cldsDao, CsarInstallerImpl.TEMPLATE_NAME_PREFIX + generatedName, false); @@ -99,15 +110,16 @@ public class CsarInstallerItCase { assertNotNull(templateFromDB.getBpmnText()); assertNotNull(templateFromDB.getImageText()); assertNotNull(templateFromDB.getPropText()); + assertTrue(templateFromDB.getPropText().contains("global") + && templateFromDB.getPropText().contains("node_templates:")); assertEquals(templateFromDB.getName(), CsarInstallerImpl.TEMPLATE_NAME_PREFIX + generatedName); - JSONAssert.assertEquals(templateFromDB.getPropText(), - ResourceFileUtil.getResourceAsString("example/dao/template-doc-content.json"), true); // Get the Model back from DB - CldsModel modelFromDB = CldsModel.retrieve(cldsDao, generatedName, false); + CldsModel modelFromDB = CldsModel.retrieve(cldsDao, generatedName, true); assertNotNull(modelFromDB); assertNotNull(modelFromDB.getBpmnText()); assertNotNull(modelFromDB.getImageText()); assertNotNull(modelFromDB.getPropText()); assertEquals(modelFromDB.getName(), generatedName); + assertEquals(CsarInstallerImpl.MODEL_NAME_PREFIX, modelFromDB.getControlNamePrefix()); } } diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java index 34805d87a..c842068d9 100644 --- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java +++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java @@ -45,25 +45,29 @@ import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerExceptio import org.onap.clamp.clds.util.ResourceFileUtil; import org.openecomp.sdc.api.notification.IArtifactInfo; import org.openecomp.sdc.api.notification.INotificationData; +import org.openecomp.sdc.api.notification.IResourceInstance; import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; public class CsarHandlerTest { - private static final String sdcFolder = "/tmp/csar-handler-tests"; - private static final String csarArtifactName = "testArtifact.csar"; + private static final String SDC_FOLDER = "/tmp/csar-handler-tests"; + private static final String CSAR_ARTIFACT_NAME = "testArtifact.csar"; + private static final String SERVICE_UUID = "serviceUUID"; + private static final String RESOURCE1_UUID = "resource1UUID"; + private static final String BLUEPRINT1_NAME = "blueprint1-name"; @Test public void testConstructor() throws CsarHandlerException { IArtifactInfo serviceArtifact = Mockito.mock(IArtifactInfo.class); Mockito.when(serviceArtifact.getArtifactType()).thenReturn(CsarHandler.CSAR_TYPE); - Mockito.when(serviceArtifact.getArtifactName()).thenReturn(csarArtifactName); + Mockito.when(serviceArtifact.getArtifactName()).thenReturn(CSAR_ARTIFACT_NAME); List<IArtifactInfo> servicesList = new ArrayList<>(); servicesList.add(serviceArtifact); INotificationData notifData = Mockito.mock(INotificationData.class); Mockito.when(notifData.getServiceArtifacts()).thenReturn(servicesList); - CsarHandler csar = new CsarHandler(notifData, "test-controller", sdcFolder); - assertEquals(sdcFolder + "/test-controller" + "/" + csarArtifactName, csar.getFilePath()); + CsarHandler csar = new CsarHandler(notifData, "test-controller", SDC_FOLDER); + assertEquals(SDC_FOLDER + "/test-controller" + "/" + CSAR_ARTIFACT_NAME, csar.getFilePath()); } @Test(expected = CsarHandlerException.class) @@ -74,32 +78,61 @@ public class CsarHandlerTest { fail("Exception should have been raised"); } - @Test - public void testSave() - throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { + private INotificationData buildFakeSdcNotification() { + // BUild what is needed for CSAR IArtifactInfo serviceArtifact = Mockito.mock(IArtifactInfo.class); Mockito.when(serviceArtifact.getArtifactType()).thenReturn(CsarHandler.CSAR_TYPE); - Mockito.when(serviceArtifact.getArtifactName()).thenReturn(csarArtifactName); + Mockito.when(serviceArtifact.getArtifactName()).thenReturn(CSAR_ARTIFACT_NAME); List<IArtifactInfo> servicesList = new ArrayList<>(); servicesList.add(serviceArtifact); INotificationData notifData = Mockito.mock(INotificationData.class); Mockito.when(notifData.getServiceArtifacts()).thenReturn(servicesList); - CsarHandler csar = new CsarHandler(notifData, "test-controller", "/tmp/csar-handler-tests"); + // Build what is needed for UUID + Mockito.when(notifData.getServiceInvariantUUID()).thenReturn(SERVICE_UUID); + // Build fake resource with one artifact BLUEPRINT + List<IResourceInstance> resourcesList = new ArrayList<>(); + List<IArtifactInfo> artifactsListForResource = new ArrayList<>(); + IResourceInstance resource1 = Mockito.mock(IResourceInstance.class); + Mockito.when(resource1.getResourceType()).thenReturn("VF"); + Mockito.when(resource1.getResourceInvariantUUID()).thenReturn(RESOURCE1_UUID); + // Create a fake artifact for resource + IArtifactInfo blueprintArtifact = Mockito.mock(IArtifactInfo.class); + Mockito.when(blueprintArtifact.getArtifactType()).thenReturn(CsarHandler.BLUEPRINT_TYPE); + Mockito.when(blueprintArtifact.getArtifactName()).thenReturn(BLUEPRINT1_NAME); + artifactsListForResource.add(blueprintArtifact); + Mockito.when(resource1.getArtifacts()).thenReturn(artifactsListForResource); + resourcesList.add(resource1); + Mockito.when(notifData.getResources()).thenReturn(resourcesList); + return notifData; + } + + private IDistributionClientDownloadResult buildFakeSdcResut() throws IOException { IDistributionClientDownloadResult resultArtifact = Mockito.mock(IDistributionClientDownloadResult.class); Mockito.when(resultArtifact.getArtifactPayload()).thenReturn( IOUtils.toByteArray(ResourceFileUtil.getResourceAsStream("example/sdc/service-Simsfoimap0112.csar"))); + return resultArtifact; + } + + @Test + public void testSave() + throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { + CsarHandler csar = new CsarHandler(buildFakeSdcNotification(), "test-controller", "/tmp/csar-handler-tests"); // Test the save - csar.save(resultArtifact); - assertTrue((new File(sdcFolder + "/test-controller/" + csarArtifactName)).exists()); - assertEquals(csarArtifactName, csar.getArtifactElement().getArtifactName()); + csar.save(buildFakeSdcResut()); + assertTrue((new File(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME)).exists()); + assertEquals(CSAR_ARTIFACT_NAME, csar.getArtifactElement().getArtifactName()); assertNotNull(csar.getSdcCsarHelper()); // Test dcaeBlueprint String blueprint = csar.getDcaeBlueprint(); assertNotNull(blueprint); assertTrue(!blueprint.isEmpty()); assertTrue(blueprint.contains("DCAE-VES-PM-EVENT-v1")); + // Test additional properties from Sdc notif + assertEquals(BLUEPRINT1_NAME, csar.getBlueprintArtifactName()); + assertEquals(RESOURCE1_UUID, csar.getBlueprintInvariantResourceUuid()); + assertEquals(SERVICE_UUID, csar.getBlueprintInvariantServiceUuid()); // Do some cleanup - Path path = Paths.get(sdcFolder + "/test-controller/" + csarArtifactName); + Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME); Files.deleteIfExists(path); } } |