diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index 3b61dd877a..725f0c5b43 100755 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -166,7 +166,7 @@ public class RestAnnotationProcessor { static final Map delegationMap = newHashMap(); static Map>> createMethodToIndexOfParamToAnnotation( - final Class annotation) { + final Class annotation) { return new MapMaker().makeComputingMap(new Function>>() { public Map> apply(final Method method) { return new MapMaker().makeComputingMap(new GetAnnotationsForMethodParameterIndex(method, annotation)); @@ -200,7 +200,7 @@ public class RestAnnotationProcessor { } private static final Class optionsVarArgsClass = new HttpRequestOptions[] {} - .getClass(); + .getClass(); private static final Function, ? extends Part> ENTRY_TO_PART = new Function, Part>() { @@ -212,17 +212,17 @@ public class RestAnnotationProcessor { }; private final Map> methodToIndexesOfOptions = new MapMaker() - .makeComputingMap(new Function>() { - public Set apply(final Method method) { - Set 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>() { + public Set apply(final Method method) { + Set 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 { @VisibleForTesting public static Function createResponseParser(ParseSax.Factory parserFactory, Injector injector, - Method method, HttpRequest request) { + Method method, HttpRequest request) { Function transformer; Class> handler = getSaxResponseParserClassOrNull(method); if (handler != null) { @@ -261,7 +261,7 @@ public class RestAnnotationProcessor { @VisibleForTesting public static Function 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 { @SuppressWarnings("unchecked") @Inject public RestAnnotationProcessor(Injector injector, ParseSax.Factory parserFactory, HttpUtils utils, - TypeLiteral typeLiteral) { + TypeLiteral typeLiteral) { this.declaring = (Class) typeLiteral.getRawType(); this.injector = injector; this.parserFactory = parserFactory; @@ -387,7 +387,7 @@ public class RestAnnotationProcessor { public GeneratedHttpRequest 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 { } GeneratedHttpRequest request = new GeneratedHttpRequest(httpMethod, endpoint, skips, declaring, method, - args); + args); addHostHeaderIfAnnotatedWithVirtualHost(headers, request.getEndpoint().getHost(), method); addFiltersIfAnnotated(method, request); @@ -472,8 +472,9 @@ public class RestAnnotationProcessor { } 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 { } public static URI replaceQuery(Provider uriBuilderProvider, URI in, String newQuery, - @Nullable Comparator> sorter, char... skips) { + @Nullable Comparator> 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> 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 { } private Multimap addFormParams(Collection> tokenValues, Method method, - Object... args) { + Object... args) { Multimap formMap = LinkedListMultimap.create(); if (declaring.isAnnotationPresent(FormParams.class)) { FormParams form = declaring.getAnnotation(FormParams.class); @@ -539,7 +540,7 @@ public class RestAnnotationProcessor { } private Multimap addQueryParams(Collection> tokenValues, Method method, - Object... args) { + Object... args) { Multimap queryMap = LinkedListMultimap.create(); if (declaring.isAnnotationPresent(QueryParams.class)) { QueryParams query = declaring.getAnnotation(QueryParams.class); @@ -558,7 +559,7 @@ public class RestAnnotationProcessor { } private void addForm(Multimap formParams, FormParams form, - Collection> tokenValues) { + Collection> 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 { } private void addMapPayload(Map postParams, MapPayloadParams mapDefaults, - Collection> tokenValues) { + Collection> 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 { } private void addQuery(Multimap queryParams, QueryParams query, - Collection> tokenValues) { + Collection> 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 { @VisibleForTesting public static URI getEndpointInParametersOrNull(Method method, final Object[] args, Injector injector) { Map> map = indexWithAtLeastOneAnnotation(method, - methodToIndexOfParamToEndpointParamAnnotations); + methodToIndexOfParamToEndpointParamAnnotations); if (map.size() >= 1 && args.length > 0) { EndpointParam firstAnnotation = (EndpointParam) get(get(map.values(), 0), 0); Function parser = injector.getInstance(firstAnnotation.parser()); @@ -633,8 +634,8 @@ public class RestAnnotationProcessor { 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 { }); 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 { 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 { parserType = Types.newParameterizedType(ParseJson.class, returnVal); return (Key>) 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 { } 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 { Set 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 { mapBinder.bindToRequest(request, mapParams); } else { OUTER: for (Entry> entry : filterValues( - methodToIndexOfParamToDecoratorParamAnnotation.get(request.getJavaMethod()), - new Predicate>() { - public boolean apply(Set input) { - return input.size() >= 1; - } - }).entrySet()) { + methodToIndexOfParamToDecoratorParamAnnotation.get(request.getJavaMethod()), + new Predicate>() { + public boolean apply(Set 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 { } public static Map> indexWithOnlyOneAnnotation(Method method, String description, - Map>> toRefine) { + Map>> toRefine) { Map> 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> indexWithAtLeastOneAnnotation(Method method, - Map>> toRefine) { + Map>> toRefine) { Map> indexToPayloadAnnotation = filterValues(toRefine.get(method), - new Predicate>() { - public boolean apply(Set input) { - return input.size() == 1; - } - }); + new Predicate>() { + public boolean apply(Set input) { + return input.size() == 1; + } + }); return indexToPayloadAnnotation; } @@ -908,7 +909,7 @@ public class RestAnnotationProcessor { } 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 { } public Multimap buildHeaders(Collection> tokenValues, Method method, - final Object... args) { + final Object... args) { Multimap headers = LinkedHashMultimap.create(); addHeaderIfAnnotationPresentOnMethod(headers, method, tokenValues); Map> indexToHeaderParam = methodToIndexOfParamToHeaderParamAnnotations.get(method); @@ -967,7 +968,7 @@ public class RestAnnotationProcessor { } public void addHeaderIfAnnotationPresentOnMethod(Multimap headers, Method method, - Collection> tokenValues) { + Collection> tokenValues) { if (declaring.isAnnotationPresent(Headers.class)) { Headers header = declaring.getAnnotation(Headers.class); addHeader(headers, header, tokenValues); @@ -979,7 +980,7 @@ public class RestAnnotationProcessor { } private void addHeader(Multimap headers, Headers header, - Collection> tokenValues) { + Collection> tokenValues) { for (int i = 0; i < header.keys().length; i++) { String value = header.values()[i]; value = replaceTokens(value, tokenValues); diff --git a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java index b107347cb6..b0bf75a07a 100755 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -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. immediateFuture(null)).atLeastOnce(); + Futures. immediateFuture(null)).atLeastOnce(); replay(mock); caller.getCallee().onePath("foo"); @@ -278,9 +279,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { private Injector injectorForClient() { - RestContextSpec contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo", null, - Caller.class, AsyncCaller.class, ImmutableSet. of(new MockModule(), new NullLoggingModule(), - new CallerCalleeModule())); + RestContextSpec contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo", + null, Caller.class, AsyncCaller.class, + ImmutableSet. 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 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 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 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 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 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> 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 parser = (Function) 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> parser = (Function>) 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> parser = (Function>) 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> parser = (Function>) 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> parser = (Function>) 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> parser = (Function>) 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> parser = (Function>) 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> parser = (Function>) 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 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 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 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 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 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 action(@PathParam("id") String id, @PathParam("action") String action, - @BinderParam(BindMapToMatrixParams.class) Map options); + @BinderParam(BindMapToMatrixParams.class) Map 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 Class> unwrap(RestAnnotationProcessor processor, - Method method) { + Method method) { return (Class>) 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 processor = factory(TestTransformers.class); Method method = TestTransformers.class.getMethod("oneTransformerWithContext"); - GeneratedHttpRequest request = new GeneratedHttpRequest("GET", URI - .create("http://localhost"), TestTransformers.class, method); + GeneratedHttpRequest request = new GeneratedHttpRequest("GET", + URI.create("http://localhost"), TestTransformers.class, method); Function 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 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 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 headers = factory(TestHeaders.class).buildHeaders( - ImmutableMultimap. of().entries(), method, "robot"); + ImmutableMultimap. 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 headers = factory(TestHeaders.class).buildHeaders( - ImmutableMultimap. of().entries(), method, 1); + ImmutableMultimap. 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 headers = factory(TestHeaders.class).buildHeaders( - ImmutableMultimap. of().entries(), method, "robot", "egg"); + ImmutableMultimap. 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 headers = factory(TestHeaders.class).buildHeaders( - ImmutableMultimap. of().entries(), method, "robot", "egg"); + ImmutableMultimap. of().entries(), method, "robot", "egg"); assertEquals(headers.size(), 2); Collection 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 { @@ -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 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 RestAnnotationProcessor factory(Class clazz) { return ((RestAnnotationProcessor) 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 contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo", null, - String.class, Integer.class, ImmutableSet. of(new MockModule(), new NullLoggingModule(), - new AbstractModule() { + String.class, Integer.class, + ImmutableSet. 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); diff --git a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackAsyncClientTest.java b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackAsyncClientTest.java index b3ab118918..ae372f4216 100644 --- a/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackAsyncClientTest.java +++ b/sandbox/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackAsyncClientTest.java @@ -300,7 +300,7 @@ public class ElasticStackAsyncClientTest extends RestClientTest