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); } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testInvalidInputType() throws SecurityException, NoSuchMethodException { Method withEndpointLink = TestEndpointLink.class.getMethod("withEndpointLink", TestDto.class); GeneratedHttpRequest request = GeneratedHttpRequest.builder() .declaring(TestEndpointLink.class) .javaMethod(withEndpointLink) .args(ImmutableList.<Object>of(new TestDto())) .method(HttpMethod.GET) .endpoint(URI.create("http://localhost")) .build(); BindToPath binder = new BindToPath(); binder.bindToRequest(request, new Object()); }
public void testBindWithQueryParameters() throws SecurityException, NoSuchMethodException { TestDto dto = new TestDto(); Method withEndpointLink = TestEndpointLink.class.getMethod("withEndpointLink", TestDto.class); GeneratedHttpRequest request = GeneratedHttpRequest.builder() .declaring(TestEndpointLink.class) .javaMethod(withEndpointLink) .args(ImmutableList.<Object>of(dto)) .method(HttpMethod.GET) .endpoint(URI.create("http://localhost?param=value")) .build(); BindToPath binder = new BindToPath(); GeneratedHttpRequest newRequest = binder.bindToRequest(request, dto); assertEquals(newRequest.getRequestLine(), "GET http://linkuri?param=value HTTP/1.1"); }
@Test(expectedExceptions = BindException.class) public void testAnnotationNotPresent() throws SecurityException, NoSuchMethodException { TestDto dto = new TestDto(); Method withoutEndpointLink = TestEndpointLink.class.getMethod("withoutEndpointLink", TestDto.class); GeneratedHttpRequest request = GeneratedHttpRequest.builder() .declaring(TestEndpointLink.class) .javaMethod(withoutEndpointLink) .args(ImmutableList.<Object>of(dto)) .method(HttpMethod.GET) .endpoint(URI.create("http://localhost")) .build(); BindToPath binder = new BindToPath(); binder.bindToRequest(request, dto); }