Commit dd7b559f authored by Kishore Battula's avatar Kishore Battula
Browse files

Merge branch 'users/amaverma/moveToLatesCoreLib' into 'master'

consuming new methods defined in BlobStore class

See merge request !5
parents 9398f526 efa8ecbf
Pipeline #7077 passed with stages
in 18 minutes
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
<dependency> <dependency>
<groupId>org.opengroup.osdu</groupId> <groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId> <artifactId>core-lib-azure</artifactId>
<version>0.0.19</version> <version>0.0.23</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
......
...@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.opengroup.osdu.azure.blobstorage.BlobStore; import org.opengroup.osdu.azure.blobstorage.BlobStore;
import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.wks.model.MappingsModel; import org.opengroup.osdu.wks.model.MappingsModel;
import org.opengroup.osdu.wks.provider.azure.di.AzureBootstrapConfig;
import org.opengroup.osdu.wks.provider.interfaces.MappingStore; import org.opengroup.osdu.wks.provider.interfaces.MappingStore;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -19,12 +20,18 @@ public class MappingStoreImpl implements MappingStore { ...@@ -19,12 +20,18 @@ public class MappingStoreImpl implements MappingStore {
@Autowired @Autowired
private BlobStore blobStore; private BlobStore blobStore;
@Autowired
private AzureBootstrapConfig config;
@Override @Override
public MappingsModel getMapping(final String fileName) { public MappingsModel getMapping(final String fileName) {
MappingsModel mappings = null; MappingsModel mappings = null;
try { try {
String content = blobStore.readFromBlob(DpsHeaders.DATA_PARTITION_ID, fileName + JSON_EXTENSION); String content = blobStore.readFromStorageContainer(
DpsHeaders.DATA_PARTITION_ID,
fileName + JSON_EXTENSION,
config.containerName());
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
mappings = mapper.readValue(content, MappingsModel.class); mappings = mapper.readValue(content, MappingsModel.class);
} catch (Exception e) { } catch (Exception e) {
......
...@@ -2,6 +2,7 @@ package org.opengroup.osdu.wks.provider.azure.storage; ...@@ -2,6 +2,7 @@ package org.opengroup.osdu.wks.provider.azure.storage;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
...@@ -15,7 +16,10 @@ import org.opengroup.osdu.wks.provider.azure.di.AzureBootstrapConfig; ...@@ -15,7 +16,10 @@ import org.opengroup.osdu.wks.provider.azure.di.AzureBootstrapConfig;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
public class MappingStoreImplTest { public class MappingStoreImplTest {
...@@ -25,6 +29,7 @@ public class MappingStoreImplTest { ...@@ -25,6 +29,7 @@ public class MappingStoreImplTest {
private static final String wksSchemaKind = "opendes;wks:wellbore:1.0.0"; private static final String wksSchemaKind = "opendes;wks:wellbore:1.0.0";
private static final String rawAttribute = "well_id"; private static final String rawAttribute = "well_id";
private static final String wksAttribute = "wks_id"; private static final String wksAttribute = "wks_id";
private static final String containerName = "opendes";
@InjectMocks @InjectMocks
private MappingStoreImpl mappingStore; private MappingStoreImpl mappingStore;
...@@ -35,6 +40,12 @@ public class MappingStoreImplTest { ...@@ -35,6 +40,12 @@ public class MappingStoreImplTest {
@Mock @Mock
private AzureBootstrapConfig azureBootstrapConfig; private AzureBootstrapConfig azureBootstrapConfig;
@BeforeEach
public void init() {
initMocks(this);
when(azureBootstrapConfig.containerName()).thenReturn(containerName);
}
@Test @Test
public void shouldSuccessfullyReturnMappings() throws JsonProcessingException { public void shouldSuccessfullyReturnMappings() throws JsonProcessingException {
MappingsModel mappingsModel = new MappingsModel(); MappingsModel mappingsModel = new MappingsModel();
...@@ -46,8 +57,7 @@ public class MappingStoreImplTest { ...@@ -46,8 +57,7 @@ public class MappingStoreImplTest {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
String content = mapper.writeValueAsString(mappingsModel); String content = mapper.writeValueAsString(mappingsModel);
when(blobStore.readFromBlob(DpsHeaders.DATA_PARTITION_ID, fileName + JSON_EXTENSION)).thenReturn(content); when(blobStore.readFromStorageContainer(DpsHeaders.DATA_PARTITION_ID, fileName + JSON_EXTENSION, containerName)).thenReturn(content);
MappingsModel resultMappings = mappingStore.getMapping(fileName); MappingsModel resultMappings = mappingStore.getMapping(fileName);
assertEquals(mappingsModel.toString(), resultMappings.toString()); assertEquals(mappingsModel.toString(), resultMappings.toString());
...@@ -56,7 +66,7 @@ public class MappingStoreImplTest { ...@@ -56,7 +66,7 @@ public class MappingStoreImplTest {
@Test @Test
public void shouldReturnNullWhenMappingIsInvalid() { public void shouldReturnNullWhenMappingIsInvalid() {
String content = "{\n" + " \"name\": \"invalid_json\"\n" + "}"; String content = "{\n" + " \"name\": \"invalid_json\"\n" + "}";
when(blobStore.readFromBlob(DpsHeaders.DATA_PARTITION_ID, fileName + JSON_EXTENSION)).thenReturn(content); when(blobStore.readFromStorageContainer(DpsHeaders.DATA_PARTITION_ID, fileName + JSON_EXTENSION, containerName)).thenReturn(content);
MappingsModel mappings = mappingStore.getMapping(fileName); MappingsModel mappings = mappingStore.getMapping(fileName);
assertNull(mappings); assertNull(mappings);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment