X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Fsdc%2Fcontroller%2Finstaller%2FCsarHandlerTest.java;h=f04e3fa3c6bfd000bd4ea384276c71a7446382b1;hb=536db7b811eba341aef48a745b495da068d170eb;hp=397a6a6f308d7c59fb8983b9bd215374c3b0cfbb;hpb=0c8c6ff37abb1080fec59ee2558689c312a953a1;p=clamp.git 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 397a6a6f..f04e3fa3 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 @@ -18,18 +18,17 @@ * limitations under the License. * ============LICENSE_END============================================ * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.clamp.clds.sdc.controller.installer; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; 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; - import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -38,11 +37,12 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; +import org.apache.commons.io.IOUtils; import org.junit.Test; import org.mockito.Mockito; import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException; import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; -import org.onap.clamp.clds.util.ResourceFileUtil; +import org.onap.clamp.clds.util.ResourceFileUtils; import org.onap.sdc.api.notification.IArtifactInfo; import org.onap.sdc.api.notification.INotificationData; import org.onap.sdc.api.notification.IResourceInstance; @@ -58,6 +58,7 @@ public class CsarHandlerTest { 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"; + private static final String BLUEPRINT2_NAME = "FOI.Simfoimap223S0112.event_proc_bp2.yaml"; @Test public void testConstructor() throws CsarHandlerException { @@ -111,13 +112,20 @@ public class CsarHandlerTest { 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"))); + IOUtils.toByteArray(ResourceFileUtils.getResourceAsStream("example/sdc/service-Simsfoimap0112.csar"))); + return resultArtifact; + } + + private IDistributionClientDownloadResult buildFakeSdcResultWithoutPolicyModel() throws IOException { + IDistributionClientDownloadResult resultArtifact = Mockito.mock(IDistributionClientDownloadResult.class); + Mockito.when(resultArtifact.getArtifactPayload()).thenReturn( + IOUtils.toByteArray(ResourceFileUtils.getResourceAsStream("example/sdc/service-without-policy.csar"))); return resultArtifact; } @Test public void testSave() - throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { + throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { CsarHandler csar = new CsarHandler(buildFakeSdcNotification(), "test-controller", "/tmp/csar-handler-tests"); // Test the save csar.save(buildFakeSdcResut()); @@ -125,25 +133,48 @@ public class CsarHandlerTest { assertEquals(CSAR_ARTIFACT_NAME, csar.getArtifactElement().getArtifactName()); assertNotNull(csar.getSdcCsarHelper()); // Test dcaeBlueprint - String blueprint = csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getDcaeBlueprint(); + String blueprint = csar.getMapOfBlueprints().get(BLUEPRINT1_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.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintArtifactName()); - assertEquals(RESOURCE1_UUID, csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getResourceAttached() - .getResourceInvariantUUID()); - assertEquals(SERVICE_UUID, - csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantServiceUuid()); + assertEquals(BLUEPRINT1_NAME, csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getBlueprintArtifactName()); + assertEquals(RESOURCE1_UUID, + csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getResourceAttached().getResourceInvariantUUID()); + assertEquals(SERVICE_UUID, csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getBlueprintInvariantServiceUuid()); + + // Just check the second one is there as well + assertEquals(BLUEPRINT2_NAME, csar.getMapOfBlueprints().get(BLUEPRINT2_NAME).getBlueprintArtifactName()); + blueprint = csar.getMapOfBlueprints().get(BLUEPRINT2_NAME).getDcaeBlueprint(); + assertNotNull(blueprint); + assertTrue(!blueprint.isEmpty()); + assertTrue(blueprint.contains("DCAE-VES-PM-EVENT-v1")); // Do some cleanup Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME); Files.deleteIfExists(path); + + } + + @Test + public void testLoadingOfPolicyModelFromCsar() + throws CsarHandlerException, IOException, SdcArtifactInstallerException, SdcToscaParserException { + CsarHandler csar = new CsarHandler(buildFakeSdcNotification(), "test-controller", "/tmp/csar-handler-tests"); + csar.save(buildFakeSdcResut()); + String policyModelYaml = csar.getPolicyModelYaml().get(); + assertTrue(policyModelYaml.contains("tosca_simple_yaml_1_0_0")); + } + + @Test + public void testLoadingOfNonexistentPolicyModelFromCsar() + throws CsarHandlerException, IOException, SdcArtifactInstallerException, SdcToscaParserException { + CsarHandler csar = new CsarHandler(buildFakeSdcNotification(), "test-controller", "/tmp/csar-handler-tests"); + csar.save(buildFakeSdcResultWithoutPolicyModel()); + assertFalse(csar.getPolicyModelYaml().isPresent()); } @Test public void testDoubleSave() - throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { + throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { CsarHandler csar = new CsarHandler(buildFakeSdcNotification(), "test-controller", "/tmp/csar-handler-tests"); // Test the save csar.save(buildFakeSdcResut()); @@ -151,17 +182,15 @@ public class CsarHandlerTest { assertEquals(CSAR_ARTIFACT_NAME, csar.getArtifactElement().getArtifactName()); assertNotNull(csar.getSdcCsarHelper()); // Test dcaeBlueprint - String blueprint = csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getDcaeBlueprint(); + String blueprint = csar.getMapOfBlueprints().get(BLUEPRINT1_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.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintArtifactName()); - assertEquals(RESOURCE1_UUID, csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getResourceAttached() - .getResourceInvariantUUID()); - assertEquals(SERVICE_UUID, - csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantServiceUuid()); + assertEquals(BLUEPRINT1_NAME, csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getBlueprintArtifactName()); + assertEquals(RESOURCE1_UUID, + csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getResourceAttached().getResourceInvariantUUID()); + assertEquals(SERVICE_UUID, csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getBlueprintInvariantServiceUuid()); Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME); // A double save should simply overwrite the existing csar.save(buildFakeSdcResut());