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.sdc.validation.Validator;
24 import org.openecomp.core.validation.types.MessageContainer;
25 import org.openecomp.sdc.datatypes.error.ErrorMessage;
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 Validator validator = new ContrailValidator();
42 public void testWarningMessageExistWhenConrailV1AndV2ResourcesCollidesInSameHeatFile() {
43 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
44 "/org/openecomp/validation/validators/contrailvalidatorresources/collidesinsameheatfile/");
45 validateMessage(messages,
46 "WARNING: HEAT Package includes both Contrail 2 and Contrail 3 resources. Contrail 2 resources can be found in file 'first.yaml' , resources :'jsa_net1' . Contrail 3 resources can be found in file 'first.yaml' , resources :'jsa_net2' ",
51 public void testWarningMessageExistWhenConrailV1AndV2ResourcesCollidesInDifferentHeatFiles() {
52 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
53 "/org/openecomp/validation/validators/contrailvalidatorresources/collidesindifferentheatfiles/");
54 validateMessage(messages,
55 "WARNING: HEAT Package includes both Contrail 2 and Contrail 3 resources. Contrail 2 resources can be found in file 'first.yaml' , resources :'jsa_net1', 'jsa_net3' . Contrail 3 resources can be found in file 'second.yaml' , resources :'jsa_net2', 'jsa_net4', file 'first.yaml' , resources :'jsa_net5' ",
60 public void testWarningMessageNotExistWhenConrailV1AndV2ResourcesCollidesInNonHeatFile() {
61 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
62 "/org/openecomp/validation/validators/contrailvalidatorresources/collidesinnontheatfiles/");
63 validateMessage(messages,
64 "WARNING: HEAT Package includes both Contrail 2 and Contrail 3 resources. Contrail 2 resources can be found in file 'first.yaml' , resources :'jsa_net1' . Contrail 3 resources can be found in file 'second.yaml' , resources :'jsa_net2' ",
70 public void testWarningMessageNotExistWhenOnlyConrailV1Resources() {
71 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
72 "/org/openecomp/validation/validators/contrailvalidatorresources/notcollides/");
73 validateMessage(messages,
74 "WARNING: Contrail 2.x deprecated resource is in use, Resource ID [jsa_net1]", "first.yaml",
80 public void testWarningMessageOnResourceWithContrailType() {
81 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
82 "/org/openecomp/validation/validators/contrailvalidatorresources/validatenocontrailresource/");
83 validateMessage(messages,
84 "WARNING: Contrail 2.x deprecated resource is in use, Resource ID [template_NetworkPolicy]",
89 private void validateMessage(Map<String, MessageContainer> messages, String expectedMessage,
90 String fileNameWithErrorToCheck, int sizeOfFileMessageList) {
91 Assert.assertEquals(messages.size(), 1);
92 List<ErrorMessage> errorMessageList =
93 messages.get(fileNameWithErrorToCheck).getErrorMessageList();
94 Assert.assertEquals(errorMessageList.size(), sizeOfFileMessageList);
95 Assert.assertEquals(errorMessageList.get(0).getMessage(), expectedMessage);