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=========================================================
20 package org.onap.sdc.backend.ci.tests.validation.pmdictionary;
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;
29 import java.io.IOException;
30 import java.util.List;
33 import static org.hamcrest.MatcherAssert.assertThat;
34 import static org.hamcrest.Matchers.*;
36 class CsarValidationTest {
39 void shouldNotReturnErrors_whenPnfCsarIsValid() throws OnboardPackageException, IOException {
41 FileContentHandler pnfFileContent = CsarLoader.load("validPnfCompliantWithSOL004.csar", "/Files/PNFs/validation/pmdictionary/validPnfCompliantWithSOL004.csar");
44 Map<String, List<ErrorMessage>> errorsMap = ValidatorFactory.getValidator(pnfFileContent).validateContent(pnfFileContent);
47 assertThat(errorsMap, is(anEmptyMap()));
51 void shouldReturnError_whenPMDictionaryContentIsNotCompliantWithSchema() throws OnboardPackageException, IOException {
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");
57 Map<String, List<ErrorMessage>> errorMap = ValidatorFactory.getValidator(pnfFileContent).validateContent(pnfFileContent);
58 List<ErrorMessage> errorList = errorMap.get("uploadFile");
61 assertThat(errorList, is(not(empty())));
62 assertThat(getActualErrorMessage(errorList), is(equalTo(expectedErrorMessage)));
63 assertThat(getActualErrorLevel(errorList), is(ErrorLevel.ERROR));
66 private String getActualErrorMessage(List<ErrorMessage> errorList) {
67 return errorList.get(0).getMessage();
70 private ErrorLevel getActualErrorLevel(List<ErrorMessage> errorList) {
71 return errorList.get(0).getLevel();