From 139ed5c77beddbf1b2425f4378a2469916b1b91c Mon Sep 17 00:00:00 2001 From: UnchartedBull Date: Mon, 15 Jun 2020 16:43:52 +0200 Subject: [PATCH 1/2] add test for upload error --- .../distribution/objectstore/S3PublisherTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/S3PublisherTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/S3PublisherTest.java index 0b1bfb855e..303df1eef9 100644 --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/S3PublisherTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/S3PublisherTest.java @@ -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()); From a18dc955d1f7d29953552b8b81cd1c7c60c1638b Mon Sep 17 00:00:00 2001 From: UnchartedBull Date: Mon, 15 Jun 2020 17:10:07 +0200 Subject: [PATCH 2/2] add ObjectStoreAccess Tests --- .../ObjectStoreAccessUnitTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/ObjectStoreAccessUnitTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/ObjectStoreAccessUnitTest.java index 8474269561..3e4dd9f3f6 100644 --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/ObjectStoreAccessUnitTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/ObjectStoreAccessUnitTest.java @@ -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; @@ -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> 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)); + } }