[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 / heatresource / ResourceGroupResourceValidatorTest.java
1 package org.openecomp.sdc.validation.impl.validators.heatresource;
2
3 import org.openecomp.core.validation.types.MessageContainer;
4 import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
5 import org.openecomp.sdc.validation.impl.validators.HeatResourceValidator;
6 import org.openecomp.sdc.validation.util.ValidationTestUtil;
7 import org.testng.Assert;
8 import org.testng.annotations.Test;
9
10 import java.io.IOException;
11 import java.util.Map;
12
13 /**
14  * Created by TALIO on 2/28/2017.
15  */
16 public class ResourceGroupResourceValidatorTest {
17
18   HeatResourceValidator baseValidator = new HeatResourceValidator();
19   ResourceGroupResourceValidator resourceValidator = new ResourceGroupResourceValidator();
20
21   @Test
22   public void testResourceGroupWithInvalidIndexVar() {
23     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
24         resourceValidator, HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource(),
25         "/org/openecomp/validation/validators/heat_validator/resource_group_invalid_indexvar/negative_test/input");
26
27     Assert.assertNotNull(messages);
28     Assert.assertEquals(messages.size(), 1);
29
30     Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 8);
31     Assert.assertEquals(
32         messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
33         "ERROR: Wrong value assigned to a ResourceGroup index_var property (functions are not allowed but only strings), Resource ID [resource_with_resources_group_1]");
34     Assert.assertEquals(
35         messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(1).getMessage(),
36         "WARNING: Wrong value type assigned to a nested input parameter, nested resource [resource_with_resources_group_2], property name [index_boolean], nested file [yamlFile.yaml]");
37     Assert.assertEquals(
38         messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(2).getMessage(),
39         "WARNING: Wrong value type assigned to a nested input parameter, nested resource [resource_with_resources_group_3], property name [index_boolean], nested file [yamlFile.yaml]");
40     Assert.assertEquals(
41         messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(3).getMessage(),
42         "WARNING: Wrong value type assigned to a nested input parameter, nested resource [resource_with_resources_group_3], property name [index_number], nested file [yamlFile.yaml]");
43     Assert.assertEquals(
44         messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(4).getMessage(),
45         "WARNING: Wrong value type assigned to a nested input parameter, nested resource [resource_with_resources_group_4], property name [index_boolean], nested file [yamlFile.yaml]");
46     Assert.assertEquals(
47         messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(5).getMessage(),
48         "WARNING: Wrong value type assigned to a nested input parameter, nested resource [resource_with_resources_group_5], property name [index_boolean], nested file [yamlFile.yaml]");
49     Assert.assertEquals(
50         messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(6).getMessage(),
51         "WARNING: Wrong value type assigned to a nested input parameter, nested resource [resource_with_resources_group_5], property name [index_number], nested file [yamlFile.yaml]");
52     Assert.assertEquals(
53         messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(7).getMessage(),
54         "ERROR: Wrong value assigned to a ResourceGroup index_var property (functions are not allowed but only strings), Resource ID [resource_with_resources_group_6]");
55   }
56
57   @Test
58   public void testResourceGroupWithInvalidType() {
59     Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(baseValidator,
60         resourceValidator, HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource(),
61         "/org/openecomp/validation/validators/heat_validator/resource_group_invalid_type/negative_test/input");
62
63     Assert.assertNotNull(messages);
64     Assert.assertEquals(messages.size(), 1);
65
66     Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 3);
67     Assert.assertEquals(
68         messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
69         "WARNING: OS::Heat::ResourceGroup resource with resource_def which is not pointing to nested heat file is not supported, Resource ID [resource_with_resources_group_1], resource_def type [{get_param=pcrf_vnf_id}]");
70     Assert.assertEquals(
71         messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(1).getMessage(),
72         "WARNING: OS::Heat::ResourceGroup resource with resource_def which is not pointing to nested heat file is not supported, Resource ID [resource_with_resources_group_2], resource_def type [OS::Nova::Server]");
73     Assert.assertEquals(
74         messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(2).getMessage(),
75         "WARNING: A resource has an invalid or unsupported type - null, Resource ID [resource_with_resources_group_3]");
76   }
77
78   @Test
79   public void testResourcesGroupWithNested() throws IOException {
80     Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(baseValidator,
81         resourceValidator, HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource(),
82         "/org/openecomp/validation/validators/heat_validator/resources_group_with_nested/negative_test/input");
83
84     Assert.assertNotNull(messages);
85     Assert.assertEquals(messages.size(), 3);
86
87     Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 2);
88     Assert.assertEquals(
89         messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
90         "ERROR: Referenced parameter not found in nested file - nested-from-resources-group.yaml, parameter name [resource_with_resources_group], Resource ID [property_not_in_nested]");
91     Assert.assertEquals(
92         messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(1).getMessage(),
93         "WARNING: OS::Heat::ResourceGroup resource with resource_def which is not pointing to nested heat file is not supported, Resource ID [resource_without_resources_group], resource_def type [OS::Nova::Server]");
94
95     Assert.assertEquals(messages.get("nested-pps_v1.0.yaml").getErrorMessageList().size(), 1);
96     Assert.assertEquals(
97         messages.get("nested-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
98         "ERROR: Nested files loop - [nested-pps_v1.0.yaml -- nested-from-resources-group.yaml -- hot-nimbus-pps_v1.0.yaml -- nested-pps_v1.0.yaml]");
99
100     Assert.assertEquals(messages.get("nested-not-exist.yaml").getErrorMessageList().size(), 1);
101     Assert.assertEquals(
102         messages.get("nested-not-exist.yaml").getErrorMessageList().get(0).getMessage(),
103         "ERROR: Missing nested file - nested-not-exist.yaml");
104   }
105
106 }