Change BaseSwiftApiLiveTest to inherit from BaseBlobStoreIntegrationTest and use its methods

This commit is contained in:
Zack Shoylev 2016-12-19 16:38:39 -06:00
parent f3c3f3b306
commit 6bc82ee262
11 changed files with 143 additions and 156 deletions

View File

@ -37,17 +37,17 @@ import org.testng.annotations.Test;
import com.google.common.io.ByteSource;
@Test(groups = "live", testName = "TemporaryUrlSignerLiveTest")
public class TemporaryUrlSignerLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public class TemporaryUrlSignerLiveTest extends BaseSwiftApiLiveTest {
private String name = getClass().getSimpleName();
private String containerName = getClass().getSimpleName() + "Container";
public void signForPublicAccess() throws Exception {
for (String regionId : api.getConfiguredRegions()) {
SwiftObject object = api.getObjectApi(regionId, containerName).get(name);
for (String regionId : getApi().getConfiguredRegions()) {
SwiftObject object = getApi().getObjectApi(regionId, containerName).get(name);
long expires = System.currentTimeMillis() / 1000 + 5;
String signature = TemporaryUrlSigner.checkApiEvery(api.getAccountApi(regionId), 5)
String signature = TemporaryUrlSigner.checkApiEvery(getApi().getAccountApi(regionId), 5)
.sign("GET", object.getUri().getPath(), expires);
URI signed = URI.create(format("%s?temp_url_sig=%s&temp_url_expires=%s", object.getUri(), signature, expires));
@ -70,10 +70,10 @@ public class TemporaryUrlSignerLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void setup() {
super.setup();
String key = UUID.randomUUID().toString();
for (String regionId : api.getConfiguredRegions()) {
api.getAccountApi(regionId).updateTemporaryUrlKey(key);
api.getContainerApi(regionId).create(containerName);
api.getObjectApi(regionId, containerName)
for (String regionId : getApi().getConfiguredRegions()) {
getApi().getAccountApi(regionId).updateTemporaryUrlKey(key);
getApi().getContainerApi(regionId).create(containerName);
getApi().getObjectApi(regionId, containerName)
.put(name, newByteSourcePayload(ByteSource.wrap("swifty".getBytes())));
}
}
@ -81,10 +81,9 @@ public class TemporaryUrlSignerLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
@AfterMethod
@AfterClass(groups = "live")
public void tearDown() {
for (String regionId : api.getConfiguredRegions()) {
api.getObjectApi(regionId, containerName).delete(name);
api.getContainerApi(regionId).deleteIfEmpty(containerName);
for (String regionId : getApi().getConfiguredRegions()) {
getApi().getObjectApi(regionId, containerName).delete(name);
getApi().getContainerApi(regionId).deleteIfEmpty(containerName);
}
super.tearDown();
}
}

View File

@ -25,7 +25,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import org.jclouds.openstack.swift.v1.SwiftApi;
import org.jclouds.openstack.swift.v1.domain.Account;
import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest;
import org.testng.annotations.Test;
@ -33,11 +32,11 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
@Test(groups = "live", testName = "AccountApiLiveTest")
public class AccountApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public class AccountApiLiveTest extends BaseSwiftApiLiveTest {
public void testGet() throws Exception {
for (String regionId : regions) {
AccountApi accountApi = api.getAccountApi(regionId);
AccountApi accountApi = getApi().getAccountApi(regionId);
Account account = accountApi.get();
assertNotNull(account);
@ -49,7 +48,7 @@ public class AccountApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testUpdateMetadata() throws Exception {
for (String regionId : regions) {
AccountApi accountApi = api.getAccountApi(regionId);
AccountApi accountApi = getApi().getAccountApi(regionId);
Map<String, String> meta = ImmutableMap.of("MyAdd1", "foo", "MyAdd2", "bar");
@ -61,7 +60,7 @@ public class AccountApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testDeleteMetadata() throws Exception {
for (String regionId : regions) {
AccountApi accountApi = api.getAccountApi(regionId);
AccountApi accountApi = getApi().getAccountApi(regionId);
Map<String, String> meta = ImmutableMap.of("MyDelete1", "foo", "MyDelete2", "bar");
@ -88,7 +87,7 @@ public class AccountApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testUpdateTemporaryUrlKey() throws Exception {
for (String regionId : regions) {
AccountApi accountApi = api.getAccountApi(regionId);
AccountApi accountApi = getApi().getAccountApi(regionId);
String key = UUID.randomUUID().toString();

View File

@ -30,7 +30,6 @@ import org.jboss.shrinkwrap.api.exporter.TarGzExporter;
import org.jclouds.io.ByteStreams2;
import org.jclouds.io.Payload;
import org.jclouds.io.payloads.ByteSourcePayload;
import org.jclouds.openstack.swift.v1.SwiftApi;
import org.jclouds.openstack.swift.v1.domain.BulkDeleteResponse;
import org.jclouds.openstack.swift.v1.domain.ExtractArchiveResponse;
import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest;
@ -44,7 +43,7 @@ import com.google.common.collect.Lists;
import com.google.common.io.ByteSource;
@Test(groups = "live", testName = "BulkApiLiveTest")
public class BulkApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public class BulkApiLiveTest extends BaseSwiftApiLiveTest {
private static final int OBJECT_COUNT = 10;
private String containerName = getClass().getSimpleName();
@ -53,7 +52,7 @@ public class BulkApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testNotPresentWhenDeleting() throws Exception {
for (String regionId : regions) {
BulkDeleteResponse deleteResponse = api.getBulkApi(regionId).bulkDelete(
BulkDeleteResponse deleteResponse = getApi().getBulkApi(regionId).bulkDelete(
ImmutableList.of(UUID.randomUUID().toString()));
assertEquals(deleteResponse.getDeleted(), 0);
assertEquals(deleteResponse.getNotFound(), 1);
@ -65,14 +64,14 @@ public class BulkApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
for (String regionId : regions) {
Payload payload = new ByteSourcePayload(ByteSource.wrap(tarGz));
ExtractArchiveResponse extractResponse = api.getBulkApi(regionId)
ExtractArchiveResponse extractResponse = getApi().getBulkApi(regionId)
.extractArchive(containerName, payload, "tar.gz");
assertEquals(extractResponse.getCreated(), OBJECT_COUNT);
assertTrue(extractResponse.getErrors().isEmpty());
assertEquals(api.getContainerApi(regionId).get(containerName).getObjectCount(), Long.valueOf(OBJECT_COUNT));
assertEquals(getApi().getContainerApi(regionId).get(containerName).getObjectCount(), Long.valueOf(OBJECT_COUNT));
// repeat the command
extractResponse = api.getBulkApi(regionId).extractArchive(containerName, payload, "tar.gz");
extractResponse = getApi().getBulkApi(regionId).extractArchive(containerName, payload, "tar.gz");
assertEquals(extractResponse.getCreated(), OBJECT_COUNT);
assertTrue(extractResponse.getErrors().isEmpty());
}
@ -81,11 +80,11 @@ public class BulkApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
@Test(dependsOnMethods = "testExtractArchive")
public void testBulkDelete() throws Exception {
for (String regionId : regions) {
BulkDeleteResponse deleteResponse = api.getBulkApi(regionId).bulkDelete(paths);
BulkDeleteResponse deleteResponse = getApi().getBulkApi(regionId).bulkDelete(paths);
assertEquals(deleteResponse.getDeleted(), OBJECT_COUNT);
assertEquals(deleteResponse.getNotFound(), 0);
assertTrue(deleteResponse.getErrors().isEmpty());
assertEquals(api.getContainerApi(regionId).get(containerName).getObjectCount(), Long.valueOf(0));
assertEquals(getApi().getContainerApi(regionId).get(containerName).getObjectCount(), Long.valueOf(0));
}
}
@ -94,7 +93,7 @@ public class BulkApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void setup() {
super.setup();
for (String regionId : regions) {
boolean created = api.getContainerApi(regionId).create(containerName);
boolean created = getApi().getContainerApi(regionId).create(containerName);
if (!created) {
deleteAllObjectsInContainer(regionId, containerName);
}
@ -113,13 +112,11 @@ public class BulkApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
}
}
@Override
@AfterClass(groups = "live")
public void tearDown() {
for (String regionId : regions) {
deleteAllObjectsInContainer(regionId, containerName);
api.getContainerApi(regionId).deleteIfEmpty(containerName);
getApi().getContainerApi(regionId).deleteIfEmpty(containerName);
}
super.tearDown();
}
}

View File

@ -25,7 +25,6 @@ import static org.testng.Assert.assertTrue;
import java.util.Map;
import java.util.Map.Entry;
import org.jclouds.openstack.swift.v1.SwiftApi;
import org.jclouds.openstack.swift.v1.domain.Container;
import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest;
import org.jclouds.openstack.swift.v1.options.CreateContainerOptions;
@ -45,7 +44,7 @@ import com.google.common.collect.ImmutableMultimap;
* Provides live tests for the {@link ContainerApi}.
*/
@Test(groups = "live", testName = "ContainerApiLiveTest")
public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public class ContainerApiLiveTest extends BaseSwiftApiLiveTest {
private String name = getClass().getSimpleName();
@ -56,16 +55,16 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
SwiftHeaders.STATIC_WEB_ERROR, "__error.html");
CreateContainerOptions opts = new CreateContainerOptions().headers(headers);
assertNotNull(api.getContainerApi(regionId).create(name, opts));
assertNotNull(getApi().getContainerApi(regionId).create(name, opts));
Container container = api.getContainerApi(regionId).get(name);
Container container = getApi().getContainerApi(regionId).get(name);
assertNotNull(container);
assertEquals(container.getName(), name);
assertEquals(container.getMetadata().size(), 2);
assertEquals(container.getMetadata().get("web-index"), "__index.html");
assertEquals(container.getMetadata().get("web-error"), "__error.html");
assertTrue(api.getContainerApi(regionId).deleteIfEmpty(name));
assertTrue(getApi().getContainerApi(regionId).deleteIfEmpty(name));
}
}
@ -73,18 +72,18 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
final String nameWithSpaces = "container # ! special";
for (String regionId : regions) {
assertTrue(api.getContainerApi(regionId).create(nameWithSpaces));
Container container = api.getContainerApi(regionId).get(nameWithSpaces);
assertTrue(getApi().getContainerApi(regionId).create(nameWithSpaces));
Container container = getApi().getContainerApi(regionId).get(nameWithSpaces);
assertNotNull(container);
assertEquals(container.getName(), nameWithSpaces);
assertTrue(api.getContainerApi(regionId).deleteIfEmpty(nameWithSpaces));
assertTrue(getApi().getContainerApi(regionId).deleteIfEmpty(nameWithSpaces));
}
}
public void testList() throws Exception {
for (String regionId : regions) {
ContainerApi containerApi = api.getContainerApi(regionId);
ContainerApi containerApi = getApi().getContainerApi(regionId);
FluentIterable<Container> response = containerApi.list();
assertNotNull(response);
for (Container container : response) {
@ -99,7 +98,7 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
String lexicographicallyBeforeName = name.substring(0, name.length() - 1);
for (String regionId : regions) {
ListContainerOptions options = ListContainerOptions.Builder.marker(lexicographicallyBeforeName);
Container container = api.getContainerApi(regionId).list(options).firstMatch(new Predicate<Container>() {
Container container = getApi().getContainerApi(regionId).list(options).firstMatch(new Predicate<Container>() {
@Override
public boolean apply(Container container) {
return container.getName().equals(name);
@ -117,29 +116,29 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
SwiftHeaders.STATIC_WEB_ERROR, "__error.html");
UpdateContainerOptions opts = new UpdateContainerOptions().headers(headers);
assertNotNull(api.getContainerApi(regionId).create(name));
assertNotNull(getApi().getContainerApi(regionId).create(name));
Container container = api.getContainerApi(regionId).get(name);
Container container = getApi().getContainerApi(regionId).get(name);
assertNotNull(container);
assertEquals(container.getName(), name);
assertTrue(container.getMetadata().isEmpty());
api.getContainerApi(regionId).update(name, opts);
getApi().getContainerApi(regionId).update(name, opts);
Container updatedContainer = api.getContainerApi(regionId).get(name);
Container updatedContainer = getApi().getContainerApi(regionId).get(name);
assertNotNull(updatedContainer);
assertEquals(updatedContainer.getName(), name);
assertEquals(updatedContainer.getMetadata().size(), 2);
assertEquals(updatedContainer.getMetadata().get("web-index"), "__index.html");
assertEquals(updatedContainer.getMetadata().get("web-error"), "__error.html");
assertTrue(api.getContainerApi(regionId).deleteIfEmpty(name));
assertTrue(getApi().getContainerApi(regionId).deleteIfEmpty(name));
}
}
public void testUpdateContainer() throws Exception {
for (String regionId : regions) {
ContainerApi containerApi = api.getContainerApi(regionId);
ContainerApi containerApi = getApi().getContainerApi(regionId);
assertThat(containerApi.create(name)).isTrue();
assertThat(containerApi.get(name).getAnybodyRead().get()).isFalse();
@ -153,7 +152,7 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testGet() throws Exception {
for (String regionId : regions) {
Container container = api.getContainerApi(regionId).get(name);
Container container = getApi().getContainerApi(regionId).get(name);
assertEquals(container.getName(), name);
assertTrue(container.getObjectCount() == 0);
assertTrue(container.getBytesUsed() == 0);
@ -164,7 +163,7 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
Map<String, String> meta = ImmutableMap.of("MyAdd1", "foo", "MyAdd2", "bar");
for (String regionId : regions) {
ContainerApi containerApi = api.getContainerApi(regionId);
ContainerApi containerApi = getApi().getContainerApi(regionId);
containerApi.updateMetadata(name, meta);
containerHasMetadata(containerApi, name, meta);
}
@ -174,7 +173,7 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
Map<String, String> meta = ImmutableMap.of("MyDelete1", "foo", "MyDelete2", "bar");
for (String regionId : regions) {
ContainerApi containerApi = api.getContainerApi(regionId);
ContainerApi containerApi = getApi().getContainerApi(regionId);
// update
containerApi.updateMetadata(name, meta);
containerHasMetadata(containerApi, name, meta);
@ -202,16 +201,14 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void setup() {
super.setup();
for (String regionId : regions) {
api.getContainerApi(regionId).create(name);
getApi().getContainerApi(regionId).create(name);
}
}
@Override
@AfterClass(groups = "live")
public void tearDown() {
for (String regionId : regions) {
api.getContainerApi(regionId).deleteIfEmpty(name);
getApi().getContainerApi(regionId).deleteIfEmpty(name);
}
super.tearDown();
}
}

View File

@ -19,29 +19,26 @@ package org.jclouds.openstack.swift.v1.features;
import static org.jclouds.openstack.swift.v1.options.CreateContainerOptions.Builder.anybodyRead;
import static org.testng.Assert.assertTrue;
import org.jclouds.openstack.swift.v1.SwiftApi;
import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
@Test(groups = "live", testName = "CreatePublicContainerLiveTest")
public class CreatePublicContainerLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public class CreatePublicContainerLiveTest extends BaseSwiftApiLiveTest {
private String name = getClass().getSimpleName();
public void testAnybodyReadUpdatesMetadata() throws Exception {
for (String regionId : api.getConfiguredRegions()) {
api.getContainerApi(regionId).create(name, anybodyRead());
assertTrue(api.getContainerApi(regionId).get(name).getAnybodyRead().get());
for (String regionId : getApi().getConfiguredRegions()) {
getApi().getContainerApi(regionId).create(name, anybodyRead());
assertTrue(getApi().getContainerApi(regionId).get(name).getAnybodyRead().get());
}
}
@Override
@AfterClass(groups = "live")
public void tearDown() {
for (String regionId : api.getConfiguredRegions()) {
api.getContainerApi(regionId).deleteIfEmpty(name);
for (String regionId : getApi().getConfiguredRegions()) {
getApi().getContainerApi(regionId).deleteIfEmpty(name);
}
super.tearDown();
}
}

View File

@ -38,7 +38,6 @@ import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.options.GetOptions;
import org.jclouds.io.Payload;
import org.jclouds.openstack.swift.v1.SwiftApi;
import org.jclouds.openstack.swift.v1.domain.ObjectList;
import org.jclouds.openstack.swift.v1.domain.SwiftObject;
import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest;
@ -56,7 +55,7 @@ import com.google.common.io.ByteSource;
* Provides live tests for the {@link ObjectApi}.
*/
@Test(groups = "live", testName = "ObjectApiLiveTest", singleThreaded = true)
public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public class ObjectApiLiveTest extends BaseSwiftApiLiveTest {
private String name = getClass().getSimpleName();
private String containerName = getClass().getSimpleName() + "Container";
@ -67,16 +66,16 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
final String objectName = "object # ! special";
for (String regionId : regions) {
assertNotNull(api.getContainerApi(regionId).create(containerName));
assertNotNull(api.getObjectApi(regionId, containerName).put(objectName, PAYLOAD));
assertNotNull(getApi().getContainerApi(regionId).create(containerName));
assertNotNull(getApi().getObjectApi(regionId, containerName).put(objectName, PAYLOAD));
SwiftObject object = api.getObjectApi(regionId, containerName).get(objectName);
SwiftObject object = getApi().getObjectApi(regionId, containerName).get(objectName);
assertEquals(object.getName(), objectName);
checkObject(object);
assertEquals(toStringAndClose(object.getPayload().openStream()), "swifty");
api.getObjectApi(regionId, containerName).delete(objectName);
api.getContainerApi(regionId).deleteIfEmpty(containerName);
getApi().getObjectApi(regionId, containerName).delete(objectName);
getApi().getContainerApi(regionId).deleteIfEmpty(containerName);
}
}
@ -90,15 +89,15 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
payload.getContentMetadata().setExpires(expireAt);
for (String regionId : regions) {
String etag = api.getObjectApi(regionId, containerName).put(objectName, payload);
String etag = getApi().getObjectApi(regionId, containerName).put(objectName, payload);
assertNotNull(etag);
SwiftObject object = api.getObjectApi(regionId, containerName).get(objectName);
SwiftObject object = getApi().getObjectApi(regionId, containerName).get(objectName);
assertEquals(object.getName(), objectName);
checkObject(object);
assertEquals(toStringAndClose(object.getPayload().openStream()), "swifty");
api.getObjectApi(regionId, containerName).delete(objectName);
getApi().getObjectApi(regionId, containerName).delete(objectName);
}
}
@ -114,15 +113,15 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
String destinationObject = "copy.txt";
String destinationPath = "/" + destinationContainer + "/" + destinationObject;
ContainerApi containerApi = api.getContainerApi(regionId);
ContainerApi containerApi = getApi().getContainerApi(regionId);
// create source and destination dirs
containerApi.create(sourceContainer);
containerApi.create(destinationContainer);
// get the api for this region and container
ObjectApi srcApi = api.getObjectApi(regionId, sourceContainer);
ObjectApi destApi = api.getObjectApi(regionId, destinationContainer);
ObjectApi srcApi = getApi().getObjectApi(regionId, sourceContainer);
ObjectApi destApi = getApi().getObjectApi(regionId, destinationContainer);
// Create source object
assertNotNull(srcApi.put(sourceObjectName, PAYLOAD));
@ -170,15 +169,15 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
String destinationObject = "copy.txt";
String destinationPath = "/" + destinationContainer + "/" + destinationObject;
ContainerApi containerApi = api.getContainerApi(regionId);
ContainerApi containerApi = getApi().getContainerApi(regionId);
// create source and destination dirs
containerApi.create(sourceContainer);
containerApi.create(destinationContainer);
// get the api for this region and container
ObjectApi srcApi = api.getObjectApi(regionId, sourceContainer);
ObjectApi destApi = api.getObjectApi(regionId, destinationContainer);
ObjectApi srcApi = getApi().getObjectApi(regionId, sourceContainer);
ObjectApi destApi = getApi().getObjectApi(regionId, destinationContainer);
// Create source object
assertNotNull(srcApi.put(sourceObjectName, PAYLOAD));
@ -260,15 +259,15 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
String destinationObject = "copy.txt";
String destinationPath = "/" + destinationContainer + "/" + destinationObject;
ContainerApi containerApi = api.getContainerApi(regionId);
ContainerApi containerApi = getApi().getContainerApi(regionId);
// create source and destination dirs
containerApi.create(sourceContainer);
containerApi.create(destinationContainer);
// get the api for this region and container
ObjectApi srcApi = api.getObjectApi(regionId, sourceContainer);
ObjectApi destApi = api.getObjectApi(regionId, destinationContainer);
ObjectApi srcApi = getApi().getObjectApi(regionId, sourceContainer);
ObjectApi destApi = getApi().getObjectApi(regionId, destinationContainer);
// Create source object
assertNotNull(srcApi.put(sourceObjectName, PAYLOAD));
@ -307,9 +306,9 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testList() throws Exception {
for (String regionId : regions) {
ObjectApi objectApi = api.getObjectApi(regionId, containerName);
ObjectApi objectApi = getApi().getObjectApi(regionId, containerName);
ObjectList response = objectApi.list();
assertEquals(response.getContainer(), api.getContainerApi(regionId).get(containerName));
assertEquals(response.getContainer(), getApi().getContainerApi(regionId).get(containerName));
for (SwiftObject object : response) {
checkObject(object);
}
@ -318,9 +317,9 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testListWithOptions() throws Exception {
for (String regionId : regions) {
ObjectApi objectApi = api.getObjectApi(regionId, containerName);
ObjectApi objectApi = getApi().getObjectApi(regionId, containerName);
ObjectList response = objectApi.list(ListContainerOptions.NONE);
assertEquals(response.getContainer(), api.getContainerApi(regionId).get(containerName));
assertEquals(response.getContainer(), getApi().getContainerApi(regionId).get(containerName));
for (SwiftObject object : response) {
checkObject(object);
}
@ -329,7 +328,7 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testMetadata() throws Exception {
for (String regionId : regions) {
SwiftObject object = api.getObjectApi(regionId, containerName).get(name);
SwiftObject object = getApi().getObjectApi(regionId, containerName).get(name);
assertEquals(object.getName(), name);
checkObject(object);
assertEquals(toStringAndClose(object.getPayload().openStream()), "swifty");
@ -338,7 +337,7 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testUpdateMetadata() throws Exception {
for (String regionId : regions) {
ObjectApi objectApi = api.getObjectApi(regionId, containerName);
ObjectApi objectApi = getApi().getObjectApi(regionId, containerName);
Map<String, String> meta = ImmutableMap.of("MyAdd1", "foo", "MyAdd2", "bar");
objectApi.updateMetadata(name, meta);
@ -354,7 +353,7 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testGet() throws Exception {
for (String regionId : regions) {
SwiftObject object = api.getObjectApi(regionId, containerName).get(name, GetOptions.NONE);
SwiftObject object = getApi().getObjectApi(regionId, containerName).get(name, GetOptions.NONE);
assertEquals(object.getName(), name);
checkObject(object);
assertEquals(toStringAndClose(object.getPayload().openStream()), "swifty");
@ -363,7 +362,7 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testPrivateByDefault() throws Exception {
for (String regionId : regions) {
SwiftObject object = api.getObjectApi(regionId, containerName).get(name);
SwiftObject object = getApi().getObjectApi(regionId, containerName).get(name);
try {
object.getUri().toURL().openStream();
fail("shouldn't be able to access " + object);
@ -374,7 +373,7 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testGetOptions() throws Exception {
for (String regionId : regions) {
SwiftObject object = api.getObjectApi(regionId, containerName).get(name, tail(1));
SwiftObject object = getApi().getObjectApi(regionId, containerName).get(name, tail(1));
assertEquals(object.getName(), name);
checkObject(object);
assertEquals(toStringAndClose(object.getPayload().openStream()), "y");
@ -384,7 +383,7 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testListOptions() throws Exception {
String lexicographicallyBeforeName = name.substring(0, name.length() - 1);
for (String regionId : regions) {
SwiftObject object = api.getObjectApi(regionId, containerName)
SwiftObject object = getApi().getObjectApi(regionId, containerName)
.list(marker(lexicographicallyBeforeName)).get(0);
assertEquals(object.getName(), name);
checkObject(object);
@ -393,7 +392,7 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testDeleteMetadata() throws Exception {
for (String regionId : regions) {
ObjectApi objectApi = api.getObjectApi(regionId, containerName);
ObjectApi objectApi = getApi().getObjectApi(regionId, containerName);
Map<String, String> meta = ImmutableMap.of("MyDelete1", "foo", "MyDelete2", "bar");
@ -410,21 +409,18 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void setup() {
super.setup();
for (String regionId : regions) {
api.getContainerApi(regionId).create(containerName);
api.getObjectApi(regionId, containerName).put(name, PAYLOAD);
getApi().getContainerApi(regionId).create(containerName);
getApi().getObjectApi(regionId, containerName).put(name, PAYLOAD);
}
}
@Override
@AfterClass(groups = "live")
public void tearDown() {
for (String regionId : regions) {
deleteAllObjectsInContainer(regionId, containerName);
api.getObjectApi(regionId, containerName).delete(name);
api.getContainerApi(regionId).deleteIfEmpty(containerName);
getApi().getObjectApi(regionId, containerName).delete(name);
getApi().getContainerApi(regionId).deleteIfEmpty(containerName);
}
super.tearDown();
}
static void checkObject(SwiftObject object) {

View File

@ -26,7 +26,6 @@ import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import org.jclouds.openstack.swift.v1.SwiftApi;
import org.jclouds.openstack.swift.v1.domain.DeleteStaticLargeObjectResponse;
import org.jclouds.openstack.swift.v1.domain.Segment;
import org.jclouds.openstack.swift.v1.domain.SwiftObject;
@ -40,7 +39,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.io.ByteSource;
@Test(groups = "live", testName = "StaticLargeObjectApiLiveTest", singleThreaded = true)
public class StaticLargeObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public class StaticLargeObjectApiLiveTest extends BaseSwiftApiLiveTest {
private String name = getClass().getSimpleName();
private String containerName = getClass().getSimpleName() + "Container";
@ -49,7 +48,7 @@ public class StaticLargeObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi>
public void testNotPresentWhenDeleting() throws Exception {
for (String regionId : regions) {
DeleteStaticLargeObjectResponse resp = api.getStaticLargeObjectApi(regionId, containerName).delete(UUID.randomUUID().toString());
DeleteStaticLargeObjectResponse resp = getApi().getStaticLargeObjectApi(regionId, containerName).delete(UUID.randomUUID().toString());
assertThat(resp.status()).isEqualTo("200 OK");
assertThat(resp.deleted()).isZero();
assertThat(resp.notFound()).isEqualTo(1);
@ -60,7 +59,7 @@ public class StaticLargeObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi>
@Test
public void testReplaceManifest() throws Exception {
for (String regionId : regions) {
ObjectApi objectApi = api.getObjectApi(regionId, containerName);
ObjectApi objectApi = getApi().getObjectApi(regionId, containerName);
String etag1s = objectApi.put(name + "/1", newByteSourcePayload(ByteSource.wrap(megOf1s)));
awaitConsistency();
@ -80,50 +79,50 @@ public class StaticLargeObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi>
.build();
awaitConsistency();
String etagOfEtags = api.getStaticLargeObjectApi(regionId, containerName).replaceManifest(
String etagOfEtags = getApi().getStaticLargeObjectApi(regionId, containerName).replaceManifest(
name, segments, ImmutableMap.of("myfoo", "Bar"));
assertNotNull(etagOfEtags);
awaitConsistency();
SwiftObject bigObject = api.getObjectApi(regionId, containerName).get(name);
SwiftObject bigObject = getApi().getObjectApi(regionId, containerName).get(name);
assertEquals(bigObject.getETag(), etagOfEtags);
assertEquals(bigObject.getPayload().getContentMetadata().getContentLength(), Long.valueOf(2 * 1024 * 1024));
assertEquals(bigObject.getMetadata(), ImmutableMap.of("myfoo", "Bar"));
// segments are visible
assertEquals(api.getContainerApi(regionId).get(containerName).getObjectCount(), Long.valueOf(3));
assertEquals(getApi().getContainerApi(regionId).get(containerName).getObjectCount(), Long.valueOf(3));
}
}
@Test(dependsOnMethods = "testReplaceManifest")
public void testDelete() throws Exception {
for (String regionId : regions) {
DeleteStaticLargeObjectResponse resp = api.getStaticLargeObjectApi(regionId, containerName).delete(name);
DeleteStaticLargeObjectResponse resp = getApi().getStaticLargeObjectApi(regionId, containerName).delete(name);
assertThat(resp.status()).isEqualTo("200 OK");
assertThat(resp.deleted()).isEqualTo(3);
assertThat(resp.notFound()).isZero();
assertThat(resp.errors()).isEmpty();
assertEquals(api.getContainerApi(regionId).get(containerName).getObjectCount(), Long.valueOf(0));
assertEquals(getApi().getContainerApi(regionId).get(containerName).getObjectCount(), Long.valueOf(0));
}
}
public void testDeleteSinglePartObjectWithMultiPartDelete() throws Exception {
String objectName = "testDeleteSinglePartObjectWithMultiPartDelete";
for (String regionId : regions) {
api.getObjectApi(regionId, containerName).put(objectName, newByteSourcePayload(ByteSource.wrap("swifty".getBytes())));
DeleteStaticLargeObjectResponse resp = api.getStaticLargeObjectApi(regionId, containerName).delete(objectName);
getApi().getObjectApi(regionId, containerName).put(objectName, newByteSourcePayload(ByteSource.wrap("swifty".getBytes())));
DeleteStaticLargeObjectResponse resp = getApi().getStaticLargeObjectApi(regionId, containerName).delete(objectName);
assertThat(resp.status()).isEqualTo("400 Bad Request");
assertThat(resp.deleted()).isZero();
assertThat(resp.notFound()).isZero();
assertThat(resp.errors()).hasSize(1);
api.getObjectApi(regionId, containerName).delete(objectName);
getApi().getObjectApi(regionId, containerName).delete(objectName);
}
}
protected void assertMegabyteAndETagMatches(String regionId, String name, String etag1s) {
SwiftObject object1s = api.getObjectApi(regionId, containerName).get(name);
SwiftObject object1s = getApi().getObjectApi(regionId, containerName).get(name);
assertEquals(object1s.getETag(), etag1s);
assertEquals(object1s.getPayload().getContentMetadata().getContentLength(), Long.valueOf(1024 * 1024));
}
@ -133,7 +132,7 @@ public class StaticLargeObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi>
public void setup() {
super.setup();
for (String regionId : regions) {
boolean created = api.getContainerApi(regionId).create(containerName);
boolean created = getApi().getContainerApi(regionId).create(containerName);
if (!created) {
deleteAllObjectsInContainer(regionId, containerName);
}
@ -146,13 +145,11 @@ public class StaticLargeObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi>
Arrays.fill(megOf2s, (byte) 2);
}
@Override
@AfterClass(groups = "live")
public void tearDown() {
for (String regionId : regions) {
deleteAllObjectsInContainer(regionId, containerName);
api.getContainerApi(regionId).deleteIfEmpty(containerName);
getApi().getContainerApi(regionId).deleteIfEmpty(containerName);
}
super.tearDown();
}
}

View File

@ -23,7 +23,7 @@ import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.apis.BaseApiLiveTest;
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
import org.jclouds.location.reference.LocationConstants;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.jclouds.openstack.swift.v1.SwiftApi;
@ -40,14 +40,18 @@ import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Uninterruptibles;
@Test(groups = "live", testName = "BaseSwiftApiLiveTest")
public abstract class BaseSwiftApiLiveTest<A extends SwiftApi> extends BaseApiLiveTest<A> {
protected Set<String> regions;
public abstract class BaseSwiftApiLiveTest extends BaseBlobStoreIntegrationTest {
protected BaseSwiftApiLiveTest() {
provider = "openstack-swift";
}
public SwiftApi getApi() {
return view.unwrapApi(SwiftApi.class);
}
protected Set<String> regions;
protected static final int AWAIT_CONSISTENCY_TIMEOUT_SECONDS = Integer.parseInt(System.getProperty(
"test.blobstore.await-consistency-timeout-seconds", "10"));
@ -55,18 +59,6 @@ public abstract class BaseSwiftApiLiveTest<A extends SwiftApi> extends BaseApiLi
Uninterruptibles.sleepUninterruptibly(AWAIT_CONSISTENCY_TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
@Override
@BeforeClass(groups = "live")
public void setup() {
super.setup();
String providedRegion = System.getProperty("test." + LocationConstants.PROPERTY_REGION);
if (providedRegion != null) {
regions = ImmutableSet.of(providedRegion);
} else {
regions = api.getConfiguredRegions();
}
}
@Override
protected Properties setupProperties() {
Properties props = super.setupProperties();
@ -78,7 +70,7 @@ public abstract class BaseSwiftApiLiveTest<A extends SwiftApi> extends BaseApiLi
protected void deleteAllObjectsInContainer(String regionId, final String containerName) {
Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS);
ObjectList objects = api.getObjectApi(regionId, containerName).list(new ListContainerOptions());
ObjectList objects = getApi().getObjectApi(regionId, containerName).list(new ListContainerOptions());
if (objects == null) {
return;
}
@ -88,8 +80,18 @@ public abstract class BaseSwiftApiLiveTest<A extends SwiftApi> extends BaseApiLi
}
});
if (!pathsToDelete.isEmpty()) {
BulkDeleteResponse response = api.getBulkApi(regionId).bulkDelete(pathsToDelete);
BulkDeleteResponse response = getApi().getBulkApi(regionId).bulkDelete(pathsToDelete);
checkState(response.getErrors().isEmpty(), "Errors deleting paths %s: %s", pathsToDelete, response);
}
}
@BeforeClass(groups = "live")
public void setup() {
String providedRegion = System.getProperty("test." + LocationConstants.PROPERTY_REGION);
if (providedRegion != null) {
regions = ImmutableSet.of(providedRegion);
} else {
regions = getApi().getConfiguredRegions();
}
}
}

View File

@ -37,7 +37,7 @@ public class CloudFilesAccountApiLiveTest extends AccountApiLiveTest {
public void testUrlKeyExists() throws Exception {
for (String regionId : regions) {
Account account = api.getAccountApi(regionId).get();
Account account = getApi().getAccountApi(regionId).get();
assertTrue(account.getTemporaryUrlKey().isPresent());
}
}

View File

@ -54,9 +54,9 @@ public class CloudFilesCDNApiLiveTest extends BaseCloudFilesApiLiveTest {
public void testEnable() throws Exception {
for (String regionId : regions) {
assertNotNull(api.getCDNApi(regionId).enable(name));
assertNotNull(getApi().getCDNApi(regionId).enable(name));
CDNContainer container = api.getCDNApi(regionId).get(name);
CDNContainer container = getApi().getCDNApi(regionId).get(name);
assertCDNContainerNotNull(container);
assertTrue(container.isEnabled());
}
@ -64,9 +64,9 @@ public class CloudFilesCDNApiLiveTest extends BaseCloudFilesApiLiveTest {
public void testEnableWithTTL() throws Exception {
for (String regionId : regions) {
assertNotNull(api.getCDNApi(regionId).enable(name, 777777));
assertNotNull(getApi().getCDNApi(regionId).enable(name, 777777));
CDNContainer container = api.getCDNApi(regionId).get(name);
CDNContainer container = getApi().getCDNApi(regionId).get(name);
assertCDNContainerNotNull(container);
assertTrue(container.isEnabled());
assertTrue(container.getTtl() == 777777);
@ -75,16 +75,16 @@ public class CloudFilesCDNApiLiveTest extends BaseCloudFilesApiLiveTest {
public void testDisable() throws Exception {
for (String regionId : regions) {
assertTrue(api.getCDNApi(regionId).disable(name));
assertTrue(getApi().getCDNApi(regionId).disable(name));
CDNContainer container = api.getCDNApi(regionId).get(name);
CDNContainer container = getApi().getCDNApi(regionId).get(name);
assertFalse(container.isEnabled());
}
}
public void testList() throws Exception {
for (String regionId : regions) {
List<CDNContainer> cdnResponse = api.getCDNApi(regionId).list().toList();
List<CDNContainer> cdnResponse = getApi().getCDNApi(regionId).list().toList();
assertNotNull(cdnResponse);
for (CDNContainer cdnContainer : cdnResponse) {
@ -99,7 +99,7 @@ public class CloudFilesCDNApiLiveTest extends BaseCloudFilesApiLiveTest {
for (String regionId : regions) {
ListCDNContainerOptions options = new ListCDNContainerOptions().marker(lexicographicallyBeforeName);
CDNContainer cdnContainer = api.getCDNApi(regionId).list(options).get(0);
CDNContainer cdnContainer = getApi().getCDNApi(regionId).list(options).get(0);
assertCDNContainerNotNull(cdnContainer);
assertTrue(cdnContainer.isEnabled());
}
@ -107,7 +107,7 @@ public class CloudFilesCDNApiLiveTest extends BaseCloudFilesApiLiveTest {
public void testGet() throws Exception {
for (String regionId : regions) {
CDNContainer container = api.getCDNApi(regionId).get(name);
CDNContainer container = getApi().getCDNApi(regionId).get(name);
assertCDNContainerNotNull(container);
assertTrue(container.isEnabled());
}
@ -117,12 +117,12 @@ public class CloudFilesCDNApiLiveTest extends BaseCloudFilesApiLiveTest {
for (String regionId : regions) {
String objectName = "testPurge";
Payload payload = Payloads.newByteSourcePayload(ByteSource.wrap(new byte[] {1, 2, 3}));
ObjectApi objectApi = api.getObjectApi(regionId, name);
ObjectApi objectApi = getApi().getObjectApi(regionId, name);
// create a new object
objectApi.put(objectName, payload);
CDNApi cdnApi = api.getCDNApi(regionId);
CDNApi cdnApi = getApi().getCDNApi(regionId);
assertTrue(cdnApi.purgeObject(name, "testPurge", ImmutableList.<String>of()));
// delete the object
@ -134,10 +134,10 @@ public class CloudFilesCDNApiLiveTest extends BaseCloudFilesApiLiveTest {
public void testUpdate() throws Exception {
for (String regionId : regions) {
// enable with a ttl
assertNotNull(api.getCDNApi(regionId).enable(name, 777777));
assertNotNull(getApi().getCDNApi(regionId).enable(name, 777777));
// now get the container
CDNContainer original = api.getCDNApi(regionId).get(name);
CDNContainer original = getApi().getCDNApi(regionId).get(name);
assertTrue(original.isEnabled());
assertCDNContainerNotNull(original);
@ -147,10 +147,10 @@ public class CloudFilesCDNApiLiveTest extends BaseCloudFilesApiLiveTest {
.logRetention(true)
.enabled(false);
// update the container
assertTrue(api.getCDNApi(regionId).update(name, opts));
assertTrue(getApi().getCDNApi(regionId).update(name, opts));
// now get the updated container
CDNContainer updated = api.getCDNApi(regionId).get(name);
CDNContainer updated = getApi().getCDNApi(regionId).get(name);
assertFalse(updated.isEnabled());
assertCDNContainerNotNull(updated);
@ -174,17 +174,15 @@ public class CloudFilesCDNApiLiveTest extends BaseCloudFilesApiLiveTest {
public void setup() {
super.setup();
for (String regionId : regions) {
api.getContainerApi(regionId).create(name);
getApi().getContainerApi(regionId).create(name);
}
}
@Override
@AfterClass(groups = "live")
public void tearDown() {
for (String regionId : regions) {
api.getCDNApi(regionId).disable(name);
api.getContainerApi(regionId).deleteIfEmpty(name);
getApi().getCDNApi(regionId).disable(name);
getApi().getContainerApi(regionId).deleteIfEmpty(name);
}
super.tearDown();
}
}

View File

@ -24,8 +24,13 @@ import org.testng.annotations.Test;
* Base class for all {@link CloudFilesApi} live tests.
*/
@Test(groups = "live", testName = "BaseCloudFilesApiLiveTest")
public abstract class BaseCloudFilesApiLiveTest extends BaseSwiftApiLiveTest<CloudFilesApi> {
public abstract class BaseCloudFilesApiLiveTest extends BaseSwiftApiLiveTest {
protected BaseCloudFilesApiLiveTest() {
provider = "rackspace-cloudfiles";
}
public CloudFilesApi getApi() {
return view.unwrapApi(CloudFilesApi.class);
}
}