Skip to content
Snippets Groups Projects
Commit ac0584ab authored by Sviatoslav Nekhaienko's avatar Sviatoslav Nekhaienko
Browse files

change schema retrieval order

parent 3b031962
No related branches found
No related tags found
1 merge request!105change schema retrieval order
Pipeline #29394 failed
...@@ -32,6 +32,7 @@ import java.io.UnsupportedEncodingException; ...@@ -32,6 +32,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Objects;
/** /**
* Provides implementation of the client service that retrieves schemas from the Schema Service * Provides implementation of the client service that retrieves schemas from the Schema Service
...@@ -58,13 +59,9 @@ public class SchemaProviderImpl implements SchemaService { ...@@ -58,13 +59,9 @@ public class SchemaProviderImpl implements SchemaService {
@Override @Override
public String getSchema(String kind) throws URISyntaxException, UnsupportedEncodingException { public String getSchema(String kind) throws URISyntaxException, UnsupportedEncodingException {
String schemaFromStorageService = getFromStorageService(kind); String schemaServiceSchema = getFromSchemaService(kind);
if (schemaFromStorageService != null) { return Objects.nonNull(schemaServiceSchema) ? schemaServiceSchema : getFromStorageService(kind);
return schemaFromStorageService;
}
return getFromSchemaService(kind);
} }
protected String getFromSchemaService(String kind) throws UnsupportedEncodingException, URISyntaxException { protected String getFromSchemaService(String kind) throws UnsupportedEncodingException, URISyntaxException {
......
...@@ -136,7 +136,7 @@ public class SchemaProviderImplTest { ...@@ -136,7 +136,7 @@ public class SchemaProviderImplTest {
} }
@Test @Test
public void should_call_Storage_then_Schema() throws Exception { public void should_call_Schema_then_Storage() throws Exception {
String kind = "tenant:test:test:1.0.0"; String kind = "tenant:test:test:1.0.0";
SchemaProviderImpl schemaService = Mockito.mock(SchemaProviderImpl.class); SchemaProviderImpl schemaService = Mockito.mock(SchemaProviderImpl.class);
...@@ -148,20 +148,20 @@ public class SchemaProviderImplTest { ...@@ -148,20 +148,20 @@ public class SchemaProviderImplTest {
assertNull(recordSchemaResponse); assertNull(recordSchemaResponse);
inOrder.verify(schemaService).getSchema(any()); inOrder.verify(schemaService).getSchema(any());
inOrder.verify(schemaService).getFromStorageService(any());
inOrder.verify(schemaService).getFromSchemaService(any()); inOrder.verify(schemaService).getFromSchemaService(any());
inOrder.verify(schemaService).getFromStorageService(any());
verify(schemaService, times(1)).getFromStorageService(any()); verify(schemaService, times(1)).getFromStorageService(any());
verify(schemaService, times(1)).getFromSchemaService(any()); verify(schemaService, times(1)).getFromSchemaService(any());
} }
@Test @Test
public void should_call_only_Storage_if_it_returns_result() throws Exception { public void should_call_only_SchemaService_if_it_returns_result() throws Exception {
String kind = "tenant:test:test:1.0.0"; String kind = "tenant:test:test:1.0.0";
SchemaProviderImpl schemaService = Mockito.mock(SchemaProviderImpl.class); SchemaProviderImpl schemaService = Mockito.mock(SchemaProviderImpl.class);
when(schemaService.getSchema(any())).thenCallRealMethod(); when(schemaService.getSchema(any())).thenCallRealMethod();
String someSchema = "some schema"; String someSchema = "some schema";
when(schemaService.getFromStorageService(any())).thenReturn(someSchema); when(schemaService.getFromSchemaService(any())).thenReturn(someSchema);
InOrder inOrder = inOrder(schemaService); InOrder inOrder = inOrder(schemaService);
...@@ -169,9 +169,9 @@ public class SchemaProviderImplTest { ...@@ -169,9 +169,9 @@ public class SchemaProviderImplTest {
assertEquals(recordSchemaResponse, someSchema); assertEquals(recordSchemaResponse, someSchema);
inOrder.verify(schemaService).getSchema(any()); inOrder.verify(schemaService).getSchema(any());
inOrder.verify(schemaService).getFromStorageService(any()); inOrder.verify(schemaService).getFromSchemaService(any());
verify(schemaService, times(0)).getFromSchemaService(any()); verify(schemaService, times(1)).getFromSchemaService(any());
verify(schemaService, times(1)).getFromStorageService(any()); verify(schemaService, times(0)).getFromStorageService(any());
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment