summaryrefslogtreecommitdiffstats
path: root/csarvalidation
diff options
context:
space:
mode:
Diffstat (limited to 'csarvalidation')
-rw-r--r--csarvalidation/pom.xml6
-rw-r--r--csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java77
-rw-r--r--csarvalidation/src/main/java/org/onap/cvc/csar/parser/MetadataParser.java2
-rw-r--r--csarvalidation/src/main/java/org/onap/cvc/csar/parser/NonManoArtifactsParser.java7
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/csar/CsarUtil.java242
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java16
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/csar/FileUtil.java38
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java20
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java6
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/CSARArchiveTest.java4
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java40
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java49
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/PnfMetadataParserTest.java2
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java4
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/VnfManifestParserTest.java6
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR10087IntegrationTest.java13
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206IntegrationTest.java4
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java4
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java2
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019IntegrationTest.java2
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787965IntegrationTest.java4
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java2
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR972082IntegrationTest.java4
-rw-r--r--csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java101
-rw-r--r--csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java4
-rw-r--r--csarvalidation/src/test/resources/pnf/toscaMetaFile.csarbin0 -> 5906 bytes
26 files changed, 394 insertions, 265 deletions
diff --git a/csarvalidation/pom.xml b/csarvalidation/pom.xml
index deb5216..389997d 100644
--- a/csarvalidation/pom.xml
+++ b/csarvalidation/pom.xml
@@ -67,6 +67,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.jmockit</groupId>
+ <artifactId>jmockit</artifactId>
+ <version>1.19</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.2.1</version>
diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java b/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java
index 1c05948..70cd8f3 100644
--- a/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java
+++ b/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java
@@ -92,6 +92,9 @@ public class CSARArchive implements AutoCloseable {
public static final String CSAR_ARCHIVE = "CSAR Archive";
public static final String DOESS_NOT_EXIST = " does not exist";
+ public static final String CERT = ".cert";
+ public static final String YAML = ".yaml";
+ public static final String MF = ".mf";
public enum Mode {
WITH_TOSCA_META_DIR,
@@ -496,7 +499,7 @@ public class CSARArchive implements AutoCloseable {
CSAR_ARCHIVE,
-1,
"Manifest file name should match the definition YAML name",
- definitionYaml + ".mf", //fix the name part
+ definitionYaml + MF, //fix the name part
manifest);
this.setCode("0x0013");
@@ -521,7 +524,7 @@ public class CSARArchive implements AutoCloseable {
CSAR_ARCHIVE,
-1,
"certificate file name should match the definition YAML name",
- definitionYaml + ".cert", //fix the name part
+ definitionYaml + CERT, //fix the name part
certificate);
this.setCode("0x0015");
@@ -966,32 +969,29 @@ public class CSARArchive implements AutoCloseable {
lineNo ++;
line = line.trim();
- if (line.startsWith("#") || line.trim().isEmpty()) {
- continue;
- }
-
- String []lineTokens = line.split(":");
+ if (!line.startsWith("#") && !line.trim().isEmpty()) {
+ String []lineTokens = line.split(":");
- if (lineTokens.length != 2) {
- errors.add(
- new CSARErrorIgnored(
- line,
- TOSCA_METADATA_TOSCA_META,
- lineNo,
- null));
- continue;
- }
+ if (lineTokens.length != 2) {
+ errors.add(
+ new CSARErrorIgnored(
+ line,
+ TOSCA_METADATA_TOSCA_META,
+ lineNo,
+ null));
+ continue;
+ }
- String key = lineTokens[0].trim();
- String value = lineTokens[1].trim();
+ String key = lineTokens[0].trim();
+ String value = lineTokens[1].trim();
- if(key.equalsIgnoreCase(TOSCA_METADATA_TOSCA_META_TOSCA_META_FILE_VERSION)) {
+ if(key.equalsIgnoreCase(TOSCA_METADATA_TOSCA_META_TOSCA_META_FILE_VERSION)) {
this.toscaMeta.setMetaDataFileVersion(value);
- } else if(key.equalsIgnoreCase(TOSCA_METADATA_TOSCA_META_CSAR_VERSION)){
+ } else if(key.equalsIgnoreCase(TOSCA_METADATA_TOSCA_META_CSAR_VERSION)){
this.toscaMeta.setCsarVersion(value);
- } else if(key.equalsIgnoreCase(TOSCA_METADATA_TOSCA_META_CREATED_BY)) {
+ } else if(key.equalsIgnoreCase(TOSCA_METADATA_TOSCA_META_CREATED_BY)) {
this.toscaMeta.setCompanyName(value);
- } else if(key.equalsIgnoreCase(TOSCA_METADATA_TOSCA_META_ENTRY_DEFINITIONS)) {
+ } else if(key.equalsIgnoreCase(TOSCA_METADATA_TOSCA_META_ENTRY_DEFINITIONS)) {
this.toscaMeta.setEntryDefinitionYaml(value);
this.definitionYamlFile = new File(this.tempDir.toFile().getAbsolutePath() + File.separator + (this.toscaMeta.getEntryDefinitionYaml()));
@@ -1001,7 +1001,7 @@ public class CSARArchive implements AutoCloseable {
this.toscaMeta.getEntryDefinitionYaml(),
lineNo));
}
- } else if(key.equalsIgnoreCase(getEntryManifestParamName())) {
+ } else if(key.equalsIgnoreCase(getEntryManifestParamName())) {
this.toscaMeta.setEntryManifestMf(value);
this.manifestMfFile = this.tempDir.resolve(this.toscaMeta.getEntryManifestMf()).toFile();
if (!this.manifestMfFile.exists()) {
@@ -1009,7 +1009,7 @@ public class CSARArchive implements AutoCloseable {
this.toscaMeta.getEntryManifestMf(),
lineNo, getEntryManifestParamName()));
}
- } else if(key.equalsIgnoreCase(getEntryChangeLogParamName())) {
+ } else if(key.equalsIgnoreCase(getEntryChangeLogParamName())) {
this.toscaMeta.setEntryChangeLog(value);
this.changeLogTxtFile = this.tempDir.resolve(this.toscaMeta.getEntryChangeLog()).toFile();
if (!this.changeLogTxtFile.exists()) {
@@ -1017,37 +1017,38 @@ public class CSARArchive implements AutoCloseable {
this.toscaMeta.getEntryChangeLog(),
lineNo, getEntryChangeLogParamName()));
}
- } else if(key.equalsIgnoreCase(TOSCA_METADATA_TOSCA_META_ENTRY_TESTS)) {
+ } else if(key.equalsIgnoreCase(TOSCA_METADATA_TOSCA_META_ENTRY_TESTS)) {
this.toscaMeta.setEntryTest(value);
- this.testsFolder= this.tempDir.resolve(this.toscaMeta.getEntryTest()).toFile();
+ this.testsFolder = this.tempDir.resolve(this.toscaMeta.getEntryTest()).toFile();
if (!this.testsFolder.exists() || !this.testsFolder.isDirectory()) {
errors.add(new CSARErrorInvalidEntryValueTestsNotFound(
this.toscaMeta.getEntryTest(),
lineNo));
}
- } else if(key.equalsIgnoreCase(TOSCA_METADATA_TOSCA_META_ENTRY_LICENSES)) {
+ } else if(key.equalsIgnoreCase(TOSCA_METADATA_TOSCA_META_ENTRY_LICENSES)) {
this.toscaMeta.setEntryLicense(value);
- this.licensesFolder= this.tempDir.resolve(this.toscaMeta.getEntryLicense()).toFile();
+ this.licensesFolder = this.tempDir.resolve(this.toscaMeta.getEntryLicense()).toFile();
if (!this.licensesFolder.exists() || !this.licensesFolder.isDirectory()) {
errors.add(new CSARErrorInvalidEntryValueLicenseNotFound(
this.toscaMeta.getEntryLicense(),
lineNo));
}
- } else if(key.equalsIgnoreCase(getEntryCertificateParamName())) {
+ } else if(key.equalsIgnoreCase(getEntryCertificateParamName())) {
this.toscaMeta.setEntryCertificate(value);
- this.certificatesFile= this.tempDir.resolve(this.toscaMeta.getEntryCertificate()).toFile();
+ this.certificatesFile = this.tempDir.resolve(this.toscaMeta.getEntryCertificate()).toFile();
if (!this.certificatesFile.exists()) {
errors.add(new CSARErrorInvalidEntryValueCertificatesNotFound(
this.toscaMeta.getEntryCertificate(),
lineNo));
}
- } else {
+ } else {
errors.add(
new CSARErrorIgnored(
key,
TOSCA_METADATA_TOSCA_META,
lineNo,
null));
+ }
}
}
@@ -1071,7 +1072,7 @@ public class CSARArchive implements AutoCloseable {
} else {
//definition files
- File []files = this.tempDir.toFile().listFiles((dir, name) -> name.endsWith(".yaml"));
+ File []files = this.tempDir.toFile().listFiles((dir, name) -> name.endsWith(YAML));
if (files.length == 0) {
errors.add(
@@ -1088,7 +1089,7 @@ public class CSARArchive implements AutoCloseable {
this.toscaMeta.setEntryDefinitionYaml(this.definitionYamlFile.getName());
//manifest
- files = this.tempDir.toFile().listFiles((dir, name) -> name.endsWith(".mf"));
+ files = this.tempDir.toFile().listFiles((dir, name) -> name.endsWith(MF));
if (files.length > 1) {
List<String> fileNames = new ArrayList<>();
@@ -1102,9 +1103,9 @@ public class CSARArchive implements AutoCloseable {
//name should match the definition yaml
String defYaml = this.toscaMeta.getEntryDefinitionYaml().substring(
- 0, this.toscaMeta.getEntryDefinitionYaml().lastIndexOf(".yaml"));
+ 0, this.toscaMeta.getEntryDefinitionYaml().lastIndexOf(YAML));
String mfFile = this.toscaMeta.getEntryManifestMf().substring(
- 0, this.toscaMeta.getEntryManifestMf().lastIndexOf(".mf"));
+ 0, this.toscaMeta.getEntryManifestMf().lastIndexOf(MF));
if (!defYaml.equalsIgnoreCase(mfFile)) {
errors.add(new CSARErrorMismatchDefinitionYamlVsManifestMf(
@@ -1115,7 +1116,7 @@ public class CSARArchive implements AutoCloseable {
}
//certificate
- files = this.tempDir.toFile().listFiles((dir, name) -> name.endsWith(".cert"));
+ files = this.tempDir.toFile().listFiles((dir, name) -> name.endsWith(CERT));
if (files.length > 1) {
List<String> fileNames = new ArrayList<>();
@@ -1130,9 +1131,9 @@ public class CSARArchive implements AutoCloseable {
//name should match the definition yaml
String defYaml = this.toscaMeta.getEntryDefinitionYaml().substring(
- 0, this.toscaMeta.getEntryDefinitionYaml().lastIndexOf(".yaml"));
+ 0, this.toscaMeta.getEntryDefinitionYaml().lastIndexOf(YAML));
String certFile = this.toscaMeta.getEntryCertificate().substring(
- 0, this.toscaMeta.getEntryCertificate().lastIndexOf(".cert"));
+ 0, this.toscaMeta.getEntryCertificate().lastIndexOf(CERT));
if (!defYaml.equalsIgnoreCase(certFile)) {
errors.add(new CSARErrorMismatchDefinitionYamlVsCertificateCert(
diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/parser/MetadataParser.java b/csarvalidation/src/main/java/org/onap/cvc/csar/parser/MetadataParser.java
index b0c06ee..f529c45 100644
--- a/csarvalidation/src/main/java/org/onap/cvc/csar/parser/MetadataParser.java
+++ b/csarvalidation/src/main/java/org/onap/cvc/csar/parser/MetadataParser.java
@@ -85,7 +85,7 @@ public class MetadataParser {
private boolean isNewSection(Pair<String, String> data) {
String key = data.getKey().trim();
String value = data.getValue().trim();
- return key.matches("[a-zA-z_0-9]+") && (value.isEmpty() || ManifestLine.of(value).startsWith("#"));
+ return key.matches("[a-zA-Z_0-9]+") && (value.isEmpty() || ManifestLine.of(value).startsWith("#"));
}
private boolean isSourceSection(Pair<String, String> data) {
diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/parser/NonManoArtifactsParser.java b/csarvalidation/src/main/java/org/onap/cvc/csar/parser/NonManoArtifactsParser.java
index 22e8978..1aa7d32 100644
--- a/csarvalidation/src/main/java/org/onap/cvc/csar/parser/NonManoArtifactsParser.java
+++ b/csarvalidation/src/main/java/org/onap/cvc/csar/parser/NonManoArtifactsParser.java
@@ -51,10 +51,9 @@ public class NonManoArtifactsParser {
if (isNewSection(data)) {
attributeName = data.getKey();
nonManoArtifacts.put(attributeName, new HashMap<>());
- continue;
- }
-
+ } else {
handleNonManoArtifactLine(nonManoArtifacts, attributeName, data);
+ }
}
}
@@ -68,7 +67,7 @@ public class NonManoArtifactsParser {
private boolean isNewSection(Pair<String, String> data) {
String key = data.getKey().trim();
String value = data.getValue().trim();
- return key.matches("[a-zA-z_0-9]+") && (value.isEmpty() || ManifestLine.of(value).startsWith("#"));
+ return key.matches("[a-zA-Z_0-9]+") && (value.isEmpty() || ManifestLine.of(value).startsWith("#"));
}
private void handleNonManoArtifactLine(
diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/CsarUtil.java b/csarvalidation/src/main/java/org/onap/validation/csar/CsarUtil.java
index c498479..c2d6048 100644
--- a/csarvalidation/src/main/java/org/onap/validation/csar/CsarUtil.java
+++ b/csarvalidation/src/main/java/org/onap/validation/csar/CsarUtil.java
@@ -28,133 +28,131 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Enumeration;
-
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
-
+import java.util.Map;
public class CsarUtil {
-
- private static final Logger logger = LoggerFactory.getLogger(CsarUtil.class);
-
- public static String getUnzipDir(String dirName) {
- File tmpDir = new File(File.separator + dirName);
- return tmpDir.getAbsolutePath().replace(".csar", "");
- }
-
- /**
- * unzip zip file.
- *
- * @param zipFileName
- * file name to zip
- * @param extPlace
- * extPlace
- * @return unzip file names in zip
- * @throws IOException
- * e1
- * @throws ValidationException
- */
- public static HashMap<String, String> unzip(String zipFileName, String extPlace) throws IOException {
- HashMap<String, String> unzipFileNames = new HashMap<>();
-
- try(ZipFile zipFile = new ZipFile(zipFileName)) {
-
- Enumeration<?> fileEn = zipFile.entries();
- byte[] buffer = new byte[CommonConstants.BUFFER_SIZE];
-
- while (fileEn.hasMoreElements()) {
- InputStream input = null;
- BufferedOutputStream bos = null;
- try {
- ZipEntry entry = (ZipEntry) fileEn.nextElement();
- if (entry.isDirectory()) {
- continue;
- }
-
- input = zipFile.getInputStream(entry);
- File file = new File(extPlace, entry.getName());
-
- //Currently it does not support xml based VNF descriptors.
- //So skip and proceed to YAML defined files validation only.
- if (file.getAbsolutePath().contains("xml"+System.getProperty("file.separator"))) {
- continue;
- }
-
- if (!file.getParentFile().exists()) {
- FileUtil.createDirectory(file.getParentFile().getAbsolutePath());
- }
-
- bos = new BufferedOutputStream(new FileOutputStream(file));
- while (true) {
- int length = input.read(buffer);
- if (length == -1) {
- break;
- }
- bos.write(buffer, 0, length);
- }
-
- unzipFileNames.put(file.getName(), file.getAbsolutePath());
-
- } finally {
- closeOutputStream(bos);
- closeInputStream(input);
- }
- }
- }
- return unzipFileNames;
- }
-
- /**
- * close InputStream.
- *
- * @param inputStream
- * the inputstream to close
- * @throws ValidationException
- */
- public static void closeInputStream(InputStream inputStream) {
- try {
- if (inputStream != null) {
- inputStream.close();
- }
- } catch (Exception e1) {
- logger.error("FILE_IO" + ":" + "close InputStream error! " +ErrorCodes.FILE_IO+" "+ e1.getMessage(), e1);
- throw new ValidationException(ErrorCodes.FILE_IO);
- }
- }
-
- /**
- * close OutputStream.
- *
- * @param outputStream
- * the output stream to close
- * @throws ValidationException
- */
- public static void closeOutputStream(OutputStream outputStream) {
- try {
- if (outputStream != null) {
- outputStream.close();
- }
- } catch (Exception e1) {
- logger.error("FILE_IO" + ":" + "close OutputStream error! " +ErrorCodes.FILE_IO, e1);
- throw new ValidationException(ErrorCodes.FILE_IO);
+
+ private static final Logger logger = LoggerFactory.getLogger(CsarUtil.class);
+
+ public static String getUnzipDir(String dirName) {
+ File tmpDir = new File(File.separator + dirName);
+ return tmpDir.getAbsolutePath().replace(".csar", "");
+ }
+
+ /**
+ * unzip zip file.
+ *
+ * @param zipFileName
+ * file name to zip
+ * @param extPlace
+ * extPlace
+ * @return unzip file names in zip
+ * @throws IOException
+ * e1
+ * @throws ValidationException
+ */
+ public static Map<String, String> unzip(String zipFileName, String extPlace) throws IOException {
+ HashMap<String, String> unzipFileNames = new HashMap<>();
+
+ try(ZipFile zipFile = new ZipFile(zipFileName)) {
+
+ Enumeration<?> fileEn = zipFile.entries();
+ byte[] buffer = new byte[CommonConstants.BUFFER_SIZE];
+
+ while (fileEn.hasMoreElements()) {
+ InputStream input = null;
+ BufferedOutputStream bos = null;
+ ZipEntry entry = (ZipEntry) fileEn.nextElement();
+ if (!entry.isDirectory()) {
+ try {
+ input = zipFile.getInputStream(entry);
+ File file = new File(extPlace, entry.getName());
+
+ //Currently it does not support xml based VNF descriptors.
+ //So skip and proceed to YAML defined files validation only.
+ if (file.getAbsolutePath().contains("xml"+System.getProperty("file.separator"))) {
+ continue;
+ }
+
+ if (!file.getParentFile().exists()) {
+ FileUtil.createDirectory(file.getParentFile().getAbsolutePath());
+ }
+
+ bos = new BufferedOutputStream(new FileOutputStream(file));
+ while (true) {
+ int length = input.read(buffer);
+ if (length == -1) {
+ break;
+ }
+ bos.write(buffer, 0, length);
+ }
+
+ unzipFileNames.put(file.getName(), file.getAbsolutePath());
+
+ } finally {
+ closeOutputStream(bos);
+ closeInputStream(input);
+ }
+ }
+ }
+ }
+ return unzipFileNames;
+ }
+
+ /**
+ * close InputStream.
+ *
+ * @param inputStream
+ * the inputstream to close
+ * @throws ValidationException
+ */
+ public static void closeInputStream(InputStream inputStream) {
+ try {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ } catch (Exception e1) {
+ logger.error("FILE_IO" + ":" + "close InputStream error! " +ErrorCodes.FILE_IO+" "+ e1.getMessage(), e1);
+ throw new ValidationException(ErrorCodes.FILE_IO);
+ }
+ }
+
+ /**
+ * close OutputStream.
+ *
+ * @param outputStream
+ * the output stream to close
+ * @throws ValidationException
+ */
+ public static void closeOutputStream(OutputStream outputStream) {
+ try {
+ if (outputStream != null) {
+ outputStream.close();
+ }
+ } catch (Exception e1) {
+ logger.error("FILE_IO" + ":" + "close OutputStream error! " +ErrorCodes.FILE_IO, e1);
+ throw new ValidationException(ErrorCodes.FILE_IO);
- }
- }
- /**
- *
- * @param filePath
- * @return HashMap<String, String>
- */
- public static HashMap<String, String> csarExtract(String filePath) {
-
- try {
- String tempfolder = CsarUtil.getUnzipDir(filePath);
- return CsarUtil.unzip(filePath, tempfolder);
-
- } catch (IOException e1) {
- logger.error("CSAR_EXTRACTION" + ":" + "CSAR extraction error ! " +ErrorCodes.FILE_IO+" "+ e1.getMessage(), e1);
+ }
+ }
+
+ /**
+ *
+ * @param filePath
+ * @return HashMap<String, String>
+ */
+ public static Map<String, String> csarExtract(String filePath) {
+
+ try {
+ String tempfolder = CsarUtil.getUnzipDir(filePath);
+ return CsarUtil.unzip(filePath, tempfolder);
+
+ } catch (IOException e1) {
+ logger.error("CSAR_EXTRACTION" + ":" + "CSAR extraction error ! " +ErrorCodes.FILE_IO+" "+ e1.getMessage(), e1);
throw new ValidationException(ErrorCodes.FILE_IO);
- }
- }
+ }
+ }
}
diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java b/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java
index e92f2b2..b853ca2 100644
--- a/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java
+++ b/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java
@@ -49,10 +49,10 @@ public class CsarValidator {
private static ValidatorSchemaLoader vsl;
// Map of CSAR file and un-zipped file indices
- private static HashMap<String, String> csarFiles;
+ private static Map<String, String> csarFiles;
// Map of packageId and CSAR files
- private static HashMap<String, HashMap<String, String>> csar = new HashMap<>();
+ private static Map<String, Map<String, String>> csar = new HashMap<>();
private static String MAINSERV_TEMPLATE = CommonConstants.MAINSERV_TEMPLATE;
@@ -110,12 +110,12 @@ public class CsarValidator {
//String r02454 = r02454();
- if((CommonConstants.SUCCESS_STR != vsm) && (CommonConstants.SUCCESS_STR != vms)) {
+ if((!CommonConstants.SUCCESS_STR.equals(vsm)) && (!CommonConstants.SUCCESS_STR.equals(vms))) {
return vsm + " OR " + vms;
}
- if(CommonConstants.SUCCESS_STR != vtm) {
+ if(!CommonConstants.SUCCESS_STR.equals(vtm)) {
return vtm;
}
/*
@@ -422,19 +422,19 @@ public class CsarValidator {
}
}
- public static HashMap<String, HashMap<String, String>> getCsar() {
+ public static Map<String, Map<String, String>> getCsar() {
return csar;
}
- public static void setCsar(HashMap<String, HashMap<String, String>> csar) {
+ public static void setCsar(Map<String, Map<String, String>> csar) {
CsarValidator.csar = csar;
}
- public static HashMap<String, String> getCsarFiles() {
+ public static Map<String, String> getCsarFiles() {
return csarFiles;
}
- public static void setCsarFiles(HashMap<String, String> csarFiles) {
+ public static void setCsarFiles(Map<String, String> csarFiles) {
CsarValidator.csarFiles = csarFiles;
}
}
diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/FileUtil.java b/csarvalidation/src/main/java/org/onap/validation/csar/FileUtil.java
index f7471bd..a488ed3 100644
--- a/csarvalidation/src/main/java/org/onap/validation/csar/FileUtil.java
+++ b/csarvalidation/src/main/java/org/onap/validation/csar/FileUtil.java
@@ -23,13 +23,15 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipFile;
-
+import java.nio.file.Files;
+import java.nio.file.Paths;
public final class FileUtil {
public static final Logger logger = LoggerFactory.getLogger(FileUtil.class);
private static final int TRY_COUNT = 3;
+ public static final String FILE_IO_STR = "FILE_IO";
private FileUtil() {
@@ -63,18 +65,17 @@ public final class FileUtil {
*/
public static boolean deleteFile(File file) {
String hintInfo = file.isDirectory() ? "dir " : "file ";
- boolean isFileDeleted = file.delete();
- boolean isFileExist = file.exists();
- if (!isFileExist) {
- if (isFileDeleted) {
- logger.info("delete " + hintInfo + file.getAbsolutePath());
+ boolean isFileDeleted=false;
+ try {
+ if (file.exists()) {
+ Files.delete(Paths.get(file.getPath()));
+ logger.info("delete {} {}" ,hintInfo, file.getAbsolutePath());
} else {
- isFileDeleted = true;
- logger.info("file not exist. no need delete " + hintInfo + file.getAbsolutePath());
+ logger.info("file not exist. no need delete {} {}" ,hintInfo , file.getAbsolutePath());
}
- } else {
- logger.info("fail to delete " + hintInfo + file.getAbsolutePath());
-
+ isFileDeleted=true;
+ } catch (IOException e) {
+ logger.error("fail to delete {} {} ", hintInfo, file.getAbsolutePath(), ", exception :: ", e);
}
return isFileDeleted;
}
@@ -92,7 +93,7 @@ public final class FileUtil {
inputStream.close();
}
} catch (Exception e1) {
- logger.error("FILE_IO" + ":" + "close InputStream error! "+ErrorCodes.FILE_IO+ " " + e1.getMessage(), e1);
+ logger.error(FILE_IO_STR + ":" + "close InputStream error! "+ErrorCodes.FILE_IO+ " " + e1.getMessage(), e1);
throw new ValidationException(ErrorCodes.FILE_IO);
}
}
@@ -109,7 +110,7 @@ public final class FileUtil {
outputStream.close();
}
} catch (Exception e1) {
- logger.error("FILE_IO" + ":" + "close OutputStream error! "+ErrorCodes.FILE_IO+ " " + e1.getMessage(), e1);
+ logger.error(FILE_IO_STR + ":" + "close OutputStream error! "+ErrorCodes.FILE_IO+ " " + e1.getMessage(), e1);
throw new ValidationException(ErrorCodes.FILE_IO);
}
}
@@ -120,7 +121,7 @@ public final class FileUtil {
ifs.close();
}
} catch (Exception e1) {
- logger.error("FILE_IO" + ":" + "close OutputStream error! "+ErrorCodes.FILE_IO+ " " + e1.getMessage(), e1);
+ logger.error(FILE_IO_STR + ":" + "close OutputStream error! "+ErrorCodes.FILE_IO+ " " + e1.getMessage(), e1);
throw new ValidationException(ErrorCodes.FILE_IO);
}
}
@@ -172,6 +173,13 @@ public final class FileUtil {
deleteDirectory(f);
}
}
- return file.delete();
+ boolean isFileDeleted=false;
+ try {
+ Files.delete(Paths.get(file.getPath()));
+ isFileDeleted=true;
+ } catch (IOException e) {
+ logger.error("fail to delete {} {} ", file.getAbsolutePath(), ", exception :: ", e);
+ }
+ return isFileDeleted;
}
}
diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java b/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java
index 0ed0bdc..b56e5f2 100644
--- a/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java
+++ b/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java
@@ -31,13 +31,13 @@ public class ValidatorSchemaLoader {
private static final Logger LOG = LoggerFactory.getLogger(ValidatorSchemaLoader.class);
// Map of Schema files
- private Map<String, ?> toscaMeta;
+ private Map<String, Object> toscaMeta;
- private Map<String, ?> csarentryd;
+ private Map<String, Object> csarentryd;
- private Map<String, ?> mrfYaml;
+ private Map<String, Object> mrfYaml;
- private Map<String, ?> mrfManifest;
+ private Map<String, Object> mrfManifest;
// List of configured schemas
static List<String> schemaFileList = new ArrayList<>();
@@ -62,9 +62,9 @@ public class ValidatorSchemaLoader {
}
}
- private Map<String, ?> readYaml(String fileName) {
+ private Map<String, Object> readYaml(String fileName) {
Yaml yaml = new Yaml();
- return (Map<String, ?>)yaml.load(this.getClass().getResourceAsStream(fileName));
+ return (Map<String, Object>)yaml.load(this.getClass().getResourceAsStream(fileName));
}
@SuppressWarnings("unchecked")
@@ -88,19 +88,19 @@ public class ValidatorSchemaLoader {
return true;
}
- public Map<String, ?> getToscaMeta() {
+ public Map<String, Object> getToscaMeta() {
return toscaMeta;
}
- public Map<String, ?> getCsarentryd() {
+ public Map<String, Object> getCsarentryd() {
return csarentryd;
}
- public Map<String, ?> getMrfYaml() {
+ public Map<String, Object> getMrfYaml() {
return mrfYaml;
}
- public Map<String, ?> getMrfManifest() {
+ public Map<String, Object> getMrfManifest() {
return mrfManifest;
}
}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java b/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java
index 11582d1..557b6fd 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java
+++ b/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java
@@ -21,13 +21,13 @@ import java.util.Map;
public class YamlDocument {
- private final Map<String, ?> yaml;
+ private final Map<String, Object> yaml;
- YamlDocument(Map<String, ?> yaml) {
+ YamlDocument(Map<String, Object> yaml) {
this.yaml = yaml;
}
- public Map<String, ?> getYaml() {
+ public Map<String, Object> getYaml() {
return yaml;
}
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/CSARArchiveTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/CSARArchiveTest.java
index 2831532..3b18a1b 100644
--- a/csarvalidation/src/test/java/org/onap/cvc/csar/CSARArchiveTest.java
+++ b/csarvalidation/src/test/java/org/onap/cvc/csar/CSARArchiveTest.java
@@ -20,8 +20,9 @@ import java.io.IOException;
import java.util.Arrays;
import org.junit.Test;
-
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
public class CSARArchiveTest {
@Test
@@ -35,6 +36,7 @@ public class CSARArchiveTest {
csar.init("./src/test/resources/" + csarFileName + ".csar");
csar.parse();
csar.cleanup();
+ assertTrue(csar.getErrors().size() > 0);
System.out.println(csar.getErrors());
} catch (Exception e) {
// TODO Auto-generated catch block
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java
index cf24e53..4f46b74 100644
--- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java
+++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java
@@ -19,11 +19,11 @@ package org.onap.cvc.csar;
import com.google.common.collect.Lists;
import org.junit.Test;
import org.onap.cvc.csar.parser.SourcesParser;
-
import java.util.List;
import java.util.Map;
-
import static org.assertj.core.api.Assertions.assertThat;
+import java.util.Collections;
+import java.util.HashMap;
public class PnfCSARArchiveTest {
@@ -45,7 +45,7 @@ public class PnfCSARArchiveTest {
verifyThatCmsSectionWasSet(manifest);
verifyThatSourcesSectionWasSet(manifest);
verifyThatNonManoArtifactsWereSet(manifest);
- assertThat(pnfCSARArchive.getErrors().size()).isEqualTo(0);
+ assertThat(pnfCSARArchive.getErrors().size()).isZero();
}
}
@@ -76,23 +76,27 @@ public class PnfCSARArchiveTest {
private void verifyThatNonManoArtifactsWereSet(CSARArchive.Manifest manifest) {
Map<String, Map<String, List<String>>> nonManoArtifacts = manifest.getNonMano();
- assertThat(nonManoArtifacts.get("onap_ves_events").get(SOURCE_TAG))
- .isEqualTo(Lists.newArrayList("Artifacts/Events/VES_registration.yml")
- );
- assertThat(nonManoArtifacts.get("onap_pm_dictionary").get(SOURCE_TAG))
- .isEqualTo(Lists.newArrayList("Artifacts/Measurements/PM_Dictionary.yaml")
- );
- assertThat(nonManoArtifacts.get("onap_yang_modules").get(SOURCE_TAG))
- .isEqualTo(Lists.newArrayList("Artifacts/Yang_module/Yang_module.yaml")
- );
- assertThat(nonManoArtifacts.get("onap_others").get(SOURCE_TAG))
- .isEqualTo(Lists.newArrayList(
- "Artifacts/scripts/install.sh",
+ Map<String, List<String>>mapValue1=new HashMap<>();
+ Map<String, List<String>>mapValue2=new HashMap<>();
+ Map<String, List<String>>mapValue3=new HashMap<>();
+ Map<String, List<String>>mapValue4=new HashMap<>();
+
+ mapValue1.put("", Collections.singletonList(""));
+ mapValue1.put(SOURCE_TAG,Lists.newArrayList("Artifacts/Events/VES_registration.yml"));
+ mapValue2.put("", Collections.singletonList(""));
+ mapValue2.put(SOURCE_TAG,Lists.newArrayList("Artifacts/Measurements/PM_Dictionary.yaml"));
+ mapValue3.put("", Collections.singletonList(""));
+ mapValue3.put(SOURCE_TAG,Lists.newArrayList("Artifacts/Yang_module/Yang_module.yaml"));
+ mapValue4.put("", Collections.singletonList(""));
+ mapValue4.put(SOURCE_TAG,Lists.newArrayList
+ ("Artifacts/scripts/install.sh",
"Artifacts/Informational/user_guide.txt",
"Artifacts/Other/installation_guide.txt",
- "Artifacts/Other/review_log.txt"
- )
- );
+ "Artifacts/Other/review_log.txt"));
+ assertThat(nonManoArtifacts).containsEntry("onap_ves_events",mapValue1);
+ assertThat(nonManoArtifacts).containsEntry("onap_pm_dictionary",mapValue2);
+ assertThat(nonManoArtifacts).containsEntry("onap_yang_modules",mapValue3);
+ assertThat(nonManoArtifacts).containsEntry("onap_others",mapValue4);
}
} \ No newline at end of file
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java
index a708f47..5749a73 100644
--- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java
+++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java
@@ -25,6 +25,8 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
+import java.util.Collections;
+import java.util.HashMap;
import static org.assertj.core.api.Assertions.assertThat;
@@ -48,7 +50,7 @@ public class PnfManifestParserTest {
assertThat(metadata.getProviderId()).isEqualTo("Ericsson");
assertThat(metadata.getPackageVersion()).isEqualTo("1.0");
assertThat(metadata.getReleaseDateTime()).isEqualTo("2019-01-14T11:25:00+00:00");
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
@@ -64,7 +66,7 @@ public class PnfManifestParserTest {
new SourcesParser.Source("scripts/install.sh", "SHA-256", "d0e7828293355a07c2dccaaa765c80b507e60e6167067c950dc2e6b0da0dbd8b"),
new SourcesParser.Source("https://www.vendor_org.com/MRF/v4.1/scripts/scale/scale.sh", "SHA-256", "36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165")
);
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
@@ -81,7 +83,7 @@ public class PnfManifestParserTest {
new SourcesParser.Source("some_file.sh", "", ""),
new SourcesParser.Source("scripts/install.sh", "", "d0e7828293355a07c2dccaaa765c80b507e60e6167067c950dc2e6b0da0dbd8b"),
new SourcesParser.Source("https://www.vendor_org.com/MRF/v4.1/scripts/scale/scale.sh", "SHA-256", ""));
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
@@ -90,25 +92,28 @@ public class PnfManifestParserTest {
Pair<Map<String, Map<String, List<String>>>, List<CSARArchive.CSARError>> mapListPair = pnfManifestParser.fetchNonManoArtifacts().get();
Map<String, Map<String, List<String>>> nonManoArtifacts = mapListPair.getKey();
List<CSARArchive.CSARError> errors = mapListPair.getValue();
-
- assertThat(nonManoArtifacts.get("onap_ves_events").get("source"))
- .isEqualTo(Lists.newArrayList("Artifacts/Events/VES_registration.yml")
- );
- assertThat(nonManoArtifacts.get("onap_pm_dictionary").get("source"))
- .isEqualTo(Lists.newArrayList("Artifacts/Measurements/PM_Dictionary.yaml")
- );
- assertThat(nonManoArtifacts.get("onap_yang_module").get("source"))
- .isEqualTo(Lists.newArrayList("Artifacts/Yang_module/Yang_module.yaml")
- );
- assertThat(nonManoArtifacts.get("onap_others").get("source"))
- .isEqualTo(Lists.newArrayList(
- "Artifacts/scripts/install.sh",
+ Map<String, List<String>>mapValue1=new HashMap<>();
+ Map<String, List<String>>mapValue2=new HashMap<>();
+ Map<String, List<String>>mapValue3=new HashMap<>();
+ Map<String, List<String>>mapValue4=new HashMap<>();
+
+ mapValue1.put("", Collections.singletonList(""));
+ mapValue1.put("source",Lists.newArrayList("Artifacts/Events/VES_registration.yml"));
+ mapValue2.put("", Collections.singletonList(""));
+ mapValue2.put("source",Lists.newArrayList("Artifacts/Measurements/PM_Dictionary.yaml"));
+ mapValue3.put("", Collections.singletonList(""));
+ mapValue3.put("source",Lists.newArrayList("Artifacts/Yang_module/Yang_module.yaml"));
+ mapValue4.put("", Collections.singletonList(""));
+ mapValue4.put("source",Lists.newArrayList
+ ("Artifacts/scripts/install.sh",
"Artifacts/Informational/user_guide.txt",
"Artifacts/Other/installation_guide.txt",
- "Artifacts/Other/review_log.txt"
- )
- );
- assertThat(errors.size()).isEqualTo(0);
+ "Artifacts/Other/review_log.txt"));
+ assertThat(nonManoArtifacts).containsEntry("onap_ves_events",mapValue1);
+ assertThat(nonManoArtifacts).containsEntry("onap_pm_dictionary",mapValue2);
+ assertThat(nonManoArtifacts).containsEntry("onap_yang_module",mapValue3);
+ assertThat(nonManoArtifacts).containsEntry("onap_others",mapValue4);
+ assertThat(errors.size()).isZero();
}
@@ -154,7 +159,7 @@ public class PnfManifestParserTest {
"HhE7UbSCHDlDDgrOosJkbuI4UCX/njXrU2ukXbrWz/FjH84Mek039z+w4M6fBnl5"+
"4xuyO1o65LlKHoxwnRH9lQ=="
);
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
@Test
@@ -214,6 +219,6 @@ public class PnfManifestParserTest {
new SourcesParser.Source("Artifacts/Other/review_log.txt", "SHA-256", "36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165")
);
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
}
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfMetadataParserTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfMetadataParserTest.java
index c409efc..4a08a5d 100644
--- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfMetadataParserTest.java
+++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfMetadataParserTest.java
@@ -122,7 +122,7 @@ public class PnfMetadataParserTest {
//then
List<CSARArchive.CSARError> errors = data.getRight();
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java
index 388a98f..2cd648a 100644
--- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java
+++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java
@@ -56,7 +56,7 @@ public class PnfNonManoArtifactsParserTest {
pnfManifestParser.fetchNonManoArtifacts();
//then
- assertThat(nonManoArtifacts.isPresent()).isFalse();
+ assertThat(nonManoArtifacts).isNotPresent();
}
@Test
@@ -88,7 +88,7 @@ public class PnfNonManoArtifactsParserTest {
//then
List<CSARArchive.CSARError> errors = data.getRight();
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
}
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/VnfManifestParserTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/VnfManifestParserTest.java
index 91bb6b1..7fa73a7 100644
--- a/csarvalidation/src/test/java/org/onap/cvc/csar/VnfManifestParserTest.java
+++ b/csarvalidation/src/test/java/org/onap/cvc/csar/VnfManifestParserTest.java
@@ -43,7 +43,7 @@ public class VnfManifestParserTest {
CSARArchive.Manifest.Metadata metadata = metadataListPair.getKey();
List<CSARArchive.CSARError> errors = metadataListPair.getValue();
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
assertThat(metadata.getProductName()).isEqualTo(" vCSCF");
assertThat(metadata.getProviderId()).isEqualTo(" ZTE");
assertThat(metadata.getPackageVersion()).isEqualTo(" 1.0");
@@ -64,7 +64,7 @@ public class VnfManifestParserTest {
new SourcesParser.Source("scripts/install.sh", "SHA-256", "d0e7828293355a07c2dccaaa765c80b507e60e6167067c950dc2e6b0da0dbd8b"),
new SourcesParser.Source("https://www.vendor_org.com/MRF/v4.1/scripts/scale/scale.sh", "SHA-256", "36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165")
);
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
@Test
@@ -79,6 +79,6 @@ public class VnfManifestParserTest {
"AQcBoFEET3icc87PK0nNK9ENqSxItVIoSa0o0S/ISczMs1ZIzkgsKk4tsQ0N1nUM" +
"dvb05OXi5XLPLEtViMwvLVLwSE0sKlFIVHAqSk3MBkkBAJv0Fx0="
);
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
}
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR10087IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR10087IntegrationTest.java
index 921e903..2cc739c 100644
--- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR10087IntegrationTest.java
+++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR10087IntegrationTest.java
@@ -63,6 +63,19 @@ public class VTPValidateCSARR10087IntegrationTest {
}
@Test
+ public void testWithoutTOSCAMetaDir() throws Exception {
+ // given
+ configureTestCase(testCase, "pnf/toscaMetaFile.csar", "vtp-validate-csar-r10087.yaml", IS_PNF);
+
+ // when
+ testCase.execute();
+
+ // then
+ List<CSARArchive.CSARError> errors = testCase.getErrors();
+ assertThat(errors.size()).isEqualTo(7);
+ }
+
+ @Test
public void shouldReportThatDefinitionYAMLDoesNotExist() throws Exception {
// given
configureTestCase(testCase, "pnf/r10087/invalidEntryDefinitionsInToscaMeta.csar", "vtp-validate-csar-r10087.yaml", IS_PNF);
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206IntegrationTest.java
index eef9881..3eed6c6 100644
--- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206IntegrationTest.java
+++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206IntegrationTest.java
@@ -59,7 +59,7 @@ public class VTPValidateCSARR130206IntegrationTest {
// then
List<CSARArchive.CSARError> errors = testCase.getErrors();
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
@Test
@@ -77,7 +77,7 @@ public class VTPValidateCSARR130206IntegrationTest {
// then
List<CSARArchive.CSARError> errors = testCase.getErrors();
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
@Test
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java
index d2a7b8a..a10aa91 100644
--- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java
+++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java
@@ -54,7 +54,7 @@ public class VTPValidateCSARR146092IntegrationTest {
// then
final List<CSARError> errors = testCase.getErrors();
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
@Test
@@ -68,7 +68,7 @@ public class VTPValidateCSARR146092IntegrationTest {
// then
final List<CSARError> errors = testCase.getErrors();
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
@Test
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java
index 2835772..2b9b4f4 100644
--- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java
+++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java
@@ -71,7 +71,7 @@ public class VTPValidateCSARR293901IntegrationTest {
// then
List<CSARArchive.CSARError> errors = testCase.getErrors();
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
@Test
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019IntegrationTest.java
index 088eab7..d6d06b3 100644
--- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019IntegrationTest.java
+++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019IntegrationTest.java
@@ -73,7 +73,7 @@ public class VTPValidateCSARR57019IntegrationTest {
// then
List<CSARArchive.CSARError> errors = testCase.getErrors();
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
@Test
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787965IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787965IntegrationTest.java
index 49696e6..33a1754 100644
--- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787965IntegrationTest.java
+++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787965IntegrationTest.java
@@ -76,7 +76,7 @@ public class VTPValidateCSARR787965IntegrationTest {
// then
List<CSARArchive.CSARError> errors = testCase.getErrors();
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
@Test
@@ -111,7 +111,7 @@ public class VTPValidateCSARR787965IntegrationTest {
// then
List<CSARArchive.CSARError> errors = testCase.getErrors();
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
}
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java
index 5ef4e99..ac8f964 100644
--- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java
+++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java
@@ -60,7 +60,7 @@ public class VTPValidateCSARR816745IntegrationTest {
// then
List<CSARArchive.CSARError> errors = testCase.getErrors();
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
@Test
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR972082IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR972082IntegrationTest.java
index b63705b..868fad2 100644
--- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR972082IntegrationTest.java
+++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR972082IntegrationTest.java
@@ -57,7 +57,7 @@ public class VTPValidateCSARR972082IntegrationTest {
// then
final List<CSARError> errors = testCase.getErrors();
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
@Test
@@ -87,7 +87,7 @@ public class VTPValidateCSARR972082IntegrationTest {
// then
final List<CSARError> errors = testCase.getErrors();
- assertThat(errors.size()).isEqualTo(0);
+ assertThat(errors.size()).isZero();
}
@Test
diff --git a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java b/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java
index f9a8d8a..c2856d9 100644
--- a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java
+++ b/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java
@@ -21,7 +21,6 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -35,7 +34,15 @@ import org.junit.Test;
import org.onap.validation.csar.CommonConstants;
import org.onap.validation.csar.CsarValidator;
import org.onap.validation.csar.FileUtil;
-
+import org.onap.validation.csar.ValidationException;
+import org.junit.runner.RunWith;
+import mockit.integration.junit4.JMockit;
+import mockit.Expectations;
+import mockit.Mocked;
+import mockit.Mock;
+import mockit.MockUp;
+
+@RunWith(JMockit.class)
public class CsarValidatorTest {
String regex = "^\\/[a-zA-Z]\\:\\/";
@@ -162,6 +169,18 @@ public class CsarValidatorTest {
assertTrue(true);
}
+ @Test(expected = ValidationException.class)
+ public void testCloseInputStream2( @Mocked InputStream inputStream) throws IOException {
+ new Expectations(){
+ {
+ inputStream.close();
+ result = new IOException();
+ }
+ };
+ FileUtil.closeInputStream(inputStream);
+ assertTrue(true);
+ }
+
@Test
public void testCloseZipFile() throws ZipException, IOException {
File file = new File(sample1);
@@ -170,10 +189,23 @@ public class CsarValidatorTest {
assertTrue(true);
}
- @Test
- public void testCloseFileStream() throws FileNotFoundException {
+ @Test(expected = IOException.class)
+ public void testCloseFileStream() throws IOException {
FileInputStream dir3 = new FileInputStream(sample1);
FileUtil.closeFileStream(dir3);
+ dir3.available();
+
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testCloseFileStream2(@Mocked FileInputStream fileInputStream) throws IOException {
+ new Expectations(){
+ {
+ fileInputStream.close();
+ result = new IOException();
+ }
+ };
+ FileUtil.closeFileStream(fileInputStream);
}
@Test
@@ -186,6 +218,18 @@ public class CsarValidatorTest {
}
};
FileUtil.closeOutputStream(dir4);
+ assertTrue(true);
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testCloseOutptutStream2(@Mocked OutputStream outputStream) throws IOException {
+ new Expectations(){
+ {
+ outputStream.close();
+ result = new IOException();
+ }
+ };
+ FileUtil.closeOutputStream(outputStream);
}
private void testValidateCsarMeta(CsarValidator cv) {
@@ -219,4 +263,53 @@ public class CsarValidatorTest {
String result = CsarValidator.r02454();
assertEquals(true, result == CommonConstants.SUCCESS_STR);
}
+
+ @Test
+ public void testValidateCsar() throws IOException {
+ new MockUp<CsarValidator>(){
+ @Mock
+ public String validateCsarMeta(){
+ return "FAIL";
+ }
+ @Mock
+ public String validateAndScanToscaMeta(){
+ return "SUCCESS";
+ }
+ @Mock
+ public String validateMainService(){
+ return "FAIL";
+ }
+ };
+ String res=CsarValidator.validateCsar();
+ assertEquals("FAIL OR FAIL",res);
+
+ }
+
+ @Test
+ public void testValidateCsar2() throws IOException {
+ new MockUp<CsarValidator>(){
+ @Mock
+ public String validateCsarMeta(){
+ return "SUCCESS";
+ }
+ @Mock
+ public String validateAndScanToscaMeta(){
+ return "FAIL";
+ }
+ @Mock
+ public String validateMainService(){
+ return "SUCCESS";
+ }
+ };
+ String res=CsarValidator.validateCsar();
+ assertEquals("FAIL",res);
+ }
+
+ @Test
+ public void testDeleteDir(){
+ String dstPath = "./dstPathForTest1";
+ File dst = new File(dstPath);
+ dst.mkdir();
+ assertTrue(FileUtil.deleteFile(dstPath));
+ }
}
diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java
index 5641a56..7879d4e 100644
--- a/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java
+++ b/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java
@@ -52,13 +52,13 @@ public class YamlDocumentFactoryTest {
assertThat(document).isNotNull();
assertThat(document.getYaml()).containsKeys("test", "345", "test2", "2.67");
- assertThat(document.getYaml().get("test")).isEqualTo(testList);
+ assertThat(document.getYaml()).containsEntry("test", testList);
assertThat(document.getValue("test")).isEqualTo("[element1, element11]");
assertThat(document.getValue("345")).isEqualTo("element2");
assertThat(document.getValue("test2")).isEqualTo("element3");
- assertThat(document.getYaml().get("2.67")).isEqualTo(testEmptyMap);
+ assertThat(document.getYaml()).containsEntry("2.67", testEmptyMap);
assertThat(document.getValue("2.67")).isEqualTo("{}");
}
diff --git a/csarvalidation/src/test/resources/pnf/toscaMetaFile.csar b/csarvalidation/src/test/resources/pnf/toscaMetaFile.csar
new file mode 100644
index 0000000..9370df9
--- /dev/null
+++ b/csarvalidation/src/test/resources/pnf/toscaMetaFile.csar
Binary files differ