CSAR files are decompressed twice
authorTal Gitelman <tg851x@intl.att.com>
Thu, 4 Jan 2018 14:11:30 +0000 (16:11 +0200)
committerMichael Lando <ml636r@att.com>
Sun, 7 Jan 2018 16:34:13 +0000 (16:34 +0000)
in the same thread fixed

Change-Id: Id59cc7250d8431114ab90d14e03049f86a4d49ca
Issue-ID: SDC-250
Signed-off-by: Tal Gitelman <tg851x@intl.att.com>
src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java
src/test/java/org/openecomp/sdc/toscaparser/api/JToscaMetadataParse.java
src/test/resources/csars/emptyCsar.csar [new file with mode: 0644]
src/test/resources/csars/service-ServiceFdnt-csar.csar [deleted file]
src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar [moved from src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar.csar with 100% similarity]

index 07cce1c..8d7d130 100644 (file)
@@ -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(),
index b40eded..b64bd9a 100644 (file)
@@ -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 {
index 37292e5..8f55fa4 100644 (file)
@@ -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 (file)
index 0000000..15cb0ec
Binary files /dev/null and b/src/test/resources/csars/emptyCsar.csar 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 (file)
index 983dc9b..0000000
Binary files a/src/test/resources/csars/service-ServiceFdnt-csar.csar and /dev/null differ