2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.sdc.be.tosca;
23 import org.junit.Test;
24 import org.yaml.snakeyaml.Yaml;
26 import java.io.FileInputStream;
27 import java.io.IOException;
28 import java.nio.file.Files;
29 import java.nio.file.Path;
30 import java.nio.file.Paths;
31 import java.util.List;
32 import java.util.stream.Collectors;
34 import static org.junit.Assert.assertFalse;
35 import static org.junit.Assert.assertTrue;
37 public class SchemaFiles {
40 public void testValidateYamlNormativeFiles(){
41 String importToscaPath = "src/main/resources/import/tosca";
42 assertTrue(checkValidYamlInFileTree(importToscaPath));
46 public void testRainyYamlNormativeFiles(){
47 String importToscaPathTest = "src/test/resources/yamlValidation";
48 assertFalse(checkValidYamlInFileTree(importToscaPathTest));
51 private boolean checkValidYamlInFileTree(String fileTree) {
54 List<Path> fileTreeYamlList = Files.walk(Paths.get(fileTree))
55 .filter(path -> path.getFileName().toString().toLowerCase().endsWith(".yml"))
56 .collect(Collectors.toList());
58 for (Path yamlFile : fileTreeYamlList) {
60 FileInputStream inputStream = new FileInputStream(yamlFile.toAbsolutePath().toString());
61 Yaml yaml = new Yaml();
62 Object content = yaml.load(inputStream);
63 } catch (Exception e) {
64 System.out.println("Not valid yaml in file creation : " + yamlFile.toAbsolutePath().toString());
68 } catch (IOException e) {
69 System.out.println("Error in reading file from folder : " + fileTree);