Skip to content

Commit

Permalink
testcases for bucket referer and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
duan007a committed Nov 22, 2018
1 parent 479ba56 commit a91d7c5
Showing 1 changed file with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,29 @@
import com.alibaba.sdk.android.oss.model.CannedAccessControlList;
import com.alibaba.sdk.android.oss.model.CreateBucketRequest;
import com.alibaba.sdk.android.oss.model.CreateBucketResult;
import com.alibaba.sdk.android.oss.model.DeleteBucketLoggingRequest;
import com.alibaba.sdk.android.oss.model.DeleteBucketLoggingResult;
import com.alibaba.sdk.android.oss.model.DeleteBucketRequest;
import com.alibaba.sdk.android.oss.model.DeleteBucketResult;
import com.alibaba.sdk.android.oss.model.GetBucketInfoRequest;
import com.alibaba.sdk.android.oss.model.GetBucketInfoResult;
import com.alibaba.sdk.android.oss.model.GetBucketACLRequest;
import com.alibaba.sdk.android.oss.model.GetBucketACLResult;
import com.alibaba.sdk.android.oss.model.GetBucketLoggingRequest;
import com.alibaba.sdk.android.oss.model.GetBucketLoggingResult;
import com.alibaba.sdk.android.oss.model.GetBucketRefererRequest;
import com.alibaba.sdk.android.oss.model.GetBucketRefererResult;
import com.alibaba.sdk.android.oss.model.ListBucketsRequest;
import com.alibaba.sdk.android.oss.model.ListBucketsResult;
import com.alibaba.sdk.android.oss.model.OSSBucketSummary;
import com.alibaba.sdk.android.oss.model.Owner;
import com.alibaba.sdk.android.oss.model.PutBucketLoggingRequest;
import com.alibaba.sdk.android.oss.model.PutBucketLoggingResult;
import com.alibaba.sdk.android.oss.model.PutBucketRefererRequest;
import com.alibaba.sdk.android.oss.model.PutBucketRefererResult;
import com.alibaba.sdk.android.oss.model.PutObjectRequest;

import java.util.ArrayList;
import java.util.List;

/**
Expand Down Expand Up @@ -230,4 +241,96 @@ public void testListBucket() {
assertNull(e);
}
}

public void testBucketReferer() throws Exception {
final String testBucketName = "android-sdk-test-bucket-referer";
CreateBucketRequest create = new CreateBucketRequest(testBucketName);
create.setBucketACL(CannedAccessControlList.Private);
oss.createBucket(create);

// put bucket referer
try {
PutBucketRefererRequest request = new PutBucketRefererRequest();
request.setBucketName(testBucketName);
ArrayList<String> referers = new ArrayList<String>();
referers.add("http://www.taobao.com");
referers.add("http://www.aliyun.com");
request.setReferers(referers);

PutBucketRefererResult result = oss.putBucketReferer(request);
assertEquals(200, result.getStatusCode());
} catch (Exception e) {
e.getMessage();
assertNull(e);
}

// get bucket referer
try {
GetBucketRefererRequest request = new GetBucketRefererRequest();
request.setBucketName(testBucketName);
GetBucketRefererResult result = oss.getBucketReferer(request);

assertEquals(200, result.getStatusCode());
List<String> referers = result.getReferers();
assertTrue(referers.size() > 0);
} catch (Exception e) {
e.getMessage();
assertNull(e);
}

OSSTestUtils.cleanBucket(oss, testBucketName);
}

public void testBucketLogging() throws Exception {
final String sourceBucketName = "android-sdk-test-bucket-logging-source";
final String targetBucketName = "android-sdk-test-bucket-logging-target";
CreateBucketRequest create1 = new CreateBucketRequest(sourceBucketName);
create1.setBucketACL(CannedAccessControlList.Private);
oss.createBucket(create1);

CreateBucketRequest create2 = new CreateBucketRequest(targetBucketName);
create2.setBucketACL(CannedAccessControlList.Private);
oss.createBucket(create2);

// put bucket logging
try {
PutBucketLoggingRequest request = new PutBucketLoggingRequest();
request.setBucketName(sourceBucketName);
request.setTargetBucketName(targetBucketName);
request.setTargetPrefix("target-prefix");

PutBucketLoggingResult result = oss.putBucketLogging(request);
assertEquals(200, result.getStatusCode());
} catch (Exception e) {
e.getMessage();
assertNull(e);
}

// get bucket logging
try {
GetBucketLoggingRequest request = new GetBucketLoggingRequest();
request.setBucketName(sourceBucketName);
GetBucketLoggingResult result = oss.getBucketLogging(request);

assertEquals(200, result.getStatusCode());
} catch (Exception e) {
e.getMessage();
assertNull(e);
}

// delete bucket logging
try {
DeleteBucketLoggingRequest request = new DeleteBucketLoggingRequest();
request.setBucketName(sourceBucketName);
DeleteBucketLoggingResult result = oss.deleteBucketLogging(request);

assertEquals(204, result.getStatusCode());
} catch (Exception e) {
e.getMessage();
assertNull(e);
}

OSSTestUtils.cleanBucket(oss, sourceBucketName);
OSSTestUtils.cleanBucket(oss, targetBucketName);
}
}

0 comments on commit a91d7c5

Please sign in to comment.