2 * Copyright © 2016-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.
17 package org.openecomp.sdc.validation.impl.validators;
19 import java.io.IOException;
21 import org.junit.Assert;
22 import org.junit.BeforeClass;
23 import org.junit.Test;
24 import org.openecomp.core.validation.types.MessageContainer;
25 import org.openecomp.sdc.validation.util.ValidationTestUtil;
28 * Created by TALIO on 2/16/2017.
30 public class ForbiddenResourceGuideLineValidatorTest {
32 private static final String RESOURCE_PATH = "/org/openecomp/validation/validators" +
33 "/guideLineValidator/heatFloatingIpResourceType";
34 private static String mockConfigFileName =
35 "/org/openecomp/validation/configuration/mock_resource_validator_configuration.json";
37 private static ForbiddenResourceGuideLineValidator forbiddenResourceGuideLineValidator = new
38 ForbiddenResourceGuideLineValidator();
41 public static void init() throws IOException {
42 Map<String, Object> resourcesMap = new ValidationTestUtil().getResourceMap(mockConfigFileName);
44 Map<String, Object> resourceBaseValidatorMap =
45 (Map<String, Object>) resourcesMap.get("forbiddenResourceGuideLineValidator");
46 Map<String, Object> properties =
47 (Map<String, Object>) resourceBaseValidatorMap.get("properties");
49 forbiddenResourceGuideLineValidator.init(properties);
53 public void testFloatingIpResourceType() {
54 Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(
55 forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/positive");
56 Assert.assertNotNull(messages);
57 Assert.assertEquals(messages.size(), 0);
60 messages = new ValidationTestUtil().testValidator(forbiddenResourceGuideLineValidator,
61 RESOURCE_PATH + "/negative");
62 Assert.assertNotNull(messages);
63 Assert.assertEquals(messages.size(), 1);
64 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
65 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
66 "WARNING: [FRG2]: OS::Neutron::FloatingIP is in use, Resource ID [FSB2]");
69 public void testParseException(){
70 Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(
71 forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/parseException");
72 Assert.assertEquals(messages.size(), 1);
73 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
74 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
75 "ERROR: [FRG3]: Invalid HEAT format problem - [while scanning for the next token\n" +
76 "found character '\\t(TAB)' that cannot start any token. (Do not use \\t(TAB) " +
77 "for indentation)\n" + " in 'reader', line 5, column 1:\n" +
78 " \t\t\tresources:\n" +
84 public void testInvalidResourceType(){
85 Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(
86 forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/TestInvalidResourceType");
87 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
88 "WARNING: [FRG1]: A resource has an invalid or unsupported type - null, " +
89 "Resource ID [FSB2]");