summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/ForbiddenResourceGuideLineValidatorTest.java
blob: e5240a3147402c8dfc091844670ec2b24dc31bac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package org.openecomp.sdc.validation.impl.validators;

import org.openecomp.core.validation.types.MessageContainer;
import org.openecomp.sdc.validation.util.ValidationTestUtil;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.Map;

/**
 * Created by TALIO on 2/16/2017.
 */
public class ForbiddenResourceGuideLineValidatorTest {

  private static final String RESOURCE_PATH = "/org/openecomp/validation/validators" +
      "/guideLineValidator/heatFloatingIpResourceType";
  private static String mockConfigFileName =
      "/org/openecomp/validation/configuration/mock_resource_validator_configuration.json";

  ForbiddenResourceGuideLineValidator forbiddenResourceGuideLineValidator = new
      ForbiddenResourceGuideLineValidator();

  @BeforeClass
  public void init() throws IOException {
    Map<String, Object> resourcesMap = ValidationTestUtil.getResourceMap(mockConfigFileName);

    Map<String, Object> resourceBaseValidatorMap =
        (Map<String, Object>) resourcesMap.get("forbiddenResourceGuideLineValidator");
    String implementationClass =
        (String) resourceBaseValidatorMap.get("implementationClass");
    Map<String, Object> properties =
        (Map<String, Object>) resourceBaseValidatorMap.get("properties");

    forbiddenResourceGuideLineValidator.init(properties);
  }

  @Test
  public void testFloatingIpResourceType() {
    Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
        forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/positive");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.size(), 0);


    messages = ValidationTestUtil.testValidator(forbiddenResourceGuideLineValidator,
        RESOURCE_PATH + "/negative");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.size(), 1);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
        "WARNING: [FRG2]: OS::Neutron::FloatingIP is in use, Resource ID [FSB2]");
  }
  @Test
  public void testParseException(){
    Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
        forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/parseException");
    Assert.assertEquals(messages.size(), 1);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
        "ERROR: [FRG3]: Invalid HEAT format problem - [while scanning for the next token\n" +
            "found character '\\t(TAB)' that cannot start any token. (Do not use \\t(TAB) " +
            "for indentation)\n" + " in 'reader', line 5, column 1:\n" +
            "    \t\t\tresources:\n" +
            "    ^\n" +
            "]");
  }

  @Test
  public void testInvalidResourceType(){
    Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
        forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/TestInvalidResourceType");
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
        "WARNING: [FRG1]: A resource has an invalid or unsupported type - null, " +
            "Resource ID [FSB2]");
  }
}