blob: dc2fdd62a250ed99750582c549c17e63b1065f88 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.glacier;
import static org.assertj.core.api.Assertions.assertThat;
import static org.jclouds.glacier.util.TestUtils.MiB;
import static org.jclouds.glacier.util.TestUtils.buildPayload;
import java.util.UUID;
import org.jclouds.apis.BaseApiLiveTest;
import org.jclouds.glacier.domain.PaginatedVaultCollection;
import org.jclouds.glacier.util.ContentRange;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
/**
* Live test for Glacier.
*/
@Test(groups = { "integration", "live" })
public class GlacierClientLiveTest extends BaseApiLiveTest<GlacierClient>{
public GlacierClientLiveTest() {
this.provider = "glacier";
}
private final String VAULT_NAME1 = UUID.randomUUID().toString();
private final String VAULT_NAME2 = UUID.randomUUID().toString();
private final String VAULT_NAME3 = UUID.randomUUID().toString();
@Test(groups = { "integration", "live" })
public void testDeleteVaultIfEmptyOrNotFound() throws Exception {
assertThat(api.deleteVault(UUID.randomUUID().toString())).isTrue();
}
@Test(groups = { "integration", "live" })
public void testDescribeNonExistentVault() throws Exception {
assertThat(api.describeVault(UUID.randomUUID().toString())).isNull();
}
@Test(groups = { "integration", "live" })
public void testCreateVault() throws Exception {
String path = api.createVault(VAULT_NAME1).toString();
api.createVault(VAULT_NAME2);
api.createVault(VAULT_NAME3);
assertThat(path)
.contains("https://glacier.us-east-1.amazonaws.com/")
.contains("/vaults/" + VAULT_NAME1);
}
@Test(groups = { "integration", "live" }, dependsOnMethods = { "testCreateVault" })
public void testListAndDescribeVaults() throws Exception {
PaginatedVaultCollection vaults = api.listVaults();
assertThat(vaults).containsAll(ImmutableList.of(
api.describeVault(VAULT_NAME1),
api.describeVault(VAULT_NAME2),
api.describeVault(VAULT_NAME3)));
}
@Test(groups = { "integration", "live" }, dependsOnMethods = { "testCreateVault" })
public void testListMultipartUploadsWithEmptyList() throws Exception {
assertThat(api.listMultipartUploads(VAULT_NAME1)).isEmpty();
}
@Test(groups = { "integration", "live" }, dependsOnMethods = { "testListMultipartUploadsWithEmptyList" })
public void testInitiateAndAbortMultipartUpload() throws Exception {
String uploadId = api.initiateMultipartUpload(VAULT_NAME1, 8);
try {
assertThat(uploadId).isNotNull();
} finally {
api.abortMultipartUpload(VAULT_NAME1, uploadId);
}
}
@Test(groups = { "integration", "live" }, dependsOnMethods = { "testInitiateAndAbortMultipartUpload" })
public void testListMultipartUploads() throws Exception {
long partSizeInMb = 1;
String uploadId = api.initiateMultipartUpload(VAULT_NAME1, partSizeInMb);
try {
assertThat(api.uploadPart(VAULT_NAME1, uploadId,
ContentRange.fromPartNumber(0, partSizeInMb), buildPayload(partSizeInMb * MiB))).isNotNull();
assertThat(api.listMultipartUploads(VAULT_NAME1)).extracting("multipartUploadId").contains(uploadId);
assertThat(api.abortMultipartUpload(VAULT_NAME1, uploadId)).isTrue();
} finally {
api.abortMultipartUpload(VAULT_NAME1, uploadId);
}
}
@Test(groups = { "integration", "live" },
dependsOnMethods = { "testListAndDescribeVaults", "testListMultipartUploadsWithEmptyList",
"testInitiateAndAbortMultipartUpload", "testListMultipartUploads" })
public void testDeleteVault() throws Exception {
assertThat(api.deleteVault(VAULT_NAME1)).isTrue();
assertThat(api.deleteVault(VAULT_NAME2)).isTrue();
assertThat(api.deleteVault(VAULT_NAME3)).isTrue();
}
}