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 converted json file
44 public final void testParseToscaYaml() throws IOException {
45 String toscaModelYaml = ResourceFileUtil.getResourceAsString("tosca/tosca_example.yaml");
46 ToscaYamlToJsonConvertor convertor = new ToscaYamlToJsonConvertor();
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);
56 * This Test validates TOSCA yaml with constraints to JSON Schema conversion based on JSON Editor
59 * @throws IOException In case of issue when opening the tosca yaml file and converted json file
62 public final void testParseToscaYamlWithConstraints() throws IOException {
63 String toscaModelYaml = ResourceFileUtil.getResourceAsString("tosca/tosca-with-constraints.yaml");
64 ToscaYamlToJsonConvertor convertor = new ToscaYamlToJsonConvertor();
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" +
70 parsedJsonSchema, true);
74 * This Test validates TOSCA yaml with different datatypes to JSON Schema conversion based on JSON Editor
77 * @throws IOException In case of issue when opening the tosca yaml file and converted json file
80 public final void testParseToscaYamlWithTypes() throws IOException {
81 String toscaModelYaml = ResourceFileUtil.getResourceAsString("tosca/tosca-with-datatypes.yaml");
82 ToscaYamlToJsonConvertor convertor = new ToscaYamlToJsonConvertor();
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);