Skip to content
Permalink
Browse files
New base class for all OpenStack mock tests.
  • Loading branch information
Everett Toews committed Oct 11, 2013
1 parent 849a079 commit a54cdca7d80b6e7f75806e2718eaae218770340f
Showing 8 changed files with 45 additions and 144 deletions.
@@ -23,7 +23,7 @@
import java.util.Properties;

import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.jclouds.openstack.swift.v1.internal.BaseSwiftMockTest;
import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

@@ -37,7 +37,7 @@
* @author Adrian Cole
*/
@Test
public class AuthenticationMockTest extends BaseSwiftMockTest {
public class AuthenticationMockTest extends BaseOpenStackMockTest<SwiftApi> {

@DataProvider(name = "jclouds.keystone.credential-type")
Object[][] credentialTypeToPostBody() {
@@ -59,7 +59,7 @@ public void authenticateCredentialType(String credentialType, String expectedPos
Properties overrides = new Properties();
overrides.setProperty("jclouds.keystone.credential-type", credentialType);

SwiftApi api = swiftApi(server.getUrl("/").toString(), overrides);
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift", overrides);

api.accountApiInRegion("DFW").get();

@@ -19,14 +19,14 @@
import static org.jclouds.openstack.swift.v1.features.AccountApiMockTest.accountResponse;
import static org.testng.Assert.assertEquals;

import org.jclouds.openstack.swift.v1.internal.BaseSwiftMockTest;
import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest;
import org.testng.annotations.Test;

import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;

@Test
public class TemporaryUrlSignerMockTest extends BaseSwiftMockTest {
public class TemporaryUrlSignerMockTest extends BaseOpenStackMockTest<SwiftApi> {

@Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "accountApi")
public void whenAccountApiIsNull() {
@@ -39,7 +39,7 @@ public void whenAccountApiHasKey() throws Exception {
server.enqueue(accountResponse().addHeader("X-Account-Meta-Temp-URL-Key", "mykey"));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
String signature = TemporaryUrlSigner.checkApiEvery(api.accountApiInRegion("DFW"), 10000)
.sign("GET", "/v1/AUTH_account/container/object", 1323479485l);

@@ -61,7 +61,7 @@ public void whenAccountApiDoesntHaveKey() throws Exception {
server.enqueue(accountResponse());

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
TemporaryUrlSigner.checkApiEvery(api.accountApiInRegion("DFW"), 10000)
.sign("GET","/v1/AUTH_account/container/object", 1323479485l);
} finally {
@@ -22,9 +22,9 @@
import java.util.Map;
import java.util.Map.Entry;

import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest;
import org.jclouds.openstack.swift.v1.SwiftApi;
import org.jclouds.openstack.swift.v1.domain.Account;
import org.jclouds.openstack.swift.v1.internal.BaseSwiftMockTest;
import org.testng.annotations.Test;

import com.google.common.collect.ImmutableMap;
@@ -36,7 +36,7 @@
* @author Jeremy Daggett
*/
@Test
public class AccountApiMockTest extends BaseSwiftMockTest {
public class AccountApiMockTest extends BaseOpenStackMockTest<SwiftApi> {

/** upper-cases first char, and lower-cases rest!! **/
public void getKnowingServerMessesWithMetadataKeyCaseFormat() throws Exception {
@@ -48,7 +48,7 @@ public void getKnowingServerMessesWithMetadataKeyCaseFormat() throws Exception {
.addHeader("X-Account-Meta-Apiversion", "v1.1"));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
Account account = api.accountApiInRegion("DFW").get();
assertEquals(account.containerCount(), 3l);
assertEquals(account.objectCount(), 42l);
@@ -74,7 +74,7 @@ public void updateMetadata() throws Exception {
.addHeader("X-Account-Meta-ApiVersion", "v1.1"));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
assertTrue(api.accountApiInRegion("DFW").updateMetadata(metadata));

assertEquals(server.getRequestCount(), 2);
@@ -96,7 +96,7 @@ public void updateTemporaryUrlKey() throws Exception {
server.enqueue(accountResponse());

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
assertTrue(api.accountApiInRegion("DFW").updateTemporaryUrlKey("foobar"));

assertEquals(server.getRequestCount(), 2);
@@ -116,7 +116,7 @@ public void deleteMetadata() throws Exception {
server.enqueue(accountResponse());

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
assertTrue(api.accountApiInRegion("DFW").deleteMetadata(metadata));

assertEquals(server.getRequestCount(), 2);
@@ -24,9 +24,9 @@
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.exporter.TarGzExporter;
import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest;
import org.jclouds.openstack.swift.v1.SwiftApi;
import org.jclouds.openstack.swift.v1.domain.ExtractArchiveResponse;
import org.jclouds.openstack.swift.v1.internal.BaseSwiftMockTest;
import org.testng.annotations.Test;

import com.google.common.io.ByteStreams;
@@ -36,7 +36,7 @@

// TODO: cannot yet test bulk delete offline
@Test
public class BulkApiMockTest extends BaseSwiftMockTest {
public class BulkApiMockTest extends BaseOpenStackMockTest<SwiftApi> {

public void extractArchive() throws Exception {
GenericArchive files = ShrinkWrap.create(GenericArchive.class, "files.tar.gz");
@@ -51,7 +51,7 @@ public void extractArchive() throws Exception {
server.enqueue(new MockResponse().setResponseCode(201).setBody("{\"Number Files Created\": 10, \"Errors\": []}"));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
ExtractArchiveResponse response = api.bulkApiInRegion("DFW").extractArchive("myContainer",
newByteArrayPayload(tarGz), "tar.gz");
assertEquals(response.created(), 10);
@@ -26,7 +26,7 @@

import org.jclouds.openstack.swift.v1.SwiftApi;
import org.jclouds.openstack.swift.v1.domain.Container;
import org.jclouds.openstack.swift.v1.internal.BaseSwiftMockTest;
import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest;
import org.jclouds.openstack.swift.v1.options.CreateContainerOptions;
import org.testng.annotations.Test;

@@ -37,7 +37,7 @@
import com.squareup.okhttp.mockwebserver.RecordedRequest;

@Test
public class ContainerApiMockTest extends BaseSwiftMockTest {
public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {

String containerList = "" //
+ "[\n" //
@@ -51,7 +51,7 @@ public void listFirstPage() throws Exception {
server.enqueue(new MockResponse().setBody(containerList));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
ImmutableList<Container> containers = api.containerApiInRegion("DFW").listFirstPage().toList();
assertEquals(containers, ImmutableList.of(//
Container.builder() //
@@ -78,7 +78,7 @@ public void listAt() throws Exception {
server.enqueue(new MockResponse().setBody(containerList));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
ImmutableList<Container> containers = api.containerApiInRegion("DFW").listAt("test").toList();
assertEquals(containers, ImmutableList.of(//
Container.builder() //
@@ -105,7 +105,7 @@ public void createIfAbsent() throws Exception {
server.enqueue(new MockResponse().setResponseCode(201));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
assertTrue(api.containerApiInRegion("DFW").createIfAbsent("myContainer", new CreateContainerOptions()));

assertEquals(server.getRequestCount(), 2);
@@ -124,7 +124,7 @@ public void createWithOptions() throws Exception {
server.enqueue(new MockResponse().setResponseCode(201));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
assertTrue(api.containerApiInRegion("DFW").createIfAbsent("myContainer", anybodyRead().metadata(metadata)));

assertEquals(server.getRequestCount(), 2);
@@ -147,7 +147,7 @@ public void alreadyCreated() throws Exception {
server.enqueue(new MockResponse().setResponseCode(202));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
assertFalse(api.containerApiInRegion("DFW").createIfAbsent("myContainer", new CreateContainerOptions()));

assertEquals(server.getRequestCount(), 2);
@@ -170,7 +170,7 @@ public void getKnowingServerMessesWithMetadataKeyCaseFormat() throws Exception {
.addHeader("X-Container-Meta-Apiversion", "v1.1"));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
Container container = api.containerApiInRegion("DFW").get("myContainer");
assertEquals(container.name(), "myContainer");
assertEquals(container.objectCount(), 42l);
@@ -196,7 +196,7 @@ public void updateMetadata() throws Exception {
.addHeader("X-Container-Meta-ApiVersion", "v1.1"));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
assertTrue(api.containerApiInRegion("DFW").updateMetadata("myContainer", metadata));

assertEquals(server.getRequestCount(), 2);
@@ -218,7 +218,7 @@ public void deleteMetadata() throws Exception {
server.enqueue(containerResponse());

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
assertTrue(api.containerApiInRegion("DFW").deleteMetadata("myContainer", metadata));

assertEquals(server.getRequestCount(), 2);
@@ -240,7 +240,7 @@ public void deleteIfEmpty() throws Exception {
server.enqueue(new MockResponse().setResponseCode(204));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
assertTrue(api.containerApiInRegion("DFW").deleteIfEmpty("myContainer"));

assertEquals(server.getRequestCount(), 2);
@@ -259,7 +259,7 @@ public void alreadyDeleted() throws Exception {
server.enqueue(new MockResponse().setResponseCode(404));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
assertFalse(api.containerApiInRegion("DFW").deleteIfEmpty("myContainer"));

assertEquals(server.getRequestCount(), 2);
@@ -279,7 +279,7 @@ public void deleteWhenNotEmpty() throws Exception {
server.enqueue(new MockResponse().setResponseCode(409));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
api.containerApiInRegion("DFW").deleteIfEmpty("myContainer");

} finally {
@@ -32,10 +32,10 @@
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest;
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.BaseSwiftMockTest;
import org.jclouds.openstack.swift.v1.options.ListContainerOptions;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
@@ -47,7 +47,7 @@
import com.squareup.okhttp.mockwebserver.RecordedRequest;

@Test
public class ObjectApiMockTest extends BaseSwiftMockTest {
public class ObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
SimpleDateFormatDateService dates = new SimpleDateFormatDateService();

String objectList = "" //
@@ -89,7 +89,7 @@ public void list() throws Exception {
.setBody(objectList));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
ObjectList objects = api.objectApiInRegionForContainer("DFW", "myContainer").list(new ListContainerOptions());
assertEquals(objects, parsedObjectsForUrl(server.getUrl("/").toString()));
assertEquals(objects.container().name(), "myContainer");
@@ -110,7 +110,7 @@ public void listOptions() throws Exception {
server.enqueue(containerResponse().setBody(objectList));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
ObjectList objects = api.objectApiInRegionForContainer("DFW", "myContainer").list(marker("test"));
assertEquals(objects, parsedObjectsForUrl(server.getUrl("/").toString()));

@@ -131,7 +131,7 @@ public void replace() throws Exception {
.addHeader("ETag", "d9f5eb4bba4e2f2f046e54611bc8196b"));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
assertEquals(
api.objectApiInRegionForContainer("DFW", "myContainer").replace("myObject",
newStringPayload("swifty"), metadata), "d9f5eb4bba4e2f2f046e54611bc8196b");
@@ -160,7 +160,7 @@ public void headKnowingServerMessesWithMetadataKeyCaseFormat() throws Exception
.addHeader("X-Object-Meta-Apiversion", "v1.1"));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
SwiftObject object = api.objectApiInRegionForContainer("DFW", "myContainer").head("myObject");
assertEquals(object.name(), "myObject");
assertEquals(object.etag(), "8a964ee2a5e88be344f36c22562a6486");
@@ -190,7 +190,7 @@ public void get() throws Exception {
.addHeader("X-Object-Meta-Apiversion", "v1.1"));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
SwiftObject object = api.objectApiInRegionForContainer("DFW", "myContainer").get("myObject", tail(1));
assertEquals(object.name(), "myObject");
assertEquals(object.etag(), "8a964ee2a5e88be344f36c22562a6486");
@@ -222,7 +222,7 @@ public void updateMetadata() throws Exception {
.addHeader("X-Object-Meta-ApiVersion", "v1.1"));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
assertTrue(api.objectApiInRegionForContainer("DFW", "myContainer").updateMetadata("myObject", metadata));

assertEquals(server.getRequestCount(), 2);
@@ -244,7 +244,7 @@ public void deleteMetadata() throws Exception {
server.enqueue(objectResponse());

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
assertTrue(api.objectApiInRegionForContainer("DFW", "myContainer").deleteMetadata("myObject", metadata));

assertEquals(server.getRequestCount(), 2);
@@ -266,7 +266,7 @@ public void delete() throws Exception {
server.enqueue(new MockResponse().setResponseCode(204));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
api.objectApiInRegionForContainer("DFW", "myContainer").delete("myObject");

assertEquals(server.getRequestCount(), 2);
@@ -285,7 +285,7 @@ public void alreadyDeleted() throws Exception {
server.enqueue(new MockResponse().setResponseCode(404));

try {
SwiftApi api = swiftApi(server.getUrl("/").toString());
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
api.objectApiInRegionForContainer("DFW", "myContainer").delete("myObject");

assertEquals(server.getRequestCount(), 2);

0 comments on commit a54cdca

Please sign in to comment.