2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Nokia 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=========================================================
20 package org.openecomp.sdc.validation.impl.validators;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
25 import java.util.stream.Collectors;
26 import java.util.stream.Stream;
27 import org.junit.jupiter.api.Test;
29 class FileExtensionUtilsTest {
31 private static final Set<String> VALID_YAML_EXTENSIONS = Set.of(
36 private static final Set<String> INVALID_YAML_EXTENSIONS = Set.of(
42 private static final Set<String> VALID_PM_DICTIONARY_EXTENSIONS = Set.of(
52 private static final Set<String> INVALID_PM_DICTIONARY_EXTENSIONS = Set.of(
58 private static final Set<String> TEST_FILE_PREFIXES = Set.of(
64 void shouldMatchProperYamlExtensions() {
65 final boolean allValidFilesMatched = constructTestFilenamesWithExtensions(VALID_YAML_EXTENSIONS)
66 .allMatch(FileExtensionUtils::isYaml);
68 assertTrue(allValidFilesMatched);
72 void shouldNotMatchImproperYamlExtensions() {
73 final boolean allInvalidFilesNotMatched = constructTestFilenamesWithExtensions(INVALID_YAML_EXTENSIONS)
74 .noneMatch(FileExtensionUtils::isYaml);
76 assertTrue(allInvalidFilesNotMatched);
80 void shouldMatchProperPmDictionaryExtensions() {
81 final boolean allValidFilesMatched = constructTestFilenamesWithExtensions(VALID_PM_DICTIONARY_EXTENSIONS)
82 .allMatch(FileExtensionUtils::isPmDictionary);
84 assertTrue(allValidFilesMatched);
88 void shouldNotMatchImproperPmDictionaryExtensions() {
89 final boolean allInvalidFilesNotMatched = constructTestFilenamesWithExtensions(INVALID_PM_DICTIONARY_EXTENSIONS)
90 .noneMatch(FileExtensionUtils::isPmDictionary);
92 assertTrue(allInvalidFilesNotMatched);
95 private Stream<String> constructTestFilenamesWithExtensions(Set<String> extensions) {
96 return extensions.stream()
97 .flatMap(ext -> prepareFilenamesWithExtension(ext).stream());
100 private Set<String> prepareFilenamesWithExtension(String extension) {
101 return Stream.concat(
102 joinTestNamesWithExtension(extension.toLowerCase()),
103 joinTestNamesWithExtension(extension.toUpperCase())
104 ).collect(Collectors.toSet());
107 private Stream<String> joinTestNamesWithExtension(String extension) {
108 return TEST_FILE_PREFIXES.stream()
109 .map(prefix -> prefix + extension);