summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTal Gitelman <tg851x@intl.att.com>2018-01-04 16:11:30 +0200
committerMichael Lando <ml636r@att.com>2018-01-07 16:34:13 +0000
commit9542ec5708daad3dd43052d326780f7f5c9a987d (patch)
treeff2c1e881d15383b20727b7c50412b7e7dcc915e
parenteed89a056e2c51bfbc1df78995f757f3d1ed8231 (diff)
CSAR files are decompressed twice
in the same thread fixed Change-Id: Id59cc7250d8431114ab90d14e03049f86a4d49ca Issue-ID: SDC-250 Signed-off-by: Tal Gitelman <tg851x@intl.att.com>
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java4
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java9
-rw-r--r--src/test/java/org/openecomp/sdc/toscaparser/api/JToscaMetadataParse.java30
-rw-r--r--src/test/resources/csars/emptyCsar.csarbin0 -> 22 bytes
-rw-r--r--src/test/resources/csars/service-ServiceFdnt-csar.csarbin40171 -> 0 bytes
-rw-r--r--src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar (renamed from src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar.csar)bin44576 -> 44576 bytes
6 files changed, 33 insertions, 10 deletions
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java b/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
index 07cce1c..8d7d130 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
@@ -172,8 +172,7 @@ public class ToscaTemplate extends Object {
//log.info(msg)
log.debug("ToscaTemplate - Both path and yaml_dict_tpl arguments were provided. Using path and ignoring yaml_dict_tpl");
}
- }
- else {
+ } else {
// no input to process...
_abort();
}
@@ -225,6 +224,7 @@ public class ToscaTemplate extends Object {
verifyTemplate();
throw new JToscaException("jtosca aborting", JToscaErrorCodes.PATH_NOT_VALID.getValue());
}
+
private TopologyTemplate _topologyTemplate() {
return new TopologyTemplate(
_tplTopologyTemplate(),
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java b/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java
index b40eded..b64bd9a 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java
@@ -54,7 +54,6 @@ public class CSAR {
metaProperties = new LinkedHashMap<>();
}
- @SuppressWarnings("unchecked")
public boolean validate() throws JToscaException {
isValidated = true;
@@ -310,9 +309,11 @@ public class CSAR {
if(!isValidated) {
validate();
}
- tempDir = Files.createTempDirectory("JTP").toString();
- unzip(path,tempDir);
-
+
+ if(tempDir == null || tempDir.isEmpty()) {
+ tempDir = Files.createTempDirectory("JTP").toString();
+ unzip(path,tempDir);
+ }
}
private void _validateExternalReferences() throws JToscaException {
diff --git a/src/test/java/org/openecomp/sdc/toscaparser/api/JToscaMetadataParse.java b/src/test/java/org/openecomp/sdc/toscaparser/api/JToscaMetadataParse.java
index 37292e5..8f55fa4 100644
--- a/src/test/java/org/openecomp/sdc/toscaparser/api/JToscaMetadataParse.java
+++ b/src/test/java/org/openecomp/sdc/toscaparser/api/JToscaMetadataParse.java
@@ -5,12 +5,11 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
-import java.util.Collection;
import java.util.LinkedHashMap;
import org.junit.Test;
import org.openecomp.sdc.toscaparser.api.common.JToscaException;
-import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue;
+import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class JToscaMetadataParse {
@@ -29,11 +28,34 @@ public class JToscaMetadataParse {
@Test
public void noWarningsAfterParse() throws JToscaException {
- String fileStr = JToscaMetadataParse.class.getClassLoader().getResource("csars/tmpCSAR_Huawei_vSPGW_fixed.csar.csar").getFile();
+ String fileStr = JToscaMetadataParse.class.getClassLoader().getResource("csars/tmpCSAR_Huawei_vSPGW_fixed.csar").getFile();
File file = new File(fileStr);
ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
int validationIssuesCaught = ThreadLocalsHolder.getCollector().validationIssuesCaught();
assertTrue(validationIssuesCaught == 0 );
}
-
+
+ @Test
+ public void testEmptyCsar() throws JToscaException {
+ String fileStr = JToscaMetadataParse.class.getClassLoader().getResource("csars/emptyCsar.csar").getFile();
+ File file = new File(fileStr);
+ try {
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ } catch (JToscaException e) {
+ assertTrue(e.getCode().equals(JToscaErrorCodes.INVALID_CSAR_FORMAT.getValue()));
+ }
+ int validationIssuesCaught = ThreadLocalsHolder.getCollector().validationIssuesCaught();
+ assertTrue(validationIssuesCaught == 0 );
+ }
+
+ @Test
+ public void testEmptyPath() throws JToscaException {
+ String fileStr = JToscaMetadataParse.class.getClassLoader().getResource("").getFile();
+ File file = new File(fileStr);
+ try {
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ }catch (JToscaException e) {
+ assertTrue(e.getCode().equals(JToscaErrorCodes.PATH_NOT_VALID.getValue()));
+ }
+ }
}
diff --git a/src/test/resources/csars/emptyCsar.csar b/src/test/resources/csars/emptyCsar.csar
new file mode 100644
index 0000000..15cb0ec
--- /dev/null
+++ b/src/test/resources/csars/emptyCsar.csar
Binary files differ
diff --git a/src/test/resources/csars/service-ServiceFdnt-csar.csar b/src/test/resources/csars/service-ServiceFdnt-csar.csar
deleted file mode 100644
index 983dc9b..0000000
--- a/src/test/resources/csars/service-ServiceFdnt-csar.csar
+++ /dev/null
Binary files differ
diff --git a/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar.csar b/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar
index 70f8cc4..70f8cc4 100644
--- a/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar.csar
+++ b/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar
Binary files differ