mirror of https://github.com/apache/jclouds.git
updated nested parser so that it can return empty collections
This commit is contained in:
parent
db6b3375d0
commit
096b25509d
|
@ -19,7 +19,9 @@
|
|||
|
||||
package org.jclouds.http.functions;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
@ -27,7 +29,11 @@ import javax.inject.Singleton;
|
|||
import org.jclouds.http.HttpResponse;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
|
@ -36,20 +42,30 @@ import com.google.common.collect.Iterables;
|
|||
public class UnwrapOnlyNestedJsonValue<T> implements Function<HttpResponse, T> {
|
||||
|
||||
private final ParseJson<Map<String, Map<String, T>>> json;
|
||||
private final TypeLiteral<T> type;
|
||||
|
||||
@Inject
|
||||
UnwrapOnlyNestedJsonValue(ParseJson<Map<String, Map<String, T>>> json) {
|
||||
UnwrapOnlyNestedJsonValue(ParseJson<Map<String, Map<String, T>>> json, TypeLiteral<T> type) {
|
||||
this.json = json;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T apply(HttpResponse arg0) {
|
||||
Map<String, Map<String, T>> map = json.apply(arg0);
|
||||
if (map == null || map.size() == 0)
|
||||
return null;
|
||||
Map<String, T> map1 = Iterables.getOnlyElement(map.values());
|
||||
if (map1 == null || map1.size() == 0)
|
||||
if (map1 == null || map1.size() == 0) {
|
||||
if (type.getRawType().isAssignableFrom(Set.class))
|
||||
return (T) ImmutableSet.of();
|
||||
else if (type.getRawType().isAssignableFrom(List.class))
|
||||
return (T) ImmutableList.of();
|
||||
else if (type.getRawType().isAssignableFrom(Map.class))
|
||||
return (T) ImmutableMap.of();
|
||||
return null;
|
||||
}
|
||||
return Iterables.getOnlyElement(map1.values());
|
||||
}
|
||||
}
|
|
@ -212,7 +212,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testDelegateAsyncIncludesVersion() throws SecurityException, NoSuchMethodException,
|
||||
InterruptedException, ExecutionException {
|
||||
InterruptedException, ExecutionException {
|
||||
Injector child = injectorForClient();
|
||||
TransformingHttpCommandExecutorService mock = child.getInstance(TransformingHttpCommandExecutorService.class);
|
||||
|
||||
|
@ -227,7 +227,7 @@ 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();
|
||||
.andReturn(createNiceMock(ListenableFuture.class)).atLeastOnce();
|
||||
replay(mock);
|
||||
|
||||
caller.getCallee().onePath("foo");
|
||||
|
@ -256,7 +256,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);
|
||||
|
||||
|
@ -271,7 +271,7 @@ 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();
|
||||
.andReturn(Futures.<Void> immediateFuture(null)).atLeastOnce();
|
||||
replay(mock);
|
||||
|
||||
caller.getCallee().onePath("foo");
|
||||
|
@ -283,8 +283,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()));
|
||||
"userfoo", null, Caller.class, AsyncCaller.class,
|
||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new CallerCalleeModule()));
|
||||
|
||||
return createContextBuilder(contextSpec).buildInjector();
|
||||
|
||||
|
@ -299,7 +299,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
};
|
||||
|
||||
@Target( { ElementType.METHOD })
|
||||
@Target({ ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@javax.ws.rs.HttpMethod("FOO")
|
||||
public @interface FOO {
|
||||
|
@ -334,10 +334,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);
|
||||
}
|
||||
|
@ -408,7 +408,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);
|
||||
}
|
||||
|
||||
|
@ -501,7 +501,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(), "");
|
||||
|
@ -606,44 +606,44 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
@POST
|
||||
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
|
||||
void withParamByteArrayBinaryPart(
|
||||
@FormParam("name") String name,
|
||||
@PartParam(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM, filename = "{name}.tar.gz") byte[] content);
|
||||
@FormParam("name") String name,
|
||||
@PartParam(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM, filename = "{name}.tar.gz") byte[] content);
|
||||
}
|
||||
|
||||
public void testMultipartWithStringPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestMultipartForm.class.getMethod("withStringPart", String.class);
|
||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||
"foobledata");
|
||||
"foobledata");
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest,//
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"fooble\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"foobledata\r\n" + //
|
||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"fooble\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"foobledata\r\n" + //
|
||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||
}
|
||||
|
||||
public void testMultipartWithParamStringPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestMultipartForm.class.getMethod("withParamStringPart", String.class, String.class);
|
||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||
"name", "foobledata");
|
||||
"name", "foobledata");
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest,//
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"name\r\n" + // /
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"file\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"foobledata\r\n" + //
|
||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"name\r\n" + // /
|
||||
"----JCLOUDS--\r\n" + //
|
||||
"Content-Disposition: form-data; name=\"file\"\r\n" + //
|
||||
"\r\n" + //
|
||||
"foobledata\r\n" + //
|
||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||
}
|
||||
|
||||
public void testMultipartWithParamFilePart() throws SecurityException, NoSuchMethodException, IOException {
|
||||
|
@ -653,38 +653,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 {
|
||||
|
@ -694,20 +694,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 {
|
||||
|
@ -778,7 +778,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<String> testUnwrapDepth3();
|
||||
|
||||
@Target( { ElementType.METHOD })
|
||||
@Target({ ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@HttpMethod("ROWDY")
|
||||
public @interface ROWDY {
|
||||
|
@ -833,7 +833,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");
|
||||
|
||||
|
@ -848,10 +848,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"));
|
||||
|
||||
}
|
||||
|
||||
|
@ -864,10 +864,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"));
|
||||
|
||||
}
|
||||
|
||||
|
@ -880,10 +880,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"));
|
||||
|
||||
}
|
||||
|
||||
|
@ -896,7 +896,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");
|
||||
|
||||
|
@ -911,7 +911,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");
|
||||
|
||||
|
@ -926,10 +926,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")
|
||||
|
@ -941,10 +941,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")
|
||||
|
@ -956,10 +956,13 @@ 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\":{\"runit\":[\"0.7.0\",\"0.7.1\"]}}"))), ImmutableSet.of("0.7.0", "0.7.1"));
|
||||
newStringPayload("{\"runit\":{\"runit\":[\"0.7.0\",\"0.7.1\"]}}"))), ImmutableSet.of("0.7.0", "0.7.1"));
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{}}"))),
|
||||
ImmutableSet.<String> of());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -971,10 +974,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\":{\"runit\":[\"0.7.0\"]}}"))),
|
||||
"0.7.0");
|
||||
"0.7.0");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -986,9 +989,11 @@ 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\":{\"runit\":[]}}"))), null);
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{}}"))), null);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -1001,7 +1006,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);
|
||||
|
||||
parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{\"runit\":[\"0.7.0\",\"0.7.1\"]}}")));
|
||||
}
|
||||
|
@ -1053,9 +1058,9 @@ 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")).headers(
|
||||
ImmutableMultimap.of("foo", "bar")).build());
|
||||
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);
|
||||
|
@ -1103,7 +1108,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);
|
||||
|
@ -1240,7 +1245,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"));
|
||||
|
@ -1258,7 +1263,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"));
|
||||
}
|
||||
|
@ -1267,7 +1272,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"));
|
||||
}
|
||||
|
@ -1276,17 +1281,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"));
|
||||
}
|
||||
|
@ -1300,8 +1305,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");
|
||||
}
|
||||
|
||||
|
@ -1309,13 +1314,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);
|
||||
}
|
||||
|
@ -1357,7 +1362,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");
|
||||
}
|
||||
|
||||
|
@ -1373,7 +1378,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");
|
||||
}
|
||||
|
||||
|
@ -1381,7 +1386,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");
|
||||
}
|
||||
|
||||
|
@ -1389,16 +1394,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");
|
||||
}
|
||||
|
||||
|
@ -1411,9 +1416,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");
|
||||
}
|
||||
|
||||
|
@ -1454,7 +1459,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");
|
||||
}
|
||||
|
||||
|
@ -1471,7 +1476,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");
|
||||
}
|
||||
|
||||
|
@ -1479,7 +1484,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");
|
||||
}
|
||||
|
||||
|
@ -1487,17 +1492,17 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testBuildTwoMatrixs() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
Method twoMatrixs = TestMatrixReplace.class.getMethod("twoMatrixs", String.class, String.class);
|
||||
String path = factory(TestMatrixReplace.class).createRequest(twoMatrixs, new Object[] { "robot", "eggs" })
|
||||
.getEndpoint().getPath();
|
||||
.getEndpoint().getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/robot/eggs");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoMatrixsOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||
UnsupportedEncodingException {
|
||||
UnsupportedEncodingException {
|
||||
Method twoMatrixsOutOfOrder = TestMatrixReplace.class.getMethod("twoMatrixsOutOfOrder", String.class,
|
||||
String.class);
|
||||
String path = factory(TestMatrixReplace.class).createRequest(twoMatrixsOutOfOrder,
|
||||
new Object[] { "robot", "eggs" }).getEndpoint().getPath();
|
||||
String.class);
|
||||
String path = factory(TestMatrixReplace.class)
|
||||
.createRequest(twoMatrixsOutOfOrder, new Object[] { "robot", "eggs" }).getEndpoint().getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/eggs/robot");
|
||||
}
|
||||
|
||||
|
@ -1539,7 +1544,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testPutPayloadEnclosing() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class);
|
||||
HttpRequest request = factory(TestQuery.class).createRequest(method,
|
||||
new PayloadEnclosingImpl(newStringPayload("whoops")));
|
||||
new PayloadEnclosingImpl(newStringPayload("whoops")));
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, "whoops", "application/unknown", false);
|
||||
|
@ -1557,10 +1562,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);
|
||||
|
@ -1617,7 +1622,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);
|
||||
|
@ -1638,7 +1643,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);
|
||||
|
@ -1662,9 +1667,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 {
|
||||
|
@ -1680,7 +1685,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
public static class ReturnStringIf200Context extends ReturnStringIf2xx implements
|
||||
InvocationContext<ReturnStringIf200Context> {
|
||||
InvocationContext<ReturnStringIf200Context> {
|
||||
|
||||
public HttpRequest request;
|
||||
|
||||
|
@ -1702,8 +1707,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);
|
||||
|
@ -1744,7 +1749,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}")
|
||||
|
@ -1756,7 +1761,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 {
|
||||
|
@ -1770,8 +1775,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 {
|
||||
|
@ -1784,8 +1789,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 {
|
||||
|
@ -1848,7 +1853,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");
|
||||
|
@ -1891,7 +1896,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);
|
||||
|
@ -1956,7 +1961,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"));
|
||||
}
|
||||
|
@ -1965,7 +1970,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"));
|
||||
}
|
||||
|
@ -1974,7 +1979,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"));
|
||||
|
@ -1984,7 +1989,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");
|
||||
|
@ -2007,7 +2012,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> {
|
||||
|
@ -2027,7 +2032,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"));
|
||||
|
||||
}
|
||||
|
@ -2037,7 +2042,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testTwoDifferentEndpointParams() throws SecurityException, NoSuchMethodException {
|
||||
Method method = TestEndpointParams.class.getMethod("twoEndpointParams", String.class, String.class);
|
||||
URI uri = factory(TestEndpointParams.class).getEndpointInParametersOrNull(method,
|
||||
new Object[] { "robot", "egg" }, injector);
|
||||
new Object[] { "robot", "egg" }, injector);
|
||||
assertEquals(uri, URI.create("robot/egg"));
|
||||
}
|
||||
|
||||
|
@ -2048,11 +2053,11 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@PUT
|
||||
@Path("/{foo}")
|
||||
public ListenableFuture<Void> putWithPath(@PathParam("foo") String path,
|
||||
@BinderParam(BindToStringPayload.class) String content);
|
||||
@BinderParam(BindToStringPayload.class) String content);
|
||||
|
||||
@PUT
|
||||
public void twoEntities(@BinderParam(BindToStringPayload.class) String payload1,
|
||||
@BinderParam(BindToStringPayload.class) String payload2);
|
||||
@BinderParam(BindToStringPayload.class) String payload2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2150,23 +2155,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();
|
||||
|
@ -2174,16 +2179,15 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@BeforeClass
|
||||
void setupFactory() {
|
||||
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo",
|
||||
null, String.class, Integer.class, ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(),
|
||||
new AbstractModule() {
|
||||
null, 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);
|
||||
|
|
Loading…
Reference in New Issue