00c9b7d0be1d18e4deb82258ed76d7950506a6fb
[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 converted json file
42      */
43     @Test
44     public final void testParseToscaYaml() throws IOException {
45         String toscaModelYaml = ResourceFileUtil.getResourceAsString("tosca/tosca_example.yaml");
46         ToscaYamlToJsonConvertor convertor = new ToscaYamlToJsonConvertor();
47
48         String parsedJsonSchema = convertor.parseToscaYaml(toscaModelYaml);
49         assertNotNull(parsedJsonSchema);
50         JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/policy-yaml-to-json.json"),
51                 parsedJsonSchema, true);
52     }
53
54     /**
55      * This Test validates TOSCA yaml with constraints to JSON Schema conversion based on JSON Editor
56      * Schema.
57      *
58      * @throws IOException In case of issue when opening the tosca yaml file and converted json file
59      */
60     @Test
61     public final void testParseToscaYamlWithConstraints() throws IOException {
62         String toscaModelYaml = ResourceFileUtil.getResourceAsString("tosca/tosca-with-constraints.yaml");
63         ToscaYamlToJsonConvertor convertor = new ToscaYamlToJsonConvertor();
64
65         String parsedJsonSchema = convertor.parseToscaYaml(toscaModelYaml);
66         assertNotNull(parsedJsonSchema);
67         JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/policy-yaml-to-json-with-constraints" +
68                                                                              ".json"),
69                                 parsedJsonSchema, true);
70     }
71
72     /**
73      * This Test validates TOSCA yaml with different datatypes to JSON Schema conversion based on JSON Editor
74      * Schema.
75      *
76      * @throws IOException In case of issue when opening the tosca yaml file and converted json file
77      */
78     @Test
79     public final void testParseToscaYamlWithTypes() throws IOException {
80         String toscaModelYaml = ResourceFileUtil.getResourceAsString("tosca/tosca-with-datatypes.yaml");
81         ToscaYamlToJsonConvertor convertor = new ToscaYamlToJsonConvertor();
82
83         String parsedJsonSchema = convertor.parseToscaYaml(toscaModelYaml);
84         assertNotNull(parsedJsonSchema);
85         JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/policy-yaml-to-json-with-datatypes.json"),
86                                 parsedJsonSchema, true);
87     }
88 }