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