aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEddy Hautot <eh552t@intl.att.com>2018-04-06 16:28:26 +0000
committerGerrit Code Review <gerrit@onap.org>2018-04-06 16:28:26 +0000
commit65ed508ad0db466f02c3db0fe9ed6b659ca46a53 (patch)
treeea81de7afcf7d45ba3d13670d6b086ea70c811cd
parent2eb4268fa4a3245989ac348a51715cbb74153e77 (diff)
parent2e4c62864ee5eb926bdf5747c1e592afbbc2d5b8 (diff)
Merge "Change CsarHandler behavior"
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java8
-rw-r--r--src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java25
2 files changed, 29 insertions, 4 deletions
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
index 2b83905a8..62169379c 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
@@ -27,9 +27,9 @@ import com.att.aft.dme2.internal.apache.commons.io.IOUtils;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -97,9 +97,9 @@ public class CsarHandler {
+ artifactElement.getArtifactUUID() + ")");
Path path = Paths.get(csarFilePath);
Files.createDirectories(path.getParent());
- Files.createFile(path);
- try (FileOutputStream outFile = new FileOutputStream(csarFilePath)) {
- outFile.write(resultArtifact.getArtifactPayload(), 0, resultArtifact.getArtifactPayload().length);
+ // Create or replace the file
+ try (OutputStream out = Files.newOutputStream(path)) {
+ out.write(resultArtifact.getArtifactPayload(), 0, resultArtifact.getArtifactPayload().length);
}
sdcCsarHelper = factory.getSdcCsarHelper(csarFilePath);
this.loadDcaeBlueprint();
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 46bddaf4f..3a37f9457 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
@@ -135,4 +135,29 @@ public class CsarHandlerTest {
Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME);
Files.deleteIfExists(path);
}
+
+ @Test
+ public void testDoubleSave()
+ throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException {
+ CsarHandler csar = new CsarHandler(buildFakeSdcNotification(), "test-controller", "/tmp/csar-handler-tests");
+ // Test the save
+ 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());
+ Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME);
+ // A double save should simply overwrite the existing
+ csar.save(buildFakeSdcResut());
+ // Do some cleanup
+ Files.deleteIfExists(path);
+ }
}