d841694a232a5e98b644d790ee03640cdf7bcd2c
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
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_YAML = "valid_pm_dictionary.yaml";
35     private static final String INVALID_PM_DICTIONARY_YAML = "invalid_pm_dictionary.yaml";
36
37     @Test
38     public void shouldNotReturnErrorsWhenValidPmDict() {
39         Map<String, MessageContainer> messages = runValidation(
40             RESOURCE_PATH + "/" + VALID_PM_DICTIONARY_YAML);
41
42         assertNotNull(messages);
43         assertEquals(0, messages.size());
44     }
45
46     @Test
47     public void shouldReturnErrorsWhenInvalidPmDict() {
48         Map<String, MessageContainer> messages = runValidation(
49             RESOURCE_PATH + "/" + INVALID_PM_DICTIONARY_YAML);
50
51         assertNotNull(messages);
52         assertNotNull(messages.get(INVALID_PM_DICTIONARY_YAML));
53         assertEquals(4, messages.get(INVALID_PM_DICTIONARY_YAML).getErrorMessageList().size());
54     }
55
56     private Map<String, MessageContainer> runValidation(String path) {
57         PmDictionaryValidator validator = new PmDictionaryValidator();
58         return ValidationTestUtil.testValidator(validator, path);
59     }
60 }