allowed regions to be unspecified so that untargetted apis can be tested

This commit is contained in:
Adrian Cole 2011-12-14 21:52:03 -08:00
parent 7c294e8c55
commit 522d94f5ec
6 changed files with 10 additions and 49 deletions

View File

@ -26,11 +26,13 @@ import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.location.Region;
import org.jclouds.logging.Logger;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap;
@ -53,6 +55,9 @@ public class ProvideRegionToURIViaProperties implements javax.inject.Provider<Ma
private final Injector injector;
private final Multimap<String, String> constants;
@Resource
protected Logger logger = Logger.NULL;
@Inject
protected ProvideRegionToURIViaProperties(Injector injector, @Named("CONSTANTS") Multimap<String, String> constants) {
this.injector = injector;
@ -77,8 +82,7 @@ public class ProvideRegionToURIViaProperties implements javax.inject.Provider<Ma
}
return regions.build();
} catch (ConfigurationException e) {
// this happens if regions property isn't set
// services not run by AWS may not have regions, so this is ok.
logger.warn("no region name to endpoint mappings configured!");
return ImmutableMap.of();
}
}

View File

@ -51,7 +51,6 @@ public class RegionToEndpointOrProviderIfNull implements Function<Object, URI> {
this.defaultProvider = checkNotNull(defaultProvider, "defaultProvider");
this.defaultUri = checkNotNull(defaultUri, "defaultUri");
this.regionToEndpoint = checkNotNull(regionToEndpoint, "regionToEndpoint");
checkArgument(regionToEndpoint.size() > 0, "no region name to endpoint mappings configured!");
}
@Override

View File

@ -22,14 +22,11 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import javax.inject.Named;
import org.jclouds.Constants;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.date.DateService;
import org.jclouds.elb.config.ELBRestClientModule;
@ -49,7 +46,6 @@ import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
@ -174,20 +170,6 @@ public class ELBAsyncClientTest extends RestClientTest<ELBAsyncClient> {
@Named(Constants.PROPERTY_SESSION_INTERVAL) int expiration) {
return "2009-11-08T15:54:08.897Z";
}
@Override
protected void bindRegionsToProvider() {
bindRegionsToProvider(Regions.class);
}
static class Regions implements javax.inject.Provider<Map<String, URI>> {
@Override
public Map<String, URI> get() {
return ImmutableMap.<String, URI> of(Region.EU_WEST_1, URI.create("https://elb.eu-west-1.amazonaws.com"),
Region.US_EAST_1, URI.create("https://elb.us-east-1.amazonaws.com"), Region.US_WEST_1,
URI.create("https://elb.us-west-1.amazonaws.com"));
}
}
}
@Override

View File

@ -22,11 +22,9 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp;
@ -42,7 +40,6 @@ import org.jclouds.simpledb.options.ListDomainsOptions;
import org.jclouds.simpledb.xml.ListDomainsResponseHandler;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
@ -60,24 +57,6 @@ public class SimpleDBAsyncClientTest extends RestClientTest<SimpleDBAsyncClient>
@RequiresHttp
@ConfiguresRestClient
private static final class TestSimpleDBRestClientModule extends SimpleDBRestClientModule {
@Override
protected void configure() {
super.configure();
}
@Override
protected void bindRegionsToProvider() {
bindRegionsToProvider(Regions.class);
}
static class Regions implements javax.inject.Provider<Map<String, URI>> {
@Override
public Map<String, URI> get() {
return ImmutableMap.<String, URI> of(Region.EU_WEST_1, URI.create("https://sdb.eu-west-1.amazonaws.com"),
Region.US_EAST_1, URI.create("https://sdb.us-east-1.amazonaws.com"), Region.US_WEST_1,
URI.create("https://sdb.us-west-1.amazonaws.com"));
}
}
}
public void testListDomainsInRegion() throws SecurityException, NoSuchMethodException, IOException {

View File

@ -59,10 +59,6 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
@RequiresHttp
@ConfiguresRestClient
private static final class TestSQSRestClientModule extends SQSRestClientModule {
@Override
protected void configure() {
super.configure();
}
@Override
protected String provideTimeStamp(final DateService dateService,

View File

@ -23,6 +23,7 @@ import java.lang.reflect.Method;
import org.jclouds.aws.domain.Region;
import org.jclouds.elb.ELBAsyncClient;
import org.jclouds.elb.ELBAsyncClientTest;
import org.testng.annotations.Test;
/**
@ -31,10 +32,10 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "aws.ELBAsyncClientTest")
public class ELBAsyncClientTest extends org.jclouds.elb.ELBAsyncClientTest {
@Test(groups = "unit", testName = "AWSELBAsyncClientTest")
public class AWSELBAsyncClientTest extends ELBAsyncClientTest {
public ELBAsyncClientTest() {
public AWSELBAsyncClientTest() {
this.provider = "aws-elb";
}