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;
24 import org.onap.dcaegen2.services.sdk.services.external.schema.manager.model.SchemaReference;
26 import static org.junit.jupiter.api.Assertions.assertEquals;
28 class SchemaReferenceMapperTest {
30 public static final String SCHEMAS_PATH = "src/main/test/resources";
33 public void shouldReturnProperReferenceWhenSchemaReferenceHasNoHash() {
35 SchemaReferenceMapper schemaReferenceMapper = getSchemaReferenceMapper();
36 String publicUrlWithoutHash = "http://someExternalUrl/external";
37 SchemaReferenceResolver schemaReferenceResolver = new SchemaReferenceResolver(publicUrlWithoutHash);
38 SchemaReference schemaReference = new SchemaReference(schemaReferenceResolver);
40 String expectedReference = SCHEMAS_PATH + "/file_with_one_line.json#/";
43 String actualReference = schemaReferenceMapper.mapToLocalSchema(schemaReference).getFullSchemaReference();
46 assertEquals(expectedReference, actualReference);
50 public void shouldReturnProperReferenceWhenSchemaReferenceContainsHash() {
52 SchemaReferenceMapper schemaReferenceMapper = getSchemaReferenceMapper();
53 String publicUrlWithHash = "http://someExternalUrl/external#someString";
54 SchemaReferenceResolver schemaReferenceResolver = new SchemaReferenceResolver(publicUrlWithHash);
55 SchemaReference schemaReference = new SchemaReference(schemaReferenceResolver);
56 String expectedReference = SCHEMAS_PATH + "/file_with_one_line.json#/someString";
59 String actualReference = schemaReferenceMapper.mapToLocalSchema(schemaReference).getFullSchemaReference();
62 assertEquals(expectedReference, actualReference);
65 private SchemaReferenceMapper getSchemaReferenceMapper() {
66 String mappingFilePath = "src/main/test/resources/schema-map-to-tests.json";
67 UrlMapper urlMapper = new UrlMapperFactory().getUrlMapper(mappingFilePath, SCHEMAS_PATH);
68 return new SchemaReferenceMapper(urlMapper, SCHEMAS_PATH);