Upgrade Vulnerable Direct Dependencies [snakeyaml]
[sdc.git] / openecomp-be / lib / openecomp-sdc-validation-lib / openecomp-sdc-validation-impl / src / test / java / org / openecomp / sdc / validation / impl / validators / PmDictionaryValidatorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2020-2021 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
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.validation.impl.validators;
22
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.junit.jupiter.api.Assertions.assertNotNull;
25
26 import java.util.Map;
27 import org.junit.jupiter.api.Test;
28 import org.openecomp.core.validation.types.MessageContainer;
29 import org.openecomp.sdc.validation.util.ValidationTestUtil;
30
31 public class PmDictionaryValidatorTest {
32
33     private static final String RESOURCE_PATH = "/org/openecomp/validation/validators/pm_dictionary_validator";
34     private static final String VALID_PM_DICTIONARY_PACKAGE_PATH = "valid_file/";
35     private static final String INVALID_PM_DICTIONARY_PACKAGE_PATH = "invalid_file/";
36     private static final String WRONG_PM_DICTIONARY_TYPE_PACKAGE_PATH = "wrong_file_type/";
37     private static final String PM_DICTIONARY_FILE_NAME = "pmdict.yaml";
38
39
40     @Test
41     void shouldNotReturnErrorsWhenValidPmDict() {
42         // when
43         Map<String, MessageContainer> messages = runValidation(
44             RESOURCE_PATH + "/" + VALID_PM_DICTIONARY_PACKAGE_PATH);
45
46         // then
47         assertNotNull(messages);
48         assertEquals(0, messages.size());
49     }
50
51     @Test
52     void shouldReturnErrorsWhenInvalidPmDict() {
53         // when
54         Map<String, MessageContainer> messages = runValidation(
55             RESOURCE_PATH + "/" + INVALID_PM_DICTIONARY_PACKAGE_PATH);
56
57         // then
58         assertNotNull(messages);
59         assertNotNull(messages.get(PM_DICTIONARY_FILE_NAME));
60         assertEquals(4, messages.get(PM_DICTIONARY_FILE_NAME).getErrorMessageList().size());
61     }
62
63     @Test
64     void shouldNotReturnErrorsWhenInvalidPmDictButWrongPmDictionaryTypeInManifest() {
65         // when
66         Map<String, MessageContainer> messages = runValidation(
67                 RESOURCE_PATH + "/" + WRONG_PM_DICTIONARY_TYPE_PACKAGE_PATH);
68
69         // then
70         assertNotNull(messages);
71         assertEquals(0, messages.size());
72     }
73
74     private Map<String, MessageContainer> runValidation(String path) {
75         PmDictionaryValidator validator = new PmDictionaryValidator();
76         return new ValidationTestUtil().testValidator(validator, path);
77     }
78 }