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 static org.junit.jupiter.api.Assertions.assertEquals;
19 import static org.junit.jupiter.api.Assertions.assertTrue;
21 import org.apache.commons.collections4.MapUtils;
22 import org.junit.jupiter.api.Test;
23 import org.openecomp.core.validation.types.MessageContainer;
24 import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
25 import org.openecomp.sdc.validation.type.ConfigConstants;
26 import org.openecomp.sdc.validation.util.ValidationTestUtil;
28 import java.util.Collections;
29 import java.util.HashMap;
32 public class ResourceBaseValidatorTest {
33 private String testValidator = "testValidator";
36 public void testInvalidResourceType(){
37 ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
38 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
39 resourceBaseValidator, "/InvalidResourceType");
40 assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
41 "WARNING: [RBV1]: A resource has an invalid or unsupported type - null, " +
42 "Resource ID [FSB2]");
46 public void testInvalidHeatStructure(){
47 ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
48 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(resourceBaseValidator,
49 "/InvalidHeatStructure");
50 assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
51 "ERROR: [RBV2]: Invalid HEAT format problem - [while scanning for the next " +
52 "token\n" + "found character '\\t(TAB)' that cannot start any token. " +
53 "(Do not use \\t(TAB) for indentation)\n" +
54 " in 'reader', line 10, column 1:\n" +
55 " \t\t\tresources:\n" +
61 public void testInitWithEmptyPropertiesMap() {
62 ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
63 Map<String, Object> properties = new HashMap<>();
64 resourceBaseValidator.init(properties);
66 assertTrue(MapUtils.isEmpty(resourceBaseValidator.getResourceTypeToImpl()));
70 public void testInitPropertiesMap() {
71 ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
72 initProperties(resourceBaseValidator, getValidImplementationConfiguration());
74 Map<String, ImplementationConfiguration> resourceTypeToImpl =
75 resourceBaseValidator.getResourceTypeToImpl();
76 assertTrue(MapUtils.isNotEmpty(resourceTypeToImpl));
77 assertTrue(resourceTypeToImpl.containsKey(testValidator));
81 public void testInitPropertiesWithString() {
82 ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
83 Map<String, Object> properties = new HashMap<>();
84 properties.put(testValidator, "invalidValue");
86 resourceBaseValidator.init(properties);
88 assertTrue(MapUtils.isEmpty(resourceBaseValidator.getResourceTypeToImpl()));
92 public void testInitPropertiesWithoutImplClass() {
93 ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
94 initProperties(resourceBaseValidator, new HashMap<>());
96 assertTrue(MapUtils.isEmpty(resourceBaseValidator.getResourceTypeToImpl()));
99 public Map<String, Object> getValidImplementationConfiguration() {
100 Map<String, Object> implConfiguration = new HashMap<>();
101 implConfiguration.put(
102 ConfigConstants.Impl_Class, "org.openecomp.sdc.validation.impl.validators.ForbiddenResourceGuideLineValidator");
103 implConfiguration.put(ConfigConstants.Enable, true);
105 return implConfiguration;
108 private void initProperties(ResourceBaseValidator resourceBaseValidator,
109 Map<String, Object> implementationConfiguration) {
110 Map<String, Object> properties =
111 Collections.singletonMap(testValidator, implementationConfiguration);
113 resourceBaseValidator.init(properties);