mirror of https://github.com/apache/jclouds.git
Merge pull request #284 from jclouds/issue-795-support-java-7
Issue 795: support java 7
This commit is contained in:
commit
92a926d655
|
@ -96,12 +96,17 @@ public class EC2ListNodesStrategy implements ListNodesStrategy {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Future<Set<? extends Reservation<? extends RunningInstance>>> apply(String from) {
|
public Future<Set<? extends Reservation<? extends RunningInstance>>> apply(String from) {
|
||||||
return (Future<Set<? extends Reservation<? extends RunningInstance>>>) client
|
return castToSpecificTypedFuture(client.getInstanceServices().describeInstancesInRegion(from));
|
||||||
.getInstanceServices().describeInstancesInRegion(from);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}, executor, null, logger, "reservations");
|
}, executor, null, logger, "reservations");
|
||||||
|
|
||||||
return concat(concat(reservations));
|
return concat(concat(reservations));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "hide" this cast (i.e. do not perform inline) from the Java 7 compiler - see http://stackoverflow.com/questions/8637937/why-does-a-generic-cast-of-a-list-extends-set-to-listset-succeed-on-sun
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static <T> Future<T> castToSpecificTypedFuture(Future<? extends T> input) {
|
||||||
|
return (Future<T>) input;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,31 +36,30 @@ import com.google.common.collect.Multimap;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class HttpMessage extends PayloadEnclosingImpl {
|
public class HttpMessage extends PayloadEnclosingImpl {
|
||||||
public static Builder<? extends HttpMessage> builder() {
|
public static Builder builder() {
|
||||||
return new Builder<HttpMessage>();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder<T extends HttpMessage> {
|
public static class Builder {
|
||||||
protected Payload payload;
|
protected Payload payload;
|
||||||
protected Multimap<String, String> headers = ImmutableMultimap.of();
|
protected Multimap<String, String> headers = ImmutableMultimap.of();
|
||||||
|
|
||||||
public Builder<T> payload(Payload payload) {
|
public Builder payload(Payload payload) {
|
||||||
this.payload = payload;
|
this.payload = payload;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder<T> headers(Multimap<String, String> headers) {
|
public Builder headers(Multimap<String, String> headers) {
|
||||||
this.headers = ImmutableMultimap.copyOf(checkNotNull(headers, "headers"));
|
this.headers = ImmutableMultimap.copyOf(checkNotNull(headers, "headers"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
public HttpMessage build() {
|
||||||
public T build() {
|
return new HttpMessage(payload, headers);
|
||||||
return (T) new HttpMessage(payload, headers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <X extends HttpMessage> Builder<X> from(X input) {
|
public static Builder from(HttpMessage input) {
|
||||||
return new Builder<X>().payload(input.getPayload()).headers(input.getHeaders());
|
return new Builder().payload(input.getPayload()).headers(input.getHeaders());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +84,7 @@ public class HttpMessage extends PayloadEnclosingImpl {
|
||||||
return (values.size() >= 1) ? values.iterator().next() : null;
|
return (values.size() >= 1) ? values.iterator().next() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder<? extends HttpMessage> toBuilder() {
|
public Builder toBuilder() {
|
||||||
return Builder.from(this);
|
return Builder.from(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,32 +39,32 @@ import com.google.common.collect.Multimap;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class HttpRequest extends HttpMessage {
|
public class HttpRequest extends HttpMessage {
|
||||||
public static Builder<? extends HttpRequest> builder() {
|
public static Builder builder() {
|
||||||
return new Builder<HttpRequest>();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder<T extends HttpRequest> extends HttpMessage.Builder<T> {
|
public static class Builder extends HttpMessage.Builder {
|
||||||
protected String method;
|
protected String method;
|
||||||
protected URI endpoint;
|
protected URI endpoint;
|
||||||
protected char[] skips = new char[] {};
|
protected char[] skips = new char[] {};
|
||||||
protected List<HttpRequestFilter> requestFilters = ImmutableList.of();
|
protected List<HttpRequestFilter> requestFilters = ImmutableList.of();
|
||||||
|
|
||||||
public Builder<T> filters(List<HttpRequestFilter> requestFilters) {
|
public Builder filters(List<HttpRequestFilter> requestFilters) {
|
||||||
this.requestFilters = ImmutableList.copyOf(checkNotNull(requestFilters, "requestFilters"));
|
this.requestFilters = ImmutableList.copyOf(checkNotNull(requestFilters, "requestFilters"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder<T> method(String method) {
|
public Builder method(String method) {
|
||||||
this.method = checkNotNull(method, "method");
|
this.method = checkNotNull(method, "method");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder<T> endpoint(URI endpoint) {
|
public Builder endpoint(URI endpoint) {
|
||||||
this.endpoint = checkNotNull(endpoint, "endpoint");
|
this.endpoint = checkNotNull(endpoint, "endpoint");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder<T> skips(char[] skips) {
|
public Builder skips(char[] skips) {
|
||||||
char[] retval = new char[checkNotNull(skips, "skips").length];
|
char[] retval = new char[checkNotNull(skips, "skips").length];
|
||||||
System.arraycopy(skips, 0, retval, 0, skips.length);
|
System.arraycopy(skips, 0, retval, 0, skips.length);
|
||||||
this.skips = retval;
|
this.skips = retval;
|
||||||
|
@ -72,23 +72,22 @@ public class HttpRequest extends HttpMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder<T> payload(Payload payload) {
|
public Builder payload(Payload payload) {
|
||||||
return (Builder<T>) super.payload(payload);
|
return (Builder) super.payload(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder<T> headers(Multimap<String, String> headers) {
|
public Builder headers(Multimap<String, String> headers) {
|
||||||
return (Builder<T>) super.headers(headers);
|
return (Builder) super.headers(headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
public HttpRequest build() {
|
||||||
public T build() {
|
return new HttpRequest(method, endpoint, skips, requestFilters, payload, headers);
|
||||||
return (T) new HttpRequest(method, endpoint, skips, requestFilters, payload, headers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <X extends HttpRequest> Builder<X> from(X input) {
|
public static Builder from(HttpRequest input) {
|
||||||
return new Builder<X>().method(input.getMethod()).endpoint(input.getEndpoint()).skips(input.getSkips())
|
return new Builder().method(input.getMethod()).endpoint(input.getEndpoint()).skips(input.getSkips())
|
||||||
.filters(input.getFilters()).payload(input.getPayload()).headers(input.getHeaders());
|
.filters(input.getFilters()).payload(input.getPayload()).headers(input.getHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +188,7 @@ public class HttpRequest extends HttpMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder<? extends HttpRequest> toBuilder() {
|
public Builder toBuilder() {
|
||||||
return Builder.from(this);
|
return Builder.from(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class HttpResponse extends HttpMessage {
|
||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder extends HttpMessage.Builder<HttpResponse> {
|
public static class Builder extends HttpMessage.Builder {
|
||||||
private int statusCode;
|
private int statusCode;
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
|
|
|
@ -40,11 +40,21 @@ import com.google.common.collect.Multimap;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class GeneratedHttpRequest<T> extends HttpRequest {
|
public class GeneratedHttpRequest<T> extends HttpRequest {
|
||||||
public static <T> Builder<T> builder() {
|
public static Builder<?> builder() {
|
||||||
return new Builder<T>();
|
// empty builder, so can be safely cast to Builder<T> by the caller
|
||||||
|
return new Builder<Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder<T> extends HttpRequest.Builder<GeneratedHttpRequest<T>> {
|
/*
|
||||||
|
* Convenience method - cannot have the same signature as builder() - see
|
||||||
|
* http://code.google.com/p/jclouds/issues/detail?id=795
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> Builder<T> requestBuilder() {
|
||||||
|
return (Builder<T>) builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder<T> extends HttpRequest.Builder {
|
||||||
protected Class<T> declaring;
|
protected Class<T> declaring;
|
||||||
protected Method javaMethod;
|
protected Method javaMethod;
|
||||||
protected List<Object> args;
|
protected List<Object> args;
|
||||||
|
@ -69,31 +79,37 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Builder<T> filters(List<HttpRequestFilter> requestFilters) {
|
public Builder<T> filters(List<HttpRequestFilter> requestFilters) {
|
||||||
return (Builder<T>) super.filters(requestFilters);
|
return (Builder<T>) super.filters(requestFilters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Builder<T> method(String method) {
|
public Builder<T> method(String method) {
|
||||||
return (Builder<T>) super.method(method);
|
return (Builder<T>) super.method(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Builder<T> endpoint(URI endpoint) {
|
public Builder<T> endpoint(URI endpoint) {
|
||||||
return (Builder<T>) super.endpoint(endpoint);
|
return (Builder<T>) super.endpoint(endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Builder<T> skips(char[] skips) {
|
public Builder<T> skips(char[] skips) {
|
||||||
return (Builder<T>) super.skips(skips);
|
return (Builder<T>) super.skips(skips);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Builder<T> payload(Payload payload) {
|
public Builder<T> payload(Payload payload) {
|
||||||
return (Builder<T>) super.payload(payload);
|
return (Builder<T>) super.payload(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Builder<T> headers(Multimap<String, String> headers) {
|
public Builder<T> headers(Multimap<String, String> headers) {
|
||||||
return (Builder<T>) super.headers(headers);
|
return (Builder<T>) super.headers(headers);
|
||||||
|
@ -105,11 +121,24 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
|
||||||
javaMethod, args);
|
javaMethod, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <Y> Builder<Y> from(HttpRequest input) {
|
public static Builder<?> from(HttpRequest input) {
|
||||||
return new Builder<Y>().method(input.getMethod()).endpoint(input.getEndpoint()).skips(input.getSkips())
|
/*
|
||||||
|
* State added to builder will not conflict with return type so caller can
|
||||||
|
* safely cast result to Builder<T>
|
||||||
|
*/
|
||||||
|
return new Builder<Object>().method(input.getMethod()).endpoint(input.getEndpoint()).skips(input.getSkips())
|
||||||
.filters(input.getFilters()).payload(input.getPayload()).headers(input.getHeaders());
|
.filters(input.getFilters()).payload(input.getPayload()).headers(input.getHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convenience method - cannot have the same signature as from(HttpRequest) - see
|
||||||
|
* http://code.google.com/p/jclouds/issues/detail?id=795
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <Y> Builder<Y> fromRequest(HttpRequest input) {
|
||||||
|
return (Builder<Y>) from(input);
|
||||||
|
}
|
||||||
|
|
||||||
public static <Y> Builder<Y> from(GeneratedHttpRequest<Y> input) {
|
public static <Y> Builder<Y> from(GeneratedHttpRequest<Y> input) {
|
||||||
return new Builder<Y>().method(input.getMethod()).endpoint(input.getEndpoint()).skips(input.getSkips())
|
return new Builder<Y>().method(input.getMethod()).endpoint(input.getEndpoint()).skips(input.getSkips())
|
||||||
.filters(input.getFilters()).payload(input.getPayload()).headers(input.getHeaders())
|
.filters(input.getFilters()).payload(input.getPayload()).headers(input.getHeaders())
|
||||||
|
|
|
@ -420,18 +420,10 @@ public class RestAnnotationProcessor<T> {
|
||||||
GeneratedHttpRequest.Builder<T> requestBuilder;
|
GeneratedHttpRequest.Builder<T> requestBuilder;
|
||||||
HttpRequest r = RestAnnotationProcessor.findHttpRequestInArgs(args);
|
HttpRequest r = RestAnnotationProcessor.findHttpRequestInArgs(args);
|
||||||
if (r != null) {
|
if (r != null) {
|
||||||
requestBuilder = GeneratedHttpRequest.Builder.<T> from(r);
|
requestBuilder = GeneratedHttpRequest.Builder.fromRequest(r);
|
||||||
endpoint = r.getEndpoint();
|
endpoint = r.getEndpoint();
|
||||||
} else {
|
} else {
|
||||||
/*
|
requestBuilder = GeneratedHttpRequest.requestBuilder();
|
||||||
* Can't use GeneratedHttpRequest.<T>builder() because the T is too
|
|
||||||
* general for the compiler to be able to distinguish between
|
|
||||||
* GeneratedHttpRequest.builder() and HttpMessage.builder() - the
|
|
||||||
* latter is available because GHR inherits from HM.
|
|
||||||
*
|
|
||||||
* See http://code.google.com/p/jclouds/issues/detail?id=461
|
|
||||||
*/
|
|
||||||
requestBuilder = new GeneratedHttpRequest.Builder<T>();
|
|
||||||
requestBuilder.method(getHttpMethodOrConstantOrThrowException(method));
|
requestBuilder.method(getHttpMethodOrConstantOrThrowException(method));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@ import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.classextension.EasyMock.createMock;
|
import static org.easymock.classextension.EasyMock.createMock;
|
||||||
import static org.easymock.classextension.EasyMock.replay;
|
import static org.easymock.classextension.EasyMock.replay;
|
||||||
import static org.easymock.classextension.EasyMock.verify;
|
import static org.easymock.classextension.EasyMock.verify;
|
||||||
|
import static org.jclouds.utils.TestUtils.NO_INVOCATIONS;
|
||||||
|
import static org.jclouds.utils.TestUtils.SINGLE_NO_ARG_INVOCATION;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -31,6 +33,8 @@ import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.utils.TestUtils;
|
||||||
|
import org.testng.annotations.DataProvider;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.xml.sax.Locator;
|
import org.xml.sax.Locator;
|
||||||
import org.xml.sax.SAXParseException;
|
import org.xml.sax.SAXParseException;
|
||||||
|
@ -53,7 +57,17 @@ public class ParseSaxTest extends BaseHandlerTest {
|
||||||
ParseSax<String> createParser() {
|
ParseSax<String> createParser() {
|
||||||
return factory.create(injector.getInstance(TestHandler.class));
|
return factory.create(injector.getInstance(TestHandler.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DataProvider
|
||||||
|
public Object[][] runUnderJava7() {
|
||||||
|
return (TestUtils.isJava7() ? SINGLE_NO_ARG_INVOCATION : NO_INVOCATIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DataProvider
|
||||||
|
public Object[][] ignoreUnderJava7() {
|
||||||
|
return (TestUtils.isJava7() ? NO_INVOCATIONS : SINGLE_NO_ARG_INVOCATION);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddDetailsAndPropagateOkWhenRequestWithNoDataAndRuntimeExceptionThrowsOriginalException()
|
public void testAddDetailsAndPropagateOkWhenRequestWithNoDataAndRuntimeExceptionThrowsOriginalException()
|
||||||
throws ExecutionException, InterruptedException, TimeoutException, IOException {
|
throws ExecutionException, InterruptedException, TimeoutException, IOException {
|
||||||
|
@ -99,7 +113,7 @@ public class ParseSaxTest extends BaseHandlerTest {
|
||||||
assertEquals(e.getCause(), input);
|
assertEquals(e.getCause(), input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddDetailsAndPropagateOkWithValidRequestResponse() throws ExecutionException, InterruptedException,
|
public void testAddDetailsAndPropagateOkWithValidRequestResponse() throws ExecutionException, InterruptedException,
|
||||||
TimeoutException, IOException {
|
TimeoutException, IOException {
|
||||||
|
@ -118,7 +132,7 @@ public class ParseSaxTest extends BaseHandlerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(dataProvider = "ignoreUnderJava7", description = "see http://code.google.com/p/jclouds/issues/detail?id=795")
|
||||||
public void testAddDetailsAndPropagateOkWithValidRequestResponseWithSAXParseException() throws ExecutionException,
|
public void testAddDetailsAndPropagateOkWithValidRequestResponseWithSAXParseException() throws ExecutionException,
|
||||||
InterruptedException, TimeoutException, IOException {
|
InterruptedException, TimeoutException, IOException {
|
||||||
|
|
||||||
|
@ -144,4 +158,29 @@ public class ParseSaxTest extends BaseHandlerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(dataProvider = "runUnderJava7", description = "see http://code.google.com/p/jclouds/issues/detail?id=795")
|
||||||
|
public void testAddDetailsAndPropagateOkWithValidRequestResponseWithSAXParseException_java7() throws ExecutionException,
|
||||||
|
InterruptedException, TimeoutException, IOException {
|
||||||
|
|
||||||
|
ParseSax<String> parser = createParser();
|
||||||
|
HttpRequest request = new HttpRequest("GET", URI.create("http://foohost"));
|
||||||
|
HttpResponse response = new HttpResponse(304, "Not Modified", null);
|
||||||
|
Locator locator = createMock(Locator.class);
|
||||||
|
expect(locator.getColumnNumber()).andReturn(1);
|
||||||
|
expect(locator.getLineNumber()).andReturn(1);
|
||||||
|
expect(locator.getPublicId()).andReturn("publicId");
|
||||||
|
expect(locator.getSystemId()).andReturn("systemId");
|
||||||
|
replay(locator);
|
||||||
|
Exception input = new SAXParseException("foo", locator);
|
||||||
|
verify(locator);
|
||||||
|
|
||||||
|
try {
|
||||||
|
parser.setContext(request);
|
||||||
|
parser.addDetailsAndPropagate(response, input);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
assertEquals(e.getMessage(),
|
||||||
|
"request: GET http://foohost HTTP/1.1; response: HTTP/1.1 304 Not Modified; error at 1:1 in document systemId; cause: org.xml.sax.SAXParseExceptionpublicId: publicId; systemId: systemId; lineNumber: 1; columnNumber: 1; foo");
|
||||||
|
assertEquals(e.getCause(), input);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -54,8 +54,7 @@ public class BindMapToStringPayloadTest {
|
||||||
@Test
|
@Test
|
||||||
public void testCorrect() throws SecurityException, NoSuchMethodException {
|
public void testCorrect() throws SecurityException, NoSuchMethodException {
|
||||||
Method testPayload = TestPayload.class.getMethod("testPayload", String.class);
|
Method testPayload = TestPayload.class.getMethod("testPayload", String.class);
|
||||||
// can't use GHR.builder() - see http://code.google.com/p/jclouds/issues/detail?id=461
|
GeneratedHttpRequest<TestPayload> request = GeneratedHttpRequest.<TestPayload>requestBuilder()
|
||||||
GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest.Builder<TestPayload>()
|
|
||||||
.declaring(TestPayload.class).javaMethod(testPayload).args(ImmutableList.<Object> of("robot"))
|
.declaring(TestPayload.class).javaMethod(testPayload).args(ImmutableList.<Object> of("robot"))
|
||||||
.method(HttpMethod.POST).endpoint(URI.create("http://localhost")).build();
|
.method(HttpMethod.POST).endpoint(URI.create("http://localhost")).build();
|
||||||
|
|
||||||
|
@ -69,8 +68,7 @@ public class BindMapToStringPayloadTest {
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testMustHavePayloadAnnotation() throws SecurityException, NoSuchMethodException {
|
public void testMustHavePayloadAnnotation() throws SecurityException, NoSuchMethodException {
|
||||||
Method noPayload = TestPayload.class.getMethod("noPayload", String.class);
|
Method noPayload = TestPayload.class.getMethod("noPayload", String.class);
|
||||||
// can't use GHR.builder() - see http://code.google.com/p/jclouds/issues/detail?id=461
|
GeneratedHttpRequest<TestPayload> request = GeneratedHttpRequest.<TestPayload>requestBuilder()
|
||||||
GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest.Builder<TestPayload>()
|
|
||||||
.declaring(TestPayload.class).javaMethod(noPayload).args(ImmutableList.<Object> of("robot"))
|
.declaring(TestPayload.class).javaMethod(noPayload).args(ImmutableList.<Object> of("robot"))
|
||||||
.method(HttpMethod.POST).endpoint(URI.create("http://localhost")).build();
|
.method(HttpMethod.POST).endpoint(URI.create("http://localhost")).build();
|
||||||
binder().bindToRequest(request, ImmutableMap.of("fooble", "robot"));
|
binder().bindToRequest(request, ImmutableMap.of("fooble", "robot"));
|
||||||
|
|
|
@ -1816,8 +1816,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void oneTransformerWithContext() throws SecurityException, NoSuchMethodException {
|
public void oneTransformerWithContext() throws SecurityException, NoSuchMethodException {
|
||||||
RestAnnotationProcessor<TestTransformers> processor = factory(TestTransformers.class);
|
RestAnnotationProcessor<TestTransformers> processor = factory(TestTransformers.class);
|
||||||
Method method = TestTransformers.class.getMethod("oneTransformerWithContext");
|
Method method = TestTransformers.class.getMethod("oneTransformerWithContext");
|
||||||
// can't use GHR.builder() - see http://code.google.com/p/jclouds/issues/detail?id=461
|
GeneratedHttpRequest<TestTransformers> request = GeneratedHttpRequest.<TestTransformers>requestBuilder().method("GET")
|
||||||
GeneratedHttpRequest<TestTransformers> request = new GeneratedHttpRequest.Builder<TestTransformers>().method("GET")
|
|
||||||
.endpoint(URI.create("http://localhost")).declaring(TestTransformers.class).javaMethod(method)
|
.endpoint(URI.create("http://localhost")).declaring(TestTransformers.class).javaMethod(method)
|
||||||
.args(new Object[] {}).build();
|
.args(new Object[] {}).build();
|
||||||
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
|
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
|
||||||
|
@ -2349,8 +2348,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testCreateJAXBResponseParserWithAnnotation() throws SecurityException, NoSuchMethodException {
|
public void testCreateJAXBResponseParserWithAnnotation() throws SecurityException, NoSuchMethodException {
|
||||||
RestAnnotationProcessor<TestJAXBResponseParser> processor = factory(TestJAXBResponseParser.class);
|
RestAnnotationProcessor<TestJAXBResponseParser> processor = factory(TestJAXBResponseParser.class);
|
||||||
Method method = TestJAXBResponseParser.class.getMethod("jaxbGetWithAnnotation");
|
Method method = TestJAXBResponseParser.class.getMethod("jaxbGetWithAnnotation");
|
||||||
// can't use GHR.builder() - see http://code.google.com/p/jclouds/issues/detail?id=461
|
GeneratedHttpRequest<TestJAXBResponseParser> request = GeneratedHttpRequest.<TestJAXBResponseParser>requestBuilder()
|
||||||
GeneratedHttpRequest<TestJAXBResponseParser> request = new GeneratedHttpRequest.Builder<TestJAXBResponseParser>()
|
|
||||||
.method("GET").endpoint(URI.create("http://localhost")).declaring(TestJAXBResponseParser.class)
|
.method("GET").endpoint(URI.create("http://localhost")).declaring(TestJAXBResponseParser.class)
|
||||||
.javaMethod(method).args(new Object[] {}).build();
|
.javaMethod(method).args(new Object[] {}).build();
|
||||||
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
|
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
|
||||||
|
@ -2361,8 +2359,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testCreateJAXBResponseParserWithAcceptHeader() throws SecurityException, NoSuchMethodException {
|
public void testCreateJAXBResponseParserWithAcceptHeader() throws SecurityException, NoSuchMethodException {
|
||||||
RestAnnotationProcessor<TestJAXBResponseParser> processor = factory(TestJAXBResponseParser.class);
|
RestAnnotationProcessor<TestJAXBResponseParser> processor = factory(TestJAXBResponseParser.class);
|
||||||
Method method = TestJAXBResponseParser.class.getMethod("jaxbGetWithAcceptHeader");
|
Method method = TestJAXBResponseParser.class.getMethod("jaxbGetWithAcceptHeader");
|
||||||
// can't use GHR.builder() - see http://code.google.com/p/jclouds/issues/detail?id=461
|
GeneratedHttpRequest<TestJAXBResponseParser> request = GeneratedHttpRequest.<TestJAXBResponseParser>requestBuilder()
|
||||||
GeneratedHttpRequest<TestJAXBResponseParser> request = new GeneratedHttpRequest.Builder<TestJAXBResponseParser>()
|
|
||||||
.method("GET").endpoint(URI.create("http://localhost")).declaring(TestJAXBResponseParser.class)
|
.method("GET").endpoint(URI.create("http://localhost")).declaring(TestJAXBResponseParser.class)
|
||||||
.javaMethod(method).args(new Object[] {}).build();
|
.javaMethod(method).args(new Object[] {}).build();
|
||||||
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
|
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
/**
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. jclouds licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class for test
|
||||||
|
*
|
||||||
|
* @author Andrew Phillips
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class TestUtils {
|
||||||
|
public static final Object[][] NO_INVOCATIONS = new Object[0][0];
|
||||||
|
public static final Object[][] SINGLE_NO_ARG_INVOCATION = new Object[][] { new Object[0] };
|
||||||
|
|
||||||
|
public static boolean isJava7() {
|
||||||
|
System.out.println(System.getProperty("java.version", "None??"));
|
||||||
|
return System.getProperty("java.version", "").contains("1.7.");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue