e12e058d6c140338a4d959570252a7b5718be108
[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 package org.onap.sdc.backend.ci.tests.validation.pmdictionary;
21
22 import org.junit.jupiter.api.Test;
23 import org.openecomp.core.utilities.file.FileContentHandler;
24 import org.openecomp.sdc.datatypes.error.ErrorLevel;
25 import org.openecomp.sdc.datatypes.error.ErrorMessage;
26 import org.openecomp.sdc.vendorsoftwareproduct.exception.OnboardPackageException;
27 import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.ValidatorFactory;
28
29 import java.io.IOException;
30 import java.util.List;
31 import java.util.Map;
32
33 import static org.hamcrest.MatcherAssert.assertThat;
34 import static org.hamcrest.Matchers.*;
35
36 class CsarValidationTest {
37
38     @Test
39     void shouldNotReturnErrors_whenPnfCsarIsValid() throws OnboardPackageException, IOException {
40         //given
41         FileContentHandler pnfFileContent = CsarLoader.load("validPnfCompliantWithSOL004.csar", "/Files/PNFs/validation/pmdictionary/validPnfCompliantWithSOL004.csar");
42
43         //when
44         Map<String, List<ErrorMessage>> errorsMap = ValidatorFactory.getValidator(pnfFileContent).validateContent(pnfFileContent);
45
46         //then
47         assertThat(errorsMap, is(anEmptyMap()));
48     }
49
50     @Test
51     void shouldReturnError_whenPMDictionaryContentIsNotCompliantWithSchema() throws OnboardPackageException, IOException {
52         //given
53         String expectedErrorMessage = "Document number: 1, Path: /pmMetaData/, Message: Key not found: pmHeader";
54         FileContentHandler pnfFileContent = CsarLoader.load("invalidPnfCompliantWithSOL004.csar", "/Files/PNFs/validation/pmdictionary/invalidPnfCompliantWithSOL004.csar");
55
56         //when
57         Map<String, List<ErrorMessage>> errorMap = ValidatorFactory.getValidator(pnfFileContent).validateContent(pnfFileContent);
58         List<ErrorMessage> errorList = errorMap.get("uploadFile");
59
60         //then
61         assertThat(errorList, is(not(empty())));
62         assertThat(getActualErrorMessage(errorList), is(equalTo(expectedErrorMessage)));
63         assertThat(getActualErrorLevel(errorList), is(ErrorLevel.ERROR));
64     }
65
66     private String getActualErrorMessage(List<ErrorMessage> errorList) {
67         return errorList.get(0).getMessage();
68     }
69
70     private ErrorLevel getActualErrorLevel(List<ErrorMessage> errorList) {
71         return errorList.get(0).getLevel();
72     }
73 }