Fix checkstyle issue
[clamp.git] / src / test / java / org / onap / clamp / clds / tosca / ToscaYamlToJsonConvertorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * Modifications Copyright (C) 2019 Huawei Technologies Co., Ltd.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END============================================
21  * ===================================================================
22  *
23  */
24
25 package org.onap.clamp.clds.tosca;
26
27 import static org.junit.Assert.assertNotNull;
28
29 import java.io.IOException;
30
31 import org.junit.Test;
32 import org.onap.clamp.clds.util.ResourceFileUtil;
33 import org.skyscreamer.jsonassert.JSONAssert;
34
35 public class ToscaYamlToJsonConvertorTest {
36
37     /**
38      * This Test validates TOSCA yaml to JSON Schema conversion based on JSON Editor
39      * Schema.
40      *
41      * @throws IOException In case of issue when opening the tosca yaml file and
42      *                     converted json file
43      */
44     @Test
45     public final void testParseToscaYaml() throws IOException {
46         String toscaModelYaml = ResourceFileUtil.getResourceAsString("tosca/tosca_example.yaml");
47         ToscaYamlToJsonConvertor convertor = new ToscaYamlToJsonConvertor();
48
49         String parsedJsonSchema = convertor.parseToscaYaml(toscaModelYaml,
50                 "onap.policies.monitoring.cdap.tca.hi.lo.app");
51         assertNotNull(parsedJsonSchema);
52         JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/policy-yaml-to-json.json"),
53                 parsedJsonSchema, true);
54     }
55
56     /**
57      * This Test validates TOSCA yaml with constraints to JSON Schema conversion
58      * based on JSON Editor Schema.
59      *
60      * @throws IOException In case of issue when opening the tosca yaml file and
61      *                     converted json file
62      */
63     @Test
64     public final void testParseToscaYamlWithConstraints() throws IOException {
65         String toscaModelYaml = ResourceFileUtil.getResourceAsString("tosca/tosca-with-constraints.yaml");
66         ToscaYamlToJsonConvertor convertor = new ToscaYamlToJsonConvertor();
67
68         String parsedJsonSchema = convertor.parseToscaYaml(toscaModelYaml, "onap.policies.monitoring.example.app");
69         assertNotNull(parsedJsonSchema);
70         JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/policy-yaml-to-json-with-constraints.json"),
71                 parsedJsonSchema, true);
72     }
73
74     /**
75      * This Test validates TOSCA yaml with different datatypes to JSON Schema
76      * conversion based on JSON Editor Schema.
77      *
78      * @throws IOException In case of issue when opening the tosca yaml file and
79      *                     converted json file
80      */
81     @Test
82     public final void testParseToscaYamlWithTypes() throws IOException {
83         String toscaModelYaml = ResourceFileUtil.getResourceAsString("tosca/tosca-with-datatypes.yaml");
84         ToscaYamlToJsonConvertor convertor = new ToscaYamlToJsonConvertor();
85
86         String parsedJsonSchema = convertor.parseToscaYaml(toscaModelYaml, "onap.policies.monitoring.example.app");
87         assertNotNull(parsedJsonSchema);
88         JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/policy-yaml-to-json-with-datatypes.json"),
89                 parsedJsonSchema, true);
90     }
91 }