Skip to content

Commit

Permalink
getBucketLocation, RestoreObject 테스트 케이스 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
pspace-jwkwak committed Nov 23, 2022
1 parent 3b58f2f commit cc91fc2
Showing 1 changed file with 58 additions and 48 deletions.
106 changes: 58 additions & 48 deletions java/src/main/java/org/example/test/GetObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,23 @@
import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.s3.Headers;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.RestoreObjectRequest;

public class GetObject extends TestBase
{
public class GetObject extends TestBase {
@org.junit.jupiter.api.BeforeAll
static public void BeforeAll()
{
static public void BeforeAll() {
System.out.println("GetObject Start");
}

@org.junit.jupiter.api.AfterAll
static public void AfterAll()
{
static public void AfterAll() {
System.out.println("GetObject End");
}

@Test
@Tag("ERROR")
// 버킷에 존재하지 않는 오브젝트 다운로드를 할 경우 실패 확인
public void test_object_read_not_exist()
{
public void test_object_read_not_exist() {
var BucketName = GetNewBucket();
var Client = GetClient();

Expand All @@ -59,8 +56,7 @@ public void test_object_read_not_exist()
@Test
@Tag("Ifmatch")
// 존재하는 오브젝트 이름과 ETag 값으로 오브젝트를 가져오는지 확인
public void test_get_object_ifmatch_good()
{
public void test_get_object_ifmatch_good() {
var BucketName = GetNewBucket();
var Client = GetClient();
var KeyName = "foo";
Expand All @@ -76,8 +72,7 @@ public void test_get_object_ifmatch_good()
@Test
@Tag("Ifmatch")
// 오브젝트와 일치하지 않는 ETag 값을 설정하여 오브젝트 조회 실패 확인
public void test_get_object_ifmatch_failed()
{
public void test_get_object_ifmatch_failed() {
var BucketName = GetNewBucket();
var Client = GetClient();
var KeyName = "foo";
Expand All @@ -90,8 +85,7 @@ public void test_get_object_ifmatch_failed()
@Test
@Tag("Ifnonematch")
// 오브젝트와 일치하는 ETag 값을 IfsNoneMatch에 설정하여 오브젝트 조회 실패
public void test_get_object_ifnonematch_good()
{
public void test_get_object_ifnonematch_good() {
var BucketName = GetNewBucket();
var Client = GetClient();
var KeyName = "foo";
Expand All @@ -106,24 +100,23 @@ public void test_get_object_ifnonematch_good()
@Test
@Tag("Ifnonematch")
// 오브젝트와 일치하지 않는 ETag 값을 IfsNoneMatch에 설정하여 오브젝트 조회 성공
public void test_get_object_ifnonematch_failed()
{
public void test_get_object_ifnonematch_failed() {
var BucketName = GetNewBucket();
var Client = GetClient();
var KeyName = "foo";

Client.putObject(BucketName, KeyName, "bar");

var GetResponse = Client.getObject(new GetObjectRequest(BucketName, KeyName).withNonmatchingETagConstraint("ABCORZ"));
var GetResponse = Client
.getObject(new GetObjectRequest(BucketName, KeyName).withNonmatchingETagConstraint("ABCORZ"));
var Body = GetBody(GetResponse.getObjectContent());
assertEquals("bar", Body);
}

@Test
@Tag("Ifmodifiedsince")
// [지정일을 오브젝트 업로드 시간 이전으로 설정] 지정일(ifmodifiedsince)보다 이후에 수정된 오브젝트를 조회 성공
public void test_get_object_ifmodifiedsince_good()
{
public void test_get_object_ifmodifiedsince_good() {
var BucketName = GetNewBucket();
var Client = GetClient();
var KeyName = "foo";
Expand All @@ -132,16 +125,16 @@ public void test_get_object_ifmodifiedsince_good()

var MyDay = Calendar.getInstance();
MyDay.set(1994, 8, 29, 19, 43, 31);
var Response = Client.getObject(new GetObjectRequest(BucketName, KeyName).withModifiedSinceConstraint(MyDay.getTime()));
var Response = Client
.getObject(new GetObjectRequest(BucketName, KeyName).withModifiedSinceConstraint(MyDay.getTime()));
var Body = GetBody(Response.getObjectContent());
assertEquals("bar", Body);
}

@Test
@Tag("Ifmodifiedsince")
// [지정일을 오브젝트 업로드 시간 이후로 설정] 지정일(ifmodifiedsince)보다 이전에 수정된 오브젝트 조회 실패
public void test_get_object_ifmodifiedsince_failed()
{
public void test_get_object_ifmodifiedsince_failed() {
var BucketName = GetNewBucket();
var Client = GetClient();
var KeyName = "foo";
Expand All @@ -154,15 +147,15 @@ public void test_get_object_ifmodifiedsince_failed()

Delay(1000);

Response = Client.getObject(new GetObjectRequest(BucketName, KeyName).withModifiedSinceConstraint(After.getTime()));
Response = Client
.getObject(new GetObjectRequest(BucketName, KeyName).withModifiedSinceConstraint(After.getTime()));
assertNull(Response);
}

@Test
@Tag("Ifunmodifiedsince")
// [지정일을 오브젝트 업로드 시간 이전으로 설정] 지정일(ifunmodifiedsince) 이후 수정되지 않은 오브젝트 조회 실패
public void test_get_object_ifunmodifiedsince_good()
{
public void test_get_object_ifunmodifiedsince_good() {
var BucketName = GetNewBucket();
var Client = GetClient();
var KeyName = "foo";
Expand All @@ -172,15 +165,15 @@ public void test_get_object_ifunmodifiedsince_good()
var MyDay = Calendar.getInstance();
MyDay.set(1994, 8, 29, 19, 43, 31);

var Response = Client.getObject(new GetObjectRequest(BucketName, KeyName).withUnmodifiedSinceConstraint(MyDay.getTime()));
var Response = Client
.getObject(new GetObjectRequest(BucketName, KeyName).withUnmodifiedSinceConstraint(MyDay.getTime()));
assertNull(Response);
}

@Test
@Tag("Ifunmodifiedsince")
// [지정일을 오브젝트 업로드 시간 이후으로 설정] 지정일(ifunmodifiedsince) 이후 수정되지 않은 오브젝트 조회 성공
public void test_get_object_ifunmodifiedsince_failed()
{
public void test_get_object_ifunmodifiedsince_failed() {
var BucketName = GetNewBucket();
var Client = GetClient();
var KeyName = "foo";
Expand All @@ -189,16 +182,16 @@ public void test_get_object_ifunmodifiedsince_failed()

var MyDay = Calendar.getInstance();
MyDay.set(2100, 8, 29, 19, 43, 31);
var Response = Client.getObject(new GetObjectRequest(BucketName, KeyName).withUnmodifiedSinceConstraint(MyDay.getTime()));
var Response = Client
.getObject(new GetObjectRequest(BucketName, KeyName).withUnmodifiedSinceConstraint(MyDay.getTime()));
var Body = GetBody(Response.getObjectContent());
assertEquals("bar", Body);
}

@Test
@Tag("Range")
// 지정한 범위로 오브젝트 다운로드가 가능한지 확인
public void test_ranged_request_response_code()
{
public void test_ranged_request_response_code() {
var Key = "testobj";
var Content = "testcontent";

Expand All @@ -216,8 +209,7 @@ public void test_ranged_request_response_code()
@Test
@Tag("Range")
// 지정한 범위로 대용량인 오브젝트 다운로드가 가능한지 확인
public void test_ranged_big_request_response_code()
{
public void test_ranged_big_request_response_code() {
var Key = "testobj";
var Content = Utils.RandomTextToLong(8 * MainData.MB);

Expand All @@ -229,14 +221,14 @@ public void test_ranged_big_request_response_code()

var FetchedContent = GetBody(Response.getObjectContent());
assertTrue(Content.substring(3145728, 5242881).equals(FetchedContent), MainData.NOT_MATCHED);
assertEquals("bytes 3145728-5242880/8388608", Response.getObjectMetadata().getRawMetadataValue(Headers.CONTENT_RANGE));
assertEquals("bytes 3145728-5242880/8388608",
Response.getObjectMetadata().getRawMetadataValue(Headers.CONTENT_RANGE));
}

@Test
@Tag("Range")
// 특정지점부터 끝까지 오브젝트 다운로드 가능한지 확인
public void test_ranged_request_skip_leading_bytes_response_code()
{
public void test_ranged_request_skip_leading_bytes_response_code() {
var Key = "testobj";
var Content = "testcontent";

Expand All @@ -254,8 +246,7 @@ public void test_ranged_request_skip_leading_bytes_response_code()
@Test
@Tag("Range")
// 끝에서 부터 특정 길이까지 오브젝트 다운로드 가능한지 확인
public void test_ranged_request_return_trailing_bytes_response_code()
{
public void test_ranged_request_return_trailing_bytes_response_code() {
var Key = "testobj";
var Content = "testcontent";

Expand All @@ -273,16 +264,16 @@ public void test_ranged_request_return_trailing_bytes_response_code()
@Test
@Tag("Range")
// 오브젝트의 크기를 초과한 범위를 설정하여 다운로드 할경우 실패 확인
public void test_ranged_request_invalid_range()
{
public void test_ranged_request_invalid_range() {
var Key = "testobj";
var Content = "testcontent";

var BucketName = GetNewBucket();
var Client = GetClient();

Client.putObject(BucketName, Key, Content);
var e = assertThrows(AmazonServiceException.class, () -> Client.getObject(new GetObjectRequest(BucketName, Key).withRange(40, 50)));
var e = assertThrows(AmazonServiceException.class,
() -> Client.getObject(new GetObjectRequest(BucketName, Key).withRange(40, 50)));
var StatusCode = e.getStatusCode();
var ErrorCode = e.getErrorCode();
assertEquals(416, StatusCode);
Expand All @@ -292,16 +283,16 @@ public void test_ranged_request_invalid_range()
@Test
@Tag("Range")
// 비어있는 오브젝트를 범위를 지정하여 다운로드 실패 확인
public void test_ranged_request_empty_object()
{
public void test_ranged_request_empty_object() {
var Key = "testobj";
var Content = "";

var BucketName = GetNewBucket();
var Client = GetClient();

Client.putObject(BucketName, Key, Content);
var e = assertThrows(AmazonServiceException.class, () -> Client.getObject(new GetObjectRequest(BucketName, Key).withRange(40, 50)));
var e = assertThrows(AmazonServiceException.class,
() -> Client.getObject(new GetObjectRequest(BucketName, Key).withRange(40, 50)));
var StatusCode = e.getStatusCode();
var ErrorCode = e.getErrorCode();
assertEquals(416, StatusCode);
Expand All @@ -311,8 +302,7 @@ public void test_ranged_request_empty_object()
@Test
@Tag("Get")
// 같은 오브젝트를 여러번 반복하여 다운로드 성공 확인
public void test_get_object_many()
{
public void test_get_object_many() {
var BucketName = GetNewBucket();
var Client = GetClient();
var Key = "foo";
Expand All @@ -325,8 +315,7 @@ public void test_get_object_many()
@Test
@Tag("Get")
// 같은 오브젝트를 여러번 반복하여 Range 다운로드 성공 확인
public void test_range_object_many()
{
public void test_range_object_many() {
var BucketName = GetNewBucket();
var Client = GetClient();
var Key = "foo";
Expand All @@ -337,4 +326,25 @@ public void test_range_object_many()
CheckContentUsingRandomRange(BucketName, Key, Data, 50);
}

@Test
@Tag("location")
public void test_get_bucket_location()
{
var BucketName = GetNewBucket();
var Client = GetClient();
Client.getBucketLocation(BucketName);
}

@Test
@Tag("Restore")
public void test_restore_object() {
var BucketName = GetNewBucket();
var Client = GetClient();
var Key = "foo";

Client.putObject(BucketName, Key, Key);

var Request = new RestoreObjectRequest(BucketName, Key);
Client.restoreObjectV2(Request);
}
}

0 comments on commit cc91fc2

Please sign in to comment.