metaProperties = new LinkedHashMap<>();
}
- @SuppressWarnings("unchecked")
public boolean validate() throws JToscaException {
isValidated = true;
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 {
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 {
@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()));
+ }
+ }
}