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=========================================================
21 package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
23 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.core.Is.is;
25 import static org.junit.jupiter.api.Assertions.assertTrue;
26 import static org.openecomp.sdc.be.test.util.TestResourcesHandler.getResourceBytesOrFail;
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.stream.Stream;
31 import org.junit.jupiter.api.Test;
33 class PMDictionaryValidatorTest {
36 void shouldReportNoErrors_whenPmDictionaryIsValid() {
38 List<String> errors = new ArrayList<>();
39 final byte[] pmDictionaryContent = getResourceBytesOrFail(
40 "validation.files/measurements/pmEvents-valid.yaml");
43 new PMDictionaryValidator().validate(Stream.of(pmDictionaryContent), errors::add);
46 assertTrue(errors.isEmpty());
50 void shouldReportErrors_whenPmDictionaryIsInvalid() {
52 List<String> errors = new ArrayList<>();
53 final byte[] pmDictionaryContent = getResourceBytesOrFail(
54 "validation.files/measurements/pmEvents-invalid.yaml");
57 new PMDictionaryValidator().validate(Stream.of(pmDictionaryContent), errors::add);
60 assertThat(errors.size(), is(1));
61 assertThat(errors.get(0), is("Key not found: pmDictionaryHeader"));
65 void shouldReportEmptyYamlMessage_whenPmDictionaryIsEmpty() {
67 List<String> errors = new ArrayList<>();
68 final byte[] pmDictionaryContent = "".getBytes();
71 new PMDictionaryValidator().validate(Stream.of(pmDictionaryContent), errors::add);
74 assertThat(errors.size(), is(1));
75 assertThat(errors.get(0), is("PM_Dictionary YAML file is empty"));