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