summaryrefslogtreecommitdiffstats
path: root/sdc-tosca-parser
diff options
context:
space:
mode:
authorPavel Aharoni <pa0916@att.com>2017-05-24 13:23:12 +0300
committerPavel Aharoni <pa0916@att.com>2017-05-24 13:23:12 +0300
commit9e430cd9d4722c3e614c8a2fd822cff1604be1f2 (patch)
tree565af8e16f17ae46bc901093aded0e19ac1b4c1f /sdc-tosca-parser
parent67a7f1d57b6b1d7c07dc3da4db51a387f90fef28 (diff)
[SDC-24] error handling
Change-Id: Iac97052fab32f638d4cf52b094caad31f6d76902 Signed-off-by: Pavel Aharoni <pa0916@att.com>
Diffstat (limited to 'sdc-tosca-parser')
-rw-r--r--sdc-tosca-parser/pom.xml4
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java83
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorConfiguration.java46
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java49
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/SdcToscaParserErrors.java31
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java26
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java48
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java29
-rw-r--r--sdc-tosca-parser/src/main/resources/config/error-configuration.yaml18
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java (renamed from sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/BasicTest.java)15
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java12
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java143
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java2
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java2
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java2
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java23
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java2
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java2
-rw-r--r--sdc-tosca-parser/src/test/resources/config/error-configuration.yaml18
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/csar-invalid-zip.zip2
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-entry-definition-not-defined.csarbin0 -> 45157 bytes
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-invalid-conformence-level.csarbin0 -> 45194 bytes
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-invalid-input-args.csarbin0 -> 106698 bytes
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-invalid-yaml-content-meta.csarbin0 -> 45198 bytes
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-missing-entry-definition.csarbin0 -> 42668 bytes
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-missing-meta-file.csarbin0 -> 44893 bytes
26 files changed, 485 insertions, 72 deletions
diff --git a/sdc-tosca-parser/pom.xml b/sdc-tosca-parser/pom.xml
index d6b0bb8..c56b471 100644
--- a/sdc-tosca-parser/pom.xml
+++ b/sdc-tosca-parser/pom.xml
@@ -6,7 +6,7 @@
<parent>
<groupId>org.openecomp.sdc.sdc-distribution-client</groupId>
<artifactId>sdc-main-distribution-client</artifactId>
- <version>1.1.13-SNAPSHOT</version>
+ <version>1.1.14-SNAPSHOT</version>
</parent>
<artifactId>sdc-tosca-parser</artifactId>
@@ -78,7 +78,7 @@
<dependency>
<groupId>org.openecomp.sdc.sdc-distribution-client</groupId>
<artifactId>jtosca</artifactId>
- <version>0.1.6-SNAPSHOT</version>
+ <version>0.1.7-SNAPSHOT</version>
</dependency>
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java
index 7cd9ed2..e83e6aa 100644
--- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java
@@ -8,18 +8,44 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
public class ConfigurationManager {
private static Logger log = LoggerFactory.getLogger(ConfigurationManager.class.getName());
- private static final String CONFIGURATION_FILE = "config/configuration.yaml";
+ private static final String CONFIGURATION_DIR = "config/";
private static volatile ConfigurationManager instance;
- private Configuration configuration;
+// private Configuration configuration;
+// private ErrorConfiguration errorConfiguration;
+
+ Map<String, Object> configurations = new HashMap<String, Object>();
+
+
+ private ConfigurationManager() {
+ initialConfigObjectsFromFiles();
+ }
+
+ private void initialConfigObjectsFromFiles() {
+ loadConfigurationClass(ErrorConfiguration.class);
+ loadConfigurationClass(Configuration.class);
+ }
- private ConfigurationManager() {
- URL url = Resources.getResource(CONFIGURATION_FILE);
+ private <T> void loadConfigurationClass(Class<T> clazz) {
+ T object = getObjectFromYaml(clazz);
+ configurations.put(clazz.getSimpleName(), object);
+ }
+
+
+ public <T> T getObjectFromYaml(Class<T> className) {
+
+
+ String configFileName = calculateFileName(className);
+
+ URL url = Resources.getResource(CONFIGURATION_DIR + configFileName);
String configFileContents = null;
try {
configFileContents = Resources.toString(url, Charsets.UTF_8);
@@ -27,17 +53,16 @@ public class ConfigurationManager {
log.error("ConfigurationManager - Failed to load configuration file");
}
YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
- this.configuration = yamlToObjectConverter.convertFromString(configFileContents, Configuration.class);
- }
+ T object = yamlToObjectConverter.convertFromString(configFileContents, className);
- public Configuration getConfiguration() {
- return configuration;
+ return object;
}
+
public static ConfigurationManager getInstance() {
if (instance == null) {
- synchronized (ConfigurationManager.class){
- if (instance == null){
+ synchronized (ConfigurationManager.class) {
+ if (instance == null) {
instance = new ConfigurationManager();
}
}
@@ -45,7 +70,41 @@ public class ConfigurationManager {
return instance;
}
- public void setConfiguration(Configuration configuration) {
- this.configuration = configuration;
+ private static <T> String calculateFileName(Class<T> className) {
+
+ String[] words = className.getSimpleName().split("(?=\\p{Upper})");
+
+ StringBuilder builder = new StringBuilder();
+
+ // There cannot be a null value returned from "split" - words != null is
+ // redundant
+ // if (words != null) {
+ boolean isFirst = true;
+ for (int i = 0; i < words.length; i++) {
+
+ String word = words[i];
+ if (word != null && !word.isEmpty()) {
+ if (!isFirst) {
+ builder.append("-");
+ } else {
+ isFirst = false;
+ }
+ builder.append(words[i].toLowerCase());
+ }
+ }
+ return builder.toString() + ".yaml";
+
+ /*
+ * } else { return className.getSimpleName().toLowerCase() + Constants.YAML_SUFFIX; }
+ */
+
+ }
+
+ public ErrorConfiguration getErrorConfiguration() {
+ return (ErrorConfiguration) configurations.get((ErrorConfiguration.class.getSimpleName()));
+ }
+
+ public Configuration getConfiguration() {
+ return (Configuration) configurations.get((Configuration.class.getSimpleName()));
}
}
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorConfiguration.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorConfiguration.java
new file mode 100644
index 0000000..59e8c6d
--- /dev/null
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorConfiguration.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.tosca.parser.config;
+
+import java.util.Map;
+
+public class ErrorConfiguration {
+
+ private Map<String, ErrorInfo> errors;
+
+ public Map<String, ErrorInfo> getErrors() {
+ return errors;
+ }
+
+ public void setErrors(Map<String, ErrorInfo> errors) {
+ this.errors = errors;
+ }
+
+ public ErrorInfo getErrorInfo(String key) {
+ ErrorInfo clone = null;
+ ErrorInfo other = errors.get(key);
+ if (other != null) {
+ clone = new ErrorInfo();
+ clone.cloneData(other);
+ }
+ return clone;
+ }
+}
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java
new file mode 100644
index 0000000..01df115
--- /dev/null
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.tosca.parser.config;
+
+public class ErrorInfo {
+
+ private String code;
+ private String message;
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public void cloneData(ErrorInfo other) {
+ this.code = other.getCode();
+ this.message = other.getMessage();
+ }
+
+}
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/SdcToscaParserErrors.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/SdcToscaParserErrors.java
new file mode 100644
index 0000000..ce84a9c
--- /dev/null
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/SdcToscaParserErrors.java
@@ -0,0 +1,31 @@
+package org.openecomp.sdc.tosca.parser.config;
+
+import java.util.EnumMap;
+import java.util.Map;
+
+import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes;
+
+public enum SdcToscaParserErrors {
+
+ BAD_FORMAT, CONFORMANCE_LEVEL_ERROR, FILE_NOT_FOUND, GENERAL_ERROR;
+
+ private static final Map<JToscaErrorCodes, SdcToscaParserErrors> JTOSCA_ERRORS =
+ new EnumMap<JToscaErrorCodes, SdcToscaParserErrors>(JToscaErrorCodes.class) {{
+
+ put(JToscaErrorCodes.GENERAL_ERROR, GENERAL_ERROR);
+
+ put(JToscaErrorCodes.PATH_NOT_VALID, FILE_NOT_FOUND);
+ //CSAR contents problems
+ put(JToscaErrorCodes.MISSING_META_FILE, BAD_FORMAT);
+ put(JToscaErrorCodes.INVALID_META_YAML_CONTENT, BAD_FORMAT);
+ put(JToscaErrorCodes.ENTRY_DEFINITION_NOT_DEFINED, BAD_FORMAT);
+ put(JToscaErrorCodes.MISSING_ENTRY_DEFINITION_FILE, BAD_FORMAT);
+ put(JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR, BAD_FORMAT);
+ put(JToscaErrorCodes.INVALID_CSAR_FORMAT, BAD_FORMAT);
+ }};
+
+ public static SdcToscaParserErrors getSdcErrorByJToscaError(JToscaErrorCodes jToscaErrorCode) {
+ return JTOSCA_ERRORS.get(jToscaErrorCode);
+ }
+
+}
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java
index f41141f..a7fd99d 100644
--- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java
@@ -1,12 +1,20 @@
package org.openecomp.sdc.tosca.parser.exceptions;
-public class SdcToscaParserException extends Exception{
- /**
- *
- */
- private static final long serialVersionUID = 626014844866501196L;
-
- public SdcToscaParserException(String string) {
- super(string);
- }
+public class SdcToscaParserException extends Exception {
+
+ private static final long serialVersionUID = 626014844866501196L;
+ private String code;
+
+ public SdcToscaParserException(String string, String code) {
+ super(string);
+ this.code = code;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
}
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
index df1d470..c53dcec 100644
--- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
@@ -22,6 +22,8 @@ package org.openecomp.sdc.tosca.parser.impl;
import java.util.*;
import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
@@ -49,7 +51,8 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
private static final String PATH_DELIMITER = "#";
private static final String PREFIX = "port_";
- private static final String[] SUFFIX = new String[]{"_network_role_tag", "_ip_requirements", "_subnetpoolid"};
+ Pattern SUFFIX = Pattern.compile("(_network_role_tag|_ip_requirements|_subnetpoolid)$");
+// private static final String[] SUFFIX = new String[]{"_network_role_tag", "_ip_requirements", "_subnetpoolid"};
private ToscaTemplate toscaTemplate;
private static Logger log = LoggerFactory.getLogger(SdcCsarHelperImpl.class.getName());
@@ -91,6 +94,11 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
public Map<String, Map<String, Object>> getCpPropertiesFromVfc(NodeTemplate vfc) {
+ if (vfc == null) {
+ log.error("getCpPropertiesFromVfc - vfc is null");
+ return new HashMap<>();
+ }
+
List<String> paths = new ArrayList<>();
paths.add("network_role_tag");
paths.add("ip_requirements#ip_count_required#count");
@@ -102,22 +110,25 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
Map<String, Map<String, Object>> cps = new HashMap<>();
- for (Map.Entry<String, Property> entry : props.entrySet()) {
- String fullCpName = entry.getKey();
-
- if (fullCpName.startsWith(PREFIX) &&
- Arrays.stream(SUFFIX).parallel().anyMatch(fullCpName::endsWith))
- {
- //this is CP - get all it's properties according to paths list
- String cpName = fullCpName.replaceAll("^("+PREFIX+")", "").replaceAll("("+String.join("|", SUFFIX)+")$", "");
- cps.put(cpName, new HashMap<>());
- for (String path: paths) {
- String fullPathToSearch = PREFIX + cpName + "_" + path;
- String value = getNodeTemplatePropertyLeafValue(vfc, fullPathToSearch);
- if (value != null) {
- value = StringUtils.stripStart(value, "[");
- value = StringUtils.stripEnd(value, "]");
- cps.get(cpName).put(path, value);
+ if (props != null) {
+ for (Map.Entry<String, Property> entry : props.entrySet()) {
+ String fullCpName = entry.getKey();
+ Matcher matcher = SUFFIX.matcher(fullCpName);
+
+ if (fullCpName.startsWith(PREFIX) && matcher.find()) {
+ //this is CP - get all it's properties according to paths list
+ String cpName = fullCpName.replaceAll("^(" + PREFIX + ")", "").replaceAll(matcher.group(1), "");
+
+ List<String> propertiesToSearch = paths.stream().filter(i -> i.contains(StringUtils.stripStart(matcher.group(1), "_"))).collect(Collectors.toList());
+ for (String item : propertiesToSearch) {
+ String fullPathToSearch = PREFIX + cpName + "_" + item;
+ Object value = getNodeTemplatePropertyAsObject(vfc, fullPathToSearch);
+ if (value != null) {
+ if (!cps.containsKey(cpName))
+ cps.put(cpName, new HashMap<>());
+ }
+
+ cps.get(cpName).put(item, value);
}
}
}
@@ -569,7 +580,8 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
Object current = property.getValue();
return iterateProcessPath(1, current, split);
}
- log.error("processProperties - property not found");
+ String propName = (split != null && split.length > 0 ? split[0] : null);
+ log.error("processProperties - property {} not found", propName);
return null;
}
}
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
index 14c332c..2ddde1f 100644
--- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
@@ -2,17 +2,18 @@ package org.openecomp.sdc.tosca.parser.impl;
import org.openecomp.sdc.tosca.parser.api.ConformanceLevel;
import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
-import org.openecomp.sdc.tosca.parser.config.Configuration;
-import org.openecomp.sdc.tosca.parser.config.ConfigurationManager;
+import org.openecomp.sdc.tosca.parser.config.*;
import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.openecomp.sdc.tosca.parser.utils.GeneralUtility;
import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
import org.openecomp.sdc.toscaparser.api.common.JToscaException;
+import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes;
public class SdcToscaParserFactory {
private static volatile SdcToscaParserFactory instance;
private static Configuration configuration;
+ private static ErrorConfiguration errorConfiguration;
private SdcToscaParserFactory() {
@@ -28,6 +29,7 @@ public class SdcToscaParserFactory {
if (instance == null) {
instance = new SdcToscaParserFactory();
configuration = ConfigurationManager.getInstance().getConfiguration();
+ errorConfiguration = ConfigurationManager.getInstance().getErrorConfiguration();
}
}
}
@@ -40,11 +42,15 @@ public class SdcToscaParserFactory {
* @param csarPath - the absolute path to CSAR file.
* @return ISdcCsarHelper object.
* @throws SdcToscaParserException - in case the path or CSAR are invalid.
- * @throws JToscaException - in case the path or CSAR are invalid.
*/
- public ISdcCsarHelper getSdcCsarHelper(String csarPath) throws JToscaException, SdcToscaParserException {
+ public ISdcCsarHelper getSdcCsarHelper(String csarPath) throws SdcToscaParserException {
synchronized (SdcToscaParserFactory.class) {
- ToscaTemplate tosca = new ToscaTemplate(csarPath, null, true, null);
+ ToscaTemplate tosca = null;
+ try {
+ tosca = new ToscaTemplate(csarPath, null, true, null);
+ } catch (JToscaException e) {
+ throwSdcToscaParserException(e);
+ }
SdcCsarHelperImpl sdcCsarHelperImpl = new SdcCsarHelperImpl(tosca);
validateCsarVersion(sdcCsarHelperImpl.getConformanceLevel());
return sdcCsarHelperImpl;
@@ -57,11 +63,20 @@ public class SdcToscaParserFactory {
String maxVersion = level.getMaxVersion();
if (cSarVersion != null) {
if ((GeneralUtility.conformanceLevelCompare(cSarVersion, minVersion) < 0) || (GeneralUtility.conformanceLevelCompare(cSarVersion, maxVersion) > 0)) {
- throw new SdcToscaParserException("Model is not supported. Parser supports versions " + minVersion + " to " + maxVersion);
+ throwConformanceLevelException(minVersion, maxVersion);
}
} else {
- throw new SdcToscaParserException("Model is not supported. Parser supports versions " + minVersion + " to " + maxVersion);
+ throwConformanceLevelException(minVersion, maxVersion);
}
}
+ private void throwConformanceLevelException(String minVersion, String maxVersion) throws SdcToscaParserException {
+ ErrorInfo errorInfo = errorConfiguration.getErrorInfo(SdcToscaParserErrors.CONFORMANCE_LEVEL_ERROR.toString());
+ throw new SdcToscaParserException(String.format(errorInfo.getMessage(), minVersion, maxVersion), errorInfo.getCode());
+ }
+
+ private void throwSdcToscaParserException(JToscaException e) throws SdcToscaParserException {
+ ErrorInfo errorInfo = errorConfiguration.getErrorInfo(SdcToscaParserErrors.getSdcErrorByJToscaError(JToscaErrorCodes.getByCode(e.getCode())).toString());
+ throw new SdcToscaParserException(errorInfo.getMessage(), errorInfo.getCode());
+ }
} \ No newline at end of file
diff --git a/sdc-tosca-parser/src/main/resources/config/error-configuration.yaml b/sdc-tosca-parser/src/main/resources/config/error-configuration.yaml
new file mode 100644
index 0000000..3febd33
--- /dev/null
+++ b/sdc-tosca-parser/src/main/resources/config/error-configuration.yaml
@@ -0,0 +1,18 @@
+# Errors
+errors:
+ FILE_NOT_FOUND: {
+ code: TP0001,
+ message: "Error: CSAR file not found."
+ }
+ BAD_FORMAT: {
+ code: TP0002,
+ message: "Error: CSAR file bad format. Check the log for details."
+ }
+ CONFORMANCE_LEVEL_ERROR: {
+ code: TP0003,
+ message: "Error: CSAR version is unsupported. Parser supports versions %s to %s."
+ }
+ GENERAL_ERROR: {
+ code: TP0004,
+ message: "Error: an unexpected internal error occured."
+ } \ No newline at end of file
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/BasicTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java
index 0eb58f8..6746df7 100644
--- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/BasicTest.java
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java
@@ -11,13 +11,13 @@ import java.util.Map;
import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.common.JToscaException;
+import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
-public abstract class BasicTest {
+public abstract class SdcToscaParserBasicTest {
public static final String VF_CUSTOMIZATION_UUID = "56179cd8-de4a-4c38-919b-bbc4452d2d73";
static SdcToscaParserFactory factory;
@@ -97,18 +97,11 @@ public abstract class BasicTest {
};
};
- private static ISdcCsarHelper getCsarHelper(String path) throws JToscaException, IOException, SdcToscaParserException {
+ protected static ISdcCsarHelper getCsarHelper(String path) throws SdcToscaParserException {
System.out.println("Parsing CSAR "+path+"...");
- String fileStr1 = BasicTest.class.getClassLoader().getResource(path).getFile();
+ String fileStr1 = SdcToscaParserBasicTest.class.getClassLoader().getResource(path).getFile();
File file1 = new File(fileStr1);
ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath());
- List<String> exceptionReport = ExceptionCollector.getCriticalsReport();
- if (!exceptionReport.isEmpty()){
- System.out.println("TOSCA Errors found in CSAR - failing the tests...");
- System.out.println(exceptionReport.toString());
- ExceptionCollector.clear();
- //throw new SdcToscaParserException("CSAR didn't pass validation");
- }
return sdcCsarHelper;
}
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java
index 0e6387d..8c96303 100644
--- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java
@@ -1,5 +1,6 @@
package org.openecomp.sdc.impl;
+import org.openecomp.sdc.tosca.parser.config.ErrorConfiguration;
import org.testng.annotations.Test;
import org.openecomp.sdc.tosca.parser.config.Configuration;
import org.openecomp.sdc.tosca.parser.config.ConfigurationManager;
@@ -8,7 +9,7 @@ import java.io.IOException;
import static org.testng.Assert.assertNotNull;
-public class ToscaParserConfigurationTest extends BasicTest {
+public class ToscaParserConfigurationTest extends SdcToscaParserBasicTest {
@Test
public void testConfigurationConformanceLevel() throws IOException {
@@ -18,4 +19,13 @@ public class ToscaParserConfigurationTest extends BasicTest {
assertNotNull(config.getConformanceLevel().getMaxVersion());
assertNotNull(config.getConformanceLevel().getMinVersion());
}
+
+
+ @Test
+ public void testErrorConfigurations() throws IOException {
+ ErrorConfiguration errorConfig = ConfigurationManager.getInstance().getErrorConfiguration();
+ assertNotNull(errorConfig);
+ assertNotNull(errorConfig.getErrors());
+ }
+
}
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java
new file mode 100644
index 0000000..8451a58
--- /dev/null
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java
@@ -0,0 +1,143 @@
+package org.openecomp.sdc.impl;
+
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+import java.io.File;
+
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes;
+
+
+/*put(JToscaErrorCodes.GENERAL_ERROR, GENERAL_ERROR);
+
+put(JToscaErrorCodes.PATH_NOT_VALID, FILE_NOT_FOUND);
+//CSAR contents problems
+put(JToscaErrorCodes.MISSING_META_FILE, BAD_FORMAT);
+put(JToscaErrorCodes.INVALID_META_YAML_CONTENT, BAD_FORMAT);
+put(JToscaErrorCodes.ENTRY_DEFINITION_NOT_DEFINED, BAD_FORMAT);
+put(JToscaErrorCodes.MISSING_ENTRY_DEFINITION_FILE, BAD_FORMAT);
+put(JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR, BAD_FORMAT);
+
+ MISSING_META_FILE("JT1001"),
+/* INVALID_META_YAML_CONTENT("JT1002"),
+/* ENTRY_DEFINITION_NOT_DEFINED("JT1003"),
+/* MISSING_ENTRY_DEFINITION_FILE("JT1004"),
+/* GENERAL_ERROR("JT1005"),
+/* PATH_NOT_VALID("JT1006"),
+/* CSAR_TOSCA_VALIDATION_ERROR("JT1007");
+
+*/
+
+/*
+ *
+ * # Errors
+errors:
+ FILE_NOT_FOUND: {
+ code: TP0001,
+ message: "Error: CSAR file not found."
+ }
+ BAD_FORMAT: {
+ code: TP0002,
+ message: "Error: CSAR file bad format. Check the log for details."
+ }
+ CONFORMANCE_LEVEL_ERROR: {
+ code: TP0003,
+ message: "Error: CSAR version is unsupported. Parser supports versions %s to %s."
+ }
+ GENERAL_ERROR: {
+ code: TP0004,
+ message: "Error: an unexpected internal error occured."
+ }
+ *
+ */
+
+public class ToscaParserErrorHandlingTest extends SdcToscaParserBasicTest {
+
+
+ @Test
+ public void testMissingMetadata(){
+ String csarPath = "csars/service-missing-meta-file.csar";
+ String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
+ File file = new File(fileLocationString);
+ Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
+ testThrowable(captureThrowable, "TP0002");
+ }
+
+
+ @Test
+ public void testInvalidYamlContentMeta(){
+ String csarPath = "csars/service-invalid-yaml-content-meta.csar";
+ String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
+ File file = new File(fileLocationString);
+ Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
+ testThrowable(captureThrowable, "TP0002");
+ }
+
+ @Test
+ public void testEntryDefinitionNotDefined(){
+ String csarPath = "csars/service-entry-definition-not-defined.csar";
+ String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
+ File file = new File(fileLocationString);
+ Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
+ testThrowable(captureThrowable, "TP0002");
+ }
+
+ @Test
+ public void testMissingEntryDefinitionFile(){
+ String csarPath = "csars/service-missing-entry-definition.csar";
+ String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
+ File file = new File(fileLocationString);
+ Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
+ testThrowable(captureThrowable, "TP0002");
+ }
+
+ //@Test - PA - there are currently no critical erros in JTosca
+ public void tesValidationError(){
+ String csarPath = "csars/service-invalid-input-args.csar";
+ String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
+ File file = new File(fileLocationString);
+ Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
+ testThrowable(captureThrowable, "TP0002");
+ }
+
+ @Test
+ public void testInValidConformanceLevelError(){
+ String csarPath = "csars/service-invalid-conformence-level.csar";
+ String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
+ File file = new File(fileLocationString);
+ Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
+ testThrowable(captureThrowable, "TP0003");
+ }
+
+ @Test
+ public void testFileNotFound(){
+ Throwable captureThrowable = captureThrowable("csars/XXX.csar");
+ testThrowable(captureThrowable, "TP0001");
+ }
+
+ @Test
+ public void testInvalidCsarFormat(){
+ String csarPath = "csars/csar-invalid-zip.zip";
+ String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
+ File file = new File(fileLocationString);
+ Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
+ testThrowable(captureThrowable, "TP0002");
+ }
+
+ private static void testThrowable(Throwable captureThrowable, String expectedCode) {
+ assertNotNull(captureThrowable);
+ assertTrue(captureThrowable instanceof SdcToscaParserException, "Error thrown is of type "+captureThrowable.getClass().getSimpleName());
+ assertEquals(((SdcToscaParserException)captureThrowable).getCode(), expectedCode);
+ }
+
+ public static Throwable captureThrowable(String csarPath) {
+ Throwable result = null;
+ try {
+ factory.getSdcCsarHelper(csarPath);
+ } catch( Throwable throwable ) {
+ result = throwable;
+ }
+ return result;
+ }
+}
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java
index b903867..9f349ae 100644
--- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java
@@ -5,7 +5,7 @@ import org.openecomp.sdc.tosca.parser.utils.GeneralUtility;
import static org.testng.Assert.assertTrue;
-public class ToscaParserGeneralUtilTest extends BasicTest {
+public class ToscaParserGeneralUtilTest extends SdcToscaParserBasicTest {
@Test
public void testVersionCompare() {
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java
index 58e967a..01c888f 100644
--- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java
@@ -10,7 +10,7 @@ import java.util.List;
import static org.testng.Assert.*;
-public class ToscaParserGroupTest extends BasicTest{
+public class ToscaParserGroupTest extends SdcToscaParserBasicTest{
//region getVfModulesByVf
@Test
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java
index 802d5b8..4fbc9c3 100644
--- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java
@@ -7,7 +7,7 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
-public class ToscaParserMetadataTest extends BasicTest {
+public class ToscaParserMetadataTest extends SdcToscaParserBasicTest {
//region getServiceMetadata
@Test
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java
index c9215a2..dd895c3 100644
--- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java
@@ -14,7 +14,7 @@ import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.openecomp.sdc.toscaparser.api.Group;
import org.openecomp.sdc.toscaparser.api.NodeTemplate;
-public class ToscaParserNodeTemplateTest extends BasicTest {
+public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
//region getServiceVfList
@Test
@@ -311,13 +311,22 @@ public class ToscaParserNodeTemplateTest extends BasicTest {
List<NodeTemplate> vfcs = complexCps.getVfcListByVf(VF_CUSTOMIZATION_UUID);
Map<String, Map<String, Object>> cps = complexCps.getCpPropertiesFromVfc(vfcs.get(0));
- assertEquals("1", cps.get("port_fe1_sigtran").get("ip_requirements#ip_count_required#count"));
- assertEquals("true", cps.get("port_fe1_sigtran").get("ip_requirements#dhcp_enabled"));
- assertEquals("4", cps.get("port_fe1_sigtran").get("ip_requirements#ip_version"));
+ assertEquals(5, cps.size());
- assertEquals("2", cps.get("port_fe_cluster").get("ip_requirements#ip_count_required#count"));
- assertEquals("true", cps.get("port_fe_cluster").get("ip_requirements#dhcp_enabled"));
- assertEquals("4", cps.get("port_fe_cluster").get("ip_requirements#ip_version"));
+ assertEquals(1, cps.get("port_fe1_sigtran").get("ip_requirements#ip_count_required#count"));
+ assertEquals(true, cps.get("port_fe1_sigtran").get("ip_requirements#dhcp_enabled"));
+ assertEquals(4, cps.get("port_fe1_sigtran").get("ip_requirements#ip_version"));
+
+ assertEquals(2, cps.get("port_fe_cluster").get("ip_requirements#ip_count_required#count"));
+ assertEquals(true, cps.get("port_fe_cluster").get("ip_requirements#dhcp_enabled"));
+ assertEquals(4, cps.get("port_fe_cluster").get("ip_requirements#ip_version"));
+ }
+
+ @Test
+ public void testGetCpPropertiesFromVfcForNullVFC() {
+ Map<String, Map<String, Object>> cps = complexCps.getCpPropertiesFromVfc(null);
+ assertNotNull(cps);
+ assertEquals(0, cps.size());
}
//endregion
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java
index 0599dcc..0b172f5 100644
--- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java
@@ -9,7 +9,7 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
-public class ToscaParserServiceInputTest extends BasicTest {
+public class ToscaParserServiceInputTest extends SdcToscaParserBasicTest {
//region getServiceInputs
@Test
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java
index c61f465..6461a92 100644
--- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java
@@ -20,7 +20,7 @@ import org.openecomp.sdc.toscaparser.api.Property;
//import static org.junit.Assert.assertEquals;
//import static org.junit.Assert.assertNull;
-public class ToscaParserSubsMappingsTest extends BasicTest {
+public class ToscaParserSubsMappingsTest extends SdcToscaParserBasicTest {
//region getServiceSubstitutionMappingsTypeName
@Test
diff --git a/sdc-tosca-parser/src/test/resources/config/error-configuration.yaml b/sdc-tosca-parser/src/test/resources/config/error-configuration.yaml
new file mode 100644
index 0000000..3febd33
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/config/error-configuration.yaml
@@ -0,0 +1,18 @@
+# Errors
+errors:
+ FILE_NOT_FOUND: {
+ code: TP0001,
+ message: "Error: CSAR file not found."
+ }
+ BAD_FORMAT: {
+ code: TP0002,
+ message: "Error: CSAR file bad format. Check the log for details."
+ }
+ CONFORMANCE_LEVEL_ERROR: {
+ code: TP0003,
+ message: "Error: CSAR version is unsupported. Parser supports versions %s to %s."
+ }
+ GENERAL_ERROR: {
+ code: TP0004,
+ message: "Error: an unexpected internal error occured."
+ } \ No newline at end of file
diff --git a/sdc-tosca-parser/src/test/resources/csars/csar-invalid-zip.zip b/sdc-tosca-parser/src/test/resources/csars/csar-invalid-zip.zip
new file mode 100644
index 0000000..04de055
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/csar-invalid-zip.zip
@@ -0,0 +1,2 @@
+SDC-TOSCA-Meta-File-Version: 1.0
+SDC-TOSCA-Definitions-Version: 2.0
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-entry-definition-not-defined.csar b/sdc-tosca-parser/src/test/resources/csars/service-entry-definition-not-defined.csar
new file mode 100644
index 0000000..47e65b6
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-entry-definition-not-defined.csar
Binary files differ
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-invalid-conformence-level.csar b/sdc-tosca-parser/src/test/resources/csars/service-invalid-conformence-level.csar
new file mode 100644
index 0000000..12621f0
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-invalid-conformence-level.csar
Binary files differ
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-invalid-input-args.csar b/sdc-tosca-parser/src/test/resources/csars/service-invalid-input-args.csar
new file mode 100644
index 0000000..22f9970
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-invalid-input-args.csar
Binary files differ
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-invalid-yaml-content-meta.csar b/sdc-tosca-parser/src/test/resources/csars/service-invalid-yaml-content-meta.csar
new file mode 100644
index 0000000..f77af6f
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-invalid-yaml-content-meta.csar
Binary files differ
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-missing-entry-definition.csar b/sdc-tosca-parser/src/test/resources/csars/service-missing-entry-definition.csar
new file mode 100644
index 0000000..8fd1962
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-missing-entry-definition.csar
Binary files differ
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-missing-meta-file.csar b/sdc-tosca-parser/src/test/resources/csars/service-missing-meta-file.csar
new file mode 100644
index 0000000..79348db
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-missing-meta-file.csar
Binary files differ