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.Assertions;
24 import org.junit.jupiter.api.BeforeAll;
25 import org.junit.jupiter.api.Test;
26 import org.onap.dcaegen2.services.sdk.services.external.schema.manager.exception.NoLocalReferenceException;
28 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
29 import static org.junit.jupiter.api.Assertions.assertEquals;
30 import static org.junit.jupiter.api.Assertions.assertThrows;
33 private static final String MAPPING_FILE_PATH = "src/main/test/resources/schema-map-to-tests.json";
34 private static final String SCHEMAS_PATH = "src/main/test/resources";
35 private static UrlMapper urlMapper;
38 public static void setUp() {
39 urlMapper = new UrlMapperFactory().getUrlMapper(MAPPING_FILE_PATH, SCHEMAS_PATH);
43 public void shouldThrowExceptionWhenNoMappingExists() {
45 String notMappedPublicUrl = "http://localhost:8080/notExisting";
49 assertThrows(NoLocalReferenceException.class, () -> urlMapper.mapToLocalUrl(notMappedPublicUrl));
53 public void shouldThrowExceptionWhenLocalSchemaFileIsEmpty() {
55 String publicUrlToEmptyLocal = "http://someExternalUrl/emptySchema";
59 assertThrows(NoLocalReferenceException.class, () -> urlMapper.mapToLocalUrl(publicUrlToEmptyLocal));
63 public void shouldThrowExceptionWhenFileHasInvalidYamlStructure() {
65 String publicUrlToInvalidYamlLocal = "http://someExternalUrl/invalidYamlFile";
69 assertThrows(NoLocalReferenceException.class, () -> urlMapper.mapToLocalUrl(publicUrlToInvalidYamlLocal));
73 public void shouldThrowExceptionWhenLocalFileDoesNotExist() {
75 String publicUrlToNotExistingLocalFile = "http://someExternalUrl/missingFile";
79 assertThrows(NoLocalReferenceException.class, () -> urlMapper.mapToLocalUrl(publicUrlToNotExistingLocalFile));
83 public void shouldReturnLocalUrlWhenFileValidAndFound() {
85 String publicUrl = "http://someExternalUrl/external";
89 assertEquals("file_with_one_line.json", urlMapper.mapToLocalUrl(publicUrl));
93 public void shouldNotThrowExceptionWhenMappingFileDoesNotExist() {
94 String invalidMappingFilePath = "src/main/test/resources/missing-schema.json";
96 Assertions.assertDoesNotThrow(() -> new UrlMapperFactory().getUrlMapper(invalidMappingFilePath, SCHEMAS_PATH));