Sorted out unit-test libraries in onboarding
[sdc.git] / openecomp-be / lib / openecomp-sdc-validation-lib / openecomp-sdc-validation-impl / src / test / java / org / openecomp / sdc / validation / impl / validators / ContrailValidatorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.validation.impl.validators;
22
23 import java.util.List;
24 import java.util.Map;
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;
31
32 /**
33  * @author Avrahamg
34  * @since October 06, 2016
35  */
36 public class ContrailValidatorTest {
37
38   private static final String RESOURCE_PATH = "/org/openecomp/validation/validators/contrailvalidatorresources";
39   private Validator validator = new ContrailValidator();
40
41   @Test
42   public void testWarningMessageExistWhenConrailV1AndV2ResourcesCollidesInSameHeatFile() {
43     Map<String, MessageContainer> messages = 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 :" +
49             "'jsa_net2' ",
50         "first.yaml", 2);
51   }
52
53   @Test
54   public void testParseException(){
55     Map<String, MessageContainer> messages = 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" +
63             "    ^\n" +
64             "]",
65         "first.yaml", 1);
66
67   }
68
69   @Test
70   public void testWarningMessageExistWhenConrailV1AndV2ResourcesCollidesInDifferentHeatFiles() {
71     Map<String, MessageContainer> messages = 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' ",
78         "first.yaml", 3);
79   }
80
81   @Test
82   public void testWarningMessageNotExistWhenConrailV1AndV2ResourcesCollidesInNonHeatFile() {
83     Map<String, MessageContainer> messages = 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' ",
90         "first.yaml", 2);
91     ;
92   }
93
94   @Test
95   public void testWarningMessageNotExistWhenOnlyConrailV1Resources() {
96     Map<String, MessageContainer> messages = 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",
101         2);
102   }
103
104
105   @Test
106   public void testWarningMessageOnResourceWithContrailType() {
107     Map<String, MessageContainer> messages = 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]",
112         "first.yaml", 1);
113   }
114
115   @Test
116   public void testInvalidHeatStructure(){
117     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
118         RESOURCE_PATH + "/invalidHeatStructure/");
119     validateMessage(messages,
120         "ERROR: [CTL1]: Invalid HEAT format problem - [The file 'first.yaml' " +
121             "has no content]",
122         "first.yaml", 1);
123   }
124
125   @Test
126   public void testInvalidHeatStructuredueToParsingError(){
127     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
128         RESOURCE_PATH + "/invalidHeatStructure/");
129     validateMessage(messages,
130         "ERROR: [CTL1]: Invalid HEAT format problem - [The file 'first.yaml' " +
131             "has no content]",
132         "first.yaml", 1);
133   }
134
135
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);
143   }
144
145
146 }