mirror of https://github.com/apache/jclouds.git
fixed issue where body of a Payload arg wasn't being added to the http request
This commit is contained in:
parent
6e975662c1
commit
1063924f6a
|
@ -166,7 +166,7 @@ public class RestAnnotationProcessor<T> {
|
|||
static final Map<MethodKey, Method> delegationMap = newHashMap();
|
||||
|
||||
static Map<Method, Map<Integer, Set<Annotation>>> createMethodToIndexOfParamToAnnotation(
|
||||
final Class<? extends Annotation> annotation) {
|
||||
final Class<? extends Annotation> annotation) {
|
||||
return new MapMaker().makeComputingMap(new Function<Method, Map<Integer, Set<Annotation>>>() {
|
||||
public Map<Integer, Set<Annotation>> apply(final Method method) {
|
||||
return new MapMaker().makeComputingMap(new GetAnnotationsForMethodParameterIndex(method, annotation));
|
||||
|
@ -200,7 +200,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private static final Class<? extends HttpRequestOptions[]> optionsVarArgsClass = new HttpRequestOptions[] {}
|
||||
.getClass();
|
||||
.getClass();
|
||||
|
||||
private static final Function<? super Entry<String, String>, ? extends Part> ENTRY_TO_PART = new Function<Entry<String, String>, Part>() {
|
||||
|
||||
|
@ -212,17 +212,17 @@ public class RestAnnotationProcessor<T> {
|
|||
};
|
||||
|
||||
private final Map<Method, Set<Integer>> methodToIndexesOfOptions = new MapMaker()
|
||||
.makeComputingMap(new Function<Method, Set<Integer>>() {
|
||||
public Set<Integer> apply(final Method method) {
|
||||
Set<Integer> toReturn = newHashSet();
|
||||
for (int index = 0; index < method.getParameterTypes().length; index++) {
|
||||
Class<?> type = method.getParameterTypes()[index];
|
||||
if (HttpRequestOptions.class.isAssignableFrom(type) || optionsVarArgsClass.isAssignableFrom(type))
|
||||
toReturn.add(index);
|
||||
}
|
||||
return toReturn;
|
||||
.makeComputingMap(new Function<Method, Set<Integer>>() {
|
||||
public Set<Integer> apply(final Method method) {
|
||||
Set<Integer> toReturn = newHashSet();
|
||||
for (int index = 0; index < method.getParameterTypes().length; index++) {
|
||||
Class<?> type = method.getParameterTypes()[index];
|
||||
if (HttpRequestOptions.class.isAssignableFrom(type) || optionsVarArgsClass.isAssignableFrom(type))
|
||||
toReturn.add(index);
|
||||
}
|
||||
});
|
||||
return toReturn;
|
||||
}
|
||||
});
|
||||
|
||||
private final ParseSax.Factory parserFactory;
|
||||
private final HttpUtils utils;
|
||||
|
@ -240,7 +240,7 @@ public class RestAnnotationProcessor<T> {
|
|||
|
||||
@VisibleForTesting
|
||||
public static Function<HttpResponse, ?> createResponseParser(ParseSax.Factory parserFactory, Injector injector,
|
||||
Method method, HttpRequest request) {
|
||||
Method method, HttpRequest request) {
|
||||
Function<HttpResponse, ?> transformer;
|
||||
Class<? extends HandlerWithResult<?>> handler = getSaxResponseParserClassOrNull(method);
|
||||
if (handler != null) {
|
||||
|
@ -261,7 +261,7 @@ public class RestAnnotationProcessor<T> {
|
|||
|
||||
@VisibleForTesting
|
||||
public static Function<Exception, ?> createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(
|
||||
Injector injector, Method method) {
|
||||
Injector injector, Method method) {
|
||||
ExceptionParser annotation = method.getAnnotation(ExceptionParser.class);
|
||||
if (annotation != null) {
|
||||
return injector.getInstance(annotation.value());
|
||||
|
@ -272,7 +272,7 @@ public class RestAnnotationProcessor<T> {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Inject
|
||||
public RestAnnotationProcessor(Injector injector, ParseSax.Factory parserFactory, HttpUtils utils,
|
||||
TypeLiteral<T> typeLiteral) {
|
||||
TypeLiteral<T> typeLiteral) {
|
||||
this.declaring = (Class<T>) typeLiteral.getRawType();
|
||||
this.injector = injector;
|
||||
this.parserFactory = parserFactory;
|
||||
|
@ -387,7 +387,7 @@ public class RestAnnotationProcessor<T> {
|
|||
public GeneratedHttpRequest<T> createRequest(Method method, Object... args) {
|
||||
inputParamValidator.validateMethodParametersOrThrow(method, args);
|
||||
ClassMethodArgs cma = logger.isTraceEnabled() ? new ClassMethodArgs(method.getDeclaringClass(), method, args)
|
||||
: null;
|
||||
: null;
|
||||
|
||||
URI endpoint = callerEndpoint;
|
||||
try {
|
||||
|
@ -457,7 +457,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
GeneratedHttpRequest<T> request = new GeneratedHttpRequest<T>(httpMethod, endpoint, skips, declaring, method,
|
||||
args);
|
||||
args);
|
||||
addHostHeaderIfAnnotatedWithVirtualHost(headers, request.getEndpoint().getHost(), method);
|
||||
addFiltersIfAnnotated(method, request);
|
||||
|
||||
|
@ -472,8 +472,9 @@ public class RestAnnotationProcessor<T> {
|
|||
} else if (formParams.size() > 0) {
|
||||
payload = Payloads.newUrlEncodedFormPayload(formParams, skips);
|
||||
} else if (headers.containsKey(CONTENT_TYPE)) {
|
||||
payload = Payloads.newByteArrayPayload(new byte[]{});
|
||||
payload.getContentMetadata().setContentType(Iterables.get(headers.get(CONTENT_TYPE),0));
|
||||
if (payload == null)
|
||||
payload = Payloads.newByteArrayPayload(new byte[] {});
|
||||
payload.getContentMetadata().setContentType(Iterables.get(headers.get(CONTENT_TYPE), 0));
|
||||
}
|
||||
if (payload != null) {
|
||||
request.setPayload(payload);
|
||||
|
@ -496,14 +497,14 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
public static URI replaceQuery(Provider<UriBuilder> uriBuilderProvider, URI in, String newQuery,
|
||||
@Nullable Comparator<Entry<String, String>> sorter, char... skips) {
|
||||
@Nullable Comparator<Entry<String, String>> sorter, char... skips) {
|
||||
UriBuilder builder = uriBuilderProvider.get().uri(in);
|
||||
builder.replaceQuery(makeQueryLine(parseQueryToMap(newQuery), sorter, skips));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private void addMatrixParams(UriBuilder builder, Collection<Entry<String, String>> tokenValues, Method method,
|
||||
Object... args) {
|
||||
Object... args) {
|
||||
if (declaring.isAnnotationPresent(MatrixParams.class)) {
|
||||
MatrixParams matrix = declaring.getAnnotation(MatrixParams.class);
|
||||
addMatrix(builder, matrix, tokenValues);
|
||||
|
@ -520,7 +521,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private Multimap<String, String> addFormParams(Collection<Entry<String, String>> tokenValues, Method method,
|
||||
Object... args) {
|
||||
Object... args) {
|
||||
Multimap<String, String> formMap = LinkedListMultimap.create();
|
||||
if (declaring.isAnnotationPresent(FormParams.class)) {
|
||||
FormParams form = declaring.getAnnotation(FormParams.class);
|
||||
|
@ -539,7 +540,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private Multimap<String, String> addQueryParams(Collection<Entry<String, String>> tokenValues, Method method,
|
||||
Object... args) {
|
||||
Object... args) {
|
||||
Multimap<String, String> queryMap = LinkedListMultimap.create();
|
||||
if (declaring.isAnnotationPresent(QueryParams.class)) {
|
||||
QueryParams query = declaring.getAnnotation(QueryParams.class);
|
||||
|
@ -558,7 +559,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private void addForm(Multimap<String, String> formParams, FormParams form,
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
for (int i = 0; i < form.keys().length; i++) {
|
||||
if (form.values()[i].equals(FormParams.NULL)) {
|
||||
formParams.removeAll(form.keys()[i]);
|
||||
|
@ -570,7 +571,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private void addMapPayload(Map<String, String> postParams, MapPayloadParams mapDefaults,
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
for (int i = 0; i < mapDefaults.keys().length; i++) {
|
||||
if (mapDefaults.values()[i].equals(MapPayloadParams.NULL)) {
|
||||
postParams.put(mapDefaults.keys()[i], null);
|
||||
|
@ -581,7 +582,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private void addQuery(Multimap<String, String> queryParams, QueryParams query,
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
for (int i = 0; i < query.keys().length; i++) {
|
||||
if (query.values()[i].equals(QueryParams.NULL)) {
|
||||
queryParams.removeAll(query.keys()[i]);
|
||||
|
@ -624,7 +625,7 @@ public class RestAnnotationProcessor<T> {
|
|||
@VisibleForTesting
|
||||
public static URI getEndpointInParametersOrNull(Method method, final Object[] args, Injector injector) {
|
||||
Map<Integer, Set<Annotation>> map = indexWithAtLeastOneAnnotation(method,
|
||||
methodToIndexOfParamToEndpointParamAnnotations);
|
||||
methodToIndexOfParamToEndpointParamAnnotations);
|
||||
if (map.size() >= 1 && args.length > 0) {
|
||||
EndpointParam firstAnnotation = (EndpointParam) get(get(map.values(), 0), 0);
|
||||
Function<Object, URI> parser = injector.getInstance(firstAnnotation.parser());
|
||||
|
@ -633,8 +634,8 @@ public class RestAnnotationProcessor<T> {
|
|||
int index = map.keySet().iterator().next();
|
||||
try {
|
||||
URI returnVal = parser.apply(args[index]);
|
||||
checkArgument(returnVal != null, String.format("endpoint for [%s] not configured for %s", args[index],
|
||||
method));
|
||||
checkArgument(returnVal != null,
|
||||
String.format("endpoint for [%s] not configured for %s", args[index], method));
|
||||
return returnVal;
|
||||
} catch (NullPointerException e) {
|
||||
throw new IllegalArgumentException(String.format("argument at index %d on method %s", index, method), e);
|
||||
|
@ -651,12 +652,12 @@ public class RestAnnotationProcessor<T> {
|
|||
});
|
||||
try {
|
||||
URI returnVal = parser.apply(argsToParse);
|
||||
checkArgument(returnVal != null, String.format("endpoint for [%s] not configured for %s", argsToParse,
|
||||
method));
|
||||
checkArgument(returnVal != null,
|
||||
String.format("endpoint for [%s] not configured for %s", argsToParse, method));
|
||||
return returnVal;
|
||||
} catch (NullPointerException e) {
|
||||
throw new IllegalArgumentException(String.format("argument at indexes %s on method %s", map.keySet(),
|
||||
method), e);
|
||||
method), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -697,13 +698,13 @@ public class RestAnnotationProcessor<T> {
|
|||
ResponseParser annotation = method.getAnnotation(ResponseParser.class);
|
||||
if (annotation == null) {
|
||||
if (method.getReturnType().equals(void.class)
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureVoidLiteral)) {
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureVoidLiteral)) {
|
||||
return Key.get(ReleasePayloadAndReturn.class);
|
||||
} else if (method.getReturnType().equals(boolean.class) || method.getReturnType().equals(Boolean.class)
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureBooleanLiteral)) {
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureBooleanLiteral)) {
|
||||
return Key.get(ReturnTrueIf2xx.class);
|
||||
} else if (method.getReturnType().equals(InputStream.class)
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureInputStreamLiteral)) {
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureInputStreamLiteral)) {
|
||||
return Key.get(ReturnInputStream.class);
|
||||
} else if (getAcceptHeadersOrNull(method).contains(MediaType.APPLICATION_JSON)) {
|
||||
Type returnVal;
|
||||
|
@ -724,10 +725,10 @@ public class RestAnnotationProcessor<T> {
|
|||
parserType = Types.newParameterizedType(ParseJson.class, returnVal);
|
||||
return (Key<? extends Function<HttpResponse, ?>>) Key.get(parserType);
|
||||
} else if (method.getReturnType().equals(String.class)
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureStringLiteral)) {
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureStringLiteral)) {
|
||||
return Key.get(ReturnStringIf2xx.class);
|
||||
} else if (method.getReturnType().equals(URI.class)
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureURILiteral)) {
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureURILiteral)) {
|
||||
return Key.get(ParseURIFromListOrLocationHeaderIf20x.class);
|
||||
} else {
|
||||
throw new IllegalStateException("You must specify a ResponseParser annotation on: " + method.toString());
|
||||
|
@ -759,7 +760,7 @@ public class RestAnnotationProcessor<T> {
|
|||
} else {
|
||||
if (postBinders[0] instanceof org.jclouds.rest.MapBinder) {
|
||||
throw new IllegalArgumentException("we currently do not support multiple varargs postBinders in: "
|
||||
+ method.getName());
|
||||
+ method.getName());
|
||||
}
|
||||
}
|
||||
} else if (arg instanceof org.jclouds.rest.MapBinder) {
|
||||
|
@ -808,8 +809,8 @@ public class RestAnnotationProcessor<T> {
|
|||
Set<String> requests = getHttpMethods(method);
|
||||
if (requests == null || requests.size() != 1) {
|
||||
throw new IllegalStateException(
|
||||
"You must use at least one, but no more than one http method or pathparam annotation on: "
|
||||
+ method.toString());
|
||||
"You must use at least one, but no more than one http method or pathparam annotation on: "
|
||||
+ method.toString());
|
||||
}
|
||||
return requests.iterator().next();
|
||||
}
|
||||
|
@ -831,12 +832,12 @@ public class RestAnnotationProcessor<T> {
|
|||
mapBinder.bindToRequest(request, mapParams);
|
||||
} else {
|
||||
OUTER: for (Entry<Integer, Set<Annotation>> entry : filterValues(
|
||||
methodToIndexOfParamToDecoratorParamAnnotation.get(request.getJavaMethod()),
|
||||
new Predicate<Set<Annotation>>() {
|
||||
public boolean apply(Set<Annotation> input) {
|
||||
return input.size() >= 1;
|
||||
}
|
||||
}).entrySet()) {
|
||||
methodToIndexOfParamToDecoratorParamAnnotation.get(request.getJavaMethod()),
|
||||
new Predicate<Set<Annotation>>() {
|
||||
public boolean apply(Set<Annotation> input) {
|
||||
return input.size() >= 1;
|
||||
}
|
||||
}).entrySet()) {
|
||||
boolean shouldBreak = false;
|
||||
BinderParam payloadAnnotation = (BinderParam) entry.getValue().iterator().next();
|
||||
Binder binder = injector.getInstance(payloadAnnotation.value());
|
||||
|
@ -872,24 +873,24 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
public static Map<Integer, Set<Annotation>> indexWithOnlyOneAnnotation(Method method, String description,
|
||||
Map<Method, Map<Integer, Set<Annotation>>> toRefine) {
|
||||
Map<Method, Map<Integer, Set<Annotation>>> toRefine) {
|
||||
Map<Integer, Set<Annotation>> indexToPayloadAnnotation = indexWithAtLeastOneAnnotation(method, toRefine);
|
||||
if (indexToPayloadAnnotation.size() > 1) {
|
||||
throw new IllegalStateException(String.format(
|
||||
"You must not specify more than one %s annotation on: %s; found %s", description, method.toString(),
|
||||
indexToPayloadAnnotation));
|
||||
"You must not specify more than one %s annotation on: %s; found %s", description, method.toString(),
|
||||
indexToPayloadAnnotation));
|
||||
}
|
||||
return indexToPayloadAnnotation;
|
||||
}
|
||||
|
||||
private static Map<Integer, Set<Annotation>> indexWithAtLeastOneAnnotation(Method method,
|
||||
Map<Method, Map<Integer, Set<Annotation>>> toRefine) {
|
||||
Map<Method, Map<Integer, Set<Annotation>>> toRefine) {
|
||||
Map<Integer, Set<Annotation>> indexToPayloadAnnotation = filterValues(toRefine.get(method),
|
||||
new Predicate<Set<Annotation>>() {
|
||||
public boolean apply(Set<Annotation> input) {
|
||||
return input.size() == 1;
|
||||
}
|
||||
});
|
||||
new Predicate<Set<Annotation>>() {
|
||||
public boolean apply(Set<Annotation> input) {
|
||||
return input.size() == 1;
|
||||
}
|
||||
});
|
||||
return indexToPayloadAnnotation;
|
||||
}
|
||||
|
||||
|
@ -908,7 +909,7 @@ public class RestAnnotationProcessor<T> {
|
|||
} else {
|
||||
if (options[0] instanceof HttpRequestOptions) {
|
||||
throw new IllegalArgumentException("we currently do not support multiple varargs options in: "
|
||||
+ method.getName());
|
||||
+ method.getName());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -920,7 +921,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
public Multimap<String, String> buildHeaders(Collection<Entry<String, String>> tokenValues, Method method,
|
||||
final Object... args) {
|
||||
final Object... args) {
|
||||
Multimap<String, String> headers = LinkedHashMultimap.create();
|
||||
addHeaderIfAnnotationPresentOnMethod(headers, method, tokenValues);
|
||||
Map<Integer, Set<Annotation>> indexToHeaderParam = methodToIndexOfParamToHeaderParamAnnotations.get(method);
|
||||
|
@ -967,7 +968,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
public void addHeaderIfAnnotationPresentOnMethod(Multimap<String, String> headers, Method method,
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
if (declaring.isAnnotationPresent(Headers.class)) {
|
||||
Headers header = declaring.getAnnotation(Headers.class);
|
||||
addHeader(headers, header, tokenValues);
|
||||
|
@ -979,7 +980,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private void addHeader(Multimap<String, String> headers, Headers header,
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
for (int i = 0; i < header.keys().length; i++) {
|
||||
String value = header.values()[i];
|
||||
value = replaceTokens(value, tokenValues);
|
||||
|
|
|
@ -104,6 +104,7 @@ import org.jclouds.http.options.GetOptions;
|
|||
import org.jclouds.http.options.HttpRequestOptions;
|
||||
import org.jclouds.io.Payload;
|
||||
import org.jclouds.io.PayloadEnclosing;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.BaseRestClientTest;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
|
@ -208,7 +209,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testDelegateAsync() throws SecurityException, NoSuchMethodException, InterruptedException,
|
||||
ExecutionException {
|
||||
ExecutionException {
|
||||
Injector child = injectorForClient();
|
||||
TransformingHttpCommandExecutorService mock = child.getInstance(TransformingHttpCommandExecutorService.class);
|
||||
|
||||
|
@ -223,7 +224,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
AsyncCaller caller = child.getInstance(AsyncCaller.class);
|
||||
expect(mock.submit(requestLineEquals("GET http://localhost:9999/client/foo HTTP/1.1"), eq(function))).andReturn(
|
||||
createNiceMock(ListenableFuture.class)).atLeastOnce();
|
||||
createNiceMock(ListenableFuture.class)).atLeastOnce();
|
||||
replay(mock);
|
||||
|
||||
caller.getCallee().onePath("foo");
|
||||
|
@ -252,7 +253,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
public void testDelegateWithOverridingEndpoint() throws SecurityException, NoSuchMethodException,
|
||||
InterruptedException, ExecutionException {
|
||||
InterruptedException, ExecutionException {
|
||||
Injector child = injectorForClient();
|
||||
TransformingHttpCommandExecutorService mock = child.getInstance(TransformingHttpCommandExecutorService.class);
|
||||
|
||||
|
@ -267,7 +268,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
Caller caller = child.getInstance(Caller.class);
|
||||
expect(mock.submit(requestLineEquals("GET http://localhost:1111/client/foo HTTP/1.1"), eq(function))).andReturn(
|
||||
Futures.<Void> immediateFuture(null)).atLeastOnce();
|
||||
Futures.<Void> immediateFuture(null)).atLeastOnce();
|
||||
replay(mock);
|
||||
|
||||
caller.getCallee().onePath("foo");
|
||||
|
@ -278,9 +279,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
private Injector injectorForClient() {
|
||||
|
||||
RestContextSpec<Caller, AsyncCaller> contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo", null,
|
||||
Caller.class, AsyncCaller.class, ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(),
|
||||
new CallerCalleeModule()));
|
||||
RestContextSpec<Caller, AsyncCaller> contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo",
|
||||
null, Caller.class, AsyncCaller.class,
|
||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new CallerCalleeModule()));
|
||||
|
||||
return createContextBuilder(contextSpec).buildInjector();
|
||||
|
||||
|
@ -295,7 +296,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
};
|
||||
|
||||
@Target( { ElementType.METHOD })
|
||||
@Target({ ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@javax.ws.rs.HttpMethod("FOO")
|
||||
public @interface FOO {
|
||||
|
@ -330,10 +331,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
public void testUnEncodeQuery() {
|
||||
URI expects = URI
|
||||
.create("http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriancole-compute.testObjectOperations&metadata=chef:sushi&metadata=foo:bar&sessionToken=775ef26e-0740-4707-ad92-afe9814bc436");
|
||||
.create("http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriancole-compute.testObjectOperations&metadata=chef:sushi&metadata=foo:bar&sessionToken=775ef26e-0740-4707-ad92-afe9814bc436");
|
||||
|
||||
URI start = URI
|
||||
.create("http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriancole-compute.testObjectOperations&metadata=chef%3Asushi&metadata=foo%3Abar&sessionToken=775ef26e-0740-4707-ad92-afe9814bc436");
|
||||
.create("http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriancole-compute.testObjectOperations&metadata=chef%3Asushi&metadata=foo%3Abar&sessionToken=775ef26e-0740-4707-ad92-afe9814bc436");
|
||||
URI value = RestAnnotationProcessor.replaceQuery(uriBuilderProvider, start, start.getQuery(), null, '/', ':');
|
||||
assertEquals(value, expects);
|
||||
}
|
||||
|
@ -373,21 +374,34 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@POST
|
||||
@Path("")
|
||||
public void post(HttpRequestOptions options);
|
||||
|
||||
|
||||
@POST
|
||||
@Path("")
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
public void post();
|
||||
|
||||
@POST
|
||||
@Path("")
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
public void post(Payload payload);
|
||||
}
|
||||
|
||||
public void testHttpRequestOptionsPayloadParam() throws SecurityException, NoSuchMethodException, IOException {
|
||||
public void testHttpRequestOptionsNoPayloadParam() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestPayloadParamVarargs.class.getMethod("post");
|
||||
HttpRequest request = factory(TestQuery.class).createRequest(method);
|
||||
assertRequestLineEquals(request, "POST http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, "", "application/octet-stream", false);
|
||||
}
|
||||
|
||||
|
||||
public void testHttpRequestOptionsPayloadParam() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestPayloadParamVarargs.class.getMethod("post", Payload.class);
|
||||
HttpRequest request = factory(TestQuery.class).createRequest(method, Payloads.newStringPayload("foo"));
|
||||
assertRequestLineEquals(request, "POST http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, "foo", "application/octet-stream", false);
|
||||
}
|
||||
|
||||
public void testHttpRequestWithOnlyContentType() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestPayloadParamVarargs.class.getMethod("post", HttpRequestOptions.class);
|
||||
verifyTestPostOptions(method);
|
||||
|
@ -395,7 +409,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
public void testPayloadParamVarargs() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestPayloadParamVarargs.class.getMethod("varargs", Array.newInstance(HttpRequestOptions.class, 0)
|
||||
.getClass());
|
||||
.getClass());
|
||||
verifyTestPostOptions(method);
|
||||
}
|
||||
|
||||
|
@ -492,7 +506,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testOverriddenEndpointParameter() throws SecurityException, NoSuchMethodException {
|
||||
Method method = TestOverriddenEndpoint.class.getMethod("foo", URI.class);
|
||||
HttpRequest request = factory(TestOverriddenEndpoint.class).createRequest(method,
|
||||
new Object[] { URI.create("http://wowsa:8001") });
|
||||
new Object[] { URI.create("http://wowsa:8001") });
|
||||
assertEquals(request.getEndpoint().getHost(), "wowsa");
|
||||
assertEquals(request.getEndpoint().getPort(), 8001);
|
||||
assertEquals(request.getEndpoint().getPath(), "");
|
||||
|
@ -600,45 +614,45 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@POST
|
||||
@Path("")
|
||||
void withParamFileBinaryPart(@FormParam("name") String name,
|
||||
@PartParam(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM) File path);
|
||||
@PartParam(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM) File path);
|
||||
|
||||
@POST
|
||||
@Path("")
|
||||
void withParamByteArrayBinaryPart(
|
||||
@FormParam("name") String name,
|
||||
@PartParam(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM, filename = "{name}.tar.gz") byte[] content);
|
||||
@FormParam("name") String name,
|
||||
@PartParam(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM, filename = "{name}.tar.gz") byte[] content);
|
||||
}
|
||||
|
||||
public void testMultipartWithStringPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestMultipartForm.class.getMethod("withStringPart", String.class);
|
||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||
"foobledata");
|
||||
"foobledata");
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest,//
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"fooble\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"foobledata\r\n" + //
|
||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"fooble\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"foobledata\r\n" + //
|
||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||
}
|
||||
|
||||
public void testMultipartWithParamStringPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestMultipartForm.class.getMethod("withParamStringPart", String.class, String.class);
|
||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||
"name", "foobledata");
|
||||
"name", "foobledata");
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest,//
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"name\r\n" + // /
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"file\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"foobledata\r\n" + //
|
||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"name\r\n" + // /
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"file\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"foobledata\r\n" + //
|
||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||
}
|
||||
|
||||
public void testMultipartWithParamFilePart() throws SecurityException, NoSuchMethodException, IOException {
|
||||
|
@ -648,38 +662,38 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
file.deleteOnExit();
|
||||
|
||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||
"name", file);
|
||||
"name", file);
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest,//
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"name\r\n" + // /
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"foobledata\r\n" + //
|
||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"name\r\n" + // /
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"foobledata\r\n" + //
|
||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||
}
|
||||
|
||||
public void testMultipartWithParamByteArrayPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestMultipartForm.class.getMethod("withParamByteArrayBinaryPart", String.class, byte[].class);
|
||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||
"name", "goo".getBytes());
|
||||
"name", "goo".getBytes());
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest,//
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"name\r\n" + // /
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"file\"; filename=\"name.tar.gz\"\r\n" + //
|
||||
"Content-Type: application/octet-stream\r\n" + //
|
||||
"\r\n" + //
|
||||
"goo\r\n" + //
|
||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"name\r\n" + // /
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"file\"; filename=\"name.tar.gz\"\r\n" + //
|
||||
"Content-Type: application/octet-stream\r\n" + //
|
||||
"\r\n" + //
|
||||
"goo\r\n" + //
|
||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||
};
|
||||
|
||||
public void testMultipartWithParamFileBinaryPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||
|
@ -689,20 +703,20 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
file.deleteOnExit();
|
||||
|
||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||
"name", file);
|
||||
"name", file);
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest,//
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"name\r\n" + // /
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"\r\n" + //
|
||||
"Content-Type: application/octet-stream\r\n" + //
|
||||
"\r\n" + //
|
||||
"'(2\r\n" + //
|
||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"name\r\n" + // /
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"\r\n" + //
|
||||
"Content-Type: application/octet-stream\r\n" + //
|
||||
"\r\n" + //
|
||||
"'(2\r\n" + //
|
||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||
}
|
||||
|
||||
public interface TestPut {
|
||||
|
@ -761,7 +775,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<? extends Set<String>> testUnwrap4();
|
||||
|
||||
@Target( { ElementType.METHOD })
|
||||
@Target({ ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@HttpMethod("ROWDY")
|
||||
public @interface ROWDY {
|
||||
|
@ -816,7 +830,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
// now test that it works!
|
||||
|
||||
Function<HttpResponse, Wrapper> parser = (Function<HttpResponse, Wrapper>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))).foo, "bar");
|
||||
|
||||
|
@ -831,10 +845,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
// now test that it works!
|
||||
|
||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), ImmutableMap.of(
|
||||
"foo", "bar"));
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))),
|
||||
ImmutableMap.of("foo", "bar"));
|
||||
|
||||
}
|
||||
|
||||
|
@ -847,10 +861,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
// now test that it works!
|
||||
|
||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), ImmutableMap.of(
|
||||
"foo", "bar"));
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))),
|
||||
ImmutableMap.of("foo", "bar"));
|
||||
|
||||
}
|
||||
|
||||
|
@ -863,10 +877,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
// now test that it works!
|
||||
|
||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), ImmutableMap.of(
|
||||
"foo", "bar"));
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))),
|
||||
ImmutableMap.of("foo", "bar"));
|
||||
|
||||
}
|
||||
|
||||
|
@ -879,7 +893,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
// now test that it works!
|
||||
|
||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), "bar");
|
||||
|
||||
|
@ -894,7 +908,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
// now test that it works!
|
||||
|
||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), "bar");
|
||||
|
||||
|
@ -909,10 +923,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
// now test that it works!
|
||||
|
||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":[\"0.7.0\",\"0.7.1\"]}"))),
|
||||
ImmutableSet.of("0.7.0", "0.7.1"));
|
||||
ImmutableSet.of("0.7.0", "0.7.1"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -924,10 +938,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
// now test that it works!
|
||||
|
||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":[\"0.7.0\",\"0.7.1\"]}"))),
|
||||
ImmutableSet.of("0.7.0", "0.7.1"));
|
||||
ImmutableSet.of("0.7.0", "0.7.1"));
|
||||
}
|
||||
|
||||
static class TestRequestFilter1 implements HttpRequestFilter {
|
||||
|
@ -1014,7 +1028,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testConstantPathParam() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestConstantPathParam.class.getMethod("twoPaths", String.class, String.class);
|
||||
HttpRequest request = factory(TestConstantPathParam.class).createRequest(method,
|
||||
new Object[] { "1", "localhost" });
|
||||
new Object[] { "1", "localhost" });
|
||||
assertRequestLineEquals(request, "GET http://localhost:9999/v1/ralphie/1/localhost HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
@ -1151,7 +1165,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testBuildTwoHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method oneHeader = TestHeader.class.getMethod("twoHeader", String.class);
|
||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(oneHeader, new Object[] { "robot" })
|
||||
.getHeaders();
|
||||
.getHeaders();
|
||||
assertEquals(headers.size(), 2);
|
||||
assertEquals(headers.get("slash"), Collections.singletonList("/robot"));
|
||||
assertEquals(headers.get("hyphen"), Collections.singletonList("-robot"));
|
||||
|
@ -1169,7 +1183,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testBuildOneClassHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method oneHeader = TestClassHeader.class.getMethod("oneHeader", String.class);
|
||||
Multimap<String, String> headers = factory(TestClassHeader.class).createRequest(oneHeader,
|
||||
new Object[] { "robot" }).getHeaders();
|
||||
new Object[] { "robot" }).getHeaders();
|
||||
assertEquals(headers.size(), 1);
|
||||
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/robot"));
|
||||
}
|
||||
|
@ -1178,7 +1192,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testBuildOneHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method oneHeader = TestHeader.class.getMethod("oneHeader", String.class);
|
||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(oneHeader, new Object[] { "robot" })
|
||||
.getHeaders();
|
||||
.getHeaders();
|
||||
assertEquals(headers.size(), 1);
|
||||
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/robot"));
|
||||
}
|
||||
|
@ -1187,17 +1201,17 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testBuildTwoHeaders() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method twoHeaders = TestHeader.class.getMethod("twoHeaders", String.class, String.class);
|
||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(twoHeaders,
|
||||
new Object[] { "robot", "eggs" }).getHeaders();
|
||||
new Object[] { "robot", "eggs" }).getHeaders();
|
||||
assertEquals(headers.size(), 1);
|
||||
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/robot/eggs"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoHeadersOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||
UnsupportedEncodingException {
|
||||
UnsupportedEncodingException {
|
||||
Method twoHeadersOutOfOrder = TestHeader.class.getMethod("twoHeadersOutOfOrder", String.class, String.class);
|
||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(twoHeadersOutOfOrder,
|
||||
new Object[] { "robot", "eggs" }).getHeaders();
|
||||
new Object[] { "robot", "eggs" }).getHeaders();
|
||||
assertEquals(headers.size(), 1);
|
||||
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/eggs/robot"));
|
||||
}
|
||||
|
@ -1211,8 +1225,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@Test
|
||||
public void testQueryInOptions() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method oneQuery = TestQueryReplace.class.getMethod("queryInOptions", String.class, TestReplaceQueryOptions.class);
|
||||
String query = factory(TestQueryReplace.class).createRequest(oneQuery,
|
||||
new Object[] { "robot", new TestReplaceQueryOptions() }).getEndpoint().getQuery();
|
||||
String query = factory(TestQueryReplace.class)
|
||||
.createRequest(oneQuery, new Object[] { "robot", new TestReplaceQueryOptions() }).getEndpoint().getQuery();
|
||||
assertEquals(query, "x-amz-copy-source=/robot");
|
||||
}
|
||||
|
||||
|
@ -1220,13 +1234,13 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@POST
|
||||
@Path("/objects/{id}/action/{action}")
|
||||
ListenableFuture<String> action(@PathParam("id") String id, @PathParam("action") String action,
|
||||
@BinderParam(BindMapToMatrixParams.class) Map<String, String> options);
|
||||
@BinderParam(BindMapToMatrixParams.class) Map<String, String> options);
|
||||
}
|
||||
|
||||
public void testTestMapMatrixParams() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method method = TestMapMatrixParams.class.getMethod("action", String.class, String.class, Map.class);
|
||||
HttpRequest request = factory(TestMapMatrixParams.class).createRequest(method,
|
||||
new Object[] { "robot", "kill", ImmutableMap.of("death", "slow") });
|
||||
new Object[] { "robot", "kill", ImmutableMap.of("death", "slow") });
|
||||
assertRequestLineEquals(request, "POST http://localhost:9999/objects/robot/action/kill;death=slow HTTP/1.1");
|
||||
assertEquals(request.getHeaders().size(), 0);
|
||||
}
|
||||
|
@ -1268,7 +1282,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testBuildTwoQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method oneQuery = TestQueryReplace.class.getMethod("twoQuery", String.class);
|
||||
String query = factory(TestQueryReplace.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
||||
.getQuery();
|
||||
.getQuery();
|
||||
assertEquals(query, "slash=/robot&hyphen=-robot");
|
||||
}
|
||||
|
||||
|
@ -1284,7 +1298,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testBuildOneClassQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method oneQuery = TestClassQuery.class.getMethod("oneQuery", String.class);
|
||||
String query = factory(TestClassQuery.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
||||
.getQuery();
|
||||
.getQuery();
|
||||
assertEquals(query, "x-amz-copy-source=/robot");
|
||||
}
|
||||
|
||||
|
@ -1292,7 +1306,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testBuildOneQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method oneQuery = TestQueryReplace.class.getMethod("oneQuery", String.class);
|
||||
String query = factory(TestQueryReplace.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
||||
.getQuery();
|
||||
.getQuery();
|
||||
assertEquals(query, "x-amz-copy-source=/robot");
|
||||
}
|
||||
|
||||
|
@ -1300,16 +1314,16 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testBuildTwoQuerys() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method twoQuerys = TestQueryReplace.class.getMethod("twoQuerys", String.class, String.class);
|
||||
String query = factory(TestQueryReplace.class).createRequest(twoQuerys, new Object[] { "robot", "eggs" })
|
||||
.getEndpoint().getQuery();
|
||||
.getEndpoint().getQuery();
|
||||
assertEquals(query, "x-amz-copy-source=/robot/eggs");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoQuerysOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||
UnsupportedEncodingException {
|
||||
UnsupportedEncodingException {
|
||||
Method twoQuerysOutOfOrder = TestQueryReplace.class.getMethod("twoQuerysOutOfOrder", String.class, String.class);
|
||||
String query = factory(TestQueryReplace.class).createRequest(twoQuerysOutOfOrder,
|
||||
new Object[] { "robot", "eggs" }).getEndpoint().getQuery();
|
||||
String query = factory(TestQueryReplace.class)
|
||||
.createRequest(twoQuerysOutOfOrder, new Object[] { "robot", "eggs" }).getEndpoint().getQuery();
|
||||
assertEquals(query, "x-amz-copy-source=/eggs/robot");
|
||||
}
|
||||
|
||||
|
@ -1322,9 +1336,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@Test
|
||||
public void testMatrixInOptions() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method oneMatrix = TestMatrixReplace.class.getMethod("matrixInOptions", String.class,
|
||||
TestReplaceMatrixOptions.class);
|
||||
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix,
|
||||
new Object[] { "robot", new TestReplaceMatrixOptions() }).getEndpoint().getPath();
|
||||
TestReplaceMatrixOptions.class);
|
||||
String path = factory(TestMatrixReplace.class)
|
||||
.createRequest(oneMatrix, new Object[] { "robot", new TestReplaceMatrixOptions() }).getEndpoint().getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/robot");
|
||||
}
|
||||
|
||||
|
@ -1365,7 +1379,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testBuildTwoMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method oneMatrix = TestMatrixReplace.class.getMethod("twoMatrix", String.class);
|
||||
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
||||
.getPath();
|
||||
.getPath();
|
||||
assertEquals(path, "/;slash=/robot;hyphen=-robot");
|
||||
}
|
||||
|
||||
|
@ -1382,7 +1396,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testBuildOneClassMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method oneMatrix = TestClassMatrix.class.getMethod("oneMatrix", String.class);
|
||||
String path = factory(TestClassMatrix.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
||||
.getPath();
|
||||
.getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/robot");
|
||||
}
|
||||
|
||||
|
@ -1390,7 +1404,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testBuildOneMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method oneMatrix = TestMatrixReplace.class.getMethod("oneMatrix", String.class);
|
||||
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
||||
.getPath();
|
||||
.getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/robot");
|
||||
}
|
||||
|
||||
|
@ -1398,17 +1412,17 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testBuildTwoMatrixs() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method twoMatrixs = TestMatrixReplace.class.getMethod("twoMatrixs", String.class, String.class);
|
||||
String path = factory(TestMatrixReplace.class).createRequest(twoMatrixs, new Object[] { "robot", "eggs" })
|
||||
.getEndpoint().getPath();
|
||||
.getEndpoint().getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/robot/eggs");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoMatrixsOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||
UnsupportedEncodingException {
|
||||
UnsupportedEncodingException {
|
||||
Method twoMatrixsOutOfOrder = TestMatrixReplace.class.getMethod("twoMatrixsOutOfOrder", String.class,
|
||||
String.class);
|
||||
String path = factory(TestMatrixReplace.class).createRequest(twoMatrixsOutOfOrder,
|
||||
new Object[] { "robot", "eggs" }).getEndpoint().getPath();
|
||||
String.class);
|
||||
String path = factory(TestMatrixReplace.class)
|
||||
.createRequest(twoMatrixsOutOfOrder, new Object[] { "robot", "eggs" }).getEndpoint().getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/eggs/robot");
|
||||
}
|
||||
|
||||
|
@ -1460,7 +1474,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testPutPayloadEnclosing() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class);
|
||||
HttpRequest request = factory(TestQuery.class).createRequest(method,
|
||||
new PayloadEnclosingImpl(newStringPayload("whoops")));
|
||||
new PayloadEnclosingImpl(newStringPayload("whoops")));
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, "whoops", "application/unknown", false);
|
||||
|
@ -1478,7 +1492,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
public void testPutInputStreamPayloadEnclosingGenerateMD5() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
IOException {
|
||||
Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class);
|
||||
PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(newInputStreamPayload(toInputStream("whoops")));
|
||||
|
||||
|
@ -1537,7 +1551,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
public void testPutPayloadWithGeneratedMD5AndNoContentType() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
IOException {
|
||||
Payload payload = newStringPayload("whoops");
|
||||
calculateMD5(payload, crypto.md5());
|
||||
Method method = TestTransformers.class.getMethod("put", Payload.class);
|
||||
|
@ -1558,7 +1572,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
public void testPutInputStreamPayloadWithMD5() throws NoSuchAlgorithmException, IOException, SecurityException,
|
||||
NoSuchMethodException {
|
||||
NoSuchMethodException {
|
||||
Payload payload = newStringPayload("whoops");
|
||||
calculateMD5(payload, crypto.md5());
|
||||
Method method = TestTransformers.class.getMethod("put", Payload.class);
|
||||
|
@ -1582,9 +1596,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Class<? extends Function<HttpResponse, ?>> unwrap(RestAnnotationProcessor<T> processor,
|
||||
Method method) {
|
||||
Method method) {
|
||||
return (Class<? extends Function<HttpResponse, ?>>) RestAnnotationProcessor.getParserOrThrowException(method)
|
||||
.getTypeLiteral().getRawType();
|
||||
.getTypeLiteral().getRawType();
|
||||
}
|
||||
|
||||
public void testURI() throws SecurityException, NoSuchMethodException {
|
||||
|
@ -1620,8 +1634,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void oneTransformerWithContext() throws SecurityException, NoSuchMethodException {
|
||||
RestAnnotationProcessor<TestTransformers> processor = factory(TestTransformers.class);
|
||||
Method method = TestTransformers.class.getMethod("oneTransformerWithContext");
|
||||
GeneratedHttpRequest<TestTransformers> request = new GeneratedHttpRequest<TestTransformers>("GET", URI
|
||||
.create("http://localhost"), TestTransformers.class, method);
|
||||
GeneratedHttpRequest<TestTransformers> request = new GeneratedHttpRequest<TestTransformers>("GET",
|
||||
URI.create("http://localhost"), TestTransformers.class, method);
|
||||
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
|
||||
assertEquals(transformer.getClass(), ReturnStringIf200Context.class);
|
||||
assertEquals(((ReturnStringIf200Context) transformer).request, request);
|
||||
|
@ -1662,7 +1676,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@PUT
|
||||
@Path("/{id}")
|
||||
ListenableFuture<String> put(@PathParam("id") @ParamParser(FirstCharacter.class) String id,
|
||||
@BinderParam(BindToStringPayload.class) String payload);
|
||||
@BinderParam(BindToStringPayload.class) String payload);
|
||||
|
||||
@PUT
|
||||
@Path("/{id}")
|
||||
|
@ -1674,7 +1688,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@Headers(keys = "foo", values = "--{id}--")
|
||||
@ResponseParser(ReturnTrueIf2xx.class)
|
||||
ListenableFuture<String> putHeader(@PathParam("id") String id,
|
||||
@BinderParam(BindToStringPayload.class) String payload);
|
||||
@BinderParam(BindToStringPayload.class) String payload);
|
||||
}
|
||||
|
||||
public void testCreateGetVarArgOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException {
|
||||
|
@ -1688,8 +1702,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||
assertEquals(request.getHeaders().size(), 2);
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections.singletonList("localhost"));
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections.singletonList(dateService
|
||||
.rfc822DateFormat(date)));
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE),
|
||||
Collections.singletonList(dateService.rfc822DateFormat(date)));
|
||||
}
|
||||
|
||||
public void testCreateGetOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException {
|
||||
|
@ -1702,8 +1716,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||
assertEquals(request.getHeaders().size(), 2);
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections.singletonList("localhost"));
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections.singletonList(dateService
|
||||
.rfc822DateFormat(date)));
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE),
|
||||
Collections.singletonList(dateService.rfc822DateFormat(date)));
|
||||
}
|
||||
|
||||
public class PrefixOptions extends BaseHttpRequestOptions {
|
||||
|
@ -1766,7 +1780,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
@Test(dataProvider = "strings")
|
||||
public void testCreateGetRequest(String key) throws SecurityException, NoSuchMethodException,
|
||||
UnsupportedEncodingException {
|
||||
UnsupportedEncodingException {
|
||||
Method method = TestRequest.class.getMethod("get", String.class, String.class);
|
||||
HttpRequest request = factory(TestRequest.class).createRequest(method, new Object[] { key, "localhost" });
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
|
@ -1809,7 +1823,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testVirtualHostMethod() throws SecurityException, NoSuchMethodException {
|
||||
Method method = TestVirtualHostMethod.class.getMethod("get", String.class, String.class);
|
||||
HttpRequest request = factory(TestVirtualHostMethod.class).createRequest(method,
|
||||
new Object[] { "1", "localhost" });
|
||||
new Object[] { "1", "localhost" });
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/1");
|
||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||
|
@ -1874,7 +1888,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testOneHeader() throws SecurityException, NoSuchMethodException {
|
||||
Method method = TestHeaders.class.getMethod("oneHeader", String.class);
|
||||
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
||||
ImmutableMultimap.<String, String> of().entries(), method, "robot");
|
||||
ImmutableMultimap.<String, String> of().entries(), method, "robot");
|
||||
assertEquals(headers.size(), 1);
|
||||
assertEquals(headers.get("header"), Collections.singletonList("robot"));
|
||||
}
|
||||
|
@ -1883,7 +1897,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testOneIntHeader() throws SecurityException, NoSuchMethodException {
|
||||
Method method = TestHeaders.class.getMethod("oneIntHeader", int.class);
|
||||
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
||||
ImmutableMultimap.<String, String> of().entries(), method, 1);
|
||||
ImmutableMultimap.<String, String> of().entries(), method, 1);
|
||||
assertEquals(headers.size(), 1);
|
||||
assertEquals(headers.get("header"), Collections.singletonList("1"));
|
||||
}
|
||||
|
@ -1892,7 +1906,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testTwoDifferentHeaders() throws SecurityException, NoSuchMethodException {
|
||||
Method method = TestHeaders.class.getMethod("twoDifferentHeaders", String.class, String.class);
|
||||
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
||||
ImmutableMultimap.<String, String> of().entries(), method, "robot", "egg");
|
||||
ImmutableMultimap.<String, String> of().entries(), method, "robot", "egg");
|
||||
assertEquals(headers.size(), 2);
|
||||
assertEquals(headers.get("header1"), Collections.singletonList("robot"));
|
||||
assertEquals(headers.get("header2"), Collections.singletonList("egg"));
|
||||
|
@ -1902,7 +1916,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testTwoSameHeaders() throws SecurityException, NoSuchMethodException {
|
||||
Method method = TestHeaders.class.getMethod("twoSameHeaders", String.class, String.class);
|
||||
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
||||
ImmutableMultimap.<String, String> of().entries(), method, "robot", "egg");
|
||||
ImmutableMultimap.<String, String> of().entries(), method, "robot", "egg");
|
||||
assertEquals(headers.size(), 2);
|
||||
Collection<String> values = headers.get("header");
|
||||
assert values.contains("robot");
|
||||
|
@ -1925,7 +1939,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
@GET
|
||||
void twoEndpointParams(@EndpointParam(parser = ConvertTwoToURI.class) String EndpointParam1,
|
||||
@EndpointParam(parser = ConvertTwoToURI.class) String EndpointParam2);
|
||||
@EndpointParam(parser = ConvertTwoToURI.class) String EndpointParam2);
|
||||
|
||||
@Singleton
|
||||
public static class ConvertTwoToURI implements Function<Object, URI> {
|
||||
|
@ -1945,7 +1959,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testOneEndpointParam() throws SecurityException, NoSuchMethodException {
|
||||
Method method = TestEndpointParams.class.getMethod("oneEndpointParam", String.class);
|
||||
URI uri = factory(TestEndpointParams.class).getEndpointInParametersOrNull(method, new Object[] { "robot" },
|
||||
injector);
|
||||
injector);
|
||||
assertEquals(uri, URI.create("robot"));
|
||||
|
||||
}
|
||||
|
@ -1955,7 +1969,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testTwoDifferentEndpointParams() throws SecurityException, NoSuchMethodException {
|
||||
Method method = TestEndpointParams.class.getMethod("twoEndpointParams", String.class, String.class);
|
||||
URI uri = factory(TestEndpointParams.class).getEndpointInParametersOrNull(method,
|
||||
new Object[] { "robot", "egg" }, injector);
|
||||
new Object[] { "robot", "egg" }, injector);
|
||||
assertEquals(uri, URI.create("robot/egg"));
|
||||
}
|
||||
|
||||
|
@ -1967,12 +1981,12 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@PUT
|
||||
@Path("/{foo}")
|
||||
public ListenableFuture<Void> putWithPath(@PathParam("foo") String path,
|
||||
@BinderParam(BindToStringPayload.class) String content);
|
||||
@BinderParam(BindToStringPayload.class) String content);
|
||||
|
||||
@PUT
|
||||
@Path("")
|
||||
public void twoEntities(@BinderParam(BindToStringPayload.class) String payload1,
|
||||
@BinderParam(BindToStringPayload.class) String payload2);
|
||||
@BinderParam(BindToStringPayload.class) String payload2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2070,23 +2084,23 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testBuildTwoForms() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method twoForms = TestFormReplace.class.getMethod("twoForms", String.class, String.class);
|
||||
Object form = factory(TestFormReplace.class).createRequest(twoForms, "robot", "eggs").getPayload()
|
||||
.getRawContent();
|
||||
.getRawContent();
|
||||
assertEquals(form, "x-amz-copy-source=/robot/eggs");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoFormsOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||
UnsupportedEncodingException {
|
||||
UnsupportedEncodingException {
|
||||
Method twoFormsOutOfOrder = TestFormReplace.class.getMethod("twoFormsOutOfOrder", String.class, String.class);
|
||||
Object form = factory(TestFormReplace.class).createRequest(twoFormsOutOfOrder, "robot", "eggs").getPayload()
|
||||
.getRawContent();
|
||||
.getRawContent();
|
||||
assertEquals(form, "x-amz-copy-source=/eggs/robot");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> RestAnnotationProcessor<T> factory(Class<T> clazz) {
|
||||
return ((RestAnnotationProcessor<T>) injector.getInstance(Key.get(newParameterizedType(
|
||||
RestAnnotationProcessor.class, clazz))));
|
||||
RestAnnotationProcessor.class, clazz))));
|
||||
}
|
||||
|
||||
DateService dateService = new SimpleDateFormatDateService();
|
||||
|
@ -2094,16 +2108,15 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@BeforeClass
|
||||
void setupFactory() {
|
||||
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo", null,
|
||||
String.class, Integer.class, ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(),
|
||||
new AbstractModule() {
|
||||
String.class, Integer.class,
|
||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(URI.class).annotatedWith(Localhost2.class).toInstance(
|
||||
URI.create("http://localhost:1111"));
|
||||
}
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(URI.class).annotatedWith(Localhost2.class).toInstance(URI.create("http://localhost:1111"));
|
||||
}
|
||||
|
||||
}));
|
||||
}));
|
||||
|
||||
injector = createContextBuilder(contextSpec).buildInjector();
|
||||
parserFactory = injector.getInstance(ParseSax.Factory.class);
|
||||
|
|
|
@ -300,7 +300,7 @@ public class ElasticStackAsyncClientTest extends RestClientTest<ElasticStackAsyn
|
|||
|
||||
assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/drives/100/write HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
|
||||
assertPayloadEquals(httpRequest, "", MediaType.APPLICATION_OCTET_STREAM, false);
|
||||
assertPayloadEquals(httpRequest, "foo", MediaType.APPLICATION_OCTET_STREAM, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -316,7 +316,7 @@ public class ElasticStackAsyncClientTest extends RestClientTest<ElasticStackAsyn
|
|||
|
||||
assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/drives/100/write/2048 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
|
||||
assertPayloadEquals(httpRequest, "", MediaType.APPLICATION_OCTET_STREAM, false);
|
||||
assertPayloadEquals(httpRequest, "foo", MediaType.APPLICATION_OCTET_STREAM, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
|
|
@ -76,7 +76,8 @@ public class ElasticStackClientLiveTest extends
|
|||
|
||||
// TODO block until complete
|
||||
System.err.println("state " + client.getDriveInfo(info2.getUuid()));
|
||||
assertEquals(Utils.toStringAndClose(client.readDrive(info2.getUuid()).getInput()), "foo");
|
||||
assertEquals(Utils.toStringAndClose(client.readDrive(info2.getUuid(),
|
||||
ReadDriveOptions.Builder.offset(0).size(3)).getInput()), "foo");
|
||||
} finally {
|
||||
client.destroyDrive(info2.getUuid());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue