fixed built-in http client

This commit is contained in:
Adrian Cole 2011-01-25 10:23:58 -08:00
parent 0a769ca6f5
commit 1df15209ec
3 changed files with 190 additions and 182 deletions

View File

@ -47,6 +47,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
String container = getContainerName();
try {
context.getBlobStore().putBlob(container, blob);
assertConsistencyAwareContainerSize(container, 1);
HttpRequest request = context.getSigner().signRemoveBlob(container, name);
assertEquals(request.getFilters().size(), 0);
context.utils().http().invoke(request);
@ -67,6 +68,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
String container = getContainerName();
try {
context.getBlobStore().putBlob(container, blob);
assertConsistencyAwareContainerSize(container, 1);
HttpRequest request = context.getSigner().signGetBlob(container, name);
assertEquals(request.getFilters().size(), 0);
assertEquals(Strings2.toStringAndClose(context.utils().http().invoke(request).getPayload().getInput()), text);
@ -88,7 +90,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
HttpRequest request = context.getSigner().signPutBlob(container, blob);
assertEquals(request.getFilters().size(), 0);
Strings2.toStringAndClose(context.utils().http().invoke(request).getPayload().getInput());
assert context.getBlobStore().blobExists(container, name);
assertConsistencyAwareContainerSize(container, 1);
} finally {
returnContainer(container);
}

View File

@ -435,6 +435,8 @@ public class RestAnnotationProcessor<T> {
Multimap<String, String> queryParams = addQueryParams(tokenValues.entries(), method, args);
Multimap<String, String> matrixParams = addMatrixParams(tokenValues.entries(), method, args);
Multimap<String, String> headers = buildHeaders(tokenValues.entries(), method, args);
if (r != null)
headers.putAll(r.getHeaders());
if (shouldAddHostHeader(method))
headers.put(HOST, endpoint.getHost());

View File

@ -209,8 +209,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
}
@SuppressWarnings("unchecked")
public void testDelegateAsyncIncludesVersion() throws SecurityException, NoSuchMethodException, InterruptedException,
ExecutionException {
public void testDelegateAsyncIncludesVersion() throws SecurityException, NoSuchMethodException,
InterruptedException, ExecutionException {
Injector child = injectorForClient();
TransformingHttpCommandExecutorService mock = child.getInstance(TransformingHttpCommandExecutorService.class);
@ -224,8 +224,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
}
AsyncCaller caller = child.getInstance(AsyncCaller.class);
expect(mock.submit(requestLineEquals("GET http://localhost:9999/client/1/foo HTTP/1.1"), eq(function))).andReturn(
createNiceMock(ListenableFuture.class)).atLeastOnce();
expect(mock.submit(requestLineEquals("GET http://localhost:9999/client/1/foo HTTP/1.1"), eq(function)))
.andReturn(createNiceMock(ListenableFuture.class)).atLeastOnce();
replay(mock);
caller.getCallee().onePath("foo");
@ -254,7 +254,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);
@ -268,8 +268,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
}
Caller caller = child.getInstance(Caller.class);
expect(mock.submit(requestLineEquals("GET http://localhost:1111/client/1/foo HTTP/1.1"), eq(function))).andReturn(
Futures.<Void> immediateFuture(null)).atLeastOnce();
expect(mock.submit(requestLineEquals("GET http://localhost:1111/client/1/foo HTTP/1.1"), eq(function)))
.andReturn(Futures.<Void> immediateFuture(null)).atLeastOnce();
replay(mock);
caller.getCallee().onePath("foo");
@ -281,8 +281,8 @@ 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()));
null, Caller.class, AsyncCaller.class, ImmutableSet.<Module> of(new MockModule(),
new NullLoggingModule(), new CallerCalleeModule()));
return createContextBuilder(contextSpec).buildInjector();
@ -297,7 +297,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
};
@Target({ ElementType.METHOD })
@Target( { ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@javax.ws.rs.HttpMethod("FOO")
public @interface FOO {
@ -332,10 +332,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);
}
@ -369,17 +369,17 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
public interface TestPayloadParamVarargs {
@POST
public void varargs(HttpRequestOptions... options);
public void varargs(HttpRequestOptions... options);
@POST
public void post(HttpRequestOptions options);
public void post(HttpRequestOptions options);
@POST
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public void post();
@POST
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public void post(Payload payload);
}
@ -406,7 +406,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);
}
@ -445,7 +445,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
public class TestCustomMethod {
@FOO
public void foo() {
public void foo() {
}
}
@ -463,7 +463,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
public class TestOverridden implements Parent {
@POST
public void foo() {
public void foo() {
}
}
@ -479,11 +479,11 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
@POST
@Endpoint(Localhost2.class)
public void foo() {
public void foo() {
}
@POST
public void foo(@EndpointParam URI endpoint) {
public void foo(@EndpointParam URI endpoint) {
}
}
@ -499,7 +499,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(), "");
@ -508,10 +508,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
public interface TestPost {
@POST
void post(@Nullable @BinderParam(BindToStringPayload.class) String content);
void post(@Nullable @BinderParam(BindToStringPayload.class) String content);
@POST
public void postAsJson(@BinderParam(BindToJsonPayload.class) String content);
public void postAsJson(@BinderParam(BindToJsonPayload.class) String content);
@POST
@Path("/{foo}")
@ -594,54 +594,54 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
static interface TestMultipartForm {
@POST
void withStringPart(@PartParam(name = "fooble") String path);
void withStringPart(@PartParam(name = "fooble") String path);
@POST
void withParamStringPart(@FormParam("name") String name, @PartParam(name = "file") String path);
void withParamStringPart(@FormParam("name") String name, @PartParam(name = "file") String path);
@POST
void withParamFilePart(@FormParam("name") String name, @PartParam(name = "file") File path);
void withParamFilePart(@FormParam("name") String name, @PartParam(name = "file") File path);
@POST
void withParamFileBinaryPart(@FormParam("name") String name,
@PartParam(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM) File path);
void withParamFileBinaryPart(@FormParam("name") String name,
@PartParam(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM) File path);
@POST
void withParamByteArrayBinaryPart(
@FormParam("name") String name,
@PartParam(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM, filename = "{name}.tar.gz") byte[] content);
void withParamByteArrayBinaryPart(
@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 {
@ -651,38 +651,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 {
@ -692,20 +692,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 {
@ -764,7 +764,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 {
@ -819,7 +819,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");
@ -834,10 +834,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"));
}
@ -850,10 +850,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"));
}
@ -866,10 +866,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"));
}
@ -882,7 +882,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");
@ -897,7 +897,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");
@ -912,10 +912,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")
@ -927,10 +927,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 {
@ -948,11 +948,11 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
@RequestFilters(TestRequestFilter1.class)
static interface TestRequestFilter {
@GET
@RequestFilters(TestRequestFilter2.class)
@RequestFilters(TestRequestFilter2.class)
public void get();
@GET
@OverrideRequestFilters
@OverrideRequestFilters
@RequestFilters(TestRequestFilter2.class)
public void getOverride();
@ -979,9 +979,12 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
public void testRequestFilterOverrideOnRequest() throws SecurityException, NoSuchMethodException {
Method method = TestRequestFilter.class.getMethod("getOverride", HttpRequest.class);
HttpRequest request = factory(TestRequestFilter.class).createRequest(method,
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build());
HttpRequest request = factory(TestRequestFilter.class).createRequest(
method,
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).headers(
ImmutableMultimap.of("foo", "bar")).build());
assertEquals(request.getFilters().size(), 1);
assertEquals(request.getHeaders().size(), 1);
assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter2.class);
}
@ -1027,7 +1030,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);
@ -1164,7 +1167,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"));
@ -1182,7 +1185,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"));
}
@ -1191,7 +1194,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"));
}
@ -1200,17 +1203,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"));
}
@ -1224,8 +1227,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");
}
@ -1233,13 +1236,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);
}
@ -1281,7 +1284,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");
}
@ -1297,7 +1300,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");
}
@ -1305,7 +1308,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");
}
@ -1313,16 +1316,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");
}
@ -1335,9 +1338,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");
}
@ -1378,7 +1381,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");
}
@ -1395,7 +1398,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");
}
@ -1403,7 +1406,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");
}
@ -1411,59 +1414,59 @@ 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");
}
public interface TestTransformers {
@GET
int noTransformer();
int noTransformer();
@GET
@ResponseParser(ReturnStringIf2xx.class)
@ResponseParser(ReturnStringIf2xx.class)
void oneTransformer();
@GET
@ResponseParser(ReturnStringIf200Context.class)
@ResponseParser(ReturnStringIf200Context.class)
void oneTransformerWithContext();
@GET
InputStream inputStream();
InputStream inputStream();
@GET
ListenableFuture<InputStream> futureInputStream();
ListenableFuture<InputStream> futureInputStream();
@GET
URI uri();
URI uri();
@GET
ListenableFuture<URI> futureUri();
ListenableFuture<URI> futureUri();
@PUT
ListenableFuture<Void> put(Payload payload);
ListenableFuture<Void> put(Payload payload);
@PUT
@Headers(keys = "Transfer-Encoding", values = "chunked")
@Headers(keys = "Transfer-Encoding", values = "chunked")
ListenableFuture<Void> putXfer(Payload payload);
@PUT
ListenableFuture<Void> put(PayloadEnclosing payload);
ListenableFuture<Void> put(PayloadEnclosing payload);
}
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);
@ -1481,10 +1484,10 @@ 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(Strings2.toInputStream("whoops")));
PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(newInputStreamPayload(Strings2
.toInputStream("whoops")));
calculateMD5(payloadEnclosing, crypto.md5());
HttpRequest request = factory(TestQuery.class).createRequest(method, payloadEnclosing);
@ -1541,7 +1544,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);
@ -1562,7 +1565,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);
@ -1586,9 +1589,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 {
@ -1604,7 +1607,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
}
public static class ReturnStringIf200Context extends ReturnStringIf2xx implements
InvocationContext<ReturnStringIf200Context> {
InvocationContext<ReturnStringIf200Context> {
public HttpRequest request;
@ -1626,8 +1629,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
RestAnnotationProcessor<TestTransformers> processor = factory(TestTransformers.class);
Method method = TestTransformers.class.getMethod("oneTransformerWithContext");
GeneratedHttpRequest<TestTransformers> request = GeneratedHttpRequest.<TestTransformers> builder().method("GET")
.endpoint(URI.create("http://localhost")).declaring(TestTransformers.class).javaMethod(method)
.args(new Object[] {}).build();
.endpoint(URI.create("http://localhost")).declaring(TestTransformers.class).javaMethod(method).args(
new Object[] {}).build();
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
assertEquals(transformer.getClass(), ReturnStringIf200Context.class);
assertEquals(((ReturnStringIf200Context) transformer).request, request);
@ -1668,7 +1671,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}")
@ -1680,7 +1683,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 {
@ -1694,8 +1697,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 {
@ -1708,8 +1711,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 {
@ -1772,7 +1775,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");
@ -1815,7 +1818,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);
@ -1880,7 +1883,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"));
}
@ -1889,7 +1892,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"));
}
@ -1898,7 +1901,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"));
@ -1908,7 +1911,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");
@ -1931,7 +1934,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> {
@ -1951,7 +1954,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"));
}
@ -1961,22 +1964,22 @@ 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"));
}
public interface TestPayload {
@PUT
public void put(@BinderParam(BindToStringPayload.class) String content);
public void put(@BinderParam(BindToStringPayload.class) String content);
@PUT
@Path("/{foo}")
public ListenableFuture<Void> putWithPath(@PathParam("foo") String path,
@BinderParam(BindToStringPayload.class) String content);
@BinderParam(BindToStringPayload.class) String content);
@PUT
public void twoEntities(@BinderParam(BindToStringPayload.class) String payload1,
@BinderParam(BindToStringPayload.class) String payload2);
public void twoEntities(@BinderParam(BindToStringPayload.class) String payload1,
@BinderParam(BindToStringPayload.class) String payload2);
}
@Test
@ -2074,23 +2077,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();
@ -2098,15 +2101,16 @@ 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);