Skip to content
Snippets Groups Projects
Commit b102ce2a authored by Riabokon Stanislav(EPAM)[GCP]'s avatar Riabokon Stanislav(EPAM)[GCP]
Browse files

Removed a creation bucket and file (GONRG-7773)

parent ea3376cf
No related branches found
No related tags found
2 merge requests!620Update version of default branch to 0.27.0-SNAPSHOT,!467Removed a creation bucket and file (GONRG-7773)
......@@ -19,6 +19,8 @@ package org.opengroup.osdu.legal.countries;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.partition.PartitionPropertyResolver;
import org.opengroup.osdu.core.gcp.obm.driver.Driver;
......@@ -27,7 +29,6 @@ import org.opengroup.osdu.core.gcp.obm.model.Blob;
import org.opengroup.osdu.core.gcp.obm.persistence.ObmDestination;
import org.opengroup.osdu.legal.config.PartitionPropertyNames;
import org.opengroup.osdu.legal.provider.interfaces.IStorageReader;
import org.springframework.http.MediaType;
import java.util.Objects;
......@@ -57,18 +58,16 @@ public class StorageReaderImpl implements IStorageReader {
public byte[] readAllBytes() {
byte[] content = null;
try {
if (storage.getBucket(getTenantBucketName(), getDestination()) == null) {
storage.createBucket(getTenantBucketName(), getDestination());
if (Objects.isNull(storage.getBucket(getTenantBucketName(), getDestination()))) {
log.error("Bucket %s is not existing.".formatted(getTenantBucketName()));
throw new AppException(
HttpStatus.SC_INTERNAL_SERVER_ERROR, "Internal error.", "Internal error.");
}
if (Objects.isNull(storage.getBlob(getTenantBucketName(), FILE_NAME, getDestination()))) {
Blob emptyBlob = Blob.builder()
.bucket(getTenantBucketName())
.name(FILE_NAME)
.contentType(MediaType.APPLICATION_JSON.toString())
.build();
storage.createBlob(emptyBlob, new byte[0], getDestination());
content = storage.getBlobContent(getTenantBucketName(), FILE_NAME, getDestination());
return content;
log.error(
"File %s in bucket %s is not existing.".formatted(FILE_NAME, getTenantBucketName()));
throw new AppException(
HttpStatus.SC_INTERNAL_SERVER_ERROR, "Internal error.", "Internal error.");
} else {
Blob blob = storage.getBlob(getTenantBucketName(), FILE_NAME, getDestination());
if (Objects.nonNull(blob)) {
......
......@@ -17,11 +17,6 @@
package org.opengroup.osdu.legal.countries;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.opengroup.osdu.legal.countries.StorageReaderImpl.BUCKET_NAME;
import static org.powermock.api.mockito.PowerMockito.when;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
......@@ -30,9 +25,11 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.partition.PartitionPropertyResolver;
import org.opengroup.osdu.core.gcp.obm.driver.Driver;
import org.opengroup.osdu.core.gcp.obm.driver.ObmDriverRuntimeException;
import org.opengroup.osdu.core.gcp.obm.model.Blob;
import org.opengroup.osdu.core.gcp.obm.model.Bucket;
import org.opengroup.osdu.core.gcp.obm.persistence.ObmDestination;
......@@ -40,6 +37,10 @@ import org.opengroup.osdu.legal.config.PartitionPropertyNames;
import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.opengroup.osdu.legal.countries.StorageReaderImpl.BUCKET_NAME;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(MockitoJUnitRunner.class)
public class StorageReaderImplTests {
......@@ -70,15 +71,12 @@ public class StorageReaderImplTests {
bucketName = "legal-service-configuration";
}
@Test
public void should_createBucketAndObject_when_bucketDoesNotExist() {
@Test(expected = AppException.class)
public void should_throw_Exception_when_bucketDoesNotExist() {
when(tenantInfo.getName()).thenReturn(TENANT_1);
when(tenantInfo.getDataPartitionId()).thenReturn(TENANT_1);
when(storage.getBlobContent(BUCKET_FULL_NAME, FILE_NAME, getDestination())).thenReturn(
new byte[0]);
byte[] bytes = sut.readAllBytes();
assertNotNull(bytes);
sut.readAllBytes();
}
@Test
......
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