2 * Copyright © 2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.openecomp.sdc.validation.base;
18 import org.apache.commons.collections4.MapUtils;
19 import org.openecomp.core.validation.types.MessageContainer;
20 import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
21 import org.openecomp.sdc.validation.type.ConfigConstants;
22 import org.openecomp.sdc.validation.util.ValidationTestUtil;
23 import org.testng.Assert;
24 import org.testng.annotations.Test;
26 import java.util.Collections;
27 import java.util.HashMap;
31 public class ResourceBaseValidatorTest {
32 private String testValidator = "testValidator";
35 public void testInvalidResourceType(){
36 ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
37 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
38 resourceBaseValidator, "/InvalidResourceType");
39 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
40 "WARNING: [RBV1]: A resource has an invalid or unsupported type - null, " +
41 "Resource ID [FSB2]");
45 public void testInvalidHeatStructure(){
46 ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
47 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(resourceBaseValidator,
48 "/InvalidHeatStructure");
49 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
50 "ERROR: [RBV2]: Invalid HEAT format problem - [while scanning for the next " +
51 "token\n" + "found character '\\t(TAB)' that cannot start any token. " +
52 "(Do not use \\t(TAB) for indentation)\n" +
53 " in 'reader', line 10, column 1:\n" +
54 " \t\t\tresources:\n" +
60 public void testInitWithEmptyPropertiesMap() {
61 ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
62 Map<String, Object> properties = new HashMap<>();
63 resourceBaseValidator.init(properties);
65 Assert.assertTrue(MapUtils.isEmpty(resourceBaseValidator.getResourceTypeToImpl()));
69 public void testInitPropertiesMap() {
70 ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
71 initProperties(resourceBaseValidator, getValidImplementationConfiguration());
73 Map<String, ImplementationConfiguration> resourceTypeToImpl =
74 resourceBaseValidator.getResourceTypeToImpl();
75 Assert.assertTrue(MapUtils.isNotEmpty(resourceTypeToImpl));
76 Assert.assertTrue(resourceTypeToImpl.containsKey(testValidator));
80 public void testInitPropertiesWithString() {
81 ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
82 Map<String, Object> properties = new HashMap<>();
83 properties.put(testValidator, "invalidValue");
85 resourceBaseValidator.init(properties);
87 Assert.assertTrue(MapUtils.isEmpty(resourceBaseValidator.getResourceTypeToImpl()));
91 public void testInitPropertiesWithoutImplClass() {
92 ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
93 initProperties(resourceBaseValidator, new HashMap<>());
95 Assert.assertTrue(MapUtils.isEmpty(resourceBaseValidator.getResourceTypeToImpl()));
98 public Map<String, Object> getValidImplementationConfiguration() {
99 Map<String, Object> implConfiguration = new HashMap<>();
100 implConfiguration.put(
101 ConfigConstants.Impl_Class, "org.openecomp.sdc.validation.impl.validators.ForbiddenResourceGuideLineValidator");
102 implConfiguration.put(ConfigConstants.Enable, true);
104 return implConfiguration;
107 private void initProperties(ResourceBaseValidator resourceBaseValidator,
108 Map<String, Object> implementationConfiguration) {
109 Map<String, Object> properties =
110 Collections.singletonMap(testValidator, implementationConfiguration);
112 resourceBaseValidator.init(properties);