2 * ============LICENSE_START=======================================================
3 * DCAEGEN2-SERVICES-SDK
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=========================================================
21 package org.onap.dcaegen2.services.sdk.services.external.schema.manager.service;
23 import org.junit.jupiter.api.Test;
27 import static org.assertj.core.api.Assertions.assertThat;
29 public class StndDefinedValidatorBuilderTest {
31 private static final String TEST_RESOURCES = "src/main/test/resources/externalRepo/";
34 void shouldGenerateValidatorWithAllSchemaMappings() {
36 StndDefinedValidator validator = getValidator("schema-map.json");
38 Map<String, String> mappingsCache = getMappingsCache(validator);
41 assertThat(mappingsCache.size()).isEqualTo(6);
45 void shouldGenerateValidatorWithoutSchemaMappingsWithReferenceToNotExistingLocalResource() {
47 StndDefinedValidator validator = getValidator("schema-map-no-local-resource.json");
48 Map<String, String> mappingsCache = getMappingsCache(validator);
51 assertThat(mappingsCache.size()).isEqualTo(5);
55 void shouldGenerateValidatorWithoutSchemaMappingsWithEmptyLocalFileContent() {
57 StndDefinedValidator validator = getValidator("schema-map-empty-content.json");
58 Map<String, String> mappingsCache = getMappingsCache(validator);
61 assertThat(mappingsCache.size()).isEqualTo(4);
65 void shouldGenerateValidatorWithoutSchemaMappingsWithIncorrectYamlFormat() {
67 StndDefinedValidator validator = getValidator("schema-map-incorrect-yaml-format.json");
68 Map<String, String> mappingsCache = getMappingsCache(validator);
71 assertThat(mappingsCache.size()).isEqualTo(3);
75 void shouldGenerateValidatorWithoutSchemaMappingsWhenSchemaMappingFileHasNotJsonFormat() {
77 StndDefinedValidator validator = getValidator("schema-map-no-json-format.json");
78 Map<String, String> mappingsCache = getMappingsCache(validator);
81 assertThat(mappingsCache.size()).isEqualTo(0);
85 void shouldGenerateValidatorWithoutSchemaMappingsWhenSchemaMappingFileHasWrongFieldName() {
87 StndDefinedValidator validator = getValidator("schema-map-wrong-field-name.json");
88 Map<String, String> mappingsCache = getMappingsCache(validator);
91 assertThat(mappingsCache.size()).isEqualTo(0);
94 private StndDefinedValidator getValidator(String mappingFilePath) {
95 return new StndDefinedValidator.ValidatorBuilder()
96 .mappingFilePath(TEST_RESOURCES + mappingFilePath)
97 .schemasPath(TEST_RESOURCES)
98 .schemaRefPath("/event/stndDefinedFields/schemaReference")
99 .stndDefinedDataPath("/event/stndDefinedFields/data")
103 private Map<String, String> getMappingsCache(StndDefinedValidator validator) {
104 return validator.getValidatorCache()
105 .getSchemaReferenceMapper()