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 static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.junit.jupiter.api.Assertions.assertThrows;
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;
38 @ExtendWith({SdcToscaParserBasicTest.class})
39 class ToscaParserValidationIssueTest extends SdcToscaParserBasicTest {
41 protected static ConfigurationManager configurationManager = ConfigurationManager.getInstance();
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);
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);
59 public void testNoValidationIssues() throws SdcToscaParserException {
60 ISdcCsarHelper rainyCsarHelper = getCsarHelper("csars/service-ServiceFdnt-csar-rainy.csar");//conformance level 3.0
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);
71 public void testGetLowSinceConformanceLevel() throws SdcToscaParserException {
72 ISdcCsarHelper fdntCsarHelperWithInputs = getCsarHelper("csars/service-NfodService-csar.csar");//conformance level 3.0
75 List<JToscaValidationIssue> notAnalyzedReport = factory.getNotAnalyzadExceptions();
76 assertEquals(notAnalyzedReport.size(), 10);
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);
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);
91 void testCriticalIssueThrowsSdcToscaParserException() {
92 assertThrows(SdcToscaParserException.class, () -> {
93 getCsarHelper("csars/service-Nfod2images-csar.csar");//conformance level 4.0
98 public void testMultiSinceConformanceLevelIssues() {
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.");
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);