@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); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testInvalidRequestType() throws SecurityException, NoSuchMethodException { BindToPath binder = new BindToPath(); binder.bindToRequest( HttpRequest.builder().method("m").endpoint("http://localhost").build(), new Object()); }
@Test(expectedExceptions = NullPointerException.class) public void testInvalidNullRequest() throws SecurityException, NoSuchMethodException { BindToPath binder = new BindToPath(); binder.bindToRequest(null, new Object()); }