e5240a3147402c8dfc091844670ec2b24dc31bac
[sdc.git] /
1 package org.openecomp.sdc.validation.impl.validators;
2
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;
8
9 import java.io.IOException;
10 import java.util.Map;
11
12 /**
13  * Created by TALIO on 2/16/2017.
14  */
15 public class ForbiddenResourceGuideLineValidatorTest {
16
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";
21
22   ForbiddenResourceGuideLineValidator forbiddenResourceGuideLineValidator = new
23       ForbiddenResourceGuideLineValidator();
24
25   @BeforeClass
26   public void init() throws IOException {
27     Map<String, Object> resourcesMap = ValidationTestUtil.getResourceMap(mockConfigFileName);
28
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");
35
36     forbiddenResourceGuideLineValidator.init(properties);
37   }
38
39   @Test
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);
45
46
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]");
54   }
55   @Test
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" +
66             "    ^\n" +
67             "]");
68   }
69
70   @Test
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]");
77   }
78 }