2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.validation.impl.validators;
24 import org.openecomp.core.validation.types.MessageContainer;
25 import org.openecomp.sdc.common.errors.Messages;
26 import org.openecomp.sdc.validation.util.ValidationTestUtil;
27 import org.testng.Assert;
28 import org.testng.annotations.Test;
32 public class YamlValidatorTest {
35 public Map<String, MessageContainer> runValidation(String path) {
36 YamlValidator validator = new YamlValidator();
37 return ValidationTestUtil.testValidator(validator, path);
42 public void testValidYaml() {
44 Map<String, MessageContainer> messages = runValidation(
45 "/org/openecomp/validation/validators/yaml_validator/valid_yaml/input/validHeat.yaml");
46 Assert.assertNotNull(messages);
47 Assert.assertEquals(messages.size(), 0);
51 public void testInvalidTabYaml() {
53 Map<String, MessageContainer> messages = runValidation(
54 "/org/openecomp/validation/validators/yaml_validator/invalid_valid_yaml_structure/input/invalidYamlTab.yaml");
55 Assert.assertNotNull(messages);
56 Assert.assertEquals(messages.size(), 1);
57 ValidationTestUtil.validateErrorMessage(
58 messages.get("invalidYamlTab.yaml").getErrorMessageList().get(0).getMessage(),
59 "ERROR: " + Messages.INVALID_YAML_FORMAT_REASON.getErrorMessage(),
60 "while scanning for the next tokenfound character '\\t(TAB)' that cannot start any token. (Do not use \\t(TAB) for indentation) in 'reader', line 14, column 5: \tadmin_state_up: true ^");
66 public void testDuplicateKeyInYaml() {
68 Map<String, MessageContainer> messages =
69 runValidation("/org/openecomp/validation/validators/yaml_validator/duplicateKey.yaml");
70 Assert.assertNotNull(messages);
71 Assert.assertEquals(messages.size(), 1);
72 Assert.assertTrue(messages.containsKey("duplicateKey.yaml"));
73 ValidationTestUtil.validateErrorMessage(
74 messages.get("duplicateKey.yaml").getErrorMessageList().get(0).getMessage(),
75 "ERROR: " + Messages.INVALID_YAML_FORMAT_REASON.getErrorMessage(),
76 "while parsing MappingNode in 'reader', line 6, column 3: Key_1_unique: ^duplicate key: Key_2_not_unique in 'reader', line 31, column 1: ^");
81 public void testInvalidYamlStructure() {
83 Map<String, MessageContainer> messages = runValidation(
84 "/org/openecomp/validation/validators/yaml_validator/invalidYamlStructure.yaml");
85 Assert.assertNotNull(messages);
86 Assert.assertEquals(messages.size(), 1);
87 Assert.assertTrue(messages.containsKey("invalidYamlStructure.yaml"));
88 ValidationTestUtil.validateErrorMessage(
89 messages.get("invalidYamlStructure.yaml").getErrorMessageList().get(0).getMessage(),
90 "ERROR: " + Messages.INVALID_YAML_FORMAT_REASON.getErrorMessage(),
91 "while parsing a block mapping in 'reader', line 8, column 7: admin_state_up: true ^expected <block end>, but found BlockEntry in 'reader', line 10, column 7: - shared: true ^");
95 public void testEmptyYaml() {
97 Map<String, MessageContainer> messages =
98 runValidation("/org/openecomp/validation/validators/yaml_validator/emptyYaml.yaml");
99 Assert.assertNotNull(messages);
100 Assert.assertEquals(messages.size(), 1);
101 Assert.assertTrue(messages.containsKey("emptyYaml.yaml"));
102 ValidationTestUtil.validateErrorMessage(messages.get("emptyYaml.yaml").getErrorMessageList().get(0).getMessage(),
103 "ERROR: " + Messages.INVALID_YAML_FORMAT_REASON.getErrorMessage(),
104 Messages.EMPTY_YAML_FILE.getErrorMessage());