2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
25 package org.onap.clamp.clds.tosca;
27 import static org.junit.Assert.assertNotNull;
29 import java.io.IOException;
31 import org.junit.Test;
32 import org.onap.clamp.clds.util.ResourceFileUtil;
33 import org.skyscreamer.jsonassert.JSONAssert;
35 public class ToscaYamlToJsonConvertorTest {
38 * This Test validates TOSCA yaml to JSON Schema conversion based on JSON Editor
41 * @throws IOException In case of issue when opening the tosca yaml file and
45 public final void testParseToscaYaml() throws IOException {
46 String toscaModelYaml = ResourceFileUtil.getResourceAsString("tosca/tosca_example.yaml");
47 ToscaYamlToJsonConvertor convertor = new ToscaYamlToJsonConvertor();
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);
57 * This Test validates TOSCA yaml with constraints to JSON Schema conversion
58 * based on JSON Editor Schema.
60 * @throws IOException In case of issue when opening the tosca yaml file and
64 public final void testParseToscaYamlWithConstraints() throws IOException {
65 String toscaModelYaml = ResourceFileUtil.getResourceAsString("tosca/tosca-with-constraints.yaml");
66 ToscaYamlToJsonConvertor convertor = new ToscaYamlToJsonConvertor();
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);
75 * This Test validates TOSCA yaml with different datatypes to JSON Schema
76 * conversion based on JSON Editor Schema.
78 * @throws IOException In case of issue when opening the tosca yaml file and
82 public final void testParseToscaYamlWithTypes() throws IOException {
83 String toscaModelYaml = ResourceFileUtil.getResourceAsString("tosca/tosca-with-datatypes.yaml");
84 ToscaYamlToJsonConvertor convertor = new ToscaYamlToJsonConvertor();
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);