Migrate TestNG to Junit5
[sdc/sdc-tosca.git] / sdc-tosca / src / test / java / org / onap / sdc / impl / ToscaParserValidationIssueTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * sdc-tosca
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdc.impl;
22
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.junit.jupiter.api.Assertions.assertThrows;
25
26 import java.io.IOException;
27 import java.util.List;
28 import java.util.stream.Collectors;
29 import org.junit.jupiter.api.AfterAll;
30 import org.junit.jupiter.api.BeforeAll;
31 import org.junit.jupiter.api.Test;
32 import org.junit.jupiter.api.extension.ExtendWith;
33 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
34 import org.onap.sdc.tosca.parser.config.ConfigurationManager;
35 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
36 import org.onap.sdc.toscaparser.api.common.JToscaValidationIssue;
37
38 @ExtendWith({SdcToscaParserBasicTest.class})
39 class ToscaParserValidationIssueTest extends SdcToscaParserBasicTest {
40
41     protected static ConfigurationManager configurationManager = ConfigurationManager.getInstance();
42
43     @BeforeAll
44     public static void loadJtoscaValidationIssueConfiguration() throws IOException {
45         //load the tests dedicated configuration
46         configurationManager.setJtoscaValidationIssueConfiguration("jtosca-validation-issue-configuration-test.yaml");
47         factory.setConfigurationManager(configurationManager);
48     }
49
50     @AfterAll
51     public static void loadJtoscaValidationIssueOriginalConfiguration() throws IOException {
52         //load the tests dedicated configuration
53         configurationManager.setJtoscaValidationIssueConfiguration("jtosca-validation-issue-configuration.yaml");
54         factory.setConfigurationManager(configurationManager);
55
56     }
57
58     @Test
59         public void testNoValidationIssues() throws SdcToscaParserException {
60         ISdcCsarHelper rainyCsarHelper = getCsarHelper("csars/service-ServiceFdnt-csar-rainy.csar");//conformance level 3.0
61
62         //List<JToscaValidationIssue> notAnalyzedReport = factory.getNotAnalyzadExceptions();
63         //assertEquals( notAnalyzedReport.size(),0);
64         List<JToscaValidationIssue> warningsReport = factory.getWarningExceptions();
65         assertEquals(warningsReport.size(), 0);
66         List<JToscaValidationIssue> criticalsReport = factory.getCriticalExceptions();
67         assertEquals(criticalsReport.size(), 0);
68     }
69
70     @Test
71         public void testGetLowSinceConformanceLevel() throws SdcToscaParserException {
72         ISdcCsarHelper fdntCsarHelperWithInputs = getCsarHelper("csars/service-NfodService-csar.csar");//conformance level 3.0
73         //Service level
74
75         List<JToscaValidationIssue> notAnalyzedReport = factory.getNotAnalyzadExceptions();
76         assertEquals(notAnalyzedReport.size(), 10);
77         //JE003 high CL 4.0
78         assertEquals(notAnalyzedReport.stream().filter(n -> n.getCode().equals("JE003")).collect(Collectors.toList()).size(), 2);
79         assertEquals(notAnalyzedReport.stream().filter(n -> n.getCode().equals("JE235")).collect(Collectors.toList()).size(), 7);
80         assertEquals(notAnalyzedReport.stream().filter(n -> n.getCode().equals("JE236")).collect(Collectors.toList()).size(), 1);
81         List<JToscaValidationIssue> warningsReport = factory.getWarningExceptions();
82         assertEquals(warningsReport.size(), 14);
83         assertEquals(warningsReport.stream().filter(w -> w.getCode().equals("JE006")).collect(Collectors.toList()).size(), 13);
84         //JE004 low CL 2.0
85         assertEquals(warningsReport.stream().filter(w -> w.getCode().equals("JE004")).collect(Collectors.toList()).size(), 1);
86         List<JToscaValidationIssue> criticalsReport = factory.getCriticalExceptions();
87         assertEquals(criticalsReport.size(), 0);
88     }
89
90     @Test
91     void testCriticalIssueThrowsSdcToscaParserException() {
92         assertThrows(SdcToscaParserException.class, () -> {
93             getCsarHelper("csars/service-Nfod2images-csar.csar");//conformance level 4.0
94         });
95     }
96
97     @Test
98         public void testMultiSinceConformanceLevelIssues() {
99         try {
100             ISdcCsarHelper Nfod2images = getCsarHelper("csars/service-Nfod2images-csar.csar");//conformance level 4.0
101         } catch (SdcToscaParserException e) {
102             System.out.println("SdcToscaParserException is caught here - this is WAD in this specific test.");
103         }
104         List<JToscaValidationIssue> notAnalyzedReport = factory.getNotAnalyzadExceptions();
105         assertEquals(3, notAnalyzedReport.size());
106         List<JToscaValidationIssue> warningsReport = factory.getWarningExceptions();
107         assertEquals(0, warningsReport.size());
108         List<JToscaValidationIssue> criticalsReport = factory.getCriticalExceptions();
109         assertEquals(22, criticalsReport.size());
110         //JE006 multy values sinceCsarConformanceLevel
111         assertEquals(criticalsReport.stream().filter(c -> c.getCode().equals("JE006")).collect
112             (Collectors.toList()).size(), 18);
113         assertEquals(criticalsReport.stream().filter(c -> c.getCode().equals("JE003")).collect
114             (Collectors.toList()).size(), 4);
115     }
116
117
118 }