2 * Copyright 2017 Huawei Technologies Co., Ltd.
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.onap.cli.fw.schema;
19 import org.junit.Test;
20 import org.onap.cli.fw.error.OnapCommandInvalidSchema;
21 import org.yaml.snakeyaml.scanner.ScannerException;
24 import java.util.ArrayList;
25 import java.util.HashSet;
27 public class ValidateSchemaTest {
29 @Test(expected = OnapCommandInvalidSchema.class)
30 public void invalidateTest1() throws OnapCommandInvalidSchema {
31 new SchemaValidator(new File("fdsfds"));
32 new SchemaValidator(new File("fdsfds.yaml"));
35 @Test(expected = OnapCommandInvalidSchema.class)
36 public void invalidateTest2() throws OnapCommandInvalidSchema {
37 new SchemaValidator(new File("fdsfds"));
40 @Test(expected = OnapCommandInvalidSchema.class)
41 public void invalidateTest4() throws OnapCommandInvalidSchema {
43 new File(ValidateSchemaTest.class.getClassLoader().getResource("onap.properties").getFile()));
46 @Test(expected = OnapCommandInvalidSchema.class)
47 public void invalidateTest5() throws OnapCommandInvalidSchema {
48 new SchemaValidator(new File(
49 ValidateSchemaTest.class.getClassLoader().getResource("schema-invalid-file-null.yaml").getFile()));
53 public void invalidate1Test5() throws OnapCommandInvalidSchema {
54 new SchemaValidator("schema-validate-pass.yaml");
57 @Test(expected = ScannerException.class)
58 public void invalidateTest3() throws OnapCommandInvalidSchema {
60 new File(ValidateSchemaTest.class.getClassLoader().getResource("schema-invalid-file.yaml").getFile()));
64 public void validateTest() throws OnapCommandInvalidSchema {
66 new File(ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-http.yaml").getFile()))
70 new File(ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-basic.yaml").getFile()))
72 new SchemaValidator(new File(ValidateSchemaTest.class.getClassLoader()
73 .getResource("schema-validate-invalidschematype.yaml").getFile())).validate();
75 new File(ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-invalid.yaml").getFile()))
78 new File(ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-pass.yaml").getFile()))
84 public void schemaValidateInterfaceTest() throws OnapCommandInvalidSchema {
85 SchemaValidate.attributeNameExist("name", "section");
86 SchemaValidate.emptyValue("section", "attribute");
87 SchemaValidate.defaultYamlSchema("section");
88 SchemaValidate.emptySection("section");
89 SchemaValidate.invalidAttributeScope("name", new ArrayList<String>());
90 SchemaValidate.invalidAttrType("name", "section", new ArrayList<String>());
91 SchemaValidate.invalidBooleanValueMessage("section", "attribute", "value");
92 SchemaValidate.invalidRequestParam("subSection", "attribute");
93 SchemaValidate.invalidSections(new HashSet<String>(), new ArrayList<String>(), new ArrayList<String>());
94 SchemaValidate.attributeScopeEmpty("fsdf");
95 SchemaValidate.invalidType("section", "attribute", new ArrayList<String>());
96 SchemaValidate.longOptionExist("name");
97 SchemaValidate.shortOptionExist("name");
98 SchemaValidate.optionExist("option", "attrValue", "name");
99 SchemaValidate.optionDefaultExist("option", "attrValue", "name", new HashSet<String>());
100 SchemaValidate.nameExist("name", "section");
101 SchemaValidate.mandatoryAttrEmpty("param", "section");