1 package org.onap.sdc.impl;
3 import org.testng.annotations.Test;
4 import static org.testng.Assert.*;
8 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
9 import org.onap.sdc.toscaparser.api.utils.JToscaErrorCodes;
12 /*put(JToscaErrorCodes.GENERAL_ERROR, GENERAL_ERROR);
14 put(JToscaErrorCodes.PATH_NOT_VALID, FILE_NOT_FOUND);
15 //CSAR contents problems
16 put(JToscaErrorCodes.MISSING_META_FILE, BAD_FORMAT);
17 put(JToscaErrorCodes.INVALID_META_YAML_CONTENT, BAD_FORMAT);
18 put(JToscaErrorCodes.ENTRY_DEFINITION_NOT_DEFINED, BAD_FORMAT);
19 put(JToscaErrorCodes.MISSING_ENTRY_DEFINITION_FILE, BAD_FORMAT);
20 put(JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR, BAD_FORMAT);
22 MISSING_META_FILE("JT1001"),
23 /* INVALID_META_YAML_CONTENT("JT1002"),
24 /* ENTRY_DEFINITION_NOT_DEFINED("JT1003"),
25 /* MISSING_ENTRY_DEFINITION_FILE("JT1004"),
26 /* GENERAL_ERROR("JT1005"),
27 /* PATH_NOT_VALID("JT1006"),
28 /* CSAR_TOSCA_VALIDATION_ERROR("JT1007");
38 message: "Error: CSAR file not found."
42 message: "Error: CSAR file bad format. Check the log for details."
44 CONFORMANCE_LEVEL_ERROR: {
46 message: "Error: CSAR version is unsupported. Parser supports versions %s to %s."
50 message: "Error: an unexpected internal error occured."
55 public class ToscaParserErrorHandlingTest extends SdcToscaParserBasicTest {
59 public void testMissingMetadata(){
60 String csarPath = "csars/service-missing-meta-file.csar";
61 String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
62 File file = new File(fileLocationString);
63 Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
64 testThrowable(captureThrowable, "TP0002");
69 public void testInvalidYamlContentMeta(){
70 String csarPath = "csars/service-invalid-yaml-content-meta.csar";
71 String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
72 File file = new File(fileLocationString);
73 Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
74 testThrowable(captureThrowable, "TP0002");
78 public void testEntryDefinitionNotDefined(){
79 String csarPath = "csars/service-entry-definition-not-defined.csar";
80 String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
81 File file = new File(fileLocationString);
82 Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
83 testThrowable(captureThrowable, "TP0002");
87 public void testMissingEntryDefinitionFile(){
88 String csarPath = "csars/service-missing-entry-definition.csar";
89 String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
90 File file = new File(fileLocationString);
91 Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
92 testThrowable(captureThrowable, "TP0002");
95 //@Test - PA - there are currently no critical erros in JTosca
96 public void tesValidationError(){
97 String csarPath = "csars/service-invalid-input-args.csar";
98 String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
99 File file = new File(fileLocationString);
100 Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
101 testThrowable(captureThrowable, "TP0002");
105 public void testInValidConformanceLevelError(){
106 String csarPath = "csars/service-invalid-conformence-level.csar";
107 String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
108 File file = new File(fileLocationString);
109 Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
110 testThrowable(captureThrowable, "TP0003");
114 public void testFileNotFound(){
115 Throwable captureThrowable = captureThrowable("csars/XXX.csar");
116 testThrowable(captureThrowable, "TP0001");
120 public void testInvalidCsarFormat(){
121 String csarPath = "csars/csar-invalid-zip.zip";
122 String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
123 File file = new File(fileLocationString);
124 Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
125 testThrowable(captureThrowable, "TP0002");
128 private static void testThrowable(Throwable captureThrowable, String expectedCode) {
129 assertNotNull(captureThrowable);
130 assertTrue(captureThrowable instanceof SdcToscaParserException, "Error thrown is of type "+captureThrowable.getClass().getSimpleName());
131 assertEquals(((SdcToscaParserException)captureThrowable).getCode(), expectedCode);
134 public static Throwable captureThrowable(String csarPath) {
135 Throwable result = null;
137 factory.getSdcCsarHelper(csarPath);
138 } catch( Throwable throwable ) {