1 package org.openecomp.sdc.validation.impl.validators;
3 import org.openecomp.core.validation.types.MessageContainer;
4 import org.openecomp.sdc.validation.util.ValidationTestUtil;
5 import org.testng.Assert;
6 import org.testng.annotations.BeforeClass;
7 import org.testng.annotations.Test;
9 import java.io.IOException;
13 * Created by TALIO on 2/16/2017.
15 public class ForbiddenResourceGuideLineValidatorTest {
17 private static final String RESOURCE_PATH = "/org/openecomp/validation/validators" +
18 "/guideLineValidator/heatFloatingIpResourceType";
19 private static String mockConfigFileName =
20 "/org/openecomp/validation/configuration/mock_resource_validator_configuration.json";
22 ForbiddenResourceGuideLineValidator forbiddenResourceGuideLineValidator = new
23 ForbiddenResourceGuideLineValidator();
26 public void init() throws IOException {
27 Map<String, Object> resourcesMap = ValidationTestUtil.getResourceMap(mockConfigFileName);
29 Map<String, Object> resourceBaseValidatorMap =
30 (Map<String, Object>) resourcesMap.get("forbiddenResourceGuideLineValidator");
31 String implementationClass =
32 (String) resourceBaseValidatorMap.get("implementationClass");
33 Map<String, Object> properties =
34 (Map<String, Object>) resourceBaseValidatorMap.get("properties");
36 forbiddenResourceGuideLineValidator.init(properties);
40 public void testFloatingIpResourceType() {
41 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
42 forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/positive");
43 Assert.assertNotNull(messages);
44 Assert.assertEquals(messages.size(), 0);
47 messages = ValidationTestUtil.testValidator(forbiddenResourceGuideLineValidator,
48 RESOURCE_PATH + "/negative");
49 Assert.assertNotNull(messages);
50 Assert.assertEquals(messages.size(), 1);
51 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
52 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
53 "WARNING: [FRG2]: OS::Neutron::FloatingIP is in use, Resource ID [FSB2]");
56 public void testParseException(){
57 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
58 forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/parseException");
59 Assert.assertEquals(messages.size(), 1);
60 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
61 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
62 "ERROR: [FRG3]: Invalid HEAT format problem - [while scanning for the next token\n" +
63 "found character '\\t(TAB)' that cannot start any token. (Do not use \\t(TAB) " +
64 "for indentation)\n" + " in 'reader', line 5, column 1:\n" +
65 " \t\t\tresources:\n" +
71 public void testInvalidResourceType(){
72 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
73 forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/TestInvalidResourceType");
74 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
75 "WARNING: [FRG1]: A resource has an invalid or unsupported type - null, " +
76 "Resource ID [FSB2]");