fixing tests after changing provider and adding Expect test for the provider

This commit is contained in:
Mike Arnold 2012-03-20 15:26:11 -05:00
parent b01a88cf8b
commit f1bbfde1b2
17 changed files with 214 additions and 50 deletions

View File

@ -39,12 +39,14 @@ public class HPCloudObjectStoragePropertiesBuilder extends SwiftPropertiesBuilde
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(KeystoneProperties.SERVICE_TYPE, ServiceType.OBJECT_STORE);
properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV");
properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.identity.hpcloudsvc.com:35357");
properties.setProperty(PROPERTY_API_VERSION, "2.0");
Properties properties = super.defaultProperties();
properties.setProperty(KeystoneProperties.SERVICE_TYPE, ServiceType.OBJECT_STORE);
// TODO: this doesn't actually do anything yet.
properties.setProperty(KeystoneProperties.VERSION, "2.0");
properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV");
properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.identity.hpcloudsvc.com:35357");
properties.setProperty(PROPERTY_API_VERSION, "1.0");
return properties;
}

View File

@ -24,6 +24,7 @@ import java.net.URI;
import javax.inject.Singleton;
import com.google.inject.Scopes;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncClient;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageClient;
import org.jclouds.hpcloud.services.HPExtensionCDN;
@ -35,8 +36,12 @@ import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstRegionOptionallyMatchingRegionId;
import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstZone;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
import org.jclouds.openstack.keystone.v2_0.suppliers.RegionIdToURIFromAccessForTypeAndVersionSupplier;
import org.jclouds.openstack.services.ServiceType;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.CommonSwiftClient;
@ -59,24 +64,24 @@ import com.google.inject.Provides;
public class HPCloudObjectStorageRestClientModule extends
RestClientModule<HPCloudObjectStorageClient, HPCloudObjectStorageAsyncClient> {
private final KeystoneAuthenticationModule authModule;
public HPCloudObjectStorageRestClientModule() {
this(new KeystoneAuthenticationModule());
}
public HPCloudObjectStorageRestClientModule(KeystoneAuthenticationModule authModule) {
super(HPCloudObjectStorageClient.class, HPCloudObjectStorageAsyncClient.class);
this.authModule = authModule;
}
protected void configure() {
install(authModule);
install(new SwiftObjectModule());
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
@Override
protected void installLocations() {
super.installLocations();
// TODO: select this from KeystoneProperties.VERSION;
install(KeystoneAuthenticationModule.forRegions());
bind(ImplicitLocationSupplier.class).to(OnlyLocationOrFirstRegionOptionallyMatchingRegionId.class).in(Scopes.SINGLETON);
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseSwiftErrorFromHttpResponse.class);

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.hpcloud.objectstorage.lvs;
package org.jclouds.hpcloud.objectstorage;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
@ -24,8 +24,8 @@ import static org.testng.Assert.assertTrue;
import java.net.URI;
import java.util.Set;
import org.jclouds.hpcloud.objectstorage.lvs.domain.ContainerCDNMetadata;
import org.jclouds.hpcloud.objectstorage.lvs.options.ListCDNContainerOptions;
import org.jclouds.hpcloud.objectstorage.domain.ContainerCDNMetadata;
import org.jclouds.hpcloud.objectstorage.options.ListCDNContainerOptions;
import org.jclouds.openstack.swift.CommonSwiftClientLiveTest;
import org.jclouds.openstack.swift.domain.SwiftObject;
import org.testng.annotations.Test;
@ -34,12 +34,12 @@ import org.testng.annotations.Test;
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "HPCloudObjectStorageLasVegasClientLiveTest")
public class HPCloudObjectStorageLasVegasClientLiveTest extends CommonSwiftClientLiveTest<HPCloudObjectStorageLasVegasClient> {
@Test(groups = "live", testName = "HPCloudObjectStorageClientLiveTest")
public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTest<HPCloudObjectStorageClient> {
@Override
public HPCloudObjectStorageLasVegasClient getApi() {
return (HPCloudObjectStorageLasVegasClient) context.getProviderSpecificContext().getApi();
public HPCloudObjectStorageClient getApi() {
return (HPCloudObjectStorageClient) context.getProviderSpecificContext().getApi();
}
@Override

View File

@ -16,22 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.hpcloud.objectstorage.lvs;
package org.jclouds.hpcloud.objectstorage;
import org.jclouds.providers.BaseProviderMetadataTest;
import org.jclouds.providers.ProviderMetadata;
import org.testng.annotations.Test;
/**
* The HPCloudObjectStorageLasVegasProviderTest tests the {@link org.jclouds.hpcloud.objectstorage.lvs.HPCloudObjectStorageLasVegasProviderMetadata} class.
* The HPCloudObjectStorageProviderTest tests the {@link org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageProviderMetadata} class.
*
* @author Jeremy Daggett
*/
@Test(groups = "unit", testName = "HPCloudObjectStorageLasVegasProviderTest")
public class HPCloudObjectStorageLasVegasProviderTest extends BaseProviderMetadataTest {
@Test(groups = "unit", testName = "HPCloudObjectStorageProviderTest")
public class HPCloudObjectStorageProviderTest extends BaseProviderMetadataTest {
public HPCloudObjectStorageLasVegasProviderTest() {
super(new HPCloudObjectStorageLasVegasProviderMetadata(), ProviderMetadata.BLOBSTORE_TYPE);
public HPCloudObjectStorageProviderTest() {
super(new HPCloudObjectStorageProviderMetadata(), ProviderMetadata.BLOBSTORE_TYPE);
}
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration;
package org.jclouds.hpcloud.objectstorage.blobstore.integration;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobIntegrationLiveTest;
@ -26,7 +26,7 @@ import org.testng.annotations.Test;
* @author Jeremy Daggett
*/
@Test(groups = "live")
public class HPCloudObjectStorageLasVegasBlobIntegrationLiveTest extends SwiftBlobIntegrationLiveTest {
public class HPCloudObjectStorageBlobIntegrationLiveTest extends SwiftBlobIntegrationLiveTest {
@Override
protected void checkContentDisposition(Blob blob, String contentDisposition) {
assert blob.getPayload().getContentMetadata().getContentDisposition().startsWith(contentDisposition) : blob

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration;
package org.jclouds.hpcloud.objectstorage.blobstore.integration;
import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobLiveTest;
import org.testng.annotations.Test;
@ -25,6 +25,6 @@ import org.testng.annotations.Test;
* @author Jeremy Daggett
*/
@Test(groups = { "live" })
public class HPCloudObjectStorageLasVegasBlobLiveTest extends SwiftBlobLiveTest {
public class HPCloudObjectStorageBlobLiveTest extends SwiftBlobLiveTest {
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration;
package org.jclouds.hpcloud.objectstorage.blobstore.integration;
import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobMapIntegrationLiveTest;
import org.testng.annotations.Test;
@ -25,6 +25,6 @@ import org.testng.annotations.Test;
* @author Jeremy Daggett
*/
@Test(groups = "live")
public class HPCloudObjectStorageLasVegasBlobMapIntegrationLiveTest extends SwiftBlobMapIntegrationLiveTest {
public class HPCloudObjectStorageBlobMapIntegrationLiveTest extends SwiftBlobMapIntegrationLiveTest {
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration;
package org.jclouds.hpcloud.objectstorage.blobstore.integration;
import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobSignerLiveTest;
import org.testng.annotations.Test;
@ -25,6 +25,6 @@ import org.testng.annotations.Test;
* @author Jeremy Daggett
*/
@Test(groups = { "live" })
public class HPCloudObjectStorageLasVegasBlobSignerLiveTest extends SwiftBlobSignerLiveTest {
public class HPCloudObjectStorageBlobSignerLiveTest extends SwiftBlobSignerLiveTest {
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration;
package org.jclouds.hpcloud.objectstorage.blobstore.integration;
import org.jclouds.openstack.swift.blobstore.integration.SwiftContainerIntegrationLiveTest;
import org.testng.annotations.Test;
@ -25,6 +25,6 @@ import org.testng.annotations.Test;
* @author Jeremy Daggett
*/
@Test(groups = "live")
public class HPCloudObjectStorageLasVegasContainerIntegrationLiveTest extends SwiftContainerIntegrationLiveTest {
public class HPCloudObjectStorageContainerIntegrationLiveTest extends SwiftContainerIntegrationLiveTest {
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration;
package org.jclouds.hpcloud.objectstorage.blobstore.integration;
import java.io.IOException;
import java.net.MalformedURLException;
@ -28,7 +28,7 @@ import org.testng.annotations.Test;
* @author Jeremy Daggett
*/
@Test(groups = { "live" })
public class HPCloudObjectStorageLasVegasContainerLiveTest extends BaseContainerLiveTest {
public class HPCloudObjectStorageContainerLiveTest extends BaseContainerLiveTest {
@Test(enabled = false)
//@Test(expectedExceptions=UnsupportedOperationException.class)

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration;
package org.jclouds.hpcloud.objectstorage.blobstore.integration;
import org.jclouds.openstack.swift.blobstore.integration.SwiftInputStreamMapIntegrationLiveTest;
import org.testng.annotations.Test;
@ -25,6 +25,6 @@ import org.testng.annotations.Test;
* @author Jeremy Daggett
*/
@Test(groups = "live")
public class HPCloudObjectStorageLasVegasInputStreamMapIntegrationLiveTest extends SwiftInputStreamMapIntegrationLiveTest {
public class HPCloudObjectStorageInputStreamMapIntegrationLiveTest extends SwiftInputStreamMapIntegrationLiveTest {
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration;
package org.jclouds.hpcloud.objectstorage.blobstore.integration;
import java.util.Set;
@ -29,7 +29,7 @@ import com.google.common.collect.ImmutableSet;
* @author Jeremy Daggett
*/
@Test(groups = "live")
public class HPCloudObjectStorageLasVegasServiceIntegrationLiveTest extends SwiftServiceIntegrationLiveTest {
public class HPCloudObjectStorageServiceIntegrationLiveTest extends SwiftServiceIntegrationLiveTest {
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("US-NV");

View File

@ -16,16 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration;
package org.jclouds.hpcloud.objectstorage.blobstore.integration;
import org.jclouds.openstack.swift.blobstore.integration.SwiftTestInitializer;
/**
* @author Jeremy Daggett
*/
public class HPCloudObjectStorageLasVegasTestInitializer extends SwiftTestInitializer {
public class HPCloudObjectStorageTestInitializer extends SwiftTestInitializer {
public HPCloudObjectStorageLasVegasTestInitializer() {
public HPCloudObjectStorageTestInitializer() {
provider = "hpcloud-objectstorage-lvs";
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.hpcloud.objectstorage.lvs.functions;
package org.jclouds.hpcloud.objectstorage.functions;
import static org.testng.Assert.assertEquals;
@ -25,7 +25,7 @@ import java.net.URI;
import java.util.Set;
import java.util.SortedSet;
import org.jclouds.hpcloud.objectstorage.lvs.domain.ContainerCDNMetadata;
import org.jclouds.hpcloud.objectstorage.domain.ContainerCDNMetadata;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.io.Payloads;

View File

@ -0,0 +1,65 @@
package org.jclouds.hpcloud.objectstorage.internal;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextFactory;
import org.jclouds.domain.Location;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.BaseRestClientExpectTest;
import org.testng.annotations.Test;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@Test(groups = "unit", testName = "HPCloudObjectStorageExpectTest")
public class HPCloudObjectStorageExpectTest extends BaseRestClientExpectTest<BlobStore> {
protected HttpRequest keystoneAuthWithUsernameAndPassword;
protected HttpRequest keystoneAuthWithAccessKeyAndSecretKey;
protected String authToken;
protected HttpResponse responseWithKeystoneAccess;
public HPCloudObjectStorageExpectTest() {
provider = "hpcloud-objectstorage";
keystoneAuthWithUsernameAndPassword = KeystoneFixture.INSTANCE.initialAuthWithUsernameAndPassword(identity,
credential);
keystoneAuthWithAccessKeyAndSecretKey = KeystoneFixture.INSTANCE.initialAuthWithAccessKeyAndSecretKey(identity,
credential);
authToken = KeystoneFixture.INSTANCE.getAuthToken();
responseWithKeystoneAccess = KeystoneFixture.INSTANCE.responseWithAccess();
identity = KeystoneFixture.INSTANCE.getTenantName() + ":" + identity;
}
public BlobStore createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
return new BlobStoreContextFactory(setupRestProperties())
.createContext(provider, identity, credential, ImmutableSet.<Module>of(new ExpectModule(fn),
new NullLoggingModule(), module), props)
.getBlobStore();
}
public void testListObjectsWhenResponseIs2xx() throws Exception {
Map<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder().put(
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess).build();
BlobStore clientWhenServersExist = requestsSendResponses(requestResponseMap);
Set<? extends Location> locations = clientWhenServersExist.listAssignableLocations();
assertNotNull(locations);
assertEquals(locations.size(), 1);
assertEquals(locations.iterator().next().getId(), "region-a.geo-1");
}
}

View File

@ -0,0 +1,92 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.hpcloud.objectstorage.internal;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.net.HttpHeaders;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.io.Payload;
import org.jclouds.util.Strings2;
import java.io.IOException;
import java.net.URI;
import static java.lang.String.format;
import static org.jclouds.rest.BaseRestClientExpectTest.payloadFromStringWithContentType;
/**
* Base class for writing HP Cloud Object Storage Rest Client Expect tests
*
* @author Michael Arnold
*/
public enum KeystoneFixture {
INSTANCE;
public String getTenantName(){
return "12346637803162";
}
public HttpRequest initialAuthWithUsernameAndPassword(String username, String password){
return HttpRequest
.builder()
.method("POST")
.endpoint(URI.create("https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/tokens"))
.headers(ImmutableMultimap.of(HttpHeaders.ACCEPT, "application/json"))
.payload(
payloadFromStringWithContentType(
format(
"{\"auth\":{\"passwordCredentials\":{\"username\":\"%s\",\"password\":\"%s\"},\"tenantName\":\"%s\"}}",
username, password, getTenantName()), "application/json")).build();
}
public HttpRequest initialAuthWithAccessKeyAndSecretKey(String accessKey, String secretKey){
return HttpRequest
.builder()
.method("POST")
.endpoint(URI.create("https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/tokens"))
.headers(ImmutableMultimap.of(HttpHeaders.ACCEPT, "application/json"))
.payload(
payloadFromStringWithContentType(
format(
"{\"auth\":{\"apiAccessKeyCredentials\":{\"accessKey\":\"%s\",\"secretKey\":\"%s\"},\"tenantName\":\"%s\"}}",
accessKey, secretKey, getTenantName()), "application/json")).build();
}
public String getAuthToken(){
return "Auth_4f173437e4b013bee56d1007";
}
public HttpResponse responseWithAccess(){
return HttpResponse.builder().statusCode(200).message("HTTP/1.1 200").payload(
payloadFromResourceWithContentType("/keystoneAuthResponse.json", "application/json")).build();
}
public Payload payloadFromResourceWithContentType(String resource, String contentType) {
try {
return payloadFromStringWithContentType(Strings2.toStringAndClose(getClass().getResourceAsStream(resource)),
contentType);
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.hpcloud.objectstorage.lvs.options;
package org.jclouds.hpcloud.objectstorage.options;
import static org.testng.Assert.assertEquals;