Issue 320: introduced Json object to decouple us from gson libraries

This commit is contained in:
Adrian Cole 2010-07-25 17:40:44 -07:00
parent c40a14012a
commit 35a766c0fa
93 changed files with 844 additions and 780 deletions

View File

@ -0,0 +1,38 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.atmosonline.saas.config;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import com.google.inject.AbstractModule;
/**
*
*
* @author Adrian Cole
*/
public class AtmosStorageParserModule extends AbstractModule {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
}
}

View File

@ -36,8 +36,6 @@ import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
@ -45,22 +43,21 @@ import com.google.common.base.Supplier;
import com.google.inject.Provides;
/**
* Configures the EMC Atmos Online Storage authentication service connection, including logging and
* http transport.
* Configures the EMC Atmos Online Storage authentication service connection,
* including logging and http transport.
*
* @author Adrian Cole
*/
@ConfiguresRestClient
@RequiresHttp
public class AtmosStorageRestClientModule extends
RestClientModule<AtmosStorageClient, AtmosStorageAsyncClient> {
public class AtmosStorageRestClientModule extends RestClientModule<AtmosStorageClient, AtmosStorageAsyncClient> {
public AtmosStorageRestClientModule() {
super(AtmosStorageClient.class, AtmosStorageAsyncClient.class);
}
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
install(new AtmosStorageParserModule());
install(new AtmosObjectModule());
super.configure();
}
@ -77,7 +74,7 @@ public class AtmosStorageRestClientModule extends
@Provides
@TimeStamp
Supplier<String> provideTimeStampCache(@Named(Constants.PROPERTY_SESSION_INTERVAL) long seconds,
final DateService dateService) {
final DateService dateService) {
return new ExpirableSupplier<String>(new Supplier<String>() {
public String get() {
return dateService.rfc822DateFormat();
@ -87,18 +84,14 @@ public class AtmosStorageRestClientModule extends
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
ParseAtmosStorageErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(
ParseAtmosStorageErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(
ParseAtmosStorageErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseAtmosStorageErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseAtmosStorageErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseAtmosStorageErrorFromXmlContent.class);
}
@Override
protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(
AtmosStorageClientErrorRetryHandler.class);
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(AtmosStorageClientErrorRetryHandler.class);
}
}

View File

@ -0,0 +1,38 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.aws.s3.config;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import com.google.inject.AbstractModule;
/**
*
*
* @author Adrian Cole
*/
public class S3ParserModule extends AbstractModule {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
}
}

View File

@ -32,8 +32,6 @@ import org.jclouds.concurrent.ExpirableSupplier;
import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RequestSigner;
@ -56,7 +54,7 @@ public class S3RestClientModule extends AWSRestClientModule<S3Client, S3AsyncCli
@Override
protected void configure() {
install(new S3ObjectModule());
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
install(new S3ParserModule());
bind(RequestAuthorizeSignature.class).in(Scopes.SINGLETON);
super.configure();
}
@ -80,7 +78,7 @@ public class S3RestClientModule extends AWSRestClientModule<S3Client, S3AsyncCli
@TimeStamp
@Singleton
protected Supplier<String> provideTimeStampCache(@Named(Constants.PROPERTY_SESSION_INTERVAL) long seconds,
final DateService dateService) {
final DateService dateService) {
return new ExpirableSupplier<String>(new Supplier<String>() {
public String get() {
return dateService.rfc822DateFormat();

View File

@ -26,7 +26,7 @@ import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.testng.annotations.BeforeTest;
import com.google.common.collect.ImmutableMap;
@ -48,7 +48,7 @@ public class BaseEC2HandlerTest extends BaseHandlerTest {
@BeforeTest
@Override
protected void setUpInjector() {
injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
@Override
protected void configure() {

View File

@ -28,7 +28,7 @@ import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -45,7 +45,7 @@ public class DescribeAvailabilityZonesResponseHandlerTest extends BaseHandlerTes
@BeforeTest
protected void setUpInjector() {
injector = Guice.createInjector(new ParserModule() {
injector = Guice.createInjector(new SaxParserModule() {
@Override
protected void configure() {

View File

@ -27,7 +27,7 @@ import java.util.Map;
import org.jclouds.aws.domain.Region;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.rest.annotations.Provider;
import org.jclouds.util.Utils;
import org.testng.annotations.BeforeTest;
@ -47,7 +47,7 @@ public class DescribeRegionsResponseHandlerTest extends BaseHandlerTest {
@BeforeTest
@Override
protected void setUpInjector() {
injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
@Override
protected void configure() {

View File

@ -13,7 +13,7 @@ import org.easymock.IArgumentMatcher;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.RequestSigner;
@ -59,7 +59,7 @@ public class ParseAWSErrorFromXmlContentTest {
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
Class<? extends Exception> expected) {
ParseAWSErrorFromXmlContent function = Guice.createInjector(new ParserModule(), new AbstractModule() {
ParseAWSErrorFromXmlContent function = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
@Override
protected void configure() {

View File

@ -38,7 +38,7 @@ import org.jclouds.aws.s3.domain.ObjectMetadata.StorageClass;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpException;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.util.Utils;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
@ -61,7 +61,7 @@ public class S3ParserTest extends PerformanceTest {
@BeforeTest
protected void setUpInjector() {
injector = Guice.createInjector(new ParserModule());
injector = Guice.createInjector(new SaxParserModule());
factory = injector.getInstance(ParseSax.Factory.class);
assert factory != null;
}

View File

@ -39,7 +39,7 @@ import org.jclouds.aws.sqs.domain.Queue;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.io.Payloads;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -76,7 +76,7 @@ public class ListQueuesResponseHandlerTest extends PerformanceTest {
System.out.printf("queue response handle speed test %d threads %d count%n", THREAD_COUNT,
LOOP_COUNT);
injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
@Override
protected void configure() {

View File

@ -0,0 +1,38 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.azure.storage.config;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import com.google.inject.AbstractModule;
/**
*
*
* @author Adrian Cole
*/
public class AzureStorageParserModule extends AbstractModule {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
}
}

View File

@ -35,8 +35,6 @@ import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
@ -68,7 +66,7 @@ public class AzureStorageRestClientModule<S, A> extends RestClientModule<S, A> {
@Provides
@TimeStamp
protected Supplier<String> provideTimeStampCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final DateService dateService) {
final DateService dateService) {
return new ExpirableSupplier<String>(new Supplier<String>() {
public String get() {
return dateService.rfc822DateFormat();
@ -78,23 +76,19 @@ public class AzureStorageRestClientModule<S, A> extends RestClientModule<S, A> {
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
ParseAzureStorageErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(
ParseAzureStorageErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(
ParseAzureStorageErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseAzureStorageErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseAzureStorageErrorFromXmlContent.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseAzureStorageErrorFromXmlContent.class);
}
@Override
protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(
AzureStorageClientErrorRetryHandler.class);
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(AzureStorageClientErrorRetryHandler.class);
}
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
install(new AzureStorageParserModule());
super.configure();
}

View File

@ -37,7 +37,7 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
/**
* Tests behavior of {@code ParseFlavorListFromGsonResponseTest}
* Tests behavior of {@code ParseFlavorListFromJsonResponseTest}
*
* @author Adrian Cole
*/

View File

@ -158,7 +158,7 @@ public interface Constants {
*/
public static final String LOGGER_SIGNATURE = "jclouds.signature";
/**
* Name of the custom adapter bindings map for Gson
* Name of the custom adapter bindings map for Json
*/
public static final String PROPERTY_GSON_ADAPTERS = "jclouds.gson_adapters";

View File

@ -63,6 +63,18 @@ public class JsonBall implements java.io.Serializable, Comparable<String>, CharS
return value;
}
public JsonBall(double value) {
this.value = value + "";
}
public JsonBall(int value) {
this.value = value + "";
}
public JsonBall(long value) {
this.value = value + "";
}
public JsonBall(String value) {
this.value = quoteStringIfNotNumber(checkNotNull(value, "value"));
}

View File

@ -0,0 +1,71 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.http.functions.config;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
import org.xml.sax.XMLReader;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Scopes;
/**
* Contains logic for parsing objects from Strings.
*
* @author Adrian Cole
*/
public class SaxParserModule extends AbstractModule {
protected void configure() {
bind(ParseSax.Factory.class).to(Factory.class).in(Scopes.SINGLETON);
}
private static class Factory implements ParseSax.Factory {
@Inject
private SAXParserFactory factory;
public <T> ParseSax<T> create(HandlerWithResult<T> handler) {
SAXParser saxParser;
try {
saxParser = factory.newSAXParser();
XMLReader parser = saxParser.getXMLReader();
return new ParseSax<T>(parser, handler);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
@Provides
@Singleton
SAXParserFactory provideSAXParserFactory() {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(false);
factory.setValidating(false);
return factory;
}
}

View File

@ -0,0 +1,44 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.json;
import java.lang.reflect.Type;
/**
* @author Adrian Cole
*/
public interface Json {
/**
* Serialize the object into json.
*/
String toJson(Object src);
/**
* Deserialize the generic object from json. If the object is not a generic
* type, use {@link #fromJson(Object, Class)}
*/
<T> T fromJson(String json, Type type);
/**
* Deserialize the object from json. If the object is a generic type, use
* {@link #fromJson(Object, Type)}
*/
<T> T fromJson(String json, Class<T> classOfT);
}

View File

@ -16,7 +16,7 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.http.functions.config;
package org.jclouds.json.config;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
@ -26,16 +26,13 @@ import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.jclouds.Constants;
import org.jclouds.date.DateService;
import org.jclouds.domain.JsonBall;
import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
import org.xml.sax.XMLReader;
import org.jclouds.json.Json;
import org.jclouds.json.internal.GsonWrapper;
import com.google.common.collect.Maps;
import com.google.common.primitives.Bytes;
@ -54,7 +51,6 @@ import com.google.gson.reflect.TypeToken;
import com.google.inject.AbstractModule;
import com.google.inject.ImplementedBy;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.name.Named;
/**
@ -62,42 +58,12 @@ import com.google.inject.name.Named;
*
* @author Adrian Cole
*/
public class ParserModule extends AbstractModule {
protected void configure() {
bind(ParseSax.Factory.class).to(Factory.class).in(Scopes.SINGLETON);
}
private static class Factory implements ParseSax.Factory {
@Inject
private SAXParserFactory factory;
public <T> ParseSax<T> create(HandlerWithResult<T> handler) {
SAXParser saxParser;
try {
saxParser = factory.newSAXParser();
XMLReader parser = saxParser.getXMLReader();
return new ParseSax<T>(parser, handler);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
@Provides
@Singleton
SAXParserFactory provideSAXParserFactory() {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(false);
factory.setValidating(false);
return factory;
}
public class GsonModule extends AbstractModule {
@Provides
@Singleton
Gson provideGson(JsonBallAdapter jsonObjectAdapter, DateAdapter adapter, ByteListAdapter byteListAdapter,
ByteArrayAdapter byteArrayAdapter, GsonAdapterBindings bindings) throws SecurityException,
ByteArrayAdapter byteArrayAdapter, JsonAdapterBindings bindings) throws SecurityException,
NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(JsonBall.class, jsonObjectAdapter);
@ -260,7 +226,7 @@ public class ParserModule extends AbstractModule {
}
@Singleton
public static class GsonAdapterBindings {
public static class JsonAdapterBindings {
private final Map<Type, Object> bindings = Maps.newHashMap();
@com.google.inject.Inject(optional = true)
@ -272,4 +238,9 @@ public class ParserModule extends AbstractModule {
return bindings;
}
}
@Override
protected void configure() {
bind(Json.class).to(GsonWrapper.class);
}
}

View File

@ -0,0 +1,59 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.json.internal;
import java.lang.reflect.Type;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.json.Json;
import com.google.gson.Gson;
/**
* @author Adrian Cole
*/
@Singleton
public class GsonWrapper implements Json {
private final Gson gson;
@Inject
public GsonWrapper(Gson gson) {
this.gson = gson;
}
@SuppressWarnings("unchecked")
@Override
public <T> T fromJson(String json, Type type) {
return (T) gson.fromJson(json, type);
}
@Override
public <T> T fromJson(String json, Class<T> classOfT) {
return gson.fromJson(json, classOfT);
}
@Override
public String toJson(Object src) {
return gson.toJson(src);
}
}

View File

@ -26,10 +26,9 @@ import javax.inject.Inject;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.rest.MapBinder;
import com.google.gson.Gson;
/**
* Binds the object to the request as a json object.
*
@ -39,15 +38,15 @@ import com.google.gson.Gson;
public class BindToJsonPayload implements MapBinder {
@Inject
protected Gson gson;
protected Json jsonBinder;
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
bindToRequest(request, (Object) postParams);
}
public void bindToRequest(HttpRequest request, Object toBind) {
checkState(gson != null, "Program error: gson should have been injected at this point");
String json = gson.toJson(toBind);
checkState(jsonBinder != null, "Program error: json should have been injected at this point");
String json = jsonBinder.toJson(toBind);
request.setPayload(json);
request.getPayload().setContentType(MediaType.APPLICATION_JSON);
}

View File

@ -30,8 +30,9 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.http.TransformingHttpCommand;
import org.jclouds.http.TransformingHttpCommandExecutorService;
import org.jclouds.http.TransformingHttpCommandImpl;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.internal.ClassMethodArgs;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.HttpAsyncClient;
import org.jclouds.rest.HttpClient;
@ -59,32 +60,28 @@ public class RestModule extends AbstractModule {
@Override
protected void configure() {
install(new ParserModule());
install(new SaxParserModule());
install(new GsonModule());
bind(UriBuilder.class).to(UriBuilderImpl.class);
bind(AsyncRestClientProxy.Factory.class).to(Factory.class).in(
Scopes.SINGLETON);
bind(AsyncRestClientProxy.Factory.class).to(Factory.class).in(Scopes.SINGLETON);
BinderUtils.bindAsyncClient(binder(), HttpAsyncClient.class);
BinderUtils.bindClient(binder(), HttpClient.class, HttpAsyncClient.class,
ImmutableMap.<Class<?>, Class<?>> of(HttpClient.class,
HttpAsyncClient.class));
BinderUtils.bindClient(binder(), HttpClient.class, HttpAsyncClient.class, ImmutableMap.<Class<?>, Class<?>> of(
HttpClient.class, HttpAsyncClient.class));
}
@Provides
@Singleton
@Named("async")
ConcurrentMap<ClassMethodArgs, Object> provideAsyncDelegateMap(
CreateAsyncClientForCaller createAsyncClientForCaller) {
ConcurrentMap<ClassMethodArgs, Object> provideAsyncDelegateMap(CreateAsyncClientForCaller createAsyncClientForCaller) {
return new MapMaker().makeComputingMap(createAsyncClientForCaller);
}
static class CreateAsyncClientForCaller implements
Function<ClassMethodArgs, Object> {
static class CreateAsyncClientForCaller implements Function<ClassMethodArgs, Object> {
private final Injector injector;
private final AsyncRestClientProxy.Factory factory;
@Inject
CreateAsyncClientForCaller(Injector injector,
AsyncRestClientProxy.Factory factory) {
CreateAsyncClientForCaller(Injector injector, AsyncRestClientProxy.Factory factory) {
this.injector = injector;
this.factory = factory;
}
@ -94,18 +91,15 @@ public class RestModule extends AbstractModule {
public Object apply(final ClassMethodArgs from) {
Class clazz = from.getAsyncClass();
TypeLiteral typeLiteral = TypeLiteral.get(clazz);
RestAnnotationProcessor util = (RestAnnotationProcessor) injector
.getInstance(Key.get(TypeLiteral.get(Types.newParameterizedType(
RestAnnotationProcessor.class, clazz))));
// cannot use child injectors due to the super coarse guice lock on
RestAnnotationProcessor util = (RestAnnotationProcessor) injector.getInstance(Key.get(TypeLiteral.get(Types
.newParameterizedType(RestAnnotationProcessor.class, clazz))));
// cannot use child injectors due to the super coarse guice lock on
// Singleton
util.setCaller(from);
ConcurrentMap<ClassMethodArgs, Object> delegateMap = injector
.getInstance(Key.get(
new TypeLiteral<ConcurrentMap<ClassMethodArgs, Object>>() {
}, Names.named("async")));
AsyncRestClientProxy proxy = new AsyncRestClientProxy(injector,
factory, util, typeLiteral, delegateMap);
ConcurrentMap<ClassMethodArgs, Object> delegateMap = injector.getInstance(Key.get(
new TypeLiteral<ConcurrentMap<ClassMethodArgs, Object>>() {
}, Names.named("async")));
AsyncRestClientProxy proxy = new AsyncRestClientProxy(injector, factory, util, typeLiteral, delegateMap);
injector.injectMembers(proxy);
return AsyncClientFactory.create(clazz, proxy);
}
@ -116,10 +110,8 @@ public class RestModule extends AbstractModule {
private TransformingHttpCommandExecutorService executorService;
@SuppressWarnings("unchecked")
public TransformingHttpCommand<?> create(HttpRequest request,
Function<HttpResponse, ?> transformer) {
return new TransformingHttpCommandImpl(executorService, request,
transformer);
public TransformingHttpCommand<?> create(HttpRequest request, Function<HttpResponse, ?> transformer) {
return new TransformingHttpCommandImpl(executorService, request, transformer);
}
}

View File

@ -65,6 +65,7 @@ import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.io.OutputSupplier;
import com.google.inject.ProvisionException;
import com.google.inject.spi.Message;
@ -76,6 +77,28 @@ import com.google.inject.spi.Message;
*/
public class Utils {
public static <K, V> Supplier<Map<K, V>> composeMapSupplier(Iterable<Supplier<Map<K, V>>> suppliers) {
return new ListMapSupplier<K, V>(suppliers);
}
static class ListMapSupplier<K, V> implements Supplier<Map<K, V>> {
private final Iterable<Supplier<Map<K, V>>> suppliers;
ListMapSupplier(Iterable<Supplier<Map<K, V>>> suppliers) {
this.suppliers = suppliers;
}
@Override
public Map<K, V> get() {
Map<K, V> toReturn = Maps.newLinkedHashMap();
for (Supplier<Map<K, V>> supplier : suppliers) {
toReturn.putAll(supplier.get());
}
return toReturn;
}
}
public static <T> T propagateAuthorizationOrOriginalException(Exception e) {
AuthorizationException aex = getFirstThrowableOfType(e, AuthorizationException.class);
if (aex != null)
@ -132,8 +155,7 @@ public class Utils {
}
}
public static <T extends Throwable> T getFirstThrowableOfType(ProvisionException e,
Class<T> clazz) {
public static <T extends Throwable> T getFirstThrowableOfType(ProvisionException e, Class<T> clazz) {
for (Message message : e.getErrorMessages()) {
T cause = getFirstThrowableOfType(message.getCause(), clazz);
if (cause instanceof ProvisionException)
@ -184,7 +206,7 @@ public class Utils {
}
public static boolean eventuallyTrue(Supplier<Boolean> assertion, long inconsistencyMillis)
throws InterruptedException {
throws InterruptedException {
for (int i = 0; i < 30; i++) {
if (!assertion.get()) {
@ -219,14 +241,15 @@ public class Utils {
}
/**
* Encode the given string with the given encoding, if possible. If the encoding fails with
* {@link UnsupportedEncodingException}, log a warning and fall back to the system's default
* encoding.
* Encode the given string with the given encoding, if possible. If the
* encoding fails with {@link UnsupportedEncodingException}, log a warning
* and fall back to the system's default encoding.
*
* @param str
* what to encode
* @param charsetName
* the name of a supported {@link java.nio.charset.Charset </code>charset<code>}
* the name of a supported {@link java.nio.charset.Charset
* </code>charset<code>}
* @return properly encoded String.
*/
public static byte[] encodeString(String str, String charsetName) {
@ -234,15 +257,16 @@ public class Utils {
return str.getBytes(charsetName);
} catch (UnsupportedEncodingException e) {
logger.warn(e, "Failed to encode string to bytes with encoding " + charsetName
+ ". Falling back to system's default encoding");
+ ". Falling back to system's default encoding");
return str.getBytes();
}
}
/**
* Encode the given string with the UTF-8 encoding, the sane default. In the very unlikely event
* the encoding fails with {@link UnsupportedEncodingException}, log a warning and fall back to
* the system's default encoding.
* Encode the given string with the UTF-8 encoding, the sane default. In the
* very unlikely event the encoding fails with
* {@link UnsupportedEncodingException}, log a warning and fall back to the
* system's default encoding.
*
* @param str
* what to encode
@ -293,7 +317,8 @@ public class Utils {
}
/**
* Will throw an exception if the argument is null or empty. Accepts a custom error message.
* Will throw an exception if the argument is null or empty. Accepts a custom
* error message.
*
* @param nullableString
* string to verify. Can be null or empty.
@ -305,8 +330,8 @@ public class Utils {
}
/**
* Gets a set of supported providers. Idea stolen from pallets (supported-clouds). Uses
* rest.properties to populate the set.
* Gets a set of supported providers. Idea stolen from pallets
* (supported-clouds). Uses rest.properties to populate the set.
*
*/
public static Iterable<String> getSupportedProviders() {
@ -314,13 +339,12 @@ public class Utils {
}
/**
* Gets a set of supported providers. Idea stolen from pallets (supported-clouds). Uses
* rest.properties to populate the set.
* Gets a set of supported providers. Idea stolen from pallets
* (supported-clouds). Uses rest.properties to populate the set.
*
*/
@SuppressWarnings("unchecked")
public static Iterable<String> getSupportedProvidersOfType(
Class<? extends RestContextBuilder> type) {
public static Iterable<String> getSupportedProvidersOfType(Class<? extends RestContextBuilder> type) {
Properties properties = new Properties();
try {
properties.load(Utils.class.getResourceAsStream("/rest.properties"));
@ -332,25 +356,23 @@ public class Utils {
@SuppressWarnings("unchecked")
public static Iterable<String> getSupportedProvidersOfTypeInProperties(
final Class<? extends RestContextBuilder> type, final Properties properties) {
return filter(transform(filter(properties.entrySet(),
new Predicate<Map.Entry<Object, Object>>() {
final Class<? extends RestContextBuilder> type, final Properties properties) {
return filter(transform(filter(properties.entrySet(), new Predicate<Map.Entry<Object, Object>>() {
@Override
public boolean apply(Entry<Object, Object> input) {
String keyString = input.getKey().toString();
return keyString.endsWith(".contextbuilder") || keyString.endsWith(".sync");
}
@Override
public boolean apply(Entry<Object, Object> input) {
String keyString = input.getKey().toString();
return keyString.endsWith(".contextbuilder") || keyString.endsWith(".sync");
}
}), new Function<Map.Entry<Object, Object>, String>() {
}), new Function<Map.Entry<Object, Object>, String>() {
@Override
public String apply(Entry<Object, Object> from) {
String keyString = from.getKey().toString();
try {
String provider = get(Splitter.on('.').split(keyString), 0);
Class<RestContextBuilder<Object, Object>> clazz = resolveContextBuilderClass(
provider, properties);
Class<RestContextBuilder<Object, Object>> clazz = resolveContextBuilderClass(provider, properties);
if (type.isAssignableFrom(clazz))
return provider;
} catch (ClassNotFoundException e) {
@ -365,9 +387,8 @@ public class Utils {
@SuppressWarnings("unchecked")
public static <S, A> Class<RestContextBuilder<S, A>> resolveContextBuilderClass(String provider,
Properties properties) throws ClassNotFoundException, IllegalArgumentException,
SecurityException, InstantiationException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
Properties properties) throws ClassNotFoundException, IllegalArgumentException, SecurityException,
InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
String contextBuilderClassName = properties.getProperty(provider + ".contextbuilder");
String syncClassName = properties.getProperty(provider + ".sync");
String asyncClassName = properties.getProperty(provider + ".async");
@ -376,37 +397,33 @@ public class Utils {
Class.forName(syncClassName);
Class.forName(asyncClassName);
return (Class<RestContextBuilder<S, A>>) (contextBuilderClassName != null ? Class
.forName(contextBuilderClassName) : RestContextBuilder.class);
.forName(contextBuilderClassName) : RestContextBuilder.class);
} else {
checkArgument(contextBuilderClassName != null,
"please configure contextbuilder class for " + provider);
checkArgument(contextBuilderClassName != null, "please configure contextbuilder class for " + provider);
return (Class<RestContextBuilder<S, A>>) Class.forName(contextBuilderClassName);
}
}
public static <S, A> RestContextBuilder<S, A> initContextBuilder(
Class<RestContextBuilder<S, A>> contextBuilderClass, @Nullable Class<S> sync,
@Nullable Class<A> async, Properties properties) throws ClassNotFoundException,
IllegalArgumentException, SecurityException, InstantiationException,
IllegalAccessException, InvocationTargetException, NoSuchMethodException {
Class<RestContextBuilder<S, A>> contextBuilderClass, @Nullable Class<S> sync, @Nullable Class<A> async,
Properties properties) throws ClassNotFoundException, IllegalArgumentException, SecurityException,
InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
checkArgument(properties != null, "please configure properties for " + contextBuilderClass);
try {
return (RestContextBuilder<S, A>) contextBuilderClass.getConstructor(Properties.class)
.newInstance(properties);
return (RestContextBuilder<S, A>) contextBuilderClass.getConstructor(Properties.class).newInstance(properties);
} catch (NoSuchMethodException e) {
checkArgument(sync != null, "please configure sync class for " + contextBuilderClass);
checkArgument(async != null, "please configure async class for " + contextBuilderClass);
return (RestContextBuilder<S, A>) contextBuilderClass.getConstructor(sync.getClass(),
async.getClass(), Properties.class).newInstance(sync, async, properties);
return (RestContextBuilder<S, A>) contextBuilderClass.getConstructor(sync.getClass(), async.getClass(),
Properties.class).newInstance(sync, async, properties);
}
}
@SuppressWarnings("unchecked")
public static Class<PropertiesBuilder> resolvePropertiesBuilderClass(String providerName,
Properties props) throws ClassNotFoundException, InstantiationException,
IllegalAccessException, InvocationTargetException, NoSuchMethodException {
String propertiesBuilderClassName = props.getProperty(providerName + ".propertiesbuilder",
null);
public static Class<PropertiesBuilder> resolvePropertiesBuilderClass(String providerName, Properties props)
throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
String propertiesBuilderClassName = props.getProperty(providerName + ".propertiesbuilder", null);
if (propertiesBuilderClassName != null) {
return (Class<PropertiesBuilder>) Class.forName(propertiesBuilderClassName);
} else {

View File

@ -25,13 +25,13 @@ import java.util.Map;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
@ -43,14 +43,14 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "jclouds.JsonBallTest")
public class JsonBallTest {
private ParseJson<Map<String, JsonBall>> handler;
private Gson mapper;
private Json mapper;
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule());
Injector injector = Guice.createInjector(new GsonModule());
handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<Map<String, JsonBall>>>() {
}));
mapper = injector.getInstance(Gson.class);
mapper = injector.getInstance(Json.class);
}

View File

@ -27,7 +27,7 @@ import static org.easymock.classextension.EasyMock.verify;
import java.net.URI;
import org.easymock.IArgumentMatcher;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.io.Payloads;
import com.google.inject.Guice;
@ -62,7 +62,7 @@ public abstract class BaseHttpErrorHandlerTest {
protected void assertCodeMakes(String method, URI uri, int statusCode, String message,
String content, Class<? extends Exception> expected) {
HttpErrorHandler function = Guice.createInjector(new ParserModule()).getInstance(
HttpErrorHandler function = Guice.createInjector(new SaxParserModule()).getInstance(
getHandlerClass());
HttpCommand command = createMock(HttpCommand.class);

View File

@ -18,7 +18,7 @@
*/
package org.jclouds.http.functions;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
@ -32,7 +32,7 @@ public class BaseHandlerTest {
@BeforeTest
protected void setUpInjector() {
injector = Guice.createInjector(new ParserModule());
injector = Guice.createInjector(new SaxParserModule());
factory = injector.getInstance(ParseSax.Factory.class);
assert factory != null;
}

View File

@ -28,7 +28,7 @@ import java.util.Date;
import javax.inject.Singleton;
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
import org.jclouds.json.config.GsonModule.DateAdapter;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonElement;

View File

@ -35,7 +35,7 @@ import org.jclouds.gogrid.domain.ObjectType;
import org.jclouds.gogrid.domain.ServerImageState;
import org.jclouds.gogrid.domain.ServerImageType;
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
import org.jclouds.json.config.GsonModule.DateAdapter;
import com.google.common.collect.Maps;
import com.google.inject.AbstractModule;
@ -48,7 +48,7 @@ import com.google.inject.Provides;
* @author Oleksiy Yarmula
*/
public class GoGridJsonAdapterModule extends AbstractModule {
public class GoGridParserModule extends AbstractModule {
@Provides
@Singleton
@ -58,8 +58,7 @@ public class GoGridJsonAdapterModule extends AbstractModule {
bindings.put(ObjectType.class, new CustomDeserializers.ObjectTypeAdapter());
bindings.put(LoadBalancerOs.class, new CustomDeserializers.LoadBalancerOsAdapter());
bindings.put(LoadBalancerState.class, new CustomDeserializers.LoadBalancerStateAdapter());
bindings.put(LoadBalancerPersistenceType.class,
new CustomDeserializers.LoadBalancerPersistenceTypeAdapter());
bindings.put(LoadBalancerPersistenceType.class, new CustomDeserializers.LoadBalancerPersistenceTypeAdapter());
bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter());
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter());

View File

@ -102,7 +102,7 @@ public class GoGridRestClientModule extends RestClientModule<GoGridClient, GoGri
@Override
protected void configure() {
install(new GoGridJsonAdapterModule());
install(new GoGridParserModule());
super.configure();
}

View File

@ -35,8 +35,8 @@ import org.jclouds.gogrid.domain.ServerImageState;
import org.jclouds.gogrid.domain.ServerImageType;
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.Maps;
@ -79,7 +79,7 @@ public class ParseCredentialsFromJsonResponseTest {
}
Injector i = Guice.createInjector(new ParserModule() {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(DateSecondsAdapter.class);

View File

@ -29,8 +29,8 @@ import java.net.UnknownHostException;
import org.jclouds.gogrid.config.DateSecondsAdapter;
import org.jclouds.gogrid.domain.internal.ErrorResponse;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
@ -42,7 +42,7 @@ import com.google.inject.Injector;
*/
public class ParseErrorFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule() {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(DateSecondsAdapter.class);
@ -52,16 +52,12 @@ public class ParseErrorFromJsonResponseTest {
@Test
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/test_error_handler.json");
InputStream is = getClass().getResourceAsStream("/test_error_handler.json");
ParseErrorFromJsonResponse parser = i
.getInstance(ParseErrorFromJsonResponse.class);
ErrorResponse response = Iterables.getOnlyElement(parser
.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is))));
assert "No object found that matches your input criteria."
.equals(response.getMessage());
ParseErrorFromJsonResponse parser = i.getInstance(ParseErrorFromJsonResponse.class);
ErrorResponse response = Iterables.getOnlyElement(parser.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is))));
assert "No object found that matches your input criteria.".equals(response.getMessage());
assert "IllegalArgumentException".equals(response.getErrorCode());
}
}

View File

@ -38,8 +38,8 @@ import org.jclouds.gogrid.domain.ObjectType;
import org.jclouds.gogrid.domain.Option;
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSortedSet;
@ -57,13 +57,10 @@ public class ParseJobsFromJsonResponseTest {
@Test
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass()
.getResourceAsStream("/test_get_job_list.json");
InputStream is = getClass().getResourceAsStream("/test_get_job_list.json");
ParseJobListFromJsonResponse parser = i
.getInstance(ParseJobListFromJsonResponse.class);
SortedSet<Job> response = parser.apply(new HttpResponse(200, "ok",
Payloads.newInputStreamPayload(is)));
ParseJobListFromJsonResponse parser = i.getInstance(ParseJobListFromJsonResponse.class);
SortedSet<Job> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
Map<String, String> details = Maps.newTreeMap();
details.put("description", null);
@ -72,18 +69,15 @@ public class ParseJobsFromJsonResponseTest {
details.put("name", "ServerCreated40562");
details.put("type", "virtual_server");
Job job = new Job(250628L, new Option(7L, "DeleteVirtualServer",
"Delete Virtual Server"), ObjectType.VIRTUAL_SERVER, new Date(
1267404528895L), new Date(1267404538592L), JobState.SUCCEEDED, 1,
"3116784158f0af2d-24076@api.gogrid.com", ImmutableSortedSet.of(
new JobProperties(940263L, new Date(1267404528897L),
JobState.CREATED, null), new JobProperties(940264L,
new Date(1267404528967L), JobState.QUEUED, null)),
details);
Job job = new Job(250628L, new Option(7L, "DeleteVirtualServer", "Delete Virtual Server"),
ObjectType.VIRTUAL_SERVER, new Date(1267404528895L), new Date(1267404538592L), JobState.SUCCEEDED, 1,
"3116784158f0af2d-24076@api.gogrid.com", ImmutableSortedSet.of(new JobProperties(940263L, new Date(
1267404528897L), JobState.CREATED, null), new JobProperties(940264L, new Date(1267404528967L),
JobState.QUEUED, null)), details);
assertEquals(job, Iterables.getOnlyElement(response));
}
Injector i = Guice.createInjector(new ParserModule() {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(DateSecondsAdapter.class);
@ -96,10 +90,8 @@ public class ParseJobsFromJsonResponseTest {
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
public Map<Type, Object> provideCustomAdapterBindings() {
Map<Type, Object> bindings = Maps.newHashMap();
bindings.put(ObjectType.class,
new CustomDeserializers.ObjectTypeAdapter());
bindings
.put(JobState.class, new CustomDeserializers.JobStateAdapter());
bindings.put(ObjectType.class, new CustomDeserializers.ObjectTypeAdapter());
bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter());
return bindings;
}
});

View File

@ -41,8 +41,8 @@ import org.jclouds.gogrid.domain.LoadBalancerType;
import org.jclouds.gogrid.domain.Option;
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSortedSet;
@ -60,33 +60,23 @@ public class ParseLoadBalancersFromJsonResponseTest {
@Test
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/test_get_load_balancer_list.json");
InputStream is = getClass().getResourceAsStream("/test_get_load_balancer_list.json");
ParseLoadBalancerListFromJsonResponse parser = i
.getInstance(ParseLoadBalancerListFromJsonResponse.class);
SortedSet<LoadBalancer> response = parser.apply(new HttpResponse(200,
"ok", Payloads.newInputStreamPayload(is)));
ParseLoadBalancerListFromJsonResponse parser = i.getInstance(ParseLoadBalancerListFromJsonResponse.class);
SortedSet<LoadBalancer> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
Option dc = new Option(1l, "US-West-1", "US West 1 Datacenter");
LoadBalancer loadBalancer = new LoadBalancer(6372L, "Balancer", null,
new IpPortPair(
new Ip(1313082L, "204.51.240.181",
"204.51.240.176/255.255.255.240", true,
IpState.ASSIGNED, dc), 80), ImmutableSortedSet.of(
new IpPortPair(new Ip(1313086L, "204.51.240.185",
"204.51.240.176/255.255.255.240", true,
IpState.ASSIGNED, dc), 80), new IpPortPair(new Ip(
1313089L, "204.51.240.188",
"204.51.240.176/255.255.255.240", true,
IpState.ASSIGNED, dc), 80)),
LoadBalancerType.ROUND_ROBIN, LoadBalancerPersistenceType.NONE,
LoadBalancerOs.F5, LoadBalancerState.ON, dc);
LoadBalancer loadBalancer = new LoadBalancer(6372L, "Balancer", null, new IpPortPair(new Ip(1313082L,
"204.51.240.181", "204.51.240.176/255.255.255.240", true, IpState.ASSIGNED, dc), 80), ImmutableSortedSet
.of(new IpPortPair(new Ip(1313086L, "204.51.240.185", "204.51.240.176/255.255.255.240", true,
IpState.ASSIGNED, dc), 80), new IpPortPair(new Ip(1313089L, "204.51.240.188",
"204.51.240.176/255.255.255.240", true, IpState.ASSIGNED, dc), 80)), LoadBalancerType.ROUND_ROBIN,
LoadBalancerPersistenceType.NONE, LoadBalancerOs.F5, LoadBalancerState.ON, dc);
assertEquals(Iterables.getOnlyElement(response), loadBalancer);
}
Injector i = Guice.createInjector(new ParserModule() {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(DateSecondsAdapter.class);
@ -99,14 +89,10 @@ public class ParseLoadBalancersFromJsonResponseTest {
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
public Map<Type, Object> provideCustomAdapterBindings() {
Map<Type, Object> bindings = Maps.newHashMap();
bindings.put(LoadBalancerOs.class,
new CustomDeserializers.LoadBalancerOsAdapter());
bindings.put(LoadBalancerState.class,
new CustomDeserializers.LoadBalancerStateAdapter());
bindings.put(LoadBalancerPersistenceType.class,
new CustomDeserializers.LoadBalancerPersistenceTypeAdapter());
bindings.put(LoadBalancerType.class,
new CustomDeserializers.LoadBalancerTypeAdapter());
bindings.put(LoadBalancerOs.class, new CustomDeserializers.LoadBalancerOsAdapter());
bindings.put(LoadBalancerState.class, new CustomDeserializers.LoadBalancerStateAdapter());
bindings.put(LoadBalancerPersistenceType.class, new CustomDeserializers.LoadBalancerPersistenceTypeAdapter());
bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter());
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
return bindings;
}

View File

@ -35,8 +35,8 @@ import org.jclouds.gogrid.domain.ServerImageState;
import org.jclouds.gogrid.domain.ServerImageType;
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.Maps;
@ -52,18 +52,16 @@ public class ParseServerNameToCredentialsMapFromJsonResponseTest {
@Test
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/test_credentials_list.json");
InputStream is = getClass().getResourceAsStream("/test_credentials_list.json");
ParseServerNameToCredentialsMapFromJsonResponse parser = i
.getInstance(ParseServerNameToCredentialsMapFromJsonResponse.class);
Map<String, Credentials> response = parser.apply(new HttpResponse(200,
"ok", Payloads.newInputStreamPayload(is)));
Map<String, Credentials> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response.size(), 6);
}
Injector i = Guice.createInjector(new ParserModule() {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(DateSecondsAdapter.class);
@ -77,12 +75,9 @@ public class ParseServerNameToCredentialsMapFromJsonResponseTest {
public Map<Type, Object> provideCustomAdapterBindings() {
Map<Type, Object> bindings = Maps.newHashMap();
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
bindings.put(ServerImageType.class,
new CustomDeserializers.ServerImageTypeAdapter());
bindings.put(ServerImageState.class,
new CustomDeserializers.ServerImageStateAdapter());
bindings.put(ServerImageState.class,
new CustomDeserializers.ServerImageStateAdapter());
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
return bindings;
}
});

View File

@ -34,7 +34,7 @@ import java.util.SortedSet;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.gogrid.config.GoGridJsonAdapterModule;
import org.jclouds.gogrid.config.GoGridParserModule;
import org.jclouds.gogrid.domain.BillingToken;
import org.jclouds.gogrid.domain.Customer;
import org.jclouds.gogrid.domain.Ip;
@ -46,8 +46,8 @@ import org.jclouds.gogrid.domain.ServerImageState;
import org.jclouds.gogrid.domain.ServerImageType;
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSortedSet;
@ -67,43 +67,31 @@ public class ParseServersFromJsonResponseTest {
@Test
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/test_get_server_list.json");
InputStream is = getClass().getResourceAsStream("/test_get_server_list.json");
ParseServerListFromJsonResponse parser = i
.getInstance(ParseServerListFromJsonResponse.class);
SortedSet<Server> response = parser.apply(new HttpResponse(200, "ok",
Payloads.newInputStreamPayload(is)));
ParseServerListFromJsonResponse parser = i.getInstance(ParseServerListFromJsonResponse.class);
SortedSet<Server> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
Option dc = new Option(1l, "US-West-1", "US West 1 Datacenter");
Option centOs = new Option(13L, "CentOS 5.2 (32-bit)",
"CentOS 5.2 (32-bit)");
Option webServer = new Option(1L, "Web Server",
"Web or Application Server");
Server server = new Server(75245L, dc, false, "PowerServer",
"server to test the api. created by Alex", new Option(1L, "On",
"Server is in active state."), webServer, new Option(1L,
"512MB", "Server with 512MB RAM"), centOs, new Ip(1313079L,
"204.51.240.178", "204.51.240.176/255.255.255.240", true,
IpState.ASSIGNED, dc), new ServerImage(1946L,
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
"BitNami Gallery 2.3.1-0",
"http://bitnami.org/stack/gallery", centOs, null,
ServerImageType.WEB_APPLICATION_SERVER,
ServerImageState.AVAILABLE, 0.0,
"24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", true,
true, new Date(1261504577971L), new Date(1262649582180L),
ImmutableSortedSet.of(new BillingToken(38L,
"CentOS 5.2 32bit", 0.0), new BillingToken(56L,
"BitNami: Gallery", 0.0)), new Customer(24732L,
Option centOs = new Option(13L, "CentOS 5.2 (32-bit)", "CentOS 5.2 (32-bit)");
Option webServer = new Option(1L, "Web Server", "Web or Application Server");
Server server = new Server(75245L, dc, false, "PowerServer", "server to test the api. created by Alex",
new Option(1L, "On", "Server is in active state."), webServer, new Option(1L, "512MB",
"Server with 512MB RAM"), centOs, new Ip(1313079L, "204.51.240.178",
"204.51.240.176/255.255.255.240", true, IpState.ASSIGNED, dc), new ServerImage(1946L,
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c", "BitNami Gallery 2.3.1-0",
"http://bitnami.org/stack/gallery", centOs, null, ServerImageType.WEB_APPLICATION_SERVER,
ServerImageState.AVAILABLE, 0.0, "24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", true, true,
new Date(1261504577971L), new Date(1262649582180L), ImmutableSortedSet.of(new BillingToken(38L,
"CentOS 5.2 32bit", 0.0), new BillingToken(56L, "BitNami: Gallery", 0.0)), new Customer(24732L,
"BitRock")));
assertEquals(Iterables.getOnlyElement(response), server);
}
Injector i = Guice.createInjector(new ParserModule() {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
install(new GoGridJsonAdapterModule());
install(new GoGridParserModule());
super.configure();
}
@ -114,10 +102,8 @@ public class ParseServersFromJsonResponseTest {
public Map<Class, Object> provideCustomAdapterBindings() {
Map<Class, Object> bindings = Maps.newHashMap();
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
bindings.put(ServerImageType.class,
new CustomDeserializers.ServerImageTypeAdapter());
bindings.put(ServerImageState.class,
new CustomDeserializers.ServerImageStateAdapter());
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
return bindings;
}
});

View File

@ -33,7 +33,7 @@ import java.io.InputStream;
import org.jclouds.gogrid.mock.HttpCommandMock;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.io.Payloads;
import org.testng.TestException;
import org.testng.annotations.Test;
@ -52,7 +52,7 @@ public class GoGridErrorHandlerTest {
InputStream is = getClass().getResourceAsStream("/test_error_handler.json");
GoGridErrorHandler handler = Guice.createInjector(new ParserModule()).getInstance(GoGridErrorHandler.class);
GoGridErrorHandler handler = Guice.createInjector(new SaxParserModule()).getInstance(GoGridErrorHandler.class);
HttpCommand command = createHttpCommand();
handler.handleError(command, new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));

View File

@ -27,8 +27,8 @@ import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
import org.jclouds.http.functions.config.ParserModule.LongDateAdapter;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.LongDateAdapter;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonDeserializationContext;
@ -48,7 +48,7 @@ public class IBMDeveloperCloudParserModule extends AbstractModule {
public static class CurlyBraceCapableURIAdapter implements JsonDeserializer<URI> {
@Override
public URI deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
throws JsonParseException {
throws JsonParseException {
String toParse = jsonElement.getAsJsonPrimitive().getAsString();
URI toReturn = HttpUtils.createUri(toParse);
return toReturn;

View File

@ -24,7 +24,7 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule;
import org.jclouds.ibmdev.domain.Address;
import org.jclouds.io.Payloads;
import org.testng.annotations.BeforeTest;
@ -45,21 +45,14 @@ public class ParseAddressFromJsonTest {
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
Injector injector = Guice.createInjector(new IBMDeveloperCloudParserModule());
handler = injector.getInstance(ParseAddressFromJson.class);
}
public void test() {
Address address = new Address(2, "1", "129.33.196.243", "1217", "1");
Address compare = handler.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(ParseAddressFromJsonTest.class
.getResourceAsStream("/address.json"))));
.newInputStreamPayload(ParseAddressFromJsonTest.class.getResourceAsStream("/address.json"))));
assertEquals(compare, address);
}
}

View File

@ -23,7 +23,7 @@ import java.io.IOException;
import java.util.Set;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule;
import org.jclouds.ibmdev.domain.Address;
import org.jclouds.io.Payloads;
import org.testng.annotations.BeforeTest;
@ -44,13 +44,7 @@ public class ParseAddressesFromJsonTest {
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
Injector injector = Guice.createInjector(new IBMDeveloperCloudParserModule());
handler = injector.getInstance(ParseAddressesFromJson.class);
}
@ -58,8 +52,7 @@ public class ParseAddressesFromJsonTest {
Address address1 = new Address(2, "1", "129.33.196.243", "1217", "1");
Address address2 = new Address(3, "2", "129.33.196.244", "1218", null);
Set<? extends Address> compare = handler.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(ParseAddressesFromJsonTest.class
.getResourceAsStream("/addresses.json"))));
.newInputStreamPayload(ParseAddressesFromJsonTest.class.getResourceAsStream("/addresses.json"))));
assert (compare.contains(address1));
assert (compare.contains(address2));
}

View File

@ -25,8 +25,9 @@ import java.io.IOException;
import java.util.Date;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -45,13 +46,7 @@ public class ParseExpirationTimeFromJsonTest {
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
Injector injector = Guice.createInjector(new IBMDeveloperCloudParserModule(), new GsonModule());
handler = injector.getInstance(ParseExpirationTimeFromJson.class);
}

View File

@ -26,13 +26,13 @@ import java.util.Date;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule;
import org.jclouds.ibmdev.domain.Image;
import org.jclouds.ibmdev.domain.InstanceType;
import org.jclouds.ibmdev.domain.Price;
import org.jclouds.ibmdev.domain.Image.Visibility;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -52,7 +52,7 @@ public class ParseImageFromJsonTest {
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule(), new IBMDeveloperCloudParserModule());
Injector injector = Guice.createInjector(new IBMDeveloperCloudParserModule(), new GsonModule());
handler = injector.getInstance(ParseImageFromJson.class);
}

View File

@ -25,13 +25,13 @@ import java.util.Set;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule;
import org.jclouds.ibmdev.domain.Image;
import org.jclouds.ibmdev.domain.InstanceType;
import org.jclouds.ibmdev.domain.Price;
import org.jclouds.ibmdev.domain.Image.Visibility;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -51,7 +51,7 @@ public class ParseImagesFromJsonTest {
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule(), new IBMDeveloperCloudParserModule());
Injector injector = Guice.createInjector(new IBMDeveloperCloudParserModule(), new GsonModule());
handler = injector.getInstance(ParseImagesFromJson.class);
}

View File

@ -25,10 +25,11 @@ import java.io.IOException;
import java.util.Date;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule;
import org.jclouds.ibmdev.domain.Instance;
import org.jclouds.ibmdev.domain.Instance.Software;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -48,27 +49,18 @@ public class ParseInstanceFromJsonTest {
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
Injector injector = Guice.createInjector(new IBMDeveloperCloudParserModule(), new GsonModule());
handler = injector.getInstance(ParseInstanceFromJson.class);
}
public void test() {
Instance instance = new Instance(new Date(1260472231726l),
ImmutableSet.<Software> of(new Software("SUSE Linux Enterprise",
"OS", "10 SP2")), "129.33.197.78", "7430", "DEFAULT", "ABC",
"MEDIUM", 5, "aadelucc@us.ibm.com", "vm723.developer.ihost.com",
"1", "3", ImmutableSet.<String> of(), "ABC", "7430", new Date(
1263064240837l));
Instance instance = new Instance(new Date(1260472231726l), ImmutableSet.<Software> of(new Software(
"SUSE Linux Enterprise", "OS", "10 SP2")), "129.33.197.78", "7430", "DEFAULT", "ABC", "MEDIUM", 5,
"aadelucc@us.ibm.com", "vm723.developer.ihost.com", "1", "3", ImmutableSet.<String> of(), "ABC", "7430",
new Date(1263064240837l));
Instance compare = handler.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(ParseInstanceFromJsonTest.class
.getResourceAsStream("/instance.json"))));
.newInputStreamPayload(ParseInstanceFromJsonTest.class.getResourceAsStream("/instance.json"))));
assertEquals(compare, instance);
}
}

View File

@ -26,10 +26,11 @@ import java.util.Date;
import java.util.Set;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule;
import org.jclouds.ibmdev.domain.Instance;
import org.jclouds.ibmdev.domain.Instance.Software;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -50,13 +51,7 @@ public class ParseInstancesFromJsonTest {
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
Injector injector = Guice.createInjector(new IBMDeveloperCloudParserModule(), new GsonModule());
handler = injector.getInstance(ParseInstancesFromJson.class);
}

View File

@ -26,9 +26,10 @@ import java.util.Date;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule;
import org.jclouds.ibmdev.domain.Key;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -49,26 +50,17 @@ public class ParseKeyFromJsonTest {
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
handler = injector.getInstance(com.google.inject.Key
.get(new TypeLiteral<ParseJson<Key>>() {
}));
Injector injector = Guice.createInjector(new IBMDeveloperCloudParserModule(), new GsonModule());
handler = injector.getInstance(com.google.inject.Key.get(new TypeLiteral<ParseJson<Key>>() {
}));
}
public void test() {
Key key = new Key(true, ImmutableSet.<String> of("1"),
"AAAB3NzaC1yc2EAAAADAQABAAABAQCqBw7a+...", "DEFAULT", new Date(
1260428507510l));
Key key = new Key(true, ImmutableSet.<String> of("1"), "AAAB3NzaC1yc2EAAAADAQABAAABAQCqBw7a+...", "DEFAULT",
new Date(1260428507510l));
Key compare = handler.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(ParseKeyFromJsonTest.class
.getResourceAsStream("/key.json"))));
Key compare = handler.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(ParseKeyFromJsonTest.class
.getResourceAsStream("/key.json"))));
assertEquals(compare, key);
}
}

View File

@ -24,9 +24,10 @@ import java.util.Date;
import java.util.Set;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule;
import org.jclouds.ibmdev.domain.Key;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -46,27 +47,18 @@ public class ParseKeysFromJsonTest {
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
Injector injector = Guice.createInjector(new IBMDeveloperCloudParserModule(), new GsonModule());
handler = injector.getInstance(ParseKeysFromJson.class);
}
public void test() {
Key key1 = new Key(true, ImmutableSet.<String> of("1"),
"AAAB3NzaC1yc2EAAAADAQABAAABAQCqBw7a+...", "DEFAULT", new Date(
1260428507510l));
Key key2 = new Key(false, ImmutableSet.<String> of(),
"AAAB3NzaC1yc2EAAAADAQABAAABAQCqBw7a+", "BEAR", new Date(
1260428507511l));
Key key1 = new Key(true, ImmutableSet.<String> of("1"), "AAAB3NzaC1yc2EAAAADAQABAAABAQCqBw7a+...", "DEFAULT",
new Date(1260428507510l));
Key key2 = new Key(false, ImmutableSet.<String> of(), "AAAB3NzaC1yc2EAAAADAQABAAABAQCqBw7a+", "BEAR", new Date(
1260428507511l));
Set<? extends Key> compare = handler.apply(new HttpResponse(200, "ok",
Payloads.newInputStreamPayload(ParseKeysFromJsonTest.class
.getResourceAsStream("/keys.json"))));
Set<? extends Key> compare = handler.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(ParseKeysFromJsonTest.class.getResourceAsStream("/keys.json"))));
assert (compare.contains(key1));
assert (compare.contains(key2));
}

View File

@ -27,11 +27,12 @@ import java.util.Set;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule;
import org.jclouds.ibmdev.domain.Price;
import org.jclouds.ibmdev.domain.StorageOffering;
import org.jclouds.ibmdev.domain.StorageOffering.Format;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -49,17 +50,10 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", sequential = true, testName = "ibmdev.ParseStorageOfferingsFromJsonTest")
public class ParseStorageOfferingsFromJsonTest {
private UnwrapOnlyJsonValue<Set<StorageOffering>> handler;
private Injector injector;
@BeforeTest
protected void setUpInjector() throws IOException {
injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
Injector injector = Guice.createInjector(new IBMDeveloperCloudParserModule(), new GsonModule());
handler = injector.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Set<StorageOffering>>>() {
}));
}

View File

@ -25,9 +25,10 @@ import java.io.IOException;
import java.util.Date;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule;
import org.jclouds.ibmdev.domain.Volume;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -47,25 +48,17 @@ public class ParseVolumeFromJsonTest {
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
Injector injector = Guice.createInjector(new IBMDeveloperCloudParserModule(), new GsonModule());
handler = injector.getInstance(ParseVolumeFromJson.class);
}
public void test() {
Volume volume = new Volume("2", 5, 50, "aadelucc@us.ibm.com", new Date(
1260469075119l), "1", ImmutableSet.<String> of(), "ext3",
"New Storage", "67");
Volume volume = new Volume("2", 5, 50, "aadelucc@us.ibm.com", new Date(1260469075119l), "1", ImmutableSet
.<String> of(), "ext3", "New Storage", "67");
Volume compare = handler.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(ParseVolumeFromJsonTest.class
.getResourceAsStream("/volume.json"))));
.newInputStreamPayload(ParseVolumeFromJsonTest.class.getResourceAsStream("/volume.json"))));
assertEquals(compare, volume);
}
}

View File

@ -24,9 +24,10 @@ import java.util.Date;
import java.util.Set;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.config.IBMDeveloperCloudParserModule;
import org.jclouds.ibmdev.domain.Volume;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -46,28 +47,19 @@ public class ParseVolumesFromJsonTest {
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
Injector injector = Guice.createInjector(new IBMDeveloperCloudParserModule(), new GsonModule());
handler = injector.getInstance(ParseVolumesFromJson.class);
}
public void test() {
Volume volume1 = new Volume("2", 5, 50, "aadelucc@us.ibm.com", new Date(
1260469075119l), "1", ImmutableSet.<String> of(), "ext3",
"New Storage", "67");
Volume volume1 = new Volume("2", 5, 50, "aadelucc@us.ibm.com", new Date(1260469075119l), "1", ImmutableSet
.<String> of(), "ext3", "New Storage", "67");
Volume volume2 = new Volume(null, 6, 51, "aadelucc@us.ibm.com", new Date(
1260469075120l), "2", ImmutableSet.<String> of("abrad"), "ext3",
"New Storage1", "68");
Volume volume2 = new Volume(null, 6, 51, "aadelucc@us.ibm.com", new Date(1260469075120l), "2", ImmutableSet
.<String> of("abrad"), "ext3", "New Storage1", "68");
Set<? extends Volume> compare = handler.apply(new HttpResponse(200, "ok",
Payloads.newInputStreamPayload(ParseVolumesFromJsonTest.class
.getResourceAsStream("/volumes.json"))));
Set<? extends Volume> compare = handler.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(ParseVolumesFromJsonTest.class.getResourceAsStream("/volumes.json"))));
assert (compare.contains(volume1));
assert (compare.contains(volume2));
}

View File

@ -32,7 +32,7 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
/**
* Tests behavior of {@code ParseFlavorListFromGsonResponseTest}
* Tests behavior of {@code ParseFlavorListFromJsonResponseTest}
*
* @author Adrian Cole
*/

View File

@ -25,7 +25,7 @@ import java.net.UnknownHostException;
import java.util.Map;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test;
@ -41,7 +41,7 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "sdn.ParseMetadataFromJsonResponseTest")
public class ParseMetadataFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
Injector i = Guice.createInjector(new SaxParserModule());
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/metadata.json");

View File

@ -24,7 +24,7 @@ import java.io.InputStream;
import java.net.UnknownHostException;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test;
@ -39,7 +39,7 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "sdn.ParseSessionTokenFromJsonResponseTest")
public class ParseSessionTokenFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
Injector i = Guice.createInjector(new SaxParserModule());
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/login.json");

View File

@ -25,7 +25,7 @@ import java.net.URI;
import java.net.UnknownHostException;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.nirvanix.sdn.domain.UploadInfo;
import org.testng.annotations.Test;
@ -41,7 +41,7 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "sdn.ParseUploadInfoFromJsonResponse")
public class ParseUploadInfoFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
Injector i = Guice.createInjector(new SaxParserModule());
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/authtoken.json");

View File

@ -32,8 +32,6 @@ import org.jclouds.concurrent.ExpirableSupplier;
import org.jclouds.concurrent.RetryOnTimeOutExceptionSupplier;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter;
import org.jclouds.rackspace.Authentication;
import org.jclouds.rackspace.CloudFiles;
import org.jclouds.rackspace.CloudFilesCDN;
@ -49,7 +47,8 @@ import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
* Configures the Rackspace authentication service connection, including logging and http transport.
* Configures the Rackspace authentication service connection, including logging
* and http transport.
*
* @author Adrian Cole
*/
@ -58,7 +57,7 @@ public class RackspaceAuthenticationRestModule extends AbstractModule {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
install(new RackspaceParserModule());
}
/**
@ -67,9 +66,8 @@ public class RackspaceAuthenticationRestModule extends AbstractModule {
@Provides
@Singleton
@Authentication
protected Supplier<String> provideAuthenticationTokenCache(
final Supplier<AuthenticationResponse> supplier) throws InterruptedException,
ExecutionException, TimeoutException {
protected Supplier<String> provideAuthenticationTokenCache(final Supplier<AuthenticationResponse> supplier)
throws InterruptedException, ExecutionException, TimeoutException {
return new Supplier<String>() {
public String get() {
return supplier.get().getAuthToken();
@ -79,26 +77,22 @@ public class RackspaceAuthenticationRestModule extends AbstractModule {
@Provides
@Singleton
Supplier<AuthenticationResponse> provideAuthenticationResponseCache(
final AsyncClientFactory factory,
@Named(Constants.PROPERTY_IDENTITY) final String user,
@Named(Constants.PROPERTY_CREDENTIAL) final String key) {
return new ExpirableSupplier<AuthenticationResponse>(
new RetryOnTimeOutExceptionSupplier<AuthenticationResponse>(
new Supplier<AuthenticationResponse>() {
public AuthenticationResponse get() {
try {
ListenableFuture<AuthenticationResponse> response = factory
.create(RackspaceAuthAsyncClient.class).authenticate(
user, key);
return response.get(30, TimeUnit.SECONDS);
} catch (Exception e) {
Throwables.propagate(e);
assert false : e;
return null;
}
}
}), 23, TimeUnit.HOURS);
Supplier<AuthenticationResponse> provideAuthenticationResponseCache(final AsyncClientFactory factory,
@Named(Constants.PROPERTY_IDENTITY) final String user, @Named(Constants.PROPERTY_CREDENTIAL) final String key) {
return new ExpirableSupplier<AuthenticationResponse>(new RetryOnTimeOutExceptionSupplier<AuthenticationResponse>(
new Supplier<AuthenticationResponse>() {
public AuthenticationResponse get() {
try {
ListenableFuture<AuthenticationResponse> response = factory.create(RackspaceAuthAsyncClient.class)
.authenticate(user, key);
return response.get(30, TimeUnit.SECONDS);
} catch (Exception e) {
Throwables.propagate(e);
assert false : e;
return null;
}
}
}), 23, TimeUnit.HOURS);
}
@Provides
@ -114,9 +108,8 @@ public class RackspaceAuthenticationRestModule extends AbstractModule {
@Provides
@Singleton
protected AuthenticationResponse provideAuthenticationResponse(
Supplier<AuthenticationResponse> supplier) throws InterruptedException,
ExecutionException, TimeoutException {
protected AuthenticationResponse provideAuthenticationResponse(Supplier<AuthenticationResponse> supplier)
throws InterruptedException, ExecutionException, TimeoutException {
return supplier.get();
}

View File

@ -0,0 +1,37 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.rackspace.config;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import com.google.inject.AbstractModule;
/**
*
* @author Adrian Cole
*/
public class RackspaceParserModule extends AbstractModule {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
}
}

View File

@ -28,10 +28,11 @@ import java.util.Set;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.cloudfiles.domain.ObjectInfo;
import org.jclouds.rackspace.cloudfiles.functions.ParseObjectInfoListFromJsonResponse;
import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions;
import org.jclouds.rackspace.config.RackspaceParserModule;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.testng.annotations.Test;
@ -47,47 +48,31 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "cloudfiles.ParseObjectInfoListFromJsonResponseTest")
public class ParseObjectInfoListFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
Injector i = Guice.createInjector(new RackspaceParserModule(), new GsonModule());
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream(
"/cloudfiles/test_list_container.json");
InputStream is = getClass().getResourceAsStream("/cloudfiles/test_list_container.json");
Set<ObjectInfo> expects = Sets.newHashSet();
ObjectInfoImpl one = i.getInstance(ObjectInfoImpl.class);
one.name = "test_obj_1";
one.hash = i.getInstance(EncryptionService.class).fromHex(
"4281c348eaf83e70ddce0e07221c3d28");
one.hash = i.getInstance(EncryptionService.class).fromHex("4281c348eaf83e70ddce0e07221c3d28");
one.bytes = 14l;
one.content_type = "application/octet-stream";
one.last_modified = new SimpleDateFormatDateService()
.iso8601DateParse("2009-02-03T05:26:32.612Z");
one.last_modified = new SimpleDateFormatDateService().iso8601DateParse("2009-02-03T05:26:32.612Z");
expects.add(one);
ObjectInfoImpl two = i.getInstance(ObjectInfoImpl.class);
two.name = ("test_obj_2");
two.hash = (i.getInstance(EncryptionService.class)
.fromHex("b039efe731ad111bc1b0ef221c3849d0"));
two.hash = (i.getInstance(EncryptionService.class).fromHex("b039efe731ad111bc1b0ef221c3849d0"));
two.bytes = (64l);
two.content_type = ("application/octet-stream");
two.last_modified = (new SimpleDateFormatDateService()
.iso8601DateParse("2009-02-03T05:26:32.612Z"));
two.last_modified = (new SimpleDateFormatDateService().iso8601DateParse("2009-02-03T05:26:32.612Z"));
expects.add(two);
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
ListContainerOptions options = new ListContainerOptions();
expect(request.getArgs())
.andReturn(
new Object[] { "containter",
new ListContainerOptions[] { options } }).atLeastOnce();
expect(request.getArgs()).andReturn(new Object[] { "containter", new ListContainerOptions[] { options } })
.atLeastOnce();
replay(request);
ParseObjectInfoListFromJsonResponse parser = i
.getInstance(ParseObjectInfoListFromJsonResponse.class);
ParseObjectInfoListFromJsonResponse parser = i.getInstance(ParseObjectInfoListFromJsonResponse.class);
parser.setContext(request);
assertEquals(parser.apply(is), expects);
}

View File

@ -27,9 +27,10 @@ import java.util.SortedSet;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata;
import org.jclouds.rackspace.config.RackspaceParserModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSortedSet;
@ -45,39 +46,22 @@ import com.google.inject.TypeLiteral;
*/
@Test(groups = "unit", testName = "cloudfiles.ParseContainerCDNMetadataListFromJsonResponseTest")
public class ParseContainerCDNMetadataListFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
Injector i = Guice.createInjector(new RackspaceParserModule(), new GsonModule());
@Test
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream(
"/cloudfiles/test_list_cdn.json");
Set<ContainerCDNMetadata> expects = ImmutableSortedSet
.of(
InputStream is = getClass().getResourceAsStream("/cloudfiles/test_list_cdn.json");
Set<ContainerCDNMetadata> expects = ImmutableSortedSet.of(
new ContainerCDNMetadata(
"adriancole-blobstore.testCDNOperationsContainerWithCDN",
false,
3600,
URI
.create("http://c0354712.cdn.cloudfiles.rackspacecloud.com")),
new ContainerCDNMetadata(
"adriancole-blobstore5",
true,
28800,
URI
.create("http://c0404671.cdn.cloudfiles.rackspacecloud.com")),
new ContainerCDNMetadata(
"adriancole-cfcdnint.testCDNOperationsContainerWithCDN",
false,
3600,
URI
.create("http://c0320431.cdn.cloudfiles.rackspacecloud.com")));
ParseJson<SortedSet<ContainerCDNMetadata>> parser = i
.getInstance(Key
.get(new TypeLiteral<ParseJson<SortedSet<ContainerCDNMetadata>>>() {
}));
assertEquals(parser.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is))), expects);
new ContainerCDNMetadata("adriancole-blobstore.testCDNOperationsContainerWithCDN", false, 3600, URI
.create("http://c0354712.cdn.cloudfiles.rackspacecloud.com")), new ContainerCDNMetadata(
"adriancole-blobstore5", true, 28800, URI.create("http://c0404671.cdn.cloudfiles.rackspacecloud.com")),
new ContainerCDNMetadata("adriancole-cfcdnint.testCDNOperationsContainerWithCDN", false, 3600, URI
.create("http://c0320431.cdn.cloudfiles.rackspacecloud.com")));
ParseJson<SortedSet<ContainerCDNMetadata>> parser = i.getInstance(Key
.get(new TypeLiteral<ParseJson<SortedSet<ContainerCDNMetadata>>>() {
}));
assertEquals(parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is))), expects);
}
}

View File

@ -25,9 +25,10 @@ import java.util.List;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
import org.jclouds.rackspace.config.RackspaceParserModule;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
@ -44,20 +45,18 @@ import com.google.inject.TypeLiteral;
*/
@Test(groups = "unit", testName = "cloudfiles.ParseContainerListFromJsonResponse")
public class ParseContainerListFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
Injector i = Guice.createInjector(new RackspaceParserModule(), new GsonModule());
@Test
public void testApplyInputStream() {
InputStream is = Utils
.toInputStream("[ {\"name\":\"test_container_1\",\"count\":2,\"bytes\":78}, {\"name\":\"test_container_2\",\"count\":1,\"bytes\":17} ] ");
List<ContainerMetadata> expects = ImmutableList.of(new ContainerMetadata(
"test_container_1", 2, 78), new ContainerMetadata(
"test_container_2", 1, 17));
List<ContainerMetadata> expects = ImmutableList.of(new ContainerMetadata("test_container_1", 2, 78),
new ContainerMetadata("test_container_2", 1, 17));
ParseJson<List<ContainerMetadata>> parser = i.getInstance(Key
.get(new TypeLiteral<ParseJson<List<ContainerMetadata>>>() {
}));
assertEquals(parser.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is))), expects);
assertEquals(parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is))), expects);
}
}

View File

@ -28,7 +28,6 @@ import java.net.URI;
import org.jclouds.Constants;
import org.jclouds.blobstore.reference.BlobStoreConstants;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.rackspace.cloudfiles.domain.MutableObjectInfoWithMetadata;
import org.jclouds.rest.internal.GeneratedHttpRequest;
@ -46,13 +45,12 @@ import com.google.inject.name.Names;
*/
@Test(groups = "unit", testName = "cloudfiles.ParseObjectInfoFromHeadersTest")
public class ParseObjectInfoFromHeadersTest {
Injector i = Guice.createInjector(new ParserModule(), new AbstractModule() {
Injector i = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bindConstant()
.annotatedWith(Names.named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX)).to(
"sdf");
bindConstant().annotatedWith(Names.named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX)).to("sdf");
bindConstant().annotatedWith(Names.named(Constants.PROPERTY_API_VERSION)).to("1");
}

View File

@ -26,7 +26,7 @@ import java.net.URI;
import javax.ws.rs.HttpMethod;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
@ -41,7 +41,7 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "cloudservers.BindAdminPassToJsonPayloadTest")
public class BindAdminPassToJsonPayloadTest {
Injector injector = Guice.createInjector(new ParserModule());
Injector injector = Guice.createInjector(new GsonModule());
@Test(expectedExceptions = IllegalStateException.class)
public void testPostIsIncorrect() {

View File

@ -26,7 +26,7 @@ import java.net.URI;
import javax.ws.rs.HttpMethod;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
@ -41,7 +41,7 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "cloudservers.BindCreateImageToJsonPayloadTest")
public class BindCreateImageToJsonPayloadTest {
Injector injector = Guice.createInjector(new ParserModule());
Injector injector = Guice.createInjector(new GsonModule());
@Test(expectedExceptions = IllegalArgumentException.class)
public void testMustBeMap() {

View File

@ -26,7 +26,7 @@ import java.net.URI;
import javax.ws.rs.HttpMethod;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.cloudservers.domain.RebootType;
import org.testng.annotations.Test;
@ -42,7 +42,7 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "cloudservers.BindRebootTypeToJsonPayloadTest")
public class BindRebootTypeToJsonPayloadTest {
Injector injector = Guice.createInjector(new ParserModule());
Injector injector = Guice.createInjector(new GsonModule());
@Test(expectedExceptions = IllegalStateException.class)
public void testPostIsIncorrect() {

View File

@ -26,7 +26,7 @@ import java.net.URI;
import javax.ws.rs.HttpMethod;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
@ -41,7 +41,7 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "cloudservers.BindServerNameToJsonPayloadTest")
public class BindServerNameToJsonPayloadTest {
Injector injector = Guice.createInjector(new ParserModule());
Injector injector = Guice.createInjector(new GsonModule());
@Test(expectedExceptions = IllegalStateException.class)
public void testPostIsIncorrect() {

View File

@ -26,9 +26,10 @@ import java.util.List;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.cloudservers.domain.Addresses;
import org.jclouds.rackspace.config.RackspaceParserModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
@ -44,20 +45,15 @@ import com.google.inject.internal.ImmutableList;
*/
@Test(groups = "unit", testName = "cloudservers.ParseAddressesFromJsonResponseTest")
public class ParseAddressesFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
Injector i = Guice.createInjector(new RackspaceParserModule(), new GsonModule());
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/cloudservers/test_list_addresses.json");
InputStream is = getClass().getResourceAsStream("/cloudservers/test_list_addresses.json");
UnwrapOnlyJsonValue<Addresses> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<Addresses>>() {
}));
Addresses response = parser.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is)));
List<String> publicAddresses = ImmutableList.of("67.23.10.132",
"67.23.10.131");
UnwrapOnlyJsonValue<Addresses> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Addresses>>() {
}));
Addresses response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
List<String> publicAddresses = ImmutableList.of("67.23.10.132", "67.23.10.131");
List<String> privateAddresses = ImmutableList.of("10.176.42.16");

View File

@ -25,11 +25,12 @@ import java.net.UnknownHostException;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.cloudservers.domain.BackupSchedule;
import org.jclouds.rackspace.cloudservers.domain.DailyBackup;
import org.jclouds.rackspace.cloudservers.domain.WeeklyBackup;
import org.jclouds.rackspace.config.RackspaceParserModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
@ -44,20 +45,16 @@ import com.google.inject.TypeLiteral;
*/
@Test(groups = "unit", testName = "cloudservers.ParseBackupScheduleFromJsonResponseTest")
public class ParseBackupScheduleFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
Injector i = Guice.createInjector(new RackspaceParserModule(), new GsonModule());
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/cloudservers/test_list_backupschedule.json");
InputStream is = getClass().getResourceAsStream("/cloudservers/test_list_backupschedule.json");
UnwrapOnlyJsonValue<BackupSchedule> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<BackupSchedule>>() {
}));
BackupSchedule response = parser.apply(new HttpResponse(200, "ok",
Payloads.newInputStreamPayload(is)));
assertEquals(new BackupSchedule(WeeklyBackup.THURSDAY,
DailyBackup.H_0400_0600, true), response);
BackupSchedule response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(new BackupSchedule(WeeklyBackup.THURSDAY, DailyBackup.H_0400_0600, true), response);
}
public void testNoSchedule() throws UnknownHostException {
@ -65,12 +62,8 @@ public class ParseBackupScheduleFromJsonResponseTest {
UnwrapOnlyJsonValue<BackupSchedule> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<BackupSchedule>>() {
}));
BackupSchedule response = parser
.apply(new HttpResponse(
200,
"ok",
Payloads
.newStringPayload("{\"backupSchedule\":{\"enabled\" : false}}")));
BackupSchedule response = parser.apply(new HttpResponse(200, "ok", Payloads
.newStringPayload("{\"backupSchedule\":{\"enabled\" : false}}")));
assertEquals(new BackupSchedule(), response);
}
}

View File

@ -25,9 +25,10 @@ import java.net.UnknownHostException;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.cloudservers.domain.Flavor;
import org.jclouds.rackspace.config.RackspaceParserModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
@ -42,17 +43,14 @@ import com.google.inject.TypeLiteral;
*/
@Test(groups = "unit", testName = "cloudservers.ParseFlavorFromJsonResponseTest")
public class ParseFlavorFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
Injector i = Guice.createInjector(new RackspaceParserModule(), new GsonModule());
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/cloudservers/test_get_flavor_details.json");
UnwrapOnlyJsonValue<Flavor> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<Flavor>>() {
}));
Flavor response = parser.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is)));
UnwrapOnlyJsonValue<Flavor> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Flavor>>() {
}));
Flavor response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response.getId(), 1);
assertEquals(response.getName(), "256 MB Server");
assertEquals(response.getRam(), new Integer(256));

View File

@ -26,9 +26,10 @@ import java.util.List;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.cloudservers.domain.Flavor;
import org.jclouds.rackspace.config.RackspaceParserModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
@ -45,32 +46,27 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "cloudFlavors.ParseFlavorListFromJsonResponseTest")
public class ParseFlavorListFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
Injector i = Guice.createInjector(new RackspaceParserModule(), new GsonModule());
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream(
"/cloudservers/test_list_flavors.json");
InputStream is = getClass().getResourceAsStream("/cloudservers/test_list_flavors.json");
List<Flavor> expects = ImmutableList.of(new Flavor(1, "256 MB Server"),
new Flavor(2, "512 MB Server"));
List<Flavor> expects = ImmutableList.of(new Flavor(1, "256 MB Server"), new Flavor(2, "512 MB Server"));
UnwrapOnlyJsonValue<List<Flavor>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Flavor>>>() {
}));
List<Flavor> response = parser.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is)));
List<Flavor> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response, expects);
}
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/cloudservers/test_list_flavors_detail.json");
InputStream is = getClass().getResourceAsStream("/cloudservers/test_list_flavors_detail.json");
UnwrapOnlyJsonValue<List<Flavor>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Flavor>>>() {
}));
List<Flavor> response = parser.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is)));
List<Flavor> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response.get(0).getId(), 1);
assertEquals(response.get(0).getName(), "256 MB Server");
assertEquals(response.get(0).getDisk(), new Integer(10));

View File

@ -26,10 +26,11 @@ import java.net.UnknownHostException;
import org.jclouds.date.DateService;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.cloudservers.domain.Image;
import org.jclouds.rackspace.cloudservers.domain.ImageStatus;
import org.jclouds.rackspace.config.RackspaceParserModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
@ -44,36 +45,23 @@ import com.google.inject.TypeLiteral;
*/
@Test(groups = "unit", testName = "cloudservers.ParseImageFromJsonResponseTest")
public class ParseImageFromJsonResponseTest {
Injector i = Guice.createInjector(new RackspaceParserModule(), new GsonModule());
Injector i = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
DateService dateService = i.getInstance(DateService.class);
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/cloudservers/test_get_image_details.json");
InputStream is = getClass().getResourceAsStream("/cloudservers/test_get_image_details.json");
UnwrapOnlyJsonValue<Image> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<Image>>() {
}));
Image response = parser.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is)));
UnwrapOnlyJsonValue<Image> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Image>>() {
}));
Image response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response.getId(), 2);
assertEquals(response.getName(), "CentOS 5.2");
assertEquals(response.getCreated(), dateService
.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
assertEquals(response.getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
assertEquals(response.getProgress(), new Integer(80));
assertEquals(response.getServerId(), new Integer(12));
assertEquals(response.getStatus(), ImageStatus.SAVING);
assertEquals(response.getUpdated(), dateService
.iso8601SecondsDateParse(("2010-10-10T12:00:00Z")));
assertEquals(response.getUpdated(), dateService.iso8601SecondsDateParse(("2010-10-10T12:00:00Z")));
}
}

View File

@ -27,10 +27,11 @@ import java.util.List;
import org.jclouds.date.DateService;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.cloudservers.domain.Image;
import org.jclouds.rackspace.cloudservers.domain.ImageStatus;
import org.jclouds.rackspace.config.RackspaceParserModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
@ -46,31 +47,19 @@ import com.google.inject.TypeLiteral;
*/
@Test(groups = "unit", testName = "cloudImages.ParseImageListFromJsonResponseTest")
public class ParseImageListFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
Injector i = Guice.createInjector(new RackspaceParserModule(), new GsonModule());
DateService dateService = i.getInstance(DateService.class);
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/cloudservers/test_list_images.json");
List<Image> expects = ImmutableList.of(new Image(2, "CentOS 5.2"), new Image(743,
"My Server Backup"));
List<Image> expects = ImmutableList.of(new Image(2, "CentOS 5.2"), new Image(743, "My Server Backup"));
UnwrapOnlyJsonValue<List<Image>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {
}));
List<Image> response = parser.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is)));
List<Image> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response, expects);
}
@ -80,29 +69,24 @@ public class ParseImageListFromJsonResponseTest {
UnwrapOnlyJsonValue<List<Image>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {
}));
List<Image> response = parser.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is)));
List<Image> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response.get(0).getId(), 2);
assertEquals(response.get(0).getName(), "CentOS 5.2");
assertEquals(response.get(0).getCreated(), dateService
.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
assertEquals(response.get(0).getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
assertEquals(response.get(0).getProgress(), null);
assertEquals(response.get(0).getServerId(), null);
assertEquals(response.get(0).getStatus(), ImageStatus.ACTIVE);
assertEquals(response.get(0).getUpdated(), dateService
.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
assertEquals(response.get(0).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
assertEquals(response.get(1).getId(), 743);
assertEquals(response.get(1).getName(), "My Server Backup");
assertEquals(response.get(1).getCreated(), dateService
.iso8601SecondsDateParse("2009-07-07T09:56:16-05:00"));
assertEquals(response.get(1).getCreated(), dateService.iso8601SecondsDateParse("2009-07-07T09:56:16-05:00"));
;
assertEquals(response.get(1).getProgress(), new Integer(80));
assertEquals(response.get(1).getServerId(), new Integer(12));
assertEquals(response.get(1).getStatus(), ImageStatus.SAVING);
assertEquals(response.get(1).getUpdated(), dateService
.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
assertEquals(response.get(1).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
}
}

View File

@ -26,8 +26,9 @@ import java.util.List;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.config.RackspaceParserModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
@ -44,30 +45,26 @@ import com.google.inject.internal.ImmutableList;
@Test(groups = "unit", testName = "cloudservers.ParseInetAddressListFromJsonResponseTest")
public class ParseInetAddressListFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
Injector i = Guice.createInjector(new RackspaceParserModule(), new GsonModule());
public void testPublic() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/cloudservers/test_list_addresses_public.json");
InputStream is = getClass().getResourceAsStream("/cloudservers/test_list_addresses_public.json");
UnwrapOnlyJsonValue<List<String>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<String>>>() {
}));
List<String> response = parser.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is)));
List<String> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response, ImmutableList.of("67.23.10.132", "67.23.10.131"));
}
public void testPrivate() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/cloudservers/test_list_addresses_private.json");
InputStream is = getClass().getResourceAsStream("/cloudservers/test_list_addresses_private.json");
UnwrapOnlyJsonValue<List<String>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<String>>>() {
}));
List<String> response = parser.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is)));
List<String> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response, ImmutableList.of("10.176.42.16"));
}

View File

@ -26,11 +26,12 @@ import java.util.List;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.cloudservers.domain.Addresses;
import org.jclouds.rackspace.cloudservers.domain.Server;
import org.jclouds.rackspace.cloudservers.domain.ServerStatus;
import org.jclouds.rackspace.config.RackspaceParserModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
@ -48,17 +49,15 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "cloudservers.ParseServerFromJsonResponseTest")
public class ParseServerFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
Injector i = Guice.createInjector(new RackspaceParserModule(), new GsonModule());
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/cloudservers/test_get_server_detail.json");
UnwrapOnlyJsonValue<Server> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<Server>>() {
}));
Server response = parser.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is)));
UnwrapOnlyJsonValue<Server> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Server>>() {
}));
Server response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response.getId(), 1234);
assertEquals(response.getName(), "sample-server");
assertEquals(response.getImageId(), new Integer(2));
@ -72,8 +71,7 @@ public class ParseServerFromJsonResponseTest {
addresses1.getPrivateAddresses().addAll(privateAddresses);
addresses1.getPublicAddresses().addAll(publicAddresses);
assertEquals(response.getAddresses(), addresses1);
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1",
"Image Version", "2.1"));
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
}

View File

@ -26,11 +26,12 @@ import java.util.List;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.cloudservers.domain.Addresses;
import org.jclouds.rackspace.cloudservers.domain.Server;
import org.jclouds.rackspace.cloudservers.domain.ServerStatus;
import org.jclouds.rackspace.config.RackspaceParserModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
@ -49,58 +50,48 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "cloudservers.ParseServerListFromJsonResponseTest")
public class ParseServerListFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
Injector i = Guice.createInjector(new RackspaceParserModule(), new GsonModule());
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream(
"/cloudservers/test_list_servers.json");
InputStream is = getClass().getResourceAsStream("/cloudservers/test_list_servers.json");
List<Server> expects = ImmutableList.of(
new Server(1234, "sample-server"), new Server(5678,
"sample-server2"));
List<Server> expects = ImmutableList.of(new Server(1234, "sample-server"), new Server(5678, "sample-server2"));
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
}));
List<Server> response = parser.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is)));
List<Server> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response, expects);
}
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/cloudservers/test_list_servers_detail.json");
InputStream is = getClass().getResourceAsStream("/cloudservers/test_list_servers_detail.json");
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
}));
List<Server> response = parser.apply(new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is)));
List<Server> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response.get(0).getId(), 1234);
assertEquals(response.get(0).getName(), "sample-server");
assertEquals(response.get(0).getImageId(), new Integer(2));
assertEquals(response.get(0).getFlavorId(), new Integer(1));
assertEquals(response.get(0).getHostId(),
"e4d909c290d0fb1ca068ffaddf22cbd0");
assertEquals(response.get(0).getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
assertEquals(response.get(0).getStatus(), ServerStatus.BUILD);
assertEquals(response.get(0).getProgress(), new Integer(60));
List<String> publicAddresses = Lists.newArrayList("67.23.10.132",
"67.23.10.131");
List<String> publicAddresses = Lists.newArrayList("67.23.10.132", "67.23.10.131");
List<String> privateAddresses = Lists.newArrayList("10.176.42.16");
Addresses addresses1 = new Addresses();
addresses1.getPrivateAddresses().addAll(privateAddresses);
addresses1.getPublicAddresses().addAll(publicAddresses);
assertEquals(response.get(0).getAddresses(), addresses1);
assertEquals(response.get(0).getMetadata(), ImmutableMap.of(
"Server Label", "Web Head 1", "Image Version", "2.1"));
assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
assertEquals(response.get(1).getId(), 5678);
assertEquals(response.get(1).getName(), "sample-server2");
assertEquals(response.get(1).getImageId(), new Integer(2));
assertEquals(response.get(1).getFlavorId(), new Integer(1));
assertEquals(response.get(1).getHostId(),
"9e107d9d372bb6826bd81d3542a419d6");
assertEquals(response.get(1).getHostId(), "9e107d9d372bb6826bd81d3542a419d6");
assertEquals(response.get(1).getStatus(), ServerStatus.ACTIVE);
assertEquals(response.get(1).getProgress(), null);
List<String> publicAddresses2 = Lists.newArrayList("67.23.10.133");
@ -109,8 +100,7 @@ public class ParseServerListFromJsonResponseTest {
addresses2.getPrivateAddresses().addAll(privateAddresses2);
addresses2.getPublicAddresses().addAll(publicAddresses2);
assertEquals(response.get(1).getAddresses(), addresses2);
assertEquals(response.get(1).getMetadata(), ImmutableMap.of(
"Server Label", "DB 1"));
assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));
}

View File

@ -25,9 +25,10 @@ import java.net.UnknownHostException;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.cloudservers.domain.SharedIpGroup;
import org.jclouds.rackspace.config.RackspaceParserModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
@ -44,17 +45,15 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "cloudservers.ParseSharedIpGroupFromJsonResponseTest")
public class ParseSharedIpGroupFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
Injector i = Guice.createInjector(new RackspaceParserModule(), new GsonModule());
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/cloudservers/test_get_sharedipgroup_details.json");
InputStream is = getClass().getResourceAsStream("/cloudservers/test_get_sharedipgroup_details.json");
UnwrapOnlyJsonValue<SharedIpGroup> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<SharedIpGroup>>() {
}));
SharedIpGroup response = parser.apply(new HttpResponse(200, "ok",
Payloads.newInputStreamPayload(is)));
SharedIpGroup response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response.getId(), 1234);
assertEquals(response.getName(), "Shared IP Group 1");

View File

@ -26,9 +26,10 @@ import java.util.List;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.cloudservers.domain.SharedIpGroup;
import org.jclouds.rackspace.config.RackspaceParserModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
@ -45,34 +46,30 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "cloudSharedIpGroups.ParseSharedIpGroupListFromJsonResponseTest")
public class ParseSharedIpGroupListFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
Injector i = Guice.createInjector(new RackspaceParserModule(), new GsonModule());
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream(
"/cloudservers/test_list_sharedipgroups.json");
InputStream is = getClass().getResourceAsStream("/cloudservers/test_list_sharedipgroups.json");
List<SharedIpGroup> expects = ImmutableList.of(new SharedIpGroup(1234,
"Shared IP Group 1"), new SharedIpGroup(5678, "Shared IP Group 2"));
List<SharedIpGroup> expects = ImmutableList.of(new SharedIpGroup(1234, "Shared IP Group 1"), new SharedIpGroup(
5678, "Shared IP Group 2"));
UnwrapOnlyJsonValue<List<SharedIpGroup>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<SharedIpGroup>>>() {
}));
List<SharedIpGroup> response = parser.apply(new HttpResponse(200, "ok",
Payloads.newInputStreamPayload(is)));
List<SharedIpGroup> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response, expects);
}
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/cloudservers/test_list_sharedipgroups_detail.json");
InputStream is = getClass().getResourceAsStream("/cloudservers/test_list_sharedipgroups_detail.json");
UnwrapOnlyJsonValue<List<SharedIpGroup>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<SharedIpGroup>>>() {
}));
List<SharedIpGroup> response = parser.apply(new HttpResponse(200, "ok",
Payloads.newInputStreamPayload(is)));
List<SharedIpGroup> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response.get(0).getId(), 1234);
assertEquals(response.get(0).getName(), "Shared IP Group 1");
@ -80,8 +77,7 @@ public class ParseSharedIpGroupListFromJsonResponseTest {
assertEquals(response.get(1).getId(), 5678);
assertEquals(response.get(1).getName(), "Shared IP Group 2");
assertEquals(response.get(1).getServers(), ImmutableList.of(23203, 2456,
9891));
assertEquals(response.get(1).getServers(), ImmutableList.of(23203, 2456, 9891));
}

View File

@ -28,7 +28,7 @@ import java.net.URI;
import javax.ws.rs.HttpMethod;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
@ -43,21 +43,19 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "cloudservers.CreateServerOptionsTest")
public class CreateServerOptionsTest {
Injector injector = Guice.createInjector(new ParserModule());
Injector injector = Guice.createInjector(new GsonModule());
@Test
public void testAddPayloadToRequestMapOfStringStringHttpRequest() {
CreateServerOptions options = new CreateServerOptions();
HttpRequest request = buildRequest(options);
assertEquals("{\"server\":{\"name\":\"foo\",\"imageId\":1,\"flavorId\":2}}", request
.getPayload().getRawContent());
assertEquals("{\"server\":{\"name\":\"foo\",\"imageId\":1,\"flavorId\":2}}", request.getPayload().getRawContent());
}
private HttpRequest buildRequest(CreateServerOptions options) {
injector.injectMembers(options);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
options.bindToRequest(request, ImmutableMap
.of("name", "foo", "imageId", "1", "flavorId", "2"));
options.bindToRequest(request, ImmutableMap.of("name", "foo", "imageId", "1", "flavorId", "2"));
return request;
}
@ -78,8 +76,8 @@ public class CreateServerOptionsTest {
private void assertFile(HttpRequest request) {
assertEquals(
"{\"server\":{\"name\":\"foo\",\"imageId\":1,\"flavorId\":2,\"personality\":[{\"path\":\"/tmp/rhubarb\",\"contents\":\"Zm9v\"}]}}",
request.getPayload().getRawContent());
"{\"server\":{\"name\":\"foo\",\"imageId\":1,\"flavorId\":2,\"personality\":[{\"path\":\"/tmp/rhubarb\",\"contents\":\"Zm9v\"}]}}",
request.getPayload().getRawContent());
}
@Test
@ -98,9 +96,8 @@ public class CreateServerOptionsTest {
}
private void assertSharedIpGroup(HttpRequest request) {
assertEquals(
"{\"server\":{\"name\":\"foo\",\"imageId\":1,\"flavorId\":2,\"sharedIpGroupId\":3}}",
request.getPayload().getRawContent());
assertEquals("{\"server\":{\"name\":\"foo\",\"imageId\":1,\"flavorId\":2,\"sharedIpGroupId\":3}}", request
.getPayload().getRawContent());
}
@Test
@ -124,8 +121,8 @@ public class CreateServerOptionsTest {
private void assertSharedIp(HttpRequest request) {
assertEquals(
"{\"server\":{\"name\":\"foo\",\"imageId\":1,\"flavorId\":2,\"sharedIpGroupId\":3,\"addresses\":{\"public\":[\"127.0.0.1\"]}}}",
request.getPayload().getRawContent());
"{\"server\":{\"name\":\"foo\",\"imageId\":1,\"flavorId\":2,\"sharedIpGroupId\":3,\"addresses\":{\"public\":[\"127.0.0.1\"]}}}",
request.getPayload().getRawContent());
}
@Test(expectedExceptions = IllegalStateException.class)

View File

@ -26,7 +26,7 @@ import java.net.URI;
import javax.ws.rs.HttpMethod;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
@ -41,7 +41,7 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "cloudsharedIpGroups.CreateSharedIpGroupOptionsTest")
public class CreateSharedIpGroupOptionsTest {
Injector injector = Guice.createInjector(new ParserModule());
Injector injector = Guice.createInjector(new GsonModule());
@Test
public void testAddPayloadToRequestMapOfStringStringHttpRequest() {
@ -73,8 +73,7 @@ public class CreateSharedIpGroupOptionsTest {
}
private void assertSharedIpGroup(HttpRequest request) {
assertEquals("{\"sharedIpGroup\":{\"name\":\"foo\",\"server\":3}}", request.getPayload()
.getRawContent());
assertEquals("{\"sharedIpGroup\":{\"name\":\"foo\",\"server\":3}}", request.getPayload().getRawContent());
}
}

View File

@ -27,7 +27,7 @@ import java.util.HashMap;
import javax.ws.rs.HttpMethod;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
@ -41,7 +41,7 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "cloudsharedIpGroups.RebuildServerOptionsTest")
public class RebuildServerOptionsTest {
Injector injector = Guice.createInjector(new ParserModule());
Injector injector = Guice.createInjector(new GsonModule());
@Test
public void testAddPayloadToRequestMapOfStringStringHttpRequest() {

View File

@ -18,29 +18,27 @@
*/
package org.jclouds.rimuhosting.miro.binder;
import static com.google.common.base.Preconditions.checkState;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.binders.BindToJsonPayload;
import java.util.HashMap;
import java.util.Map;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.binders.BindToJsonPayload;
/**
* Generic binder for RimuHosting POSTS/PUTS. In the form of
*
*
* {"request":{...}}
*
*
* @author Ivan Meredith
*/
public class RimuHostingJsonBinder extends BindToJsonPayload {
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
bindToRequest(request, (Object) postParams);
}
public void bindToRequest(HttpRequest request, Object toBind) {
checkState(gson != null, "Program error: gson should have been injected at this point");
Map<String, Object> test = new HashMap<String, Object>();
test.put("request", toBind);
super.bindToRequest(request, test);
Map<String, Object> test = new HashMap<String, Object>();
test.put("request", toBind);
super.bindToRequest(request, test);
}
}

View File

@ -28,7 +28,7 @@ import java.util.SortedSet;
import org.jclouds.date.DateService;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.json.config.GsonModule;
import org.jclouds.twitter.domain.Location;
import org.jclouds.twitter.domain.Status;
import org.jclouds.twitter.domain.User;
@ -48,13 +48,8 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "twitter.ParseStatusesFromJsonResponseTest")
public class ParseStatusesFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(CDateAdapter.class);
super.configure();
}
});
Injector i = Guice.createInjector(new GsonModule());
DateService dateService = new SimpleDateFormatDateService();
public void testApplyInputStreamDetails() throws UnknownHostException {
@ -66,8 +61,7 @@ public class ParseStatusesFromJsonResponseTest {
new Status(
dateService.cDateParse("Tue Jun 29 20:41:15 +0000 2010"),
false,
new Location("Point", new double[] { 153.08691298,
-26.38658779 }),
new Location("Point", new double[] { 153.08691298, -26.38658779 }),
15138751340l,
"adrianfcole",
15112459535l,
@ -76,8 +70,7 @@ public class ParseStatusesFromJsonResponseTest {
"@adrianfcole hehe, yes. Still going :) hope you're keeping well!",
false,
new User(
dateService
.cDateParse("Sat Jul 26 08:08:17 +0000 2008"),
dateService.cDateParse("Sat Jul 26 08:08:17 +0000 2008"),
"London-based South African software geek & amateur photog. Since Nov 2009, travelling the world with @sunflowerkate on an extended honeymoon",
21,
315,
@ -94,18 +87,15 @@ public class ParseStatusesFromJsonResponseTest {
true,
URI
.create("http://a1.twimg.com/profile_background_images/62032362/_MG_8095_6_7HDR_tonemapped.jpg"),
false,
URI
false, URI
.create("http://a1.twimg.com/profile_images/593267212/many_moon_honeymoon_normal.jpg"),
"0099CC", "fff8ad", "f6ffd1", "333333", false,
"suprememoocow", 987, "Kuala Lumpur", URI
"0099CC", "fff8ad", "f6ffd1", "333333", false, "suprememoocow", 987, "Kuala Lumpur", URI
.create("http://newdigate.me"), -28800, false))
);
ParseJson<SortedSet<Status>> parser = i.getInstance(Key
.get(new TypeLiteral<ParseJson<SortedSet<Status>>>() {
}));
ParseJson<SortedSet<Status>> parser = i.getInstance(Key.get(new TypeLiteral<ParseJson<SortedSet<Status>>>() {
}));
SortedSet<Status> response = parser.apply(is);
assertEquals(response, expects);
}

View File

@ -34,7 +34,7 @@ import org.jclouds.compute.domain.internal.SizeImpl;
import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.functions.FindLocationForResourceInVDC;
import org.jclouds.vcloud.domain.NamedResource;
@ -61,7 +61,7 @@ public class ParseVAppTemplatesInVDCToSizeProviderTest {
public void testParse() {
InputStream is = getClass().getResourceAsStream("/bluelock/vdc.xml");
Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
Injector injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
@Override
protected void configure() {

View File

@ -28,7 +28,7 @@ import static org.testng.Assert.assertEquals;
import java.net.URI;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.domain.FenceMode;
import org.testng.annotations.Test;
@ -43,7 +43,7 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "vcloud.InstantiateVAppTemplateOptionsTest")
public class InstantiateVAppTemplateOptionsTest {
Injector injector = Guice.createInjector(new ParserModule());
Injector injector = Guice.createInjector(new SaxParserModule());
@Test
public void testInNetwork() {

View File

@ -25,7 +25,7 @@ import java.net.URI;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
@ -45,7 +45,7 @@ public class CatalogHandlerTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/catalogItem-hosting.xml");
Injector injector = Guice.createInjector(new ParserModule());
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
CatalogItem result = factory.create(injector.getInstance(CatalogItemHandler.class)).parse(is);

View File

@ -26,7 +26,7 @@ import java.net.URI;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
@ -51,7 +51,7 @@ public class CatalogItemHandlerTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/catalog.xml");
injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
@Override
protected void configure() {
@ -158,7 +158,7 @@ public class CatalogItemHandlerTest {
public void testHosting() {
InputStream is = getClass().getResourceAsStream("/catalog-hosting.xml");
injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
@Override
protected void configure() {

View File

@ -26,7 +26,7 @@ import java.net.UnknownHostException;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.domain.FenceMode;
import org.jclouds.vcloud.domain.FirewallRule;
import org.jclouds.vcloud.domain.NatRule;
@ -52,7 +52,7 @@ public class NetworkHandlerTest {
public void testTerremark() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/network-terremark.xml");
injector = Guice.createInjector(new ParserModule());
injector = Guice.createInjector(new SaxParserModule());
factory = injector.getInstance(ParseSax.Factory.class);
Network result = factory.create(
injector.getInstance(NetworkHandler.class)).parse(is);
@ -71,7 +71,7 @@ public class NetworkHandlerTest {
public void testHosting() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/network-hosting.xml");
injector = Guice.createInjector(new ParserModule());
injector = Guice.createInjector(new SaxParserModule());
factory = injector.getInstance(ParseSax.Factory.class);
Network result = (Network) factory.create(
injector.getInstance(NetworkHandler.class)).parse(is);

View File

@ -29,7 +29,7 @@ import javax.inject.Singleton;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
@ -53,7 +53,7 @@ public class OrgHandlerTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/org.xml");
Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
Injector injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
@Override
protected void configure() {
@ -98,7 +98,7 @@ public class OrgHandlerTest {
public void testHosting() {
InputStream is = getClass().getResourceAsStream("/org-hosting.xml");
Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
Injector injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
@Override
protected void configure() {

View File

@ -26,7 +26,7 @@ import java.util.SortedMap;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSortedMap;
@ -44,7 +44,7 @@ public class SupportedVersionsHandlerTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/versions.xml");
Injector injector = Guice.createInjector(new ParserModule());
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
SortedMap<String, URI> result = factory.create(

View File

@ -25,7 +25,7 @@ import java.net.URI;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.internal.VAppTemplateImpl;
@ -48,7 +48,7 @@ public class VAppTemplateHandlerTest {
public void testTerremark() {
InputStream is = getClass().getResourceAsStream("/vAppTemplate-trmk.xml");
injector = Guice.createInjector(new ParserModule());
injector = Guice.createInjector(new SaxParserModule());
factory = injector.getInstance(ParseSax.Factory.class);
VAppTemplate result = factory.create(injector.getInstance(VAppTemplateHandler.class)).parse(
is);
@ -59,7 +59,7 @@ public class VAppTemplateHandlerTest {
public void testHosting() {
InputStream is = getClass().getResourceAsStream("/vAppTemplate-hosting.xml");
injector = Guice.createInjector(new ParserModule());
injector = Guice.createInjector(new SaxParserModule());
factory = injector.getInstance(ParseSax.Factory.class);
VAppTemplate result = (VAppTemplate) factory.create(
injector.getInstance(VAppTemplateHandler.class)).parse(is);

View File

@ -25,7 +25,7 @@ import java.net.URI;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Quota;
@ -50,7 +50,7 @@ public class VDCHandlerTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/vdc.xml");
Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
Injector injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
@Override
protected void configure() {
@ -91,7 +91,7 @@ public class VDCHandlerTest {
public void testApplyHosting() {
InputStream is = getClass().getResourceAsStream("/vdc-hosting.xml");
Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
Injector injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
@Override
protected void configure() {

View File

@ -22,7 +22,7 @@ import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Bui
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.withDescription;
import static org.testng.Assert.assertEquals;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
@ -36,7 +36,7 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "vcloud.CreateInternetServiceOptionsTest")
public class AddInternetServiceOptionsTest {
Injector injector = Guice.createInjector(new ParserModule());
Injector injector = Guice.createInjector(new SaxParserModule());
@Test
public void testWithDescription() {

View File

@ -22,7 +22,7 @@ import static org.jclouds.vcloud.terremark.options.AddNodeOptions.Builder.disabl
import static org.jclouds.vcloud.terremark.options.AddNodeOptions.Builder.withDescription;
import static org.testng.Assert.assertEquals;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
@ -36,7 +36,7 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "vcloud.AddNodeOptionsTest")
public class AddNodeOptionsTest {
Injector injector = Guice.createInjector(new ParserModule());
Injector injector = Guice.createInjector(new SaxParserModule());
@Test
public void testWithDescription() {

View File

@ -30,7 +30,7 @@ import static org.testng.Assert.assertEquals;
import java.net.URI;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
@ -44,7 +44,7 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "vcloud.TerremarkInstantiateVAppTemplateOptionsTest")
public class TerremarkInstantiateVAppTemplateOptionsTest {
Injector injector = Guice.createInjector(new ParserModule());
Injector injector = Guice.createInjector(new SaxParserModule());
@Test
public void testInGroup() {

View File

@ -11,7 +11,7 @@ import java.util.Properties;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressMediaType;
@ -34,7 +34,7 @@ public class TerremarkOrgHandlerTest extends BaseHandlerTest {
@Override
@BeforeTest
protected void setUpInjector() {
injector = Guice.createInjector(new ParserModule() {
injector = Guice.createInjector(new SaxParserModule() {
@Override
public void configure() {
super.configure();

View File

@ -26,7 +26,7 @@ import java.net.URI;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
@ -50,7 +50,7 @@ public class TerremarkVDCHandlerTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/terremark/vdc.xml");
Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
Injector injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
@Override
protected void configure() {

View File

@ -27,7 +27,7 @@ import java.util.List;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
@ -59,7 +59,7 @@ public class VAppHandlerTest extends BaseHandlerTest {
@BeforeTest
@Override
protected void setUpInjector() {
injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
@Override
protected void configure() {