2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.sdc.tosca.services;
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.junit.jupiter.api.Assertions.assertFalse;
25 import static org.junit.jupiter.api.Assertions.assertNotNull;
26 import static org.junit.jupiter.api.Assertions.assertTrue;
27 import org.junit.jupiter.api.Test;
29 import java.io.InputStream;
30 import java.util.LinkedHashMap;
31 import java.util.List;
33 import java.util.Optional;
36 public class YamlUtilTest {
38 private YamlUtil yamlUtil = new YamlUtil();
41 public void testYamlToMap() {
42 InputStream is = yamlUtil.loadYamlFileIs("/yamlMap.yaml");
43 Map<String, LinkedHashMap<String, Object>> res = yamlUtil.yamlToMap(is);
45 assertEquals(res.size(), 3);
46 assertEquals(res.get("parameter1"), "value1");
47 assertEquals(res.get("parameter2"), "value2");
48 assertEquals(res.get("parameter3"), "value3");
52 public void testYamlToList() {
53 InputStream is = yamlUtil.loadYamlFileIs("/yamlList.yaml");
54 Optional<List<Object>> res = yamlUtil.yamlToList(is);
55 assertEquals(res.get().size(), 3);
56 assertEquals(res.get().get(0), "value1");
58 InputStream is2 = yamlUtil.loadYamlFileIs("/yamlListError.yaml");
59 Optional<List<Object>> res2 = yamlUtil.yamlToList(is2);
60 assertTrue(res2.isEmpty());
64 public void testIsYamlFileContentValid() {
65 String yamlString = "tosca_definitions_version: tosca_simple_yaml_1_1\n" +
68 " tosca.nodes.Root:\n" +
69 " description: The TOSCA Node Type all other TOSCA base Node Types derive from";
70 boolean res = yamlUtil.isYamlFileContentValid(yamlString);
73 String yamlString2 = "{tosca_definitions_version: tosca_simple_yaml_1_1\n" +
75 " tosca.nodes.Root:\n" +
76 " description: The TOSCA Node Type all other TOSCA base Node Types derive from}";
77 boolean res2 = yamlUtil.isYamlFileContentValid(yamlString2);