Add seed code from Open-O
[cli.git] / framework / src / test / java / org / onap / cli / fw / schema / ValidateSchemaTest.java
1 /*
2  * Copyright 2017 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.cli.fw.schema;
18
19 import org.junit.Test;
20 import org.onap.cli.fw.error.OnapCommandInvalidSchema;
21 import org.yaml.snakeyaml.scanner.ScannerException;
22
23 import java.io.File;
24 import java.util.ArrayList;
25 import java.util.HashSet;
26
27 public class ValidateSchemaTest {
28
29     @Test(expected = OnapCommandInvalidSchema.class)
30     public void invalidateTest1() throws OnapCommandInvalidSchema {
31         new SchemaValidator(new File("fdsfds"));
32         new SchemaValidator(new File("fdsfds.yaml"));
33     }
34
35     @Test(expected = OnapCommandInvalidSchema.class)
36     public void invalidateTest2() throws OnapCommandInvalidSchema {
37         new SchemaValidator(new File("fdsfds"));
38     }
39
40     @Test(expected = OnapCommandInvalidSchema.class)
41     public void invalidateTest4() throws OnapCommandInvalidSchema {
42         new SchemaValidator(
43                 new File(ValidateSchemaTest.class.getClassLoader().getResource("onap.properties").getFile()));
44     }
45
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()));
50     }
51
52     @Test
53     public void invalidate1Test5() throws OnapCommandInvalidSchema {
54         new SchemaValidator("schema-validate-pass.yaml");
55     }
56
57     @Test(expected = ScannerException.class)
58     public void invalidateTest3() throws OnapCommandInvalidSchema {
59         new SchemaValidator(
60                 new File(ValidateSchemaTest.class.getClassLoader().getResource("schema-invalid-file.yaml").getFile()));
61     }
62
63     @Test
64     public void validateTest() throws OnapCommandInvalidSchema {
65         new SchemaValidator(
66                 new File(ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-http.yaml").getFile()))
67                         .validate();
68
69         new SchemaValidator(
70                 new File(ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-basic.yaml").getFile()))
71                         .validate();
72         new SchemaValidator(new File(ValidateSchemaTest.class.getClassLoader()
73                 .getResource("schema-validate-invalidschematype.yaml").getFile())).validate();
74         new SchemaValidator(
75                 new File(ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-invalid.yaml").getFile()))
76                         .validate();
77         new SchemaValidator(
78                 new File(ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-pass.yaml").getFile()))
79                         .validate();
80
81     }
82
83     @Test
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");
102     }
103 }