Commit 4edabd59 authored by Aman Verma's avatar Aman Verma
Browse files

addressing MR comments

parent 9df77ea8
Pipeline #7078 passed with stages
in 11 minutes and 6 seconds
......@@ -17,6 +17,7 @@ package org.opengroup.osdu.schema.azure.impl.schemastore;
import org.opengroup.osdu.azure.blobstorage.BlobStore;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.schema.azure.di.AzureBootstrapConfig;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
import org.opengroup.osdu.schema.exceptions.NotFoundException;
......@@ -39,7 +40,7 @@ public class AzureSchemaStore implements ISchemaStore {
private BlobStore blobStore;
@Autowired
private String containerName;
private AzureBootstrapConfig config;
@Autowired
JaxRsDpsLog log;
......@@ -58,7 +59,7 @@ public class AzureSchemaStore implements ISchemaStore {
public String getSchema(String dataPartitionId, String filePath) throws ApplicationException, NotFoundException {
filePath = dataPartitionId + ":" + filePath + SchemaConstants.JSON_EXTENSION;
try {
String content = blobStore.readFromStorageContainer(dataPartitionId, filePath, containerName);
String content = blobStore.readFromStorageContainer(dataPartitionId, filePath, config.containerName());
if (content != null)
return content;
else
......@@ -84,7 +85,7 @@ public class AzureSchemaStore implements ISchemaStore {
filePath = dataPartitionId + ":" + filePath + SchemaConstants.JSON_EXTENSION;
try {
blobStore.writeToStorageContainer(dataPartitionId, filePath, content, containerName);
blobStore.writeToStorageContainer(dataPartitionId, filePath, content, config.containerName());
return filePath;
} catch (Exception ex) {
throw new ApplicationException(SchemaConstants.INTERNAL_SERVER_ERROR);
......@@ -104,7 +105,7 @@ public class AzureSchemaStore implements ISchemaStore {
try
{
return blobStore.deleteFromStorageContainer(dataPartitionId, filePath, containerName);
return blobStore.deleteFromStorageContainer(dataPartitionId, filePath, config.containerName());
}
catch (Exception e)
{
......
......@@ -25,6 +25,7 @@ import org.opengroup.osdu.azure.blobstorage.BlobStore;
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.DpsHeaders;
import org.opengroup.osdu.schema.azure.di.AzureBootstrapConfig;
import org.opengroup.osdu.schema.azure.impl.schemastore.AzureSchemaStore;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
......@@ -40,6 +41,9 @@ public class AzureSchemaStoreTest {
@Mock
BlobStore blobStore;
@Mock
AzureBootstrapConfig config;
@Mock
DpsHeaders headers;
......@@ -52,17 +56,19 @@ public class AzureSchemaStoreTest {
private static final String dataPartitionId = "dataPartitionId";
private static final String FILE_PATH = "/test-folder/test-file";
private static final String CONTENT = "Hello World";
private static final String containerName = "opendes";
private static final String filePath = dataPartitionId + ":" + FILE_PATH + SchemaConstants.JSON_EXTENSION;
@Before
public void init(){
initMocks(this);
doReturn(dataPartitionId).when(headers).getPartitionId();
when(config.containerName()).thenReturn(containerName);
}
@Test
public void testGetSchema() throws ApplicationException, NotFoundException {
doReturn(CONTENT).when(blobStore).readFromStorageContainer(eq(dataPartitionId), eq(filePath), any());
doReturn(CONTENT).when(blobStore).readFromStorageContainer(dataPartitionId, filePath, containerName);
Assert.assertEquals(CONTENT, schemaStore.getSchema(dataPartitionId, FILE_PATH));
}
......@@ -70,7 +76,7 @@ public class AzureSchemaStoreTest {
public void testGetSchema_NotFound() throws ApplicationException, NotFoundException {
expectedException.expect(NotFoundException.class);
expectedException.expectMessage(SchemaConstants.SCHEMA_NOT_PRESENT);
doReturn(null).when(blobStore).readFromStorageContainer(eq(dataPartitionId), eq(filePath), any());
doReturn(null).when(blobStore).readFromStorageContainer(dataPartitionId, filePath, containerName);
schemaStore.getSchema(dataPartitionId, FILE_PATH);
}
......@@ -79,13 +85,13 @@ public class AzureSchemaStoreTest {
expectedException.expect(NotFoundException.class);
expectedException.expectMessage(SchemaConstants.SCHEMA_NOT_PRESENT);
doThrow(AppException.class).when(blobStore).readFromStorageContainer(eq(dataPartitionId), eq(filePath), any());
doThrow(AppException.class).when(blobStore).readFromStorageContainer(dataPartitionId, filePath, containerName);
schemaStore.getSchema(dataPartitionId, FILE_PATH);
}
@Test
public void testDeleteSchema() throws ApplicationException {
doReturn(true).when(blobStore).deleteFromStorageContainer(eq(dataPartitionId), eq(filePath), any());
doReturn(true).when(blobStore).deleteFromStorageContainer(dataPartitionId, filePath, containerName);
Boolean result = schemaStore.cleanSchemaProject(FILE_PATH);
Assert.assertEquals(true, result);
......@@ -96,14 +102,14 @@ public class AzureSchemaStoreTest {
expectedException.expect(ApplicationException.class);
expectedException.expectMessage(SchemaConstants.INTERNAL_SERVER_ERROR);
doThrow(AppException.class).when(blobStore).deleteFromStorageContainer(eq(dataPartitionId), eq(filePath), any());
doThrow(AppException.class).when(blobStore).deleteFromStorageContainer(dataPartitionId, filePath, containerName);
schemaStore.cleanSchemaProject(FILE_PATH);
}
@Test
public void testCreateSchema() throws ApplicationException {
doNothing().when(blobStore).writeToStorageContainer(eq(dataPartitionId), eq(filePath), eq(CONTENT), any());
doNothing().when(blobStore).writeToStorageContainer(dataPartitionId, filePath, CONTENT, containerName);
Assert.assertEquals(filePath, schemaStore.createSchema(FILE_PATH, CONTENT));
}
......@@ -112,7 +118,7 @@ public class AzureSchemaStoreTest {
expectedException.expect(ApplicationException.class);
expectedException.expectMessage(SchemaConstants.INTERNAL_SERVER_ERROR);
doThrow(AppException.class).when(blobStore).writeToStorageContainer(eq(dataPartitionId), eq(filePath), eq(CONTENT), any());
doThrow(AppException.class).when(blobStore).writeToStorageContainer(dataPartitionId, filePath, CONTENT, containerName);
schemaStore.createSchema(FILE_PATH, CONTENT);
}
}
Markdown is supported
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