diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessor.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessor.java index 3a2918cc945142e13c5649ed45ba8cf165b5c740..6de10d528cea2a4cbffe060409d361a21ef8c99a 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessor.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessor.java @@ -88,7 +88,7 @@ public class PropertiesProcessor { return definition.getProperties().entrySet().stream().flatMap(this::processPropertyEntry); } - protected Stream<Map<String, Object>> processPropertyEntry(Map.Entry<String, TypeProperty> entry) { + private Stream<Map<String, Object>> processPropertyEntry(Map.Entry<String, TypeProperty> entry) { Preconditions.checkNotNull(entry, "entry cannot be null"); if ("object".equals(entry.getValue().getType()) @@ -120,7 +120,7 @@ public class PropertiesProcessor { return storageSchemaEntry(getTypeByDefinitionProperty(entry.getValue()), pathPrefixWithDot + entry.getKey()); } - protected Stream<Map<String, Object>> storageSchemaEntry(String kind, String path) { + private Stream<Map<String, Object>> storageSchemaEntry(String kind, String path) { Preconditions.checkNotNullOrEmpty(kind, "kind cannot be null or empty"); Preconditions.checkNotNullOrEmpty(path, "path cannot be null or empty"); @@ -130,7 +130,7 @@ public class PropertiesProcessor { return Stream.of(map); } - protected String getTypeByDefinitionProperty(TypeProperty definitionProperty) { + private String getTypeByDefinitionProperty(TypeProperty definitionProperty) { Preconditions.checkNotNull(definitionProperty, "definitionProperty cannot be null"); return Stream.of( @@ -143,32 +143,32 @@ public class PropertiesProcessor { .orElse(getFromType(definitionProperty::getType)).get(); } - protected Supplier<String> getFromPattern(String pattern) { + private Supplier<String> getFromPattern(String pattern) { return () -> Objects.nonNull(pattern) && pattern.startsWith(LINK_PREFIX) ? LINK_TYPE : null; } - protected Supplier<String> getFromItemsPattern(Supplier<String> itemsPatternSupplier) { + private Supplier<String> getFromItemsPattern(Supplier<String> itemsPatternSupplier) { return () -> { String itemsPattern = itemsPatternSupplier.get(); return Objects.nonNull(itemsPattern) && itemsPattern.startsWith(LINK_PREFIX) ? LINK_TYPE : null; }; } - protected Supplier<String> getFromType(Supplier<String> typeSupplier) { + private Supplier<String> getFromType(Supplier<String> typeSupplier) { return () -> { String type = typeSupplier.get(); return schemaConverterConfig.getPrimitiveTypesMap().getOrDefault(type, type); }; } - protected Supplier<String> getFromFormat(Supplier<String> formatSupplier){ + private Supplier<String> getFromFormat(Supplier<String> formatSupplier){ return () -> { String format = formatSupplier.get();; return Objects.nonNull(format) ? schemaConverterConfig.getPrimitiveTypesMap().getOrDefault(format, format) : null; }; } - protected Supplier<String> getFromItemsType(Supplier<String> itemsTypeSupplier) { + private Supplier<String> getFromItemsType(Supplier<String> itemsTypeSupplier) { return () -> { String itemsType = itemsTypeSupplier.get(); return Objects.nonNull(itemsType) ? schemaConverterConfig.getPrimitiveTypesMap().getOrDefault(itemsType, itemsType) : null; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImpl.java index 98141b5d0ae7725ba5f3c7c5db788b11c39fa53b..d35c8d257f4ac4f16ce4c214558ae6f3b0f4653d 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImpl.java @@ -64,7 +64,7 @@ public class SchemaToStorageFormatImpl implements SchemaToStorageFormat { return convert(parserJsonString(schemaServiceFormat), kind); } - protected SchemaRoot parserJsonString(final String schemaServiceFormat) { + private SchemaRoot parserJsonString(final String schemaServiceFormat) { try { return objectMapper.readValue(schemaServiceFormat, SchemaRoot.class); } catch (JsonProcessingException e) { @@ -72,7 +72,7 @@ public class SchemaToStorageFormatImpl implements SchemaToStorageFormat { } } - protected String saveJsonToString(final Map<String, Object> schemaServiceFormat) { + private String saveJsonToString(final Map<String, Object> schemaServiceFormat) { try { return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(schemaServiceFormat); } catch (JsonProcessingException e) { @@ -80,7 +80,7 @@ public class SchemaToStorageFormatImpl implements SchemaToStorageFormat { } } - public Map<String, Object> convert(SchemaRoot schemaServiceSchema, String kind) { + private Map<String, Object> convert(SchemaRoot schemaServiceSchema, String kind) { Preconditions.checkNotNull(objectMapper, "schemaServiceSchema cannot be null"); Preconditions.checkNotNullOrEmpty(kind, "kind cannot be null or empty"); diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java index c824cb0dc48a87b526cf2cdc91bab8c41d23d9ed..113dc54bde6c9e4bf11e2fc36ab1725d0be77b72 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java @@ -160,7 +160,7 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { } } - protected String getSchema(String kind) throws URISyntaxException, UnsupportedEncodingException { + private String getSchema(String kind) throws URISyntaxException, UnsupportedEncodingException { return this.schemaProvider.getSchema(kind); } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/impl/SchemaProviderImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/impl/SchemaProviderImpl.java index f44c8dba7c40990e344b22de87ff943ac8ee0c17..70ef41dd6cef5e0c6687ad38f2fb1de8b6a08ffe 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/impl/SchemaProviderImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/impl/SchemaProviderImpl.java @@ -67,7 +67,7 @@ public class SchemaProviderImpl implements SchemaService { return getFromSchemaService(kind); } - public String getFromSchemaService(String kind) throws UnsupportedEncodingException, URISyntaxException { + protected String getFromSchemaService(String kind) throws UnsupportedEncodingException, URISyntaxException { HttpResponse response = getSchemaServiceResponse(kind); if (response.getResponseCode() == HttpStatus.SC_NOT_FOUND) { @@ -79,7 +79,7 @@ public class SchemaProviderImpl implements SchemaService { schemaToStorageFormat.convertToString(response.getBody(), kind); } - public String getFromStorageService(String kind) throws URISyntaxException, UnsupportedEncodingException { + protected String getFromStorageService(String kind) throws URISyntaxException, UnsupportedEncodingException { String schemaFromStorageService = storageService.getStorageSchema(kind); if (schemaFromStorageService != null) { @@ -91,7 +91,7 @@ public class SchemaProviderImpl implements SchemaService { return null; } - protected HttpResponse getSchemaServiceResponse(String kind) throws UnsupportedEncodingException, URISyntaxException { + private HttpResponse getSchemaServiceResponse(String kind) throws UnsupportedEncodingException, URISyntaxException { String url = String.format("%s/%s", configurationProperties.getSchemaHost(), URLEncoder.encode(kind, StandardCharsets.UTF_8.toString())); FetchServiceHttpRequest request = FetchServiceHttpRequest.builder() .httpMethod(HttpMethods.GET) diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/impl/SchemaProviderImplTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/impl/SchemaProviderImplTest.java index ad121b7d1d7fcd711148c715fa52e0e7598affbd..a3c5b46e73f938c8b5824fe484a7aa993919d5a0 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/impl/SchemaProviderImplTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/impl/SchemaProviderImplTest.java @@ -12,31 +12,34 @@ // See the License for the specific language governing permissions and // limitations under the License.package org.opengroup.osdu.indexer.service.impl; +package org.opengroup.osdu.indexer.service.impl; + +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.http.HttpStatus; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.Spy; +import org.mockito.*; import org.opengroup.osdu.core.common.http.IUrlFetchService; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.http.HttpResponse; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.schema.converter.SchemaToStorageFormatImpl; import org.opengroup.osdu.indexer.service.StorageService; -import org.opengroup.osdu.indexer.service.impl.SchemaProviderImpl; +import org.powermock.api.mockito.PowerMockito; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.test.context.junit4.SpringRunner; import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; +import java.util.Map; +import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; +import static org.powermock.api.mockito.PowerMockito.when; @RunWith(SpringRunner.class) public class SchemaProviderImplTest { @@ -77,4 +80,98 @@ public class SchemaProviderImplTest { "}", schema); } + + @Test + public void should_returnValidResponse_givenValidSchema() throws Exception { + + String validSchemaFromSchemaService = "{\n" + + "\"properties\": {" + + " \"data\":{\n" + + " \"allOf\":[\n" + + " {\n" + + " \"type\":\"object\",\n" + + " \"properties\":{\n" + + " \"WellID\":{\n" + + " \"type\":\"string\",\n" + + " \"pattern\":\"^srn:<namespace>:master-data\\\\/Well:[^:]+:[0-9]*$\"\n" + + " }\n" + + " }\n" + + " }\n" + + " ]\n" + + " }\n" + + " }\n" + + "}"; + String kind = "tenant:test:test:1.0.0"; + + HttpResponse httpResponse = new HttpResponse(); + httpResponse.setResponseCode(org.springframework.http.HttpStatus.OK.value()); + httpResponse.setBody(validSchemaFromSchemaService); + + PowerMockito.when(this.urlFetchService.sendRequest(any())).thenReturn(httpResponse); + + String recordSchemaResponse = this.sut.getSchema(kind); + + Map<String, Object> result = objectMapper.readValue(recordSchemaResponse, + new TypeReference<Map<String,Object>>(){}); + assertEquals("Schema must have two root items", 2, result.size()); + assertEquals("Wrong kind", "tenant:test:test:1.0.0", result.get("kind")); + assertEquals("Wrong schema attributes", "[{path=WellID, kind=link}]", result.get("schema").toString()); + + assertNotNull(recordSchemaResponse); + } + + @Test + public void should_returnNullResponse_givenAbsentKind_getSchemaByKind() throws Exception { + + String kind = "tenant:test:test:1.0.0"; + + HttpResponse httpResponse = new HttpResponse(); + httpResponse.setResponseCode(org.springframework.http.HttpStatus.NOT_FOUND.value()); + + PowerMockito.when(this.urlFetchService.sendRequest(any())).thenReturn(httpResponse); + + String recordSchemaResponse = this.sut.getSchema(kind); + + assertNull(recordSchemaResponse); + } + + @Test + public void should_call_Storage_then_Schema() throws Exception { + String kind = "tenant:test:test:1.0.0"; + + SchemaProviderImpl schemaService = Mockito.mock(SchemaProviderImpl.class); + PowerMockito.when(schemaService.getSchema(any())).thenCallRealMethod(); + + InOrder inOrder = inOrder(schemaService); + + String recordSchemaResponse = schemaService.getSchema(kind); + assertNull(recordSchemaResponse); + + inOrder.verify(schemaService).getSchema(any()); + inOrder.verify(schemaService).getFromStorageService(any()); + inOrder.verify(schemaService).getFromSchemaService(any()); + verify(schemaService, times(1)).getFromStorageService(any()); + verify(schemaService, times(1)).getFromSchemaService(any()); + } + + @Test + public void should_call_only_Storage_if_it_returns_result() throws Exception { + String kind = "tenant:test:test:1.0.0"; + + SchemaProviderImpl schemaService = Mockito.mock(SchemaProviderImpl.class); + when(schemaService.getSchema(any())).thenCallRealMethod(); + String someSchema = "some schema"; + when(schemaService.getFromStorageService(any())).thenReturn(someSchema); + + InOrder inOrder = inOrder(schemaService); + + String recordSchemaResponse = schemaService.getSchema(kind); + assertEquals(recordSchemaResponse, someSchema); + + inOrder.verify(schemaService).getSchema(any()); + inOrder.verify(schemaService).getFromStorageService(any()); + verify(schemaService, times(0)).getFromSchemaService(any()); + verify(schemaService, times(1)).getFromStorageService(any()); + } + } \ No newline at end of file diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexerSchemaServiceTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexerSchemaServiceTest.java index 65e6b0d8f5b19e36b9d191d41dfec1e9c89aada1..9cc054aaaa67619bd8631e00b74fc4d330bad954 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexerSchemaServiceTest.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexerSchemaServiceTest.java @@ -23,19 +23,18 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.http.RequestStatus; import org.opengroup.osdu.core.common.model.indexer.IndexSchema; import org.opengroup.osdu.core.common.model.indexer.OperationType; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; +import org.opengroup.osdu.core.common.search.IndicesService; import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; import org.opengroup.osdu.indexer.service.IndexSchemaServiceImpl; import org.opengroup.osdu.indexer.service.IndexerMappingService; import org.opengroup.osdu.indexer.service.SchemaService; -import org.opengroup.osdu.indexer.service.StorageService; -import org.opengroup.osdu.core.common.model.http.RequestStatus; -import org.opengroup.osdu.core.common.search.IndicesService; -import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.indexer.util.ElasticClientHandler; -import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; @@ -63,8 +62,6 @@ public class IndexerSchemaServiceTest { @Mock private JaxRsDpsLog log; @Mock - private StorageService storageService; - @Mock private ElasticClientHandler elasticClientHandler; @Mock private ElasticIndexNameResolver elasticIndexNameResolver; diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/SchemaProviderTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/SchemaProviderTest.java deleted file mode 100644 index ddacb1a97ba139c5ac63b156f8998e57d2963df7..0000000000000000000000000000000000000000 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/SchemaProviderTest.java +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright 2017-2019, Schlumberger -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.indexer.azure.service; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.*; -import org.opengroup.osdu.core.common.http.IUrlFetchService; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.core.common.model.http.HttpResponse; -import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; -import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; -import org.opengroup.osdu.indexer.schema.converter.SchemaToStorageFormatImpl; -import org.opengroup.osdu.indexer.service.StorageService; -import org.opengroup.osdu.indexer.service.impl.SchemaProviderImpl; -import org.springframework.http.HttpStatus; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(SpringRunner.class) -public class SchemaProviderTest { - - private ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build(); - private JaxRsDpsLog log = Mockito.mock(JaxRsDpsLog.class); - - @Spy - private SchemaToStorageFormatImpl schemaToStorageFormatImpl = new SchemaToStorageFormatImpl(objectMapper, log, null); - @Mock - private IUrlFetchService urlFetchService; - @Mock - private IRequestInfo requestInfo; - @Mock - private StorageService storageService; - @Mock - private IndexerConfigurationProperties configurationProperties; - - @InjectMocks - private SchemaProviderImpl sut; - - @Before - public void setup() { - when(this.requestInfo.getHeadersMap()).thenReturn(new HashMap<>()); - } - - @Test - public void should_returnValidResponse_givenValidSchema() throws Exception { - - String validSchemaFromSchemaService = "{\n" + - "\"properties\": {" + - " \"data\":{\n" + - " \"allOf\":[\n" + - " {\n" + - " \"type\":\"object\",\n" + - " \"properties\":{\n" + - " \"WellID\":{\n" + - " \"type\":\"string\",\n" + - " \"pattern\":\"^srn:<namespace>:master-data\\\\/Well:[^:]+:[0-9]*$\"\n" + - " }\n" + - " }\n" + - " }\n" + - " ]\n" + - " }\n" + - " }\n" + - "}"; - String kind = "tenant:test:test:1.0.0"; - - HttpResponse httpResponse = new HttpResponse(); - httpResponse.setResponseCode(HttpStatus.OK.value()); - httpResponse.setBody(validSchemaFromSchemaService); - - when(this.urlFetchService.sendRequest(any())).thenReturn(httpResponse); - - String recordSchemaResponse = this.sut.getSchema(kind); - - Map<String, Object> result = objectMapper.readValue(recordSchemaResponse, - new TypeReference<Map<String,Object>>(){}); - assertEquals("Schema must have two root items", 2, result.size()); - assertEquals("Wrong kind", "tenant:test:test:1.0.0", result.get("kind")); - assertEquals("Wrong schema attributes", "[{path=WellID, kind=link}]", result.get("schema").toString()); - - assertNotNull(recordSchemaResponse); - } - - @Test - public void should_returnNullResponse_givenAbsentKind_getSchemaByKind() throws Exception { - - String kind = "tenant:test:test:1.0.0"; - - HttpResponse httpResponse = new HttpResponse(); - httpResponse.setResponseCode(HttpStatus.NOT_FOUND.value()); - - when(this.urlFetchService.sendRequest(any())).thenReturn(httpResponse); - - String recordSchemaResponse = this.sut.getSchema(kind); - - assertNull(recordSchemaResponse); - } - - @Test - public void should_call_Storage_then_Schema() throws Exception { - String kind = "tenant:test:test:1.0.0"; - - SchemaProviderImpl schemaService = Mockito.mock(SchemaProviderImpl.class); - when(schemaService.getSchema(any())).thenCallRealMethod(); - - InOrder inOrder = inOrder(schemaService); - - String recordSchemaResponse = schemaService.getSchema(kind); - assertNull(recordSchemaResponse); - - inOrder.verify(schemaService).getSchema(any()); - inOrder.verify(schemaService).getFromStorageService(any()); - inOrder.verify(schemaService).getFromSchemaService(any()); - verify(schemaService, times(1)).getFromStorageService(any()); - verify(schemaService, times(1)).getFromSchemaService(any()); - } - - @Test - public void should_call_only_Storage_if_it_returns_result() throws Exception { - String kind = "tenant:test:test:1.0.0"; - - SchemaProviderImpl schemaService = Mockito.mock(SchemaProviderImpl.class); - when(schemaService.getSchema(any())).thenCallRealMethod(); - String someSchema = "some schema"; - when(schemaService.getFromStorageService(any())).thenReturn(someSchema); - - InOrder inOrder = inOrder(schemaService); - - String recordSchemaResponse = schemaService.getSchema(kind); - assertEquals(recordSchemaResponse, someSchema); - - inOrder.verify(schemaService).getSchema(any()); - inOrder.verify(schemaService).getFromStorageService(any()); - verify(schemaService, times(0)).getFromSchemaService(any()); - verify(schemaService, times(1)).getFromStorageService(any()); - } -} diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/StorageServiceTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/StorageServiceTest.java index 035b64283f6bd4a7e47c94d4582547f580b39073..d32955169190c779486a55fe6b549b7ef7b20c09 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/StorageServiceTest.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/StorageServiceTest.java @@ -169,6 +169,51 @@ public class StorageServiceTest { assertNull(recordQueryResponse.getResults()); } + @Test + public void should_returnValidResponse_givenValidKind_getSchemaByKind() throws Exception { + + String validSchemaFromStorage = "{" + + " \"kind\": \"tenant:test:test:1.0.0\"," + + " \"schema\": [" + + " {" + + " \"path\": \"msg\"," + + " \"kind\": \"string\"" + + " }," + + " {" + + " \"path\": \"references.entity\"," + + " \"kind\": \"string\"" + + " }" + + " ]," + + " \"ext\": null" + + "}"; + String kind = "tenant:test:test:1.0.0"; + + HttpResponse httpResponse = new HttpResponse(); + httpResponse.setResponseCode(HttpStatus.OK.value()); + httpResponse.setBody(validSchemaFromStorage); + + when(this.urlFetchService.sendRequest(ArgumentMatchers.any())).thenReturn(httpResponse); + + String recordSchemaResponse = this.sut.getStorageSchema(kind); + + assertNotNull(recordSchemaResponse); + } + + @Test + public void should_returnNullResponse_givenAbsentKind_getSchemaByKind() throws Exception { + + String kind = "tenant:test:test:1.0.0"; + + HttpResponse httpResponse = new HttpResponse(); + httpResponse.setResponseCode(HttpStatus.NOT_FOUND.value()); + + when(this.urlFetchService.sendRequest(ArgumentMatchers.any())).thenReturn(httpResponse); + + String recordSchemaResponse = this.sut.getStorageSchema(kind); + + assertNull(recordSchemaResponse); + } + @Test public void should_returnOneValidRecords_givenValidData_getValidStorageRecordsWithInvalidConversionTest() throws URISyntaxException {