2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.sdc.impl;
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;
31 import java.io.IOException;
32 import java.util.List;
33 import java.util.stream.Collectors;
35 import static org.testng.Assert.assertEquals;
37 public class ToscaParserValidationIssueTest extends SdcToscaParserBasicTest {
38 protected static ConfigurationManager configurationManager = ConfigurationManager.getInstance();
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);
48 public void loadJtoscaValidationIssueOriginalConfiguration() throws IOException {
49 //load the tests dedicated configuration
50 configurationManager.setJtoscaValidationIssueConfiguration("jtosca-validation-issue-configuration.yaml");
51 factory.setConfigurationManager(configurationManager);
57 public void testNoValidationIssues() throws SdcToscaParserException {
58 ISdcCsarHelper rainyCsarHelper = getCsarHelper("csars/service-ServiceFdnt-csar-rainy.csar");//conformance level 3.0
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);
68 public void testGetLowSinceConformanceLevel() throws SdcToscaParserException {
69 ISdcCsarHelper fdntCsarHelperWithInputs = getCsarHelper("csars/service-NfodService-csar.csar");//conformance level 3.0
72 List<JToscaValidationIssue> notAnalyzedReport = factory.getNotAnalyzadExceptions();
73 assertEquals( notAnalyzedReport.size(),10);
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);
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);
87 @Test(expectedExceptions = SdcToscaParserException.class)
88 public void testCriticalIssueThrowsSdcToscaParserException() throws SdcToscaParserException {
89 getCsarHelper("csars/service-Nfod2images-csar.csar");//conformance level 4.0
93 public void testMultiSinceConformanceLevelIssues() {
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.");
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);