public void oneTransformerWithContext() throws SecurityException, NoSuchMethodException { GeneratedHttpRequest request = GeneratedHttpRequest.builder() .method("GET") .endpoint("http://localhost") .invocation( Invocation.create(method(TestTransformers.class, "oneTransformerWithContext"), ImmutableList.of())).build(); Function<HttpResponse, ?> transformer = this.transformer.apply(request); assertEquals(transformer.getClass(), ReturnStringIf200Context.class); assertEquals(((ReturnStringIf200Context) transformer).request, request); }
@Test public void testDecodes() throws SecurityException, NoSuchMethodException { Invokable<?, Object> testPayload = method(TestPayload.class, "changeAdminPass", String.class); GeneratedHttpRequest request = GeneratedHttpRequest.builder() .invocation(Invocation.create(testPayload, ImmutableList.<Object> of("foo"))) .method("POST").endpoint("http://localhost").build(); GeneratedHttpRequest newRequest = binder() .bindToRequest(request, ImmutableMap.<String,Object>of("adminPass", "foo")); assertEquals(newRequest.getRequestLine(), request.getRequestLine()); assertEquals(newRequest.getPayload().getRawContent(), "{\"changePassword\":{\"adminPass\":\"foo\"}}"); }
@Test public void testCorrect() throws SecurityException, NoSuchMethodException { Invokable<?, Object> testPayload = method(TestPayload.class, "testPayload", String.class); GeneratedHttpRequest request = GeneratedHttpRequest.builder() .invocation(Invocation.create(testPayload, ImmutableList.<Object> of("robot"))) .method("POST").endpoint("http://localhost").build(); GeneratedHttpRequest newRequest = binder().bindToRequest(request, ImmutableMap.<String, Object> of("fooble", "robot")); assertEquals(newRequest.getRequestLine(), request.getRequestLine()); assertEquals(newRequest.getPayload().getRawContent(), "name robot"); }
@BeforeClass void setUp() throws SecurityException, NoSuchMethodException { putBucket = GeneratedHttpRequest.builder() .method("PUT") .endpoint("https://adriancole-blobstore113.s3.amazonaws.com/") .invocation( Invocation.create(method(S3Client.class, "putBucketInRegion", String.class, String.class, PutBucketOptions[].class), Lists.<Object> newArrayList(null, "bucket"))).build(); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testMustHavePayloadAnnotation() throws SecurityException, NoSuchMethodException { Invokable<?, Object> noPayload = method(TestPayload.class, "noPayload", String.class); GeneratedHttpRequest request = GeneratedHttpRequest.builder() .invocation(Invocation.create(noPayload, ImmutableList.<Object> of("robot"))) .method("POST").endpoint("http://localhost").build(); binder().bindToRequest(request, ImmutableMap.<String, Object>of("fooble", "robot")); }
@Test public void testDecodes() throws SecurityException, NoSuchMethodException { Invokable<?, Object> testPayload = method(TestPayload.class, "changeAdminPass", String.class); GeneratedHttpRequest request = GeneratedHttpRequest.builder() .invocation(Invocation.create(testPayload, ImmutableList.<Object> of("foo"))) .method("POST").endpoint("http://localhost").build(); GeneratedHttpRequest newRequest = binder() .bindToRequest(request, ImmutableMap.<String, Object>of("adminPass", "foo")); assertEquals(newRequest.getRequestLine(), request.getRequestLine()); assertEquals(newRequest.getPayload().getRawContent(), "{\"changePassword\":{\"adminPass\":\"foo\"}}"); }
@BeforeTest protected void setUpRequest() { try { toString = Invocation.create(method(String.class, "toString"), ImmutableList.of()); } catch (SecurityException e) { throw propagate(e); } request = GeneratedHttpRequest.builder().method("POST").endpoint("http://localhost/key").invocation(toString) .build(); }
@Test void testGetBucketLocationSignature() { Invocation invocation = Invocation.create(method(S3Client.class, "getBucketLocation", String.class), ImmutableList.<Object>of(BUCKET_NAME)); HttpRequest getBucketLocation = GeneratedHttpRequest.builder().method("GET") .invocation(invocation) .endpoint("https://" + BUCKET_NAME + ".s3.cn-north-1.amazonaws.com.cn/") .addHeader(HttpHeaders.HOST, BUCKET_NAME + ".s3.cn-north-1.amazonaws.com.cn") .addQueryParam("location", "") .build(); HttpRequest filtered = filter(temporaryCredentials).filter(getBucketLocation); assertEquals(filtered.getFirstHeaderOrNull("Authorization"), GET_BUCKET_LOCATION_SIGNATURE_RESULT); }
protected GeneratedHttpRequest requestForArgs(List<Object> args) { try { Invocation invocation = Invocation.create(method(String.class, "toString"), args); return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key")) .invocation(invocation).build(); } catch (SecurityException e) { throw Throwables.propagate(e); } } }
protected GeneratedHttpRequest requestForArgs(List<Object> args) { try { Invocation invocation = Invocation.create(method(String.class, "toString"), args); return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key")) .invocation(invocation).build(); } catch (SecurityException e) { throw Throwables.propagate(e); } } }
protected GeneratedHttpRequest requestForArgs(List<Object> args) { return GeneratedHttpRequest.builder().method("POST").endpoint("http://localhost/key") .invocation(Invocation.create(toString.getInvokable(), args)).build(); } }
GeneratedHttpRequest requestForEndpointAndArgs(String endpoint, List<Object> args) { try { Invocation invocation = Invocation.create(method(String.class, "toString"), args); return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create(endpoint)).invocation(invocation) .build(); } catch (SecurityException e) { throw Throwables.propagate(e); } } }
private GeneratedHttpRequest callerArgs(ImmutableList<Object> args) { try { return GeneratedHttpRequest.builder().method("GET").endpoint("http://localhost") .invocation(Invocation.create(Invokable.from(String.class.getMethod("toString")))) .caller(Invocation.create(Invokable.from(String.class.getMethod("toString")), args)).build(); } catch (Exception e) { throw propagate(e); } } }
protected GeneratedHttpRequest requestForArgs(List<Object> args) { try { Invocation invocation = Invocation.create(method(String.class, "toString"), args); return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key")) .invocation(invocation).build(); } catch (SecurityException e) { throw Throwables.propagate(e); } } }
@BeforeClass void setUp() throws SecurityException, NoSuchMethodException { putBucket = GeneratedHttpRequest.builder() .method("PUT") .endpoint("https://adriancole-blobstore113.s3.amazonaws.com/") .invocation( Invocation.create(method(S3Client.class, "putBucketInRegion", String.class, String.class, PutBucketOptions[].class), Lists.<Object> newArrayList(null, "bucket"))).build(); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testMustHavePayloadAnnotation() throws SecurityException, NoSuchMethodException { Invokable<?, Object> noPayload = method(TestPayload.class, "noPayload", String.class); GeneratedHttpRequest request = GeneratedHttpRequest.builder() .invocation(Invocation.create(noPayload, ImmutableList.<Object> of("robot"))) .method("POST").endpoint("http://localhost").build(); binder().bindToRequest(request, ImmutableMap.<String,Object>of("fooble", "robot")); }
private GeneratedHttpRequest args(ImmutableList<Object> args) { try { return GeneratedHttpRequest.builder().method("GET").endpoint("http://localhost") .invocation(Invocation.create(Invokable.from(String.class.getMethod("toString")), args)).build(); } catch (Exception e) { throw propagate(e); } }
protected GeneratedHttpRequest requestForArgs(List<Object> args) { try { Invocation invocation = Invocation.create(method(String.class, "toString"), args); return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key")) .invocation(invocation).build(); } catch (SecurityException e) { throw Throwables.propagate(e); } } }
GeneratedHttpRequest requestForEndpointAndArgs(String endpoint, List<Object> args) { try { Invocation invocation = Invocation.create(method(String.class, "toString"), args); return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create(endpoint)).invocation(invocation) .build(); } catch (SecurityException e) { throw Throwables.propagate(e); } } }
@BeforeTest protected void setUpRequest() { try { toString = Invocation.create(method(String.class, "toString"), ImmutableList.of()); } catch (SecurityException e) { throw propagate(e); } request = GeneratedHttpRequest.builder().method("POST").endpoint("http://localhost/key").invocation(toString) .build(); }