e74643fde91997b702b0a08599ec4537f20bf25f
[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 org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
24 import org.onap.sdc.tosca.parser.config.ConfigurationManager;
25 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
26 import org.onap.sdc.toscaparser.api.common.JToscaValidationIssue;
27 import org.testng.annotations.AfterClass;
28 import org.testng.annotations.BeforeClass;
29 import org.testng.annotations.Test;
30
31 import java.io.IOException;
32 import java.util.List;
33 import java.util.stream.Collectors;
34
35 import static org.testng.Assert.assertEquals;
36
37 public class ToscaParserValidationIssueTest extends SdcToscaParserBasicTest {
38         protected static ConfigurationManager configurationManager = ConfigurationManager.getInstance();
39
40         @BeforeClass
41         public void loadJtoscaValidationIssueConfiguration() throws IOException {
42                 //load the tests dedicated configuration
43                 configurationManager.setJtoscaValidationIssueConfiguration( "jtosca-validation-issue-configuration-test.yaml");
44                 factory.setConfigurationManager(configurationManager);
45         }
46
47         @AfterClass
48         public void loadJtoscaValidationIssueOriginalConfiguration() throws IOException {
49                 //load the tests dedicated configuration
50                 configurationManager.setJtoscaValidationIssueConfiguration("jtosca-validation-issue-configuration.yaml");
51                 factory.setConfigurationManager(configurationManager);
52
53         }
54
55
56         @Test
57         public void testNoValidationIssues() throws SdcToscaParserException {
58                 ISdcCsarHelper rainyCsarHelper = getCsarHelper("csars/service-ServiceFdnt-csar-rainy.csar");//conformance level 3.0
59
60                 //List<JToscaValidationIssue> notAnalyzedReport = factory.getNotAnalyzadExceptions();
61                 //assertEquals( notAnalyzedReport.size(),0);
62                 List<JToscaValidationIssue> warningsReport = factory.getWarningExceptions();
63                 assertEquals( warningsReport.size(),0);
64                 List<JToscaValidationIssue> criticalsReport = factory.getCriticalExceptions();
65                 assertEquals( criticalsReport.size(),0);
66         }
67         @Test
68         public void testGetLowSinceConformanceLevel() throws SdcToscaParserException {
69                 ISdcCsarHelper fdntCsarHelperWithInputs = getCsarHelper("csars/service-NfodService-csar.csar");//conformance level 3.0
70                 //Service level
71
72                 List<JToscaValidationIssue> notAnalyzedReport = factory.getNotAnalyzadExceptions();
73                 assertEquals( notAnalyzedReport.size(),10);
74                 //JE003 high CL 4.0
75                 assertEquals( notAnalyzedReport.stream().filter(n->n.getCode().equals("JE003")).collect(Collectors.toList()).size(), 2);
76                 assertEquals( notAnalyzedReport.stream().filter(n->n.getCode().equals("JE235")).collect(Collectors.toList()).size(), 7);
77                 assertEquals( notAnalyzedReport.stream().filter(n->n.getCode().equals("JE236")).collect(Collectors.toList()).size(), 1);
78                 List<JToscaValidationIssue> warningsReport = factory.getWarningExceptions();
79                 assertEquals( warningsReport.size(),14);
80                 assertEquals( warningsReport.stream().filter(w->w.getCode().equals("JE006")).collect(Collectors.toList()).size(), 13);
81                 //JE004 low CL 2.0
82                 assertEquals( warningsReport.stream().filter(w->w.getCode().equals("JE004")).collect(Collectors.toList()).size(), 1);
83                 List<JToscaValidationIssue> criticalsReport = factory.getCriticalExceptions();
84                 assertEquals( criticalsReport.size(),0);
85         }
86
87         @Test(expectedExceptions = SdcToscaParserException.class)
88         public void testCriticalIssueThrowsSdcToscaParserException() throws SdcToscaParserException {
89                 getCsarHelper("csars/service-Nfod2images-csar.csar");//conformance level 4.0
90         }
91
92         @Test
93         public void testMultiSinceConformanceLevelIssues() {
94                 try {
95                         ISdcCsarHelper Nfod2images = getCsarHelper("csars/service-Nfod2images-csar.csar");//conformance level 4.0
96                 } catch (SdcToscaParserException e) {
97                         System.out.println("SdcToscaParserException is caught here - this is WAD in this specific test.");
98                 }
99                 List<JToscaValidationIssue> notAnalyzedReport = factory.getNotAnalyzadExceptions();
100                 assertEquals(3, notAnalyzedReport.size());
101                 List<JToscaValidationIssue> warningsReport = factory.getWarningExceptions();
102                 assertEquals( 0, warningsReport.size());
103                 List<JToscaValidationIssue> criticalsReport = factory.getCriticalExceptions();
104                 assertEquals( 22, criticalsReport.size());
105                 //JE006 multy values sinceCsarConformanceLevel
106                 assertEquals( criticalsReport.stream().filter(c->c.getCode().equals("JE006")).collect
107                                 (Collectors.toList()).size(), 18);
108                 assertEquals( criticalsReport.stream().filter(c->c.getCode().equals("JE003")).collect
109                                 (Collectors.toList()).size(), 4);
110         }
111
112
113 }