[SDC-29] Amdocs OnBoard 1707 initial commit.
[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 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;
29
30 import java.util.List;
31 import java.util.Map;
32
33 /**
34  * @author Avrahamg
35  * @since October 06, 2016
36  */
37 public class ContrailValidatorTest {
38
39   private Validator validator = new ContrailValidator();
40
41   @Test
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' ",
47         "first.yaml", 2);
48   }
49
50   @Test
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' ",
56         "first.yaml", 3);
57   }
58
59   @Test
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' ",
65         "first.yaml", 2);
66     ;
67   }
68
69   @Test
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",
75         2);
76   }
77
78
79   @Test
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]",
85         "first.yaml", 1);
86     ;
87   }
88
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);
96   }
97
98
99 }