コード例 #1
0
  @Test
  public void handle_multipart_post() throws Exception {
    final String data =
        "person:   Ed Shryane\n"
            + "address:  Ripe NCC Singel 258\n"
            + "phone:    +31-61238-2827\n"
            + "nic-hdl:  ES222-RIPE\n"
            + "mnt-by:   TEST-DBM-MNT\n"
            + "changed:  [email protected] 20120829\n"
            + "source:   test\n"
            + "remarks:  something\n"
            + "override: password";
    final String help = null;
    final String nnew = null;
    final String diff = null;
    final String redirect = null;
    final String source = "test";

    subject.doMultipartPost(request, source, data, help, nnew, diff, redirect);

    verify(messageHandler)
        .handle(
            argThat(
                new ArgumentMatcher<UpdateRequest>() {
                  @Override
                  public boolean matches(final Object argument) {
                    UpdateRequest updateRequest = (UpdateRequest) argument;
                    assertThat(updateRequest.getKeyword(), is(Keyword.NONE));
                    assertThat(updateRequest.getUpdateMessage(), is(data));
                    return true;
                  }
                }),
            any(UpdateContext.class));
  }
コード例 #2
0
  @Test
  public void handle_only_diff_parameter() throws Exception {
    final String data = null;
    final String help = null;
    final String nnew = null;
    final String diff = "YES";
    final String redirect = null;
    final String source = "test";
    final String contentType = "UTF-8";

    final Response response =
        subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);

    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_BAD_REQUEST));
    assertThat(response.getEntity().toString(), is("Invalid request"));
  }
コード例 #3
0
  @Test
  public void handle_invalid_encoding() throws Exception {
    final String data = "person";
    final String help = null;
    final String nnew = null;
    final String diff = null;
    final String redirect = null;
    final String source = "test";
    final String contentType = "text/plain; charset=RGRFE";

    final Response response =
        subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);

    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
    assertThat(response.getEntity().toString(), is("OK"));
  }
コード例 #4
0
  @Test
  public void handle_redirect_not_allowed() throws Exception {
    final String data = "person";
    final String help = null;
    final String nnew = null;
    final String diff = null;
    final String redirect = "YES";
    final String source = "test";
    final String contentType = "UTF-8";

    final Response response =
        subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);

    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_FORBIDDEN));
    assertThat(
        response.getEntity().toString(), is("Not allowed to disable notifications: 127.0.0.1"));
  }
コード例 #5
0
  @Test
  public void handle_redirect_allowed() throws Exception {
    final String data = "person";
    final String help = null;
    final String nnew = null;
    final String diff = null;
    final String redirect = "YES";
    final String source = "test";
    final String contentType = "UTF-8";

    when(ipRanges.isTrusted(any(Interval.class))).thenReturn(true);
    final Response response =
        subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);

    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
    assertThat(response.getEntity().toString(), is("OK"));
  }
コード例 #6
0
  @Test
  public void handle_unauthorised() throws Exception {
    final String data = "person";
    final String help = null;
    final String nnew = null;
    final String diff = null;
    final String redirect = null;
    final String source = "test";
    final String contentType = "UTF-8";

    when(messageHandler.handle(any(UpdateRequest.class), any(UpdateContext.class)))
        .thenReturn(new UpdateResponse(UpdateStatus.FAILED_AUTHENTICATION, "FAILED"));
    final Response response =
        subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);

    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_UNAUTHORIZED));
    assertThat(response.getEntity().toString(), is("FAILED"));
  }
コード例 #7
0
  @Test
  public void handle_invalid_content_type() throws Exception {
    final String data = "person";
    final String help = null;
    final String nnew = null;
    final String diff = null;
    final String redirect = null;
    final String source = "test";
    final String contentType = "invalid";

    final Response response =
        subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);

    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
    assertThat(response.getEntity().toString(), is("OK"));
    List<Object> contentLengthResponse = response.getMetadata().get(HttpHeaders.CONTENT_TYPE);
    assertThat(contentLengthResponse.size(), is(1));
    assertThat(contentLengthResponse.get(0).toString(), is("text/plain"));
  }
コード例 #8
0
  @Test
  public void content_type_and_content_length_in_response() throws Exception {
    final String data = "person";
    final String help = null;
    final String nnew = null;
    final String diff = null;
    final String redirect = null;
    final String source = "test";
    final String contentType = "text/plain; charset=US-ASCII";

    final Response response =
        subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);

    List<Object> contentLengthResponse = response.getMetadata().get(HttpHeaders.CONTENT_TYPE);
    assertThat(contentLengthResponse.size(), is(1));
    assertThat(contentLengthResponse.get(0).toString(), is("text/plain"));
    List<Object> contentTypeResponse = response.getMetadata().get(HttpHeaders.CONTENT_LENGTH);
    assertThat(contentTypeResponse.size(), is(1));
    assertThat(contentTypeResponse.get(0).toString(), is("2"));
  }
コード例 #9
0
  @Test
  public void throw_runtime_exception() throws Exception {
    try {
      final String data = "person";
      final String help = null;
      final String nnew = null;
      final String diff = null;
      final String redirect = null;
      final String source = "test";
      final String contentType = "UTF-8";

      doThrow(new RuntimeException("some message", new IllegalStateException("some message")))
          .when(messageHandler)
          .handle(any(UpdateRequest.class), any(UpdateContext.class));

      subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);
      fail();
    } catch (RuntimeException e) {
      assertThat(e.getMessage(), is("some message"));
    }
  }