Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Object Store / S3 Publisher Test #585

Merged
merged 3 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import app.coronawarn.server.services.distribution.config.DistributionServiceConfig;
import app.coronawarn.server.services.distribution.objectstore.client.ObjectStoreClient;
import app.coronawarn.server.services.distribution.objectstore.client.ObjectStoreClient.HeaderKey;
import app.coronawarn.server.services.distribution.objectstore.client.S3Object;
import app.coronawarn.server.services.distribution.objectstore.publish.LocalFile;
import java.io.File;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -111,4 +114,36 @@ void testPutObjectSetsSpecifiedCacheControlHeader() {
.putObject(eq(expBucketName), eq(EXP_S3_KEY), eq(expPath), headers.capture());
Assertions.assertThat(headers.getValue()).contains(expHeader);
}

@Test
void putObjectSetsSpecifiedFileChecksum() {
when(testLocalFile.getChecksum()).thenReturn("test-hash");

ArgumentCaptor<Map<HeaderKey, String>> headers = ArgumentCaptor.forClass(Map.class);
var expHash = "test-hash";
var expHeader = entry(HeaderKey.CWA_HASH, expHash);

objectStoreAccess.putObject(testLocalFile);

verify(objectStoreClient, atLeastOnce())
.putObject(eq(expBucketName), eq(EXP_S3_KEY), eq(expPath), headers.capture());
Assertions.assertThat(headers.getValue()).contains(expHeader);
}

@Test
void shouldDeleteMatchingFiles() {
var fileToDelete1 = new S3Object("test-file-1");
var fileToDelete2 = new S3Object("test-file-2");
var fileToDelete3 = new S3Object("test-file-3");

var filesToDelete = List.of(fileToDelete1, fileToDelete2, fileToDelete3);
var filesToDeleteObjectName = List
.of(fileToDelete1.getObjectName(), fileToDelete2.getObjectName(), fileToDelete3.getObjectName());

when(objectStoreClient.getObjects(any(), any())).thenReturn(filesToDelete);

objectStoreAccess.deleteObjectsWithPrefix("");

verify(objectStoreClient, times(1)).removeObjects(eq(expBucketName), eq(filesToDeleteObjectName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ void uploadOneDueToOneChanged() throws IOException {
verify(objectStoreAccess, times(1)).putObject(any());
}

@Test
void uploadAllDueToError() throws IOException {
when(objectStoreAccess.getObjectsWithPrefix("version")).thenThrow(new ObjectStoreOperationFailedException(""));

s3Publisher.publish(publishingPath);

verify(objectStoreAccess, times(3)).putObject(any());
}

@Test
void executorGetsShutDown() throws IOException {
when(objectStoreAccess.getObjectsWithPrefix("version")).thenReturn(emptyList());
Expand Down