2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.sdc.validation.impl.validators;
23 import org.openecomp.core.validation.types.MessageContainer;
24 import org.openecomp.sdc.datatypes.error.ErrorMessage;
25 import org.openecomp.sdc.validation.Validator;
26 import org.openecomp.sdc.validation.util.ValidationTestUtil;
27 import org.testng.Assert;
28 import org.testng.annotations.Test;
30 import java.util.List;
35 * @since October 06, 2016
37 public class ContrailValidatorTest {
39 private static final String RESOURCE_PATH = "/org/openecomp/validation/validators/contrailvalidatorresources";
40 private Validator validator = new ContrailValidator();
43 public void testWarningMessageExistWhenConrailV1AndV2ResourcesCollidesInSameHeatFile() {
44 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
45 RESOURCE_PATH + "/collidesinsameheatfile/");
46 validateMessage(messages,
47 "WARNING: [CTL2]: HEAT Package includes both Contrail 2 and Contrail 3 " +
48 "resources. Contrail 2 resources can be found in file 'first.yaml' , resources :" +
49 "'jsa_net1' . Contrail 3 resources can be found in file 'first.yaml' , resources :" +
55 public void testParseException(){
56 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
57 RESOURCE_PATH + "/parseException/");
58 validateMessage(messages,
59 "ERROR: [CTL4]: Invalid HEAT format problem - [while scanning for the next " +
60 "token\n" + "found character '\\t(TAB)' that cannot start any token. " +
61 "(Do not use \\t(TAB) for indentation)\n" +
62 " in 'reader', line 10, column 1:\n" +
63 " \t\t\tresources:\n" +
71 public void testWarningMessageExistWhenConrailV1AndV2ResourcesCollidesInDifferentHeatFiles() {
72 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
73 RESOURCE_PATH + "/collidesindifferentheatfiles/");
74 validateMessage(messages,
75 "WARNING: [CTL2]: HEAT Package includes both Contrail 2 and Contrail 3 " +
76 "resources. Contrail 2 resources can be found in file 'first.yaml' , resources :" +
77 "'jsa_net1', 'jsa_net3' . Contrail 3 resources can be found in file 'second.yaml' , " +
78 "resources :'jsa_net2', 'jsa_net4', file 'first.yaml' , resources :'jsa_net5' ",
83 public void testWarningMessageNotExistWhenConrailV1AndV2ResourcesCollidesInNonHeatFile() {
84 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
85 RESOURCE_PATH + "/collidesinnontheatfiles/");
86 validateMessage(messages,
87 "WARNING: [CTL2]: HEAT Package includes both Contrail 2 and Contrail 3 " +
88 "resources. Contrail 2 resources can be found in file 'first.yaml' , resources :" +
89 "'jsa_net1' . Contrail 3 resources can be found in file 'second.yaml' , " +
90 "resources :'jsa_net2' ",
96 public void testWarningMessageNotExistWhenOnlyConrailV1Resources() {
97 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
98 RESOURCE_PATH + "/notcollides/");
99 validateMessage(messages,
100 "WARNING: [CTL3]: Contrail 2.x deprecated resource is in use, " +
101 "Resource ID [jsa_net1]", "first.yaml",
107 public void testWarningMessageOnResourceWithContrailType() {
108 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
109 RESOURCE_PATH + "/validatenocontrailresource/");
110 validateMessage(messages,
111 "WARNING: [CTL3]: Contrail 2.x deprecated resource is in use, " +
112 "Resource ID [template_NetworkPolicy]",
117 public void testInvalidHeatStructure(){
118 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
119 RESOURCE_PATH + "/invalidHeatStructure/");
120 validateMessage(messages,
121 "ERROR: [CTL1]: Invalid HEAT format problem - [The file 'first.yaml' " +
127 public void testInvalidHeatStructuredueToParsingError(){
128 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
129 RESOURCE_PATH + "/invalidHeatStructure/");
130 validateMessage(messages,
131 "ERROR: [CTL1]: Invalid HEAT format problem - [The file 'first.yaml' " +
137 private void validateMessage(Map<String, MessageContainer> messages, String expectedMessage,
138 String fileNameWithErrorToCheck, int sizeOfFileMessageList) {
139 Assert.assertEquals(messages.size(), 1);
140 List<ErrorMessage> errorMessageList =
141 messages.get(fileNameWithErrorToCheck).getErrorMessageList();
142 Assert.assertEquals(errorMessageList.size(), sizeOfFileMessageList);
143 Assert.assertEquals(errorMessageList.get(0).getMessage(), expectedMessage);