22ef7720dc44d49068327bea4476cb21c004ea40
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
22
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;
27
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.stream.Stream;
31 import org.junit.jupiter.api.Test;
32
33 class PMDictionaryValidatorTest {
34
35     @Test
36     void shouldReportNoErrors_whenPmDictionaryIsValid() {
37         // given
38         List<String> errors = new ArrayList<>();
39         final byte[] pmDictionaryContent = getResourceBytesOrFail(
40             "validation.files/measurements/pmEvents-valid.yaml");
41
42         // when
43         new PMDictionaryValidator().validate(Stream.of(pmDictionaryContent), errors::add);
44
45         // then
46         assertTrue(errors.isEmpty());
47     }
48
49     @Test
50     void shouldReportErrors_whenPmDictionaryIsInvalid() {
51         // given
52         List<String> errors = new ArrayList<>();
53         final byte[] pmDictionaryContent = getResourceBytesOrFail(
54             "validation.files/measurements/pmEvents-invalid.yaml");
55
56         // when
57         new PMDictionaryValidator().validate(Stream.of(pmDictionaryContent), errors::add);
58
59         // then
60         assertThat(errors.size(), is(1));
61         assertThat(errors.get(0), is("Key not found: pmDictionaryHeader"));
62     }
63
64     @Test
65     void shouldReportEmptyYamlMessage_whenPmDictionaryIsEmpty() {
66         // given
67         List<String> errors = new ArrayList<>();
68         final byte[] pmDictionaryContent = "".getBytes();
69
70         // when
71         new PMDictionaryValidator().validate(Stream.of(pmDictionaryContent), errors::add);
72
73         // then
74         assertThat(errors.size(), is(1));
75         assertThat(errors.get(0), is("PM_Dictionary YAML file is empty"));
76     }
77 }