diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java | 52 | ||||
-rw-r--r-- | src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java | 28 |
2 files changed, 59 insertions, 21 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 c0300eff6..b741f7c75 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 @@ -33,6 +33,10 @@ import com.att.aft.dme2.internal.apache.commons.io.IOUtils; import com.att.aft.dme2.internal.apache.commons.lang.RandomStringUtils; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,10 +46,13 @@ import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException; import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; import org.onap.clamp.clds.model.CldsModel; import org.onap.clamp.clds.model.CldsTemplate; +import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact; import org.onap.clamp.clds.sdc.controller.installer.CsarHandler; import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller; import org.onap.clamp.clds.sdc.controller.installer.CsarInstallerImpl; import org.onap.clamp.clds.util.ResourceFileUtil; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IResourceInstance; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.onap.sdc.toscaparser.api.elements.Metadata; @@ -69,24 +76,45 @@ public class CsarInstallerItCase { public void testInstallTheCsarFail() throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { CsarHandler csarHandler = Mockito.mock(CsarHandler.class); - Mockito.when(csarHandler.getDcaeBlueprint()).thenReturn(IOUtils + BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class); + Map<String, BlueprintArtifact> blueprintMap = new HashMap<>(); + blueprintMap.put("resourceid", blueprintArtifact); + Mockito.when(csarHandler.getMapOfBlueprints()).thenReturn(blueprintMap); + Mockito.when(blueprintArtifact.getDcaeBlueprint()).thenReturn(IOUtils .toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/not-recognized.yaml"))); csarInstaller.installTheCsar(csarHandler); fail("Should have raised an SdcArtifactInstallerException"); } private CsarHandler buildFakeCsarHandler(String generatedName) throws IOException { - CsarHandler csarHandler = Mockito.mock(CsarHandler.class); - Mockito.when(csarHandler.getDcaeBlueprint()) + // Create fake notification + INotificationData notificationData = Mockito.mock(INotificationData.class); + Mockito.when(notificationData.getServiceVersion()).thenReturn("1.0"); + // Create fake resource in notification + List<IResourceInstance> listResources = new ArrayList<>(); + IResourceInstance resource = Mockito.mock(IResourceInstance.class); + Mockito.when(resource.getResourceInstanceName()).thenReturn("mm-e 0"); + Mockito.when(resource.getResourceInvariantUUID()).thenReturn("mme0-invariantUuid"); + Mockito.when(notificationData.getResources()).thenReturn(listResources); + // Create fake blueprint artifact + BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class); + Mockito.when(blueprintArtifact.getDcaeBlueprint()) .thenReturn(ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca.yaml")); + Mockito.when(blueprintArtifact.getBlueprintArtifactName()).thenReturn(CSAR_ARTIFACT_NAME); + Mockito.when(blueprintArtifact.getBlueprintInvariantServiceUuid()).thenReturn(INVARIANT_SERVICE_UUID); + Mockito.when(blueprintArtifact.getBlueprintInvariantResourceUuid()).thenReturn(INVARIANT_RESOURCE1_UUID); + Map<String, BlueprintArtifact> blueprintMap = new HashMap<>(); + blueprintMap.put("resourceid", blueprintArtifact); + // Build fake csarhandler + CsarHandler csarHandler = Mockito.mock(CsarHandler.class); + Mockito.when(csarHandler.getSdcNotification()).thenReturn(notificationData); + Mockito.when(csarHandler.getMapOfBlueprints()).thenReturn(blueprintMap); + // Build fake csar Helper ISdcCsarHelper csarHelper = Mockito.mock(ISdcCsarHelper.class); Metadata data = Mockito.mock(Metadata.class); 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(INVARIANT_SERVICE_UUID); - Mockito.when(csarHandler.getBlueprintInvariantResourceUuid()).thenReturn(INVARIANT_RESOURCE1_UUID); return csarHandler; } @@ -104,24 +132,26 @@ public class CsarInstallerItCase { public void testInstallTheCsarTca() throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { String generatedName = RandomStringUtils.randomAlphanumeric(5); - csarInstaller.installTheCsar(buildFakeCsarHandler(generatedName)); + CsarHandler csar = buildFakeCsarHandler(generatedName); + csarInstaller.installTheCsar(csar); // Get the template back from DB CldsTemplate templateFromDb = CldsTemplate.retrieve(cldsDao, - CsarInstallerImpl.TEMPLATE_NAME_PREFIX + generatedName, false); + CsarInstallerImpl.TEMPLATE_NAME_PREFIX + CsarInstallerImpl.buildModelName(csar), false); assertNotNull(templateFromDb); 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); + assertEquals(templateFromDb.getName(), + CsarInstallerImpl.TEMPLATE_NAME_PREFIX + CsarInstallerImpl.buildModelName(csar)); // Get the Model back from DB - CldsModel modelFromDb = CldsModel.retrieve(cldsDao, generatedName, true); + CldsModel modelFromDb = CldsModel.retrieve(cldsDao, CsarInstallerImpl.buildModelName(csar), true); assertNotNull(modelFromDb); assertNotNull(modelFromDb.getBpmnText()); assertNotNull(modelFromDb.getImageText()); assertNotNull(modelFromDb.getPropText()); - assertEquals(modelFromDb.getName(), generatedName); + assertEquals(CsarInstallerImpl.buildModelName(csar), modelFromDb.getName()); 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 3a37f9457..b02e8bab4 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 @@ -55,7 +55,9 @@ public class CsarHandlerTest { 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"; + private static final String RESOURCE1_INSTANCE_NAME = "sim-1802 0"; + private static final String RESOURCE1_INSTANCE_NAME_IN_CSAR = "sim18020"; + private static final String BLUEPRINT1_NAME = "FOI.Simfoimap223S0112.event_proc_bp.yaml"; @Test public void testConstructor() throws CsarHandlerException { @@ -93,10 +95,10 @@ public class CsarHandlerTest { IResourceInstance resource1 = Mockito.mock(IResourceInstance.class); Mockito.when(resource1.getResourceType()).thenReturn("VF"); Mockito.when(resource1.getResourceInvariantUUID()).thenReturn(RESOURCE1_UUID); + Mockito.when(resource1.getResourceInstanceName()).thenReturn(RESOURCE1_INSTANCE_NAME); // 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); List<IArtifactInfo> artifactsListForResource = new ArrayList<>(); artifactsListForResource.add(blueprintArtifact); Mockito.when(resource1.getArtifacts()).thenReturn(artifactsListForResource); @@ -123,14 +125,17 @@ public class CsarHandlerTest { assertEquals(CSAR_ARTIFACT_NAME, csar.getArtifactElement().getArtifactName()); assertNotNull(csar.getSdcCsarHelper()); // Test dcaeBlueprint - String blueprint = csar.getDcaeBlueprint(); + String blueprint = csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).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()); + assertEquals(BLUEPRINT1_NAME, + csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintArtifactName()); + assertEquals(RESOURCE1_UUID, + csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantResourceUuid()); + assertEquals(SERVICE_UUID, + csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantServiceUuid()); // Do some cleanup Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME); Files.deleteIfExists(path); @@ -146,14 +151,17 @@ public class CsarHandlerTest { assertEquals(CSAR_ARTIFACT_NAME, csar.getArtifactElement().getArtifactName()); assertNotNull(csar.getSdcCsarHelper()); // Test dcaeBlueprint - String blueprint = csar.getDcaeBlueprint(); + String blueprint = csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).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()); + assertEquals(BLUEPRINT1_NAME, + csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintArtifactName()); + assertEquals(RESOURCE1_UUID, + csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantResourceUuid()); + assertEquals(SERVICE_UUID, + csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantServiceUuid()); Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME); // A double save should simply overwrite the existing csar.save(buildFakeSdcResut()); |