コード例 #1
0
  @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());
  }
コード例 #2
0
  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");
  }
コード例 #3
0
  @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);
  }
コード例 #4
0
 @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());
 }
コード例 #5
0
 @Test(expectedExceptions = NullPointerException.class)
 public void testInvalidNullRequest() throws SecurityException, NoSuchMethodException {
   BindToPath binder = new BindToPath();
   binder.bindToRequest(null, new Object());
 }