import org.onap.sdc.tosca.parser.config.SdcToscaParserErrors;
import org.onap.sdc.tosca.parser.utils.GeneralUtility;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
-import org.onap.sdc.tosca.parser.config.*;
import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.onap.sdc.toscaparser.api.ToscaTemplate;
import org.onap.sdc.toscaparser.api.common.JToscaValidationIssue;
private void validateCsarVersion(String cSarVersion) throws SdcToscaParserException {
ConformanceLevel level = configurationManager.getConfiguration().getConformanceLevel();
String minVersion = level.getMinVersion();
- String maxVersion = level.getMaxVersion();
if (cSarVersion != null) {
- if ((GeneralUtility.conformanceLevelCompare(cSarVersion, minVersion) < 0) || (GeneralUtility.conformanceLevelCompare(cSarVersion, maxVersion) > 0)) {
- throwConformanceLevelException(minVersion, maxVersion);
+ if (GeneralUtility.conformanceLevelCompare(cSarVersion, minVersion) < 0) {
+ throwConformanceLevelException(minVersion);
}
} else {
- throwConformanceLevelException(minVersion, maxVersion);
+ throwConformanceLevelException(minVersion);
}
}
}
return false;
}
- private void throwConformanceLevelException(String minVersion, String maxVersion) throws SdcToscaParserException {
+ private void throwConformanceLevelException(String minVersion) throws SdcToscaParserException {
ErrorInfo errorInfo = configurationManager.getErrorConfiguration().getErrorInfo(SdcToscaParserErrors.CONFORMANCE_LEVEL_ERROR.toString());
- throw new SdcToscaParserException(String.format(errorInfo.getMessage(), minVersion, maxVersion), errorInfo.getCode());
+ throw new SdcToscaParserException(String.format(errorInfo.getMessage(), minVersion), errorInfo.getCode());
}
private void throwSdcToscaParserException(JToscaException e) throws SdcToscaParserException {
import org.onap.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 testInValidConformanceLevelError(){
+ public void testInValidMinConformanceLevelError(){
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 testIgnoreMaxConformanceLevelNoError(){
+ String csarPath = "csars/service-max-conformence-level.csar";
+ //TODO: Currently, the conformentce level of the csar for this test is 99 (hard coded). Consider to add ability to replace the configuration in run time.
+ String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
+ File file = new File(fileLocationString);
+ Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
+ assertNull(captureThrowable);
+ }
@Test
public void testFileNotFound(){