mirror of https://github.com/apache/jclouds.git
fixed built-in http client
This commit is contained in:
parent
0a769ca6f5
commit
1df15209ec
|
@ -47,6 +47,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
String container = getContainerName();
|
String container = getContainerName();
|
||||||
try {
|
try {
|
||||||
context.getBlobStore().putBlob(container, blob);
|
context.getBlobStore().putBlob(container, blob);
|
||||||
|
assertConsistencyAwareContainerSize(container, 1);
|
||||||
HttpRequest request = context.getSigner().signRemoveBlob(container, name);
|
HttpRequest request = context.getSigner().signRemoveBlob(container, name);
|
||||||
assertEquals(request.getFilters().size(), 0);
|
assertEquals(request.getFilters().size(), 0);
|
||||||
context.utils().http().invoke(request);
|
context.utils().http().invoke(request);
|
||||||
|
@ -67,6 +68,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
String container = getContainerName();
|
String container = getContainerName();
|
||||||
try {
|
try {
|
||||||
context.getBlobStore().putBlob(container, blob);
|
context.getBlobStore().putBlob(container, blob);
|
||||||
|
assertConsistencyAwareContainerSize(container, 1);
|
||||||
HttpRequest request = context.getSigner().signGetBlob(container, name);
|
HttpRequest request = context.getSigner().signGetBlob(container, name);
|
||||||
assertEquals(request.getFilters().size(), 0);
|
assertEquals(request.getFilters().size(), 0);
|
||||||
assertEquals(Strings2.toStringAndClose(context.utils().http().invoke(request).getPayload().getInput()), text);
|
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);
|
HttpRequest request = context.getSigner().signPutBlob(container, blob);
|
||||||
assertEquals(request.getFilters().size(), 0);
|
assertEquals(request.getFilters().size(), 0);
|
||||||
Strings2.toStringAndClose(context.utils().http().invoke(request).getPayload().getInput());
|
Strings2.toStringAndClose(context.utils().http().invoke(request).getPayload().getInput());
|
||||||
assert context.getBlobStore().blobExists(container, name);
|
assertConsistencyAwareContainerSize(container, 1);
|
||||||
} finally {
|
} finally {
|
||||||
returnContainer(container);
|
returnContainer(container);
|
||||||
}
|
}
|
||||||
|
|
|
@ -435,6 +435,8 @@ public class RestAnnotationProcessor<T> {
|
||||||
Multimap<String, String> queryParams = addQueryParams(tokenValues.entries(), method, args);
|
Multimap<String, String> queryParams = addQueryParams(tokenValues.entries(), method, args);
|
||||||
Multimap<String, String> matrixParams = addMatrixParams(tokenValues.entries(), method, args);
|
Multimap<String, String> matrixParams = addMatrixParams(tokenValues.entries(), method, args);
|
||||||
Multimap<String, String> headers = buildHeaders(tokenValues.entries(), method, args);
|
Multimap<String, String> headers = buildHeaders(tokenValues.entries(), method, args);
|
||||||
|
if (r != null)
|
||||||
|
headers.putAll(r.getHeaders());
|
||||||
|
|
||||||
if (shouldAddHostHeader(method))
|
if (shouldAddHostHeader(method))
|
||||||
headers.put(HOST, endpoint.getHost());
|
headers.put(HOST, endpoint.getHost());
|
||||||
|
|
|
@ -209,8 +209,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testDelegateAsyncIncludesVersion() throws SecurityException, NoSuchMethodException, InterruptedException,
|
public void testDelegateAsyncIncludesVersion() throws SecurityException, NoSuchMethodException,
|
||||||
ExecutionException {
|
InterruptedException, ExecutionException {
|
||||||
Injector child = injectorForClient();
|
Injector child = injectorForClient();
|
||||||
TransformingHttpCommandExecutorService mock = child.getInstance(TransformingHttpCommandExecutorService.class);
|
TransformingHttpCommandExecutorService mock = child.getInstance(TransformingHttpCommandExecutorService.class);
|
||||||
|
|
||||||
|
@ -224,8 +224,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncCaller caller = child.getInstance(AsyncCaller.class);
|
AsyncCaller caller = child.getInstance(AsyncCaller.class);
|
||||||
expect(mock.submit(requestLineEquals("GET http://localhost:9999/client/1/foo HTTP/1.1"), eq(function))).andReturn(
|
expect(mock.submit(requestLineEquals("GET http://localhost:9999/client/1/foo HTTP/1.1"), eq(function)))
|
||||||
createNiceMock(ListenableFuture.class)).atLeastOnce();
|
.andReturn(createNiceMock(ListenableFuture.class)).atLeastOnce();
|
||||||
replay(mock);
|
replay(mock);
|
||||||
|
|
||||||
caller.getCallee().onePath("foo");
|
caller.getCallee().onePath("foo");
|
||||||
|
@ -254,7 +254,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDelegateWithOverridingEndpoint() throws SecurityException, NoSuchMethodException,
|
public void testDelegateWithOverridingEndpoint() throws SecurityException, NoSuchMethodException,
|
||||||
InterruptedException, ExecutionException {
|
InterruptedException, ExecutionException {
|
||||||
Injector child = injectorForClient();
|
Injector child = injectorForClient();
|
||||||
TransformingHttpCommandExecutorService mock = child.getInstance(TransformingHttpCommandExecutorService.class);
|
TransformingHttpCommandExecutorService mock = child.getInstance(TransformingHttpCommandExecutorService.class);
|
||||||
|
|
||||||
|
@ -268,8 +268,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
Caller caller = child.getInstance(Caller.class);
|
Caller caller = child.getInstance(Caller.class);
|
||||||
expect(mock.submit(requestLineEquals("GET http://localhost:1111/client/1/foo HTTP/1.1"), eq(function))).andReturn(
|
expect(mock.submit(requestLineEquals("GET http://localhost:1111/client/1/foo HTTP/1.1"), eq(function)))
|
||||||
Futures.<Void> immediateFuture(null)).atLeastOnce();
|
.andReturn(Futures.<Void> immediateFuture(null)).atLeastOnce();
|
||||||
replay(mock);
|
replay(mock);
|
||||||
|
|
||||||
caller.getCallee().onePath("foo");
|
caller.getCallee().onePath("foo");
|
||||||
|
@ -281,8 +281,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
private Injector injectorForClient() {
|
private Injector injectorForClient() {
|
||||||
|
|
||||||
RestContextSpec<Caller, AsyncCaller> contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo",
|
RestContextSpec<Caller, AsyncCaller> contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo",
|
||||||
null, Caller.class, AsyncCaller.class,
|
null, Caller.class, AsyncCaller.class, ImmutableSet.<Module> of(new MockModule(),
|
||||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new CallerCalleeModule()));
|
new NullLoggingModule(), new CallerCalleeModule()));
|
||||||
|
|
||||||
return createContextBuilder(contextSpec).buildInjector();
|
return createContextBuilder(contextSpec).buildInjector();
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@Target({ ElementType.METHOD })
|
@Target( { ElementType.METHOD })
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@javax.ws.rs.HttpMethod("FOO")
|
@javax.ws.rs.HttpMethod("FOO")
|
||||||
public @interface FOO {
|
public @interface FOO {
|
||||||
|
@ -332,10 +332,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
public void testUnEncodeQuery() {
|
public void testUnEncodeQuery() {
|
||||||
URI expects = URI
|
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
|
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, '/', ':');
|
URI value = RestAnnotationProcessor.replaceQuery(uriBuilderProvider, start, start.getQuery(), null, '/', ':');
|
||||||
assertEquals(value, expects);
|
assertEquals(value, expects);
|
||||||
}
|
}
|
||||||
|
@ -369,17 +369,17 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
public interface TestPayloadParamVarargs {
|
public interface TestPayloadParamVarargs {
|
||||||
@POST
|
@POST
|
||||||
public void varargs(HttpRequestOptions... options);
|
public void varargs(HttpRequestOptions... options);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
public void post(HttpRequestOptions options);
|
public void post(HttpRequestOptions options);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
public void post();
|
public void post();
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
public void post(Payload payload);
|
public void post(Payload payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,7 +406,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
public void testPayloadParamVarargs() throws SecurityException, NoSuchMethodException, IOException {
|
public void testPayloadParamVarargs() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TestPayloadParamVarargs.class.getMethod("varargs", Array.newInstance(HttpRequestOptions.class, 0)
|
Method method = TestPayloadParamVarargs.class.getMethod("varargs", Array.newInstance(HttpRequestOptions.class, 0)
|
||||||
.getClass());
|
.getClass());
|
||||||
verifyTestPostOptions(method);
|
verifyTestPostOptions(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,7 +445,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
public class TestCustomMethod {
|
public class TestCustomMethod {
|
||||||
@FOO
|
@FOO
|
||||||
public void foo() {
|
public void foo() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,7 +463,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
public class TestOverridden implements Parent {
|
public class TestOverridden implements Parent {
|
||||||
@POST
|
@POST
|
||||||
public void foo() {
|
public void foo() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,11 +479,11 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Endpoint(Localhost2.class)
|
@Endpoint(Localhost2.class)
|
||||||
public void foo() {
|
public void foo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@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 {
|
public void testOverriddenEndpointParameter() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestOverriddenEndpoint.class.getMethod("foo", URI.class);
|
Method method = TestOverriddenEndpoint.class.getMethod("foo", URI.class);
|
||||||
HttpRequest request = factory(TestOverriddenEndpoint.class).createRequest(method,
|
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().getHost(), "wowsa");
|
||||||
assertEquals(request.getEndpoint().getPort(), 8001);
|
assertEquals(request.getEndpoint().getPort(), 8001);
|
||||||
assertEquals(request.getEndpoint().getPath(), "");
|
assertEquals(request.getEndpoint().getPath(), "");
|
||||||
|
@ -508,10 +508,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
public interface TestPost {
|
public interface TestPost {
|
||||||
@POST
|
@POST
|
||||||
void post(@Nullable @BinderParam(BindToStringPayload.class) String content);
|
void post(@Nullable @BinderParam(BindToStringPayload.class) String content);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
public void postAsJson(@BinderParam(BindToJsonPayload.class) String content);
|
public void postAsJson(@BinderParam(BindToJsonPayload.class) String content);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/{foo}")
|
@Path("/{foo}")
|
||||||
|
@ -594,54 +594,54 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
static interface TestMultipartForm {
|
static interface TestMultipartForm {
|
||||||
@POST
|
@POST
|
||||||
void withStringPart(@PartParam(name = "fooble") String path);
|
void withStringPart(@PartParam(name = "fooble") String path);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
void withParamStringPart(@FormParam("name") String name, @PartParam(name = "file") String path);
|
void withParamStringPart(@FormParam("name") String name, @PartParam(name = "file") String path);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
void withParamFilePart(@FormParam("name") String name, @PartParam(name = "file") File path);
|
void withParamFilePart(@FormParam("name") String name, @PartParam(name = "file") File path);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
void withParamFileBinaryPart(@FormParam("name") String name,
|
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
|
@POST
|
||||||
void withParamByteArrayBinaryPart(
|
void withParamByteArrayBinaryPart(
|
||||||
@FormParam("name") String name,
|
@FormParam("name") String name,
|
||||||
@PartParam(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM, filename = "{name}.tar.gz") byte[] content);
|
@PartParam(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM, filename = "{name}.tar.gz") byte[] content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipartWithStringPart() throws SecurityException, NoSuchMethodException, IOException {
|
public void testMultipartWithStringPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TestMultipartForm.class.getMethod("withStringPart", String.class);
|
Method method = TestMultipartForm.class.getMethod("withStringPart", String.class);
|
||||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||||
"foobledata");
|
"foobledata");
|
||||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest,//
|
assertPayloadEquals(httpRequest,//
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"fooble\"\r\n" + //
|
"Content-Disposition: form-data; name=\"fooble\"\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"foobledata\r\n" + //
|
"foobledata\r\n" + //
|
||||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipartWithParamStringPart() throws SecurityException, NoSuchMethodException, IOException {
|
public void testMultipartWithParamStringPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TestMultipartForm.class.getMethod("withParamStringPart", String.class, String.class);
|
Method method = TestMultipartForm.class.getMethod("withParamStringPart", String.class, String.class);
|
||||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||||
"name", "foobledata");
|
"name", "foobledata");
|
||||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest,//
|
assertPayloadEquals(httpRequest,//
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"name\r\n" + // /
|
"name\r\n" + // /
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"file\"\r\n" + //
|
"Content-Disposition: form-data; name=\"file\"\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"foobledata\r\n" + //
|
"foobledata\r\n" + //
|
||||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipartWithParamFilePart() throws SecurityException, NoSuchMethodException, IOException {
|
public void testMultipartWithParamFilePart() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
|
@ -651,38 +651,38 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
file.deleteOnExit();
|
file.deleteOnExit();
|
||||||
|
|
||||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||||
"name", file);
|
"name", file);
|
||||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest,//
|
assertPayloadEquals(httpRequest,//
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"name\r\n" + // /
|
"name\r\n" + // /
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"\r\n" + //
|
"Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"foobledata\r\n" + //
|
"foobledata\r\n" + //
|
||||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipartWithParamByteArrayPart() throws SecurityException, NoSuchMethodException, IOException {
|
public void testMultipartWithParamByteArrayPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TestMultipartForm.class.getMethod("withParamByteArrayBinaryPart", String.class, byte[].class);
|
Method method = TestMultipartForm.class.getMethod("withParamByteArrayBinaryPart", String.class, byte[].class);
|
||||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||||
"name", "goo".getBytes());
|
"name", "goo".getBytes());
|
||||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest,//
|
assertPayloadEquals(httpRequest,//
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"name\r\n" + // /
|
"name\r\n" + // /
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"file\"; filename=\"name.tar.gz\"\r\n" + //
|
"Content-Disposition: form-data; name=\"file\"; filename=\"name.tar.gz\"\r\n" + //
|
||||||
"Content-Type: application/octet-stream\r\n" + //
|
"Content-Type: application/octet-stream\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"goo\r\n" + //
|
"goo\r\n" + //
|
||||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||||
};
|
};
|
||||||
|
|
||||||
public void testMultipartWithParamFileBinaryPart() throws SecurityException, NoSuchMethodException, IOException {
|
public void testMultipartWithParamFileBinaryPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
|
@ -692,20 +692,20 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
file.deleteOnExit();
|
file.deleteOnExit();
|
||||||
|
|
||||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||||
"name", file);
|
"name", file);
|
||||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest,//
|
assertPayloadEquals(httpRequest,//
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"name\r\n" + // /
|
"name\r\n" + // /
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"\r\n" + //
|
"Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"\r\n" + //
|
||||||
"Content-Type: application/octet-stream\r\n" + //
|
"Content-Type: application/octet-stream\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"'(2\r\n" + //
|
"'(2\r\n" + //
|
||||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface TestPut {
|
public interface TestPut {
|
||||||
|
@ -764,7 +764,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
ListenableFuture<? extends Set<String>> testUnwrap4();
|
ListenableFuture<? extends Set<String>> testUnwrap4();
|
||||||
|
|
||||||
@Target({ ElementType.METHOD })
|
@Target( { ElementType.METHOD })
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@HttpMethod("ROWDY")
|
@HttpMethod("ROWDY")
|
||||||
public @interface ROWDY {
|
public @interface ROWDY {
|
||||||
|
@ -819,7 +819,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
// now test that it works!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Wrapper> parser = (Function<HttpResponse, Wrapper>) RestAnnotationProcessor
|
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");
|
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!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
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\"}"))),
|
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), ImmutableMap.of(
|
||||||
ImmutableMap.of("foo", "bar"));
|
"foo", "bar"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -850,10 +850,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
// now test that it works!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
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\"}"))),
|
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), ImmutableMap.of(
|
||||||
ImmutableMap.of("foo", "bar"));
|
"foo", "bar"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -866,10 +866,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
// now test that it works!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
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\"}"))),
|
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), ImmutableMap.of(
|
||||||
ImmutableMap.of("foo", "bar"));
|
"foo", "bar"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -882,7 +882,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
// now test that it works!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
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");
|
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!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
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");
|
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!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
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\"]}"))),
|
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")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -927,10 +927,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
// now test that it works!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
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\"]}"))),
|
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 {
|
static class TestRequestFilter1 implements HttpRequestFilter {
|
||||||
|
@ -948,11 +948,11 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@RequestFilters(TestRequestFilter1.class)
|
@RequestFilters(TestRequestFilter1.class)
|
||||||
static interface TestRequestFilter {
|
static interface TestRequestFilter {
|
||||||
@GET
|
@GET
|
||||||
@RequestFilters(TestRequestFilter2.class)
|
@RequestFilters(TestRequestFilter2.class)
|
||||||
public void get();
|
public void get();
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@OverrideRequestFilters
|
@OverrideRequestFilters
|
||||||
@RequestFilters(TestRequestFilter2.class)
|
@RequestFilters(TestRequestFilter2.class)
|
||||||
public void getOverride();
|
public void getOverride();
|
||||||
|
|
||||||
|
@ -979,9 +979,12 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
public void testRequestFilterOverrideOnRequest() throws SecurityException, NoSuchMethodException {
|
public void testRequestFilterOverrideOnRequest() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestRequestFilter.class.getMethod("getOverride", HttpRequest.class);
|
Method method = TestRequestFilter.class.getMethod("getOverride", HttpRequest.class);
|
||||||
HttpRequest request = factory(TestRequestFilter.class).createRequest(method,
|
HttpRequest request = factory(TestRequestFilter.class).createRequest(
|
||||||
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build());
|
method,
|
||||||
|
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).headers(
|
||||||
|
ImmutableMultimap.of("foo", "bar")).build());
|
||||||
assertEquals(request.getFilters().size(), 1);
|
assertEquals(request.getFilters().size(), 1);
|
||||||
|
assertEquals(request.getHeaders().size(), 1);
|
||||||
assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter2.class);
|
assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter2.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1027,7 +1030,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testConstantPathParam() throws SecurityException, NoSuchMethodException, IOException {
|
public void testConstantPathParam() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TestConstantPathParam.class.getMethod("twoPaths", String.class, String.class);
|
Method method = TestConstantPathParam.class.getMethod("twoPaths", String.class, String.class);
|
||||||
HttpRequest request = factory(TestConstantPathParam.class).createRequest(method,
|
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");
|
assertRequestLineEquals(request, "GET http://localhost:9999/v1/ralphie/1/localhost HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
@ -1164,7 +1167,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildTwoHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildTwoHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneHeader = TestHeader.class.getMethod("twoHeader", String.class);
|
Method oneHeader = TestHeader.class.getMethod("twoHeader", String.class);
|
||||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(oneHeader, new Object[] { "robot" })
|
Multimap<String, String> headers = factory(TestHeader.class).createRequest(oneHeader, new Object[] { "robot" })
|
||||||
.getHeaders();
|
.getHeaders();
|
||||||
assertEquals(headers.size(), 2);
|
assertEquals(headers.size(), 2);
|
||||||
assertEquals(headers.get("slash"), Collections.singletonList("/robot"));
|
assertEquals(headers.get("slash"), Collections.singletonList("/robot"));
|
||||||
assertEquals(headers.get("hyphen"), 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 {
|
public void testBuildOneClassHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneHeader = TestClassHeader.class.getMethod("oneHeader", String.class);
|
Method oneHeader = TestClassHeader.class.getMethod("oneHeader", String.class);
|
||||||
Multimap<String, String> headers = factory(TestClassHeader.class).createRequest(oneHeader,
|
Multimap<String, String> headers = factory(TestClassHeader.class).createRequest(oneHeader,
|
||||||
new Object[] { "robot" }).getHeaders();
|
new Object[] { "robot" }).getHeaders();
|
||||||
assertEquals(headers.size(), 1);
|
assertEquals(headers.size(), 1);
|
||||||
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/robot"));
|
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 {
|
public void testBuildOneHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneHeader = TestHeader.class.getMethod("oneHeader", String.class);
|
Method oneHeader = TestHeader.class.getMethod("oneHeader", String.class);
|
||||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(oneHeader, new Object[] { "robot" })
|
Multimap<String, String> headers = factory(TestHeader.class).createRequest(oneHeader, new Object[] { "robot" })
|
||||||
.getHeaders();
|
.getHeaders();
|
||||||
assertEquals(headers.size(), 1);
|
assertEquals(headers.size(), 1);
|
||||||
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/robot"));
|
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 {
|
public void testBuildTwoHeaders() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method twoHeaders = TestHeader.class.getMethod("twoHeaders", String.class, String.class);
|
Method twoHeaders = TestHeader.class.getMethod("twoHeaders", String.class, String.class);
|
||||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(twoHeaders,
|
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.size(), 1);
|
||||||
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/robot/eggs"));
|
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/robot/eggs"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildTwoHeadersOutOfOrder() throws SecurityException, NoSuchMethodException,
|
public void testBuildTwoHeadersOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||||
UnsupportedEncodingException {
|
UnsupportedEncodingException {
|
||||||
Method twoHeadersOutOfOrder = TestHeader.class.getMethod("twoHeadersOutOfOrder", String.class, String.class);
|
Method twoHeadersOutOfOrder = TestHeader.class.getMethod("twoHeadersOutOfOrder", String.class, String.class);
|
||||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(twoHeadersOutOfOrder,
|
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.size(), 1);
|
||||||
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/eggs/robot"));
|
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/eggs/robot"));
|
||||||
}
|
}
|
||||||
|
@ -1224,8 +1227,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@Test
|
@Test
|
||||||
public void testQueryInOptions() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testQueryInOptions() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneQuery = TestQueryReplace.class.getMethod("queryInOptions", String.class, TestReplaceQueryOptions.class);
|
Method oneQuery = TestQueryReplace.class.getMethod("queryInOptions", String.class, TestReplaceQueryOptions.class);
|
||||||
String query = factory(TestQueryReplace.class)
|
String query = factory(TestQueryReplace.class).createRequest(oneQuery,
|
||||||
.createRequest(oneQuery, new Object[] { "robot", new TestReplaceQueryOptions() }).getEndpoint().getQuery();
|
new Object[] { "robot", new TestReplaceQueryOptions() }).getEndpoint().getQuery();
|
||||||
assertEquals(query, "x-amz-copy-source=/robot");
|
assertEquals(query, "x-amz-copy-source=/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1233,13 +1236,13 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@POST
|
@POST
|
||||||
@Path("/objects/{id}/action/{action}")
|
@Path("/objects/{id}/action/{action}")
|
||||||
ListenableFuture<String> action(@PathParam("id") String id, @PathParam("action") String 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 {
|
public void testTestMapMatrixParams() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method method = TestMapMatrixParams.class.getMethod("action", String.class, String.class, Map.class);
|
Method method = TestMapMatrixParams.class.getMethod("action", String.class, String.class, Map.class);
|
||||||
HttpRequest request = factory(TestMapMatrixParams.class).createRequest(method,
|
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");
|
assertRequestLineEquals(request, "POST http://localhost:9999/objects/robot/action/kill;death=slow HTTP/1.1");
|
||||||
assertEquals(request.getHeaders().size(), 0);
|
assertEquals(request.getHeaders().size(), 0);
|
||||||
}
|
}
|
||||||
|
@ -1281,7 +1284,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildTwoQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildTwoQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneQuery = TestQueryReplace.class.getMethod("twoQuery", String.class);
|
Method oneQuery = TestQueryReplace.class.getMethod("twoQuery", String.class);
|
||||||
String query = factory(TestQueryReplace.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
String query = factory(TestQueryReplace.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
||||||
.getQuery();
|
.getQuery();
|
||||||
assertEquals(query, "slash=/robot&hyphen=-robot");
|
assertEquals(query, "slash=/robot&hyphen=-robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1297,7 +1300,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildOneClassQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildOneClassQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneQuery = TestClassQuery.class.getMethod("oneQuery", String.class);
|
Method oneQuery = TestClassQuery.class.getMethod("oneQuery", String.class);
|
||||||
String query = factory(TestClassQuery.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
String query = factory(TestClassQuery.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
||||||
.getQuery();
|
.getQuery();
|
||||||
assertEquals(query, "x-amz-copy-source=/robot");
|
assertEquals(query, "x-amz-copy-source=/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1305,7 +1308,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildOneQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildOneQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneQuery = TestQueryReplace.class.getMethod("oneQuery", String.class);
|
Method oneQuery = TestQueryReplace.class.getMethod("oneQuery", String.class);
|
||||||
String query = factory(TestQueryReplace.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
String query = factory(TestQueryReplace.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
||||||
.getQuery();
|
.getQuery();
|
||||||
assertEquals(query, "x-amz-copy-source=/robot");
|
assertEquals(query, "x-amz-copy-source=/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1313,16 +1316,16 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildTwoQuerys() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildTwoQuerys() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method twoQuerys = TestQueryReplace.class.getMethod("twoQuerys", String.class, String.class);
|
Method twoQuerys = TestQueryReplace.class.getMethod("twoQuerys", String.class, String.class);
|
||||||
String query = factory(TestQueryReplace.class).createRequest(twoQuerys, new Object[] { "robot", "eggs" })
|
String query = factory(TestQueryReplace.class).createRequest(twoQuerys, new Object[] { "robot", "eggs" })
|
||||||
.getEndpoint().getQuery();
|
.getEndpoint().getQuery();
|
||||||
assertEquals(query, "x-amz-copy-source=/robot/eggs");
|
assertEquals(query, "x-amz-copy-source=/robot/eggs");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildTwoQuerysOutOfOrder() throws SecurityException, NoSuchMethodException,
|
public void testBuildTwoQuerysOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||||
UnsupportedEncodingException {
|
UnsupportedEncodingException {
|
||||||
Method twoQuerysOutOfOrder = TestQueryReplace.class.getMethod("twoQuerysOutOfOrder", String.class, String.class);
|
Method twoQuerysOutOfOrder = TestQueryReplace.class.getMethod("twoQuerysOutOfOrder", String.class, String.class);
|
||||||
String query = factory(TestQueryReplace.class)
|
String query = factory(TestQueryReplace.class).createRequest(twoQuerysOutOfOrder,
|
||||||
.createRequest(twoQuerysOutOfOrder, new Object[] { "robot", "eggs" }).getEndpoint().getQuery();
|
new Object[] { "robot", "eggs" }).getEndpoint().getQuery();
|
||||||
assertEquals(query, "x-amz-copy-source=/eggs/robot");
|
assertEquals(query, "x-amz-copy-source=/eggs/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1335,9 +1338,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@Test
|
@Test
|
||||||
public void testMatrixInOptions() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testMatrixInOptions() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneMatrix = TestMatrixReplace.class.getMethod("matrixInOptions", String.class,
|
Method oneMatrix = TestMatrixReplace.class.getMethod("matrixInOptions", String.class,
|
||||||
TestReplaceMatrixOptions.class);
|
TestReplaceMatrixOptions.class);
|
||||||
String path = factory(TestMatrixReplace.class)
|
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix,
|
||||||
.createRequest(oneMatrix, new Object[] { "robot", new TestReplaceMatrixOptions() }).getEndpoint().getPath();
|
new Object[] { "robot", new TestReplaceMatrixOptions() }).getEndpoint().getPath();
|
||||||
assertEquals(path, "/;x-amz-copy-source=/robot");
|
assertEquals(path, "/;x-amz-copy-source=/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1378,7 +1381,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildTwoMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildTwoMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneMatrix = TestMatrixReplace.class.getMethod("twoMatrix", String.class);
|
Method oneMatrix = TestMatrixReplace.class.getMethod("twoMatrix", String.class);
|
||||||
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
||||||
.getPath();
|
.getPath();
|
||||||
assertEquals(path, "/;slash=/robot;hyphen=-robot");
|
assertEquals(path, "/;slash=/robot;hyphen=-robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1395,7 +1398,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildOneClassMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildOneClassMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneMatrix = TestClassMatrix.class.getMethod("oneMatrix", String.class);
|
Method oneMatrix = TestClassMatrix.class.getMethod("oneMatrix", String.class);
|
||||||
String path = factory(TestClassMatrix.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
String path = factory(TestClassMatrix.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
||||||
.getPath();
|
.getPath();
|
||||||
assertEquals(path, "/;x-amz-copy-source=/robot");
|
assertEquals(path, "/;x-amz-copy-source=/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1403,7 +1406,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildOneMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildOneMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneMatrix = TestMatrixReplace.class.getMethod("oneMatrix", String.class);
|
Method oneMatrix = TestMatrixReplace.class.getMethod("oneMatrix", String.class);
|
||||||
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
||||||
.getPath();
|
.getPath();
|
||||||
assertEquals(path, "/;x-amz-copy-source=/robot");
|
assertEquals(path, "/;x-amz-copy-source=/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1411,59 +1414,59 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildTwoMatrixs() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildTwoMatrixs() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method twoMatrixs = TestMatrixReplace.class.getMethod("twoMatrixs", String.class, String.class);
|
Method twoMatrixs = TestMatrixReplace.class.getMethod("twoMatrixs", String.class, String.class);
|
||||||
String path = factory(TestMatrixReplace.class).createRequest(twoMatrixs, new Object[] { "robot", "eggs" })
|
String path = factory(TestMatrixReplace.class).createRequest(twoMatrixs, new Object[] { "robot", "eggs" })
|
||||||
.getEndpoint().getPath();
|
.getEndpoint().getPath();
|
||||||
assertEquals(path, "/;x-amz-copy-source=/robot/eggs");
|
assertEquals(path, "/;x-amz-copy-source=/robot/eggs");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildTwoMatrixsOutOfOrder() throws SecurityException, NoSuchMethodException,
|
public void testBuildTwoMatrixsOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||||
UnsupportedEncodingException {
|
UnsupportedEncodingException {
|
||||||
Method twoMatrixsOutOfOrder = TestMatrixReplace.class.getMethod("twoMatrixsOutOfOrder", String.class,
|
Method twoMatrixsOutOfOrder = TestMatrixReplace.class.getMethod("twoMatrixsOutOfOrder", String.class,
|
||||||
String.class);
|
String.class);
|
||||||
String path = factory(TestMatrixReplace.class)
|
String path = factory(TestMatrixReplace.class).createRequest(twoMatrixsOutOfOrder,
|
||||||
.createRequest(twoMatrixsOutOfOrder, new Object[] { "robot", "eggs" }).getEndpoint().getPath();
|
new Object[] { "robot", "eggs" }).getEndpoint().getPath();
|
||||||
assertEquals(path, "/;x-amz-copy-source=/eggs/robot");
|
assertEquals(path, "/;x-amz-copy-source=/eggs/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface TestTransformers {
|
public interface TestTransformers {
|
||||||
@GET
|
@GET
|
||||||
int noTransformer();
|
int noTransformer();
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ReturnStringIf2xx.class)
|
@ResponseParser(ReturnStringIf2xx.class)
|
||||||
void oneTransformer();
|
void oneTransformer();
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ReturnStringIf200Context.class)
|
@ResponseParser(ReturnStringIf200Context.class)
|
||||||
void oneTransformerWithContext();
|
void oneTransformerWithContext();
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
InputStream inputStream();
|
InputStream inputStream();
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
ListenableFuture<InputStream> futureInputStream();
|
ListenableFuture<InputStream> futureInputStream();
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
URI uri();
|
URI uri();
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
ListenableFuture<URI> futureUri();
|
ListenableFuture<URI> futureUri();
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
ListenableFuture<Void> put(Payload payload);
|
ListenableFuture<Void> put(Payload payload);
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Headers(keys = "Transfer-Encoding", values = "chunked")
|
@Headers(keys = "Transfer-Encoding", values = "chunked")
|
||||||
ListenableFuture<Void> putXfer(Payload payload);
|
ListenableFuture<Void> putXfer(Payload payload);
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
ListenableFuture<Void> put(PayloadEnclosing payload);
|
ListenableFuture<Void> put(PayloadEnclosing payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPutPayloadEnclosing() throws SecurityException, NoSuchMethodException, IOException {
|
public void testPutPayloadEnclosing() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class);
|
Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class);
|
||||||
HttpRequest request = factory(TestQuery.class).createRequest(method,
|
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");
|
assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, "whoops", "application/unknown", false);
|
assertPayloadEquals(request, "whoops", "application/unknown", false);
|
||||||
|
@ -1481,10 +1484,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPutInputStreamPayloadEnclosingGenerateMD5() throws SecurityException, NoSuchMethodException,
|
public void testPutInputStreamPayloadEnclosingGenerateMD5() throws SecurityException, NoSuchMethodException,
|
||||||
IOException {
|
IOException {
|
||||||
Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class);
|
Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class);
|
||||||
PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(
|
PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(newInputStreamPayload(Strings2
|
||||||
newInputStreamPayload(Strings2.toInputStream("whoops")));
|
.toInputStream("whoops")));
|
||||||
|
|
||||||
calculateMD5(payloadEnclosing, crypto.md5());
|
calculateMD5(payloadEnclosing, crypto.md5());
|
||||||
HttpRequest request = factory(TestQuery.class).createRequest(method, payloadEnclosing);
|
HttpRequest request = factory(TestQuery.class).createRequest(method, payloadEnclosing);
|
||||||
|
@ -1541,7 +1544,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPutPayloadWithGeneratedMD5AndNoContentType() throws SecurityException, NoSuchMethodException,
|
public void testPutPayloadWithGeneratedMD5AndNoContentType() throws SecurityException, NoSuchMethodException,
|
||||||
IOException {
|
IOException {
|
||||||
Payload payload = newStringPayload("whoops");
|
Payload payload = newStringPayload("whoops");
|
||||||
calculateMD5(payload, crypto.md5());
|
calculateMD5(payload, crypto.md5());
|
||||||
Method method = TestTransformers.class.getMethod("put", Payload.class);
|
Method method = TestTransformers.class.getMethod("put", Payload.class);
|
||||||
|
@ -1562,7 +1565,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPutInputStreamPayloadWithMD5() throws NoSuchAlgorithmException, IOException, SecurityException,
|
public void testPutInputStreamPayloadWithMD5() throws NoSuchAlgorithmException, IOException, SecurityException,
|
||||||
NoSuchMethodException {
|
NoSuchMethodException {
|
||||||
Payload payload = newStringPayload("whoops");
|
Payload payload = newStringPayload("whoops");
|
||||||
calculateMD5(payload, crypto.md5());
|
calculateMD5(payload, crypto.md5());
|
||||||
Method method = TestTransformers.class.getMethod("put", Payload.class);
|
Method method = TestTransformers.class.getMethod("put", Payload.class);
|
||||||
|
@ -1586,9 +1589,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> Class<? extends Function<HttpResponse, ?>> unwrap(RestAnnotationProcessor<T> processor,
|
public static <T> Class<? extends Function<HttpResponse, ?>> unwrap(RestAnnotationProcessor<T> processor,
|
||||||
Method method) {
|
Method method) {
|
||||||
return (Class<? extends Function<HttpResponse, ?>>) RestAnnotationProcessor.getParserOrThrowException(method)
|
return (Class<? extends Function<HttpResponse, ?>>) RestAnnotationProcessor.getParserOrThrowException(method)
|
||||||
.getTypeLiteral().getRawType();
|
.getTypeLiteral().getRawType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testURI() throws SecurityException, NoSuchMethodException {
|
public void testURI() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -1604,7 +1607,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ReturnStringIf200Context extends ReturnStringIf2xx implements
|
public static class ReturnStringIf200Context extends ReturnStringIf2xx implements
|
||||||
InvocationContext<ReturnStringIf200Context> {
|
InvocationContext<ReturnStringIf200Context> {
|
||||||
|
|
||||||
public HttpRequest request;
|
public HttpRequest request;
|
||||||
|
|
||||||
|
@ -1626,8 +1629,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
RestAnnotationProcessor<TestTransformers> processor = factory(TestTransformers.class);
|
RestAnnotationProcessor<TestTransformers> processor = factory(TestTransformers.class);
|
||||||
Method method = TestTransformers.class.getMethod("oneTransformerWithContext");
|
Method method = TestTransformers.class.getMethod("oneTransformerWithContext");
|
||||||
GeneratedHttpRequest<TestTransformers> request = GeneratedHttpRequest.<TestTransformers> builder().method("GET")
|
GeneratedHttpRequest<TestTransformers> request = GeneratedHttpRequest.<TestTransformers> builder().method("GET")
|
||||||
.endpoint(URI.create("http://localhost")).declaring(TestTransformers.class).javaMethod(method)
|
.endpoint(URI.create("http://localhost")).declaring(TestTransformers.class).javaMethod(method).args(
|
||||||
.args(new Object[] {}).build();
|
new Object[] {}).build();
|
||||||
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
|
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
|
||||||
assertEquals(transformer.getClass(), ReturnStringIf200Context.class);
|
assertEquals(transformer.getClass(), ReturnStringIf200Context.class);
|
||||||
assertEquals(((ReturnStringIf200Context) transformer).request, request);
|
assertEquals(((ReturnStringIf200Context) transformer).request, request);
|
||||||
|
@ -1668,7 +1671,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@PUT
|
@PUT
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
ListenableFuture<String> put(@PathParam("id") @ParamParser(FirstCharacter.class) String id,
|
ListenableFuture<String> put(@PathParam("id") @ParamParser(FirstCharacter.class) String id,
|
||||||
@BinderParam(BindToStringPayload.class) String payload);
|
@BinderParam(BindToStringPayload.class) String payload);
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
|
@ -1680,7 +1683,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@Headers(keys = "foo", values = "--{id}--")
|
@Headers(keys = "foo", values = "--{id}--")
|
||||||
@ResponseParser(ReturnTrueIf2xx.class)
|
@ResponseParser(ReturnTrueIf2xx.class)
|
||||||
ListenableFuture<String> putHeader(@PathParam("id") String id,
|
ListenableFuture<String> putHeader(@PathParam("id") String id,
|
||||||
@BinderParam(BindToStringPayload.class) String payload);
|
@BinderParam(BindToStringPayload.class) String payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateGetVarArgOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException {
|
public void testCreateGetVarArgOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -1694,8 +1697,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(request.getHeaders().size(), 2);
|
assertEquals(request.getHeaders().size(), 2);
|
||||||
assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections.singletonList("localhost"));
|
assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections.singletonList("localhost"));
|
||||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE),
|
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections.singletonList(dateService
|
||||||
Collections.singletonList(dateService.rfc822DateFormat(date)));
|
.rfc822DateFormat(date)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateGetOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException {
|
public void testCreateGetOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -1708,8 +1711,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(request.getHeaders().size(), 2);
|
assertEquals(request.getHeaders().size(), 2);
|
||||||
assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections.singletonList("localhost"));
|
assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections.singletonList("localhost"));
|
||||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE),
|
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections.singletonList(dateService
|
||||||
Collections.singletonList(dateService.rfc822DateFormat(date)));
|
.rfc822DateFormat(date)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PrefixOptions extends BaseHttpRequestOptions {
|
public class PrefixOptions extends BaseHttpRequestOptions {
|
||||||
|
@ -1772,7 +1775,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
@Test(dataProvider = "strings")
|
@Test(dataProvider = "strings")
|
||||||
public void testCreateGetRequest(String key) throws SecurityException, NoSuchMethodException,
|
public void testCreateGetRequest(String key) throws SecurityException, NoSuchMethodException,
|
||||||
UnsupportedEncodingException {
|
UnsupportedEncodingException {
|
||||||
Method method = TestRequest.class.getMethod("get", String.class, String.class);
|
Method method = TestRequest.class.getMethod("get", String.class, String.class);
|
||||||
HttpRequest request = factory(TestRequest.class).createRequest(method, new Object[] { key, "localhost" });
|
HttpRequest request = factory(TestRequest.class).createRequest(method, new Object[] { key, "localhost" });
|
||||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||||
|
@ -1815,7 +1818,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testVirtualHostMethod() throws SecurityException, NoSuchMethodException {
|
public void testVirtualHostMethod() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestVirtualHostMethod.class.getMethod("get", String.class, String.class);
|
Method method = TestVirtualHostMethod.class.getMethod("get", String.class, String.class);
|
||||||
HttpRequest request = factory(TestVirtualHostMethod.class).createRequest(method,
|
HttpRequest request = factory(TestVirtualHostMethod.class).createRequest(method,
|
||||||
new Object[] { "1", "localhost" });
|
new Object[] { "1", "localhost" });
|
||||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(request.getEndpoint().getPath(), "/1");
|
assertEquals(request.getEndpoint().getPath(), "/1");
|
||||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||||
|
@ -1880,7 +1883,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testOneHeader() throws SecurityException, NoSuchMethodException {
|
public void testOneHeader() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestHeaders.class.getMethod("oneHeader", String.class);
|
Method method = TestHeaders.class.getMethod("oneHeader", String.class);
|
||||||
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
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.size(), 1);
|
||||||
assertEquals(headers.get("header"), Collections.singletonList("robot"));
|
assertEquals(headers.get("header"), Collections.singletonList("robot"));
|
||||||
}
|
}
|
||||||
|
@ -1889,7 +1892,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testOneIntHeader() throws SecurityException, NoSuchMethodException {
|
public void testOneIntHeader() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestHeaders.class.getMethod("oneIntHeader", int.class);
|
Method method = TestHeaders.class.getMethod("oneIntHeader", int.class);
|
||||||
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
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.size(), 1);
|
||||||
assertEquals(headers.get("header"), Collections.singletonList("1"));
|
assertEquals(headers.get("header"), Collections.singletonList("1"));
|
||||||
}
|
}
|
||||||
|
@ -1898,7 +1901,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testTwoDifferentHeaders() throws SecurityException, NoSuchMethodException {
|
public void testTwoDifferentHeaders() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestHeaders.class.getMethod("twoDifferentHeaders", String.class, String.class);
|
Method method = TestHeaders.class.getMethod("twoDifferentHeaders", String.class, String.class);
|
||||||
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
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.size(), 2);
|
||||||
assertEquals(headers.get("header1"), Collections.singletonList("robot"));
|
assertEquals(headers.get("header1"), Collections.singletonList("robot"));
|
||||||
assertEquals(headers.get("header2"), Collections.singletonList("egg"));
|
assertEquals(headers.get("header2"), Collections.singletonList("egg"));
|
||||||
|
@ -1908,7 +1911,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testTwoSameHeaders() throws SecurityException, NoSuchMethodException {
|
public void testTwoSameHeaders() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestHeaders.class.getMethod("twoSameHeaders", String.class, String.class);
|
Method method = TestHeaders.class.getMethod("twoSameHeaders", String.class, String.class);
|
||||||
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
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.size(), 2);
|
||||||
Collection<String> values = headers.get("header");
|
Collection<String> values = headers.get("header");
|
||||||
assert values.contains("robot");
|
assert values.contains("robot");
|
||||||
|
@ -1931,7 +1934,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
void twoEndpointParams(@EndpointParam(parser = ConvertTwoToURI.class) String EndpointParam1,
|
void twoEndpointParams(@EndpointParam(parser = ConvertTwoToURI.class) String EndpointParam1,
|
||||||
@EndpointParam(parser = ConvertTwoToURI.class) String EndpointParam2);
|
@EndpointParam(parser = ConvertTwoToURI.class) String EndpointParam2);
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public static class ConvertTwoToURI implements Function<Object, URI> {
|
public static class ConvertTwoToURI implements Function<Object, URI> {
|
||||||
|
@ -1951,7 +1954,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testOneEndpointParam() throws SecurityException, NoSuchMethodException {
|
public void testOneEndpointParam() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestEndpointParams.class.getMethod("oneEndpointParam", String.class);
|
Method method = TestEndpointParams.class.getMethod("oneEndpointParam", String.class);
|
||||||
URI uri = factory(TestEndpointParams.class).getEndpointInParametersOrNull(method, new Object[] { "robot" },
|
URI uri = factory(TestEndpointParams.class).getEndpointInParametersOrNull(method, new Object[] { "robot" },
|
||||||
injector);
|
injector);
|
||||||
assertEquals(uri, URI.create("robot"));
|
assertEquals(uri, URI.create("robot"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1961,22 +1964,22 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testTwoDifferentEndpointParams() throws SecurityException, NoSuchMethodException {
|
public void testTwoDifferentEndpointParams() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestEndpointParams.class.getMethod("twoEndpointParams", String.class, String.class);
|
Method method = TestEndpointParams.class.getMethod("twoEndpointParams", String.class, String.class);
|
||||||
URI uri = factory(TestEndpointParams.class).getEndpointInParametersOrNull(method,
|
URI uri = factory(TestEndpointParams.class).getEndpointInParametersOrNull(method,
|
||||||
new Object[] { "robot", "egg" }, injector);
|
new Object[] { "robot", "egg" }, injector);
|
||||||
assertEquals(uri, URI.create("robot/egg"));
|
assertEquals(uri, URI.create("robot/egg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface TestPayload {
|
public interface TestPayload {
|
||||||
@PUT
|
@PUT
|
||||||
public void put(@BinderParam(BindToStringPayload.class) String content);
|
public void put(@BinderParam(BindToStringPayload.class) String content);
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("/{foo}")
|
@Path("/{foo}")
|
||||||
public ListenableFuture<Void> putWithPath(@PathParam("foo") String path,
|
public ListenableFuture<Void> putWithPath(@PathParam("foo") String path,
|
||||||
@BinderParam(BindToStringPayload.class) String content);
|
@BinderParam(BindToStringPayload.class) String content);
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
public void twoEntities(@BinderParam(BindToStringPayload.class) String payload1,
|
public void twoEntities(@BinderParam(BindToStringPayload.class) String payload1,
|
||||||
@BinderParam(BindToStringPayload.class) String payload2);
|
@BinderParam(BindToStringPayload.class) String payload2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2074,23 +2077,23 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildTwoForms() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildTwoForms() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method twoForms = TestFormReplace.class.getMethod("twoForms", String.class, String.class);
|
Method twoForms = TestFormReplace.class.getMethod("twoForms", String.class, String.class);
|
||||||
Object form = factory(TestFormReplace.class).createRequest(twoForms, "robot", "eggs").getPayload()
|
Object form = factory(TestFormReplace.class).createRequest(twoForms, "robot", "eggs").getPayload()
|
||||||
.getRawContent();
|
.getRawContent();
|
||||||
assertEquals(form, "x-amz-copy-source=/robot/eggs");
|
assertEquals(form, "x-amz-copy-source=/robot/eggs");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildTwoFormsOutOfOrder() throws SecurityException, NoSuchMethodException,
|
public void testBuildTwoFormsOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||||
UnsupportedEncodingException {
|
UnsupportedEncodingException {
|
||||||
Method twoFormsOutOfOrder = TestFormReplace.class.getMethod("twoFormsOutOfOrder", String.class, String.class);
|
Method twoFormsOutOfOrder = TestFormReplace.class.getMethod("twoFormsOutOfOrder", String.class, String.class);
|
||||||
Object form = factory(TestFormReplace.class).createRequest(twoFormsOutOfOrder, "robot", "eggs").getPayload()
|
Object form = factory(TestFormReplace.class).createRequest(twoFormsOutOfOrder, "robot", "eggs").getPayload()
|
||||||
.getRawContent();
|
.getRawContent();
|
||||||
assertEquals(form, "x-amz-copy-source=/eggs/robot");
|
assertEquals(form, "x-amz-copy-source=/eggs/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private <T> RestAnnotationProcessor<T> factory(Class<T> clazz) {
|
private <T> RestAnnotationProcessor<T> factory(Class<T> clazz) {
|
||||||
return ((RestAnnotationProcessor<T>) injector.getInstance(Key.get(newParameterizedType(
|
return ((RestAnnotationProcessor<T>) injector.getInstance(Key.get(newParameterizedType(
|
||||||
RestAnnotationProcessor.class, clazz))));
|
RestAnnotationProcessor.class, clazz))));
|
||||||
}
|
}
|
||||||
|
|
||||||
DateService dateService = new SimpleDateFormatDateService();
|
DateService dateService = new SimpleDateFormatDateService();
|
||||||
|
@ -2098,15 +2101,16 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
void setupFactory() {
|
void setupFactory() {
|
||||||
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo", null,
|
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo", null,
|
||||||
String.class, Integer.class,
|
String.class, Integer.class, ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(),
|
||||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
|
new AbstractModule() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(URI.class).annotatedWith(Localhost2.class).toInstance(URI.create("http://localhost:1111"));
|
bind(URI.class).annotatedWith(Localhost2.class).toInstance(
|
||||||
}
|
URI.create("http://localhost:1111"));
|
||||||
|
}
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
injector = createContextBuilder(contextSpec).buildInjector();
|
injector = createContextBuilder(contextSpec).buildInjector();
|
||||||
parserFactory = injector.getInstance(ParseSax.Factory.class);
|
parserFactory = injector.getInstance(ParseSax.Factory.class);
|
||||||
|
|
Loading…
Reference in New Issue