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 / ForbiddenResourceGuideLineValidatorTest.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.validation.impl.validators;
18
19 import java.io.IOException;
20 import java.util.Map;
21 import org.junit.Assert;
22 import org.junit.BeforeClass;
23 import org.junit.Test;
24 import org.openecomp.core.validation.types.MessageContainer;
25 import org.openecomp.sdc.validation.util.ValidationTestUtil;
26
27 /**
28  * Created by TALIO on 2/16/2017.
29  */
30 public class ForbiddenResourceGuideLineValidatorTest {
31
32   private static final String RESOURCE_PATH = "/org/openecomp/validation/validators" +
33       "/guideLineValidator/heatFloatingIpResourceType";
34   private static String mockConfigFileName =
35       "/org/openecomp/validation/configuration/mock_resource_validator_configuration.json";
36
37   private static ForbiddenResourceGuideLineValidator forbiddenResourceGuideLineValidator = new
38       ForbiddenResourceGuideLineValidator();
39
40   @BeforeClass
41   public static void init() throws IOException {
42     Map<String, Object> resourcesMap = ValidationTestUtil.getResourceMap(mockConfigFileName);
43
44     Map<String, Object> resourceBaseValidatorMap =
45         (Map<String, Object>) resourcesMap.get("forbiddenResourceGuideLineValidator");
46     Map<String, Object> properties =
47         (Map<String, Object>) resourceBaseValidatorMap.get("properties");
48
49     forbiddenResourceGuideLineValidator.init(properties);
50   }
51
52   @Test
53   public void testFloatingIpResourceType() {
54     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
55         forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/positive");
56     Assert.assertNotNull(messages);
57     Assert.assertEquals(messages.size(), 0);
58
59
60     messages = ValidationTestUtil.testValidator(forbiddenResourceGuideLineValidator,
61         RESOURCE_PATH + "/negative");
62     Assert.assertNotNull(messages);
63     Assert.assertEquals(messages.size(), 1);
64     Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
65     Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
66         "WARNING: [FRG2]: OS::Neutron::FloatingIP is in use, Resource ID [FSB2]");
67   }
68   @Test
69   public void testParseException(){
70     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
71         forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/parseException");
72     Assert.assertEquals(messages.size(), 1);
73     Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
74     Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
75         "ERROR: [FRG3]: Invalid HEAT format problem - [while scanning for the next token\n" +
76             "found character '\\t(TAB)' that cannot start any token. (Do not use \\t(TAB) " +
77             "for indentation)\n" + " in 'reader', line 5, column 1:\n" +
78             "    \t\t\tresources:\n" +
79             "    ^\n" +
80             "]");
81   }
82
83   @Test
84   public void testInvalidResourceType(){
85     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
86         forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/TestInvalidResourceType");
87     Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
88         "WARNING: [FRG1]: A resource has an invalid or unsupported type - null, " +
89             "Resource ID [FSB2]");
90   }
91 }