2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Nokia. 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.be.components.impl.validation;
22 import static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.core.Is.is;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.verifyNoInteractions;
27 import static org.mockito.Mockito.when;
29 import java.util.List;
30 import java.util.Optional;
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33 import org.onap.validation.yaml.YamlContentValidator;
34 import org.onap.validation.yaml.error.YamlDocumentValidationError;
35 import org.onap.validation.yaml.exception.YamlProcessingException;
36 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
38 class PMDictionaryValidatorTest {
40 private YamlContentValidator yamlContentValidator;
44 yamlContentValidator = mock(YamlContentValidator.class);
48 void shouldNotReturnErrors_whenArtifactTypeDoNotMatch() {
50 Optional<String> errors = new PMDictionaryValidator(yamlContentValidator)
51 .validateIfPmDictionary(ArtifactTypeEnum.DCAE_INVENTORY_BLUEPRINT.name(), "".getBytes());
54 assertTrue(errors.isEmpty());
55 verifyNoInteractions(yamlContentValidator);
59 void shouldReturnErrors_whenArtifactTypeIsPmDictionaryAndFileIsInvalid() throws YamlProcessingException {
61 byte[] fileContent = "".getBytes();
62 YamlDocumentValidationError validationError = new YamlDocumentValidationError(1, "/", "error");
63 when(yamlContentValidator.validate(fileContent)).thenReturn(List.of(validationError));
66 Optional<String> errors = new PMDictionaryValidator(yamlContentValidator)
67 .validateIfPmDictionary(ArtifactTypeEnum.PM_DICTIONARY.name(), fileContent);
70 assertTrue(errors.isPresent());
71 assertThat(errors.get(), is("Line number: 1, Path: /, Message: error"));
75 void shouldNotReturnErrors_whenArtifactTypeIsPmDictionaryAndFileIsValid() throws YamlProcessingException {
77 byte[] fileContent = "".getBytes();
78 when(yamlContentValidator.validate(fileContent)).thenReturn(List.of());
81 Optional<String> errors = new PMDictionaryValidator(yamlContentValidator)
82 .validateIfPmDictionary(ArtifactTypeEnum.PM_DICTIONARY.name(), fileContent);
85 assertTrue(errors.isEmpty());