Skip to content

Commit

Permalink
Upgrade depenedencies and minor refactoring (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyanli-amazon authored Mar 23, 2023
1 parent 7c826fc commit 8c59e59
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 73 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "maven"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ You can download release builds through the [releases section of this](https://g
<dependency>
<groupId>software.amazon.payloadoffloading</groupId>
<artifactId>payloadoffloading-common</artifactId>
<version>2.1.2</version>
<version>2.1.3</version>
</dependency>
```

Expand Down
49 changes: 24 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>software.amazon.payloadoffloading</groupId>
<artifactId>payloadoffloading-common</artifactId>
<version>2.1.2</version>
<version>2.1.3</version>
<packaging>jar</packaging>
<name>Payload offloading common library for AWS</name>
<description>Common library between extended Amazon AWS clients to save payloads up to 2GB on Amazon S3.</description>
Expand Down Expand Up @@ -36,7 +36,7 @@
</developers>

<properties>
<aws-java-sdk.version>2.16.73</aws-java-sdk.version>
<aws-java-sdk.version>2.20.30</aws-java-sdk.version>
</properties>

<dependencies>
Expand All @@ -50,29 +50,27 @@
<artifactId>utils</artifactId>
<version>${aws-java-sdk.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.14.2</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.3.3</version>
<scope>test</scope>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.2</version>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<version>1.1.1</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -83,7 +81,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand All @@ -106,31 +104,32 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<version>3.5.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<!--
TODO-RS: Java 8 is more strict about some javadoc tags.
We'll need to update quite a few to remove this workaround.
-->
<source>8</source>
<additionalparam>-Xdoclint:none</additionalparam>
<doclint>none</doclint>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package software.amazon.payloadoffloading;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.ServerSideEncryption;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;


public class AwsManagedCmkTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package software.amazon.payloadoffloading;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.ServerSideEncryption;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class CustomerKeyTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package software.amazon.payloadoffloading;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.ObjectCannedACL;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.junit.Assert.*;

/**
* Tests the PayloadStorageConfiguration class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package software.amazon.payloadoffloading;

import junitparams.JUnitParamsRunner;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import software.amazon.awssdk.core.exception.SdkClientException;
import software.amazon.awssdk.core.exception.SdkException;
import software.amazon.awssdk.services.s3.model.ObjectCannedACL;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;

@RunWith(JUnitParamsRunner.class)
public class S3BackedPayloadStoreTest {
private static final String S3_BUCKET_NAME = "test-bucket-name";
private static final String ANY_PAYLOAD = "AnyPayload";
Expand All @@ -25,10 +27,7 @@ public class S3BackedPayloadStoreTest {
private PayloadStore payloadStore;
private S3Dao s3Dao;

@Rule
public final ExpectedException exception = ExpectedException.none();

@Before
@BeforeEach
public void setup() {
s3Dao = mock(S3Dao.class);
payloadStore = new S3BackedPayloadStore(s3Dao, S3_BUCKET_NAME);
Expand Down Expand Up @@ -84,8 +83,8 @@ public void testStoreOriginalPayloadDoesAlwaysCreateNewObjects() {
PayloadS3Pointer anyOtherExpectedPayloadPointer = new PayloadS3Pointer(S3_BUCKET_NAME, anyOtherS3Key);
assertEquals(anyOtherExpectedPayloadPointer.toJson(), anyOtherActualPayloadPointer);

assertThat(anyS3Key, Matchers.not(anyOtherS3Key));
assertThat(anyActualPayloadPointer, Matchers.not(anyOtherActualPayloadPointer));
assertNotEquals(anyS3Key, anyOtherS3Key);
assertNotEquals(anyActualPayloadPointer, anyOtherActualPayloadPointer);
}

@Test
Expand All @@ -97,10 +96,8 @@ public void testStoreOriginalPayloadOnS3Failure() {
any(String.class),
any(String.class));

exception.expect(SdkException.class);
exception.expectMessage("S3 Exception");
//Any S3 Dao exception is thrown back as-is to clients
payloadStore.storeOriginalPayload(ANY_PAYLOAD);
assertThrows(SdkException.class, () -> payloadStore.storeOriginalPayload(ANY_PAYLOAD), "S3 Exception");
}

@Test
Expand All @@ -120,21 +117,21 @@ public void testGetOriginalPayloadOnSuccess() {

@Test
public void testGetOriginalPayloadIncorrectPointer() {
exception.expect(SdkClientException.class);
exception.expectMessage(INCORRECT_POINTER_EXCEPTION_MSG);
//Any S3 Dao exception is thrown back as-is to clients
payloadStore.getOriginalPayload("IncorrectPointer");
assertThrows(SdkClientException.class, () -> payloadStore.getOriginalPayload("IncorrectPointer"),
INCORRECT_POINTER_EXCEPTION_MSG);
verifyNoInteractions(s3Dao);
}

@Test
public void testGetOriginalPayloadOnS3Failure() {
when(s3Dao.getTextFromS3(any(String.class), any(String.class))).thenThrow(SdkException.create("S3 Exception", new Throwable()));
exception.expect(SdkException.class);
exception.expectMessage("S3 Exception");
//Any S3 Dao exception is thrown back as-is to clients
when(s3Dao.getTextFromS3(any(String.class), any(String.class)))
.thenThrow(SdkException.create("S3 Exception", new Throwable()));

PayloadS3Pointer anyPointer = new PayloadS3Pointer(S3_BUCKET_NAME, ANY_S3_KEY);
payloadStore.getOriginalPayload(anyPointer.toJson());
//Any S3 Dao exception is thrown back as-is to clients
assertThrows(SdkException.class, () -> payloadStore.getOriginalPayload(anyPointer.toJson()),
"S3 Exception");
}

@Test
Expand All @@ -152,9 +149,8 @@ public void testDeleteOriginalPayloadOnSuccess() {

@Test
public void testDeleteOriginalPayloadIncorrectPointer() {
exception.expect(SdkClientException.class);
exception.expectMessage(INCORRECT_POINTER_EXCEPTION_MSG);
payloadStore.deleteOriginalPayload("IncorrectPointer");
assertThrows(SdkClientException.class, () -> payloadStore.deleteOriginalPayload("IncorrectPointer"),
INCORRECT_POINTER_EXCEPTION_MSG);
verifyNoInteractions(s3Dao);
}
}
21 changes: 10 additions & 11 deletions src/test/java/software/amazon/payloadoffloading/S3DaoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,33 @@
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.ObjectCannedACL;
import junitparams.JUnitParamsRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.mockito.ArgumentCaptor;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.ServerSideEncryption;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@RunWith(JUnitParamsRunner.class)
public class S3DaoTest {

private static String s3ServerSideEncryptionKMSKeyId = "test-customer-managed-kms-key-id";
private static final String s3ServerSideEncryptionKMSKeyId = "test-customer-managed-kms-key-id";
private static final String S3_BUCKET_NAME = "test-bucket-name";
private static final String ANY_PAYLOAD = "AnyPayload";
private static final String ANY_S3_KEY = "AnyS3key";
private ServerSideEncryptionStrategy serverSideEncryptionStrategy = ServerSideEncryptionFactory.awsManagedCmk();
private ObjectCannedACL objectCannedACL = ObjectCannedACL.PUBLIC_READ;
private final ServerSideEncryptionStrategy serverSideEncryptionStrategy = ServerSideEncryptionFactory.awsManagedCmk();
private final ObjectCannedACL objectCannedACL = ObjectCannedACL.PUBLIC_READ;
private S3Client s3Client;
private S3Dao dao;

@Before
@BeforeEach
public void setup() {
s3Client = mock(S3Client.class);
}
Expand Down

0 comments on commit 8c59e59

Please sign in to comment.