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;
13 public class ToscaParserErrorHandlingTest extends SdcToscaParserBasicTest {
17 public void testMissingMetadata(){
18 String csarPath = "csars/service-missing-meta-file.csar";
19 String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
20 File file = new File(fileLocationString);
21 Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
22 testThrowable(captureThrowable, "TP0002");
27 public void testInvalidYamlContentMeta(){
28 String csarPath = "csars/service-invalid-yaml-content-meta.csar";
29 String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
30 File file = new File(fileLocationString);
31 Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
32 testThrowable(captureThrowable, "TP0002");
36 public void testEntryDefinitionNotDefined(){
37 String csarPath = "csars/service-entry-definition-not-defined.csar";
38 String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
39 File file = new File(fileLocationString);
40 Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
41 testThrowable(captureThrowable, "TP0002");
45 public void testMissingEntryDefinitionFile(){
46 String csarPath = "csars/service-missing-entry-definition.csar";
47 String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
48 File file = new File(fileLocationString);
49 Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
50 testThrowable(captureThrowable, "TP0002");
53 //@Test - PA - there are currently no critical erros in JTosca
54 public void tesValidationError(){
55 String csarPath = "csars/service-invalid-input-args.csar";
56 String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
57 File file = new File(fileLocationString);
58 Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
59 testThrowable(captureThrowable, "TP0002");
63 public void testInValidMinConformanceLevelError(){
64 String csarPath = "csars/service-invalid-conformence-level.csar";
65 String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
66 File file = new File(fileLocationString);
67 Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
68 testThrowable(captureThrowable, "TP0003");
72 public void testIgnoreMaxConformanceLevelNoError(){
73 String csarPath = "csars/service-max-conformence-level.csar";
74 //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.
75 String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
76 File file = new File(fileLocationString);
77 Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
78 assertNull(captureThrowable);
82 public void testFileNotFound(){
83 Throwable captureThrowable = captureThrowable("csars/XXX.csar");
84 testThrowable(captureThrowable, "TP0001");
88 public void testInvalidCsarFormat(){
89 String csarPath = "csars/csar-invalid-zip.zip";
90 String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
91 File file = new File(fileLocationString);
92 Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
93 testThrowable(captureThrowable, "TP0002");
96 private static void testThrowable(Throwable captureThrowable, String expectedCode) {
97 assertNotNull(captureThrowable);
98 assertTrue(captureThrowable instanceof SdcToscaParserException, "Error thrown is of type "+captureThrowable.getClass().getSimpleName());
99 assertEquals(((SdcToscaParserException)captureThrowable).getCode(), expectedCode);
102 public static Throwable captureThrowable(String csarPath) {
103 Throwable result = null;
105 factory.getSdcCsarHelper(csarPath);
106 } catch( Throwable throwable ) {