Esempio n. 1
0
  @Test
  public void checkRequest_ko() {
    expectedException.expect(BadRequestException.class);
    expectedException.expectMessage("Missing param: foo");

    WsUtils.checkRequest(false, "Missing param: %s", "foo");
  }
Esempio n. 2
0
  @Test
  public void write_json_by_default() throws Exception {
    TestRequest request = new TestRequest();
    DumbResponse response = new DumbResponse();

    Issues.Issue msg = Issues.Issue.newBuilder().setKey("I1").build();
    WsUtils.writeProtobuf(msg, request, response);

    assertThat(response.stream().mediaType()).isEqualTo(MediaTypes.JSON);
    assertThat(response.outputAsString()).startsWith("{").contains("\"key\":\"I1\"").endsWith("}");
  }
Esempio n. 3
0
  @Test
  public void write_protobuf() throws Exception {
    TestRequest request = new TestRequest();
    request.setMediaType(MediaTypes.PROTOBUF);
    DumbResponse response = new DumbResponse();

    Issues.Issue msg = Issues.Issue.newBuilder().setKey("I1").build();
    WsUtils.writeProtobuf(msg, request, response);

    assertThat(response.stream().mediaType()).isEqualTo(MediaTypes.PROTOBUF);
    assertThat(Issues.Issue.parseFrom(response.getFlushedOutput()).getKey()).isEqualTo("I1");
  }
Esempio n. 4
0
 @Test
 public void checkRequest_ok() {
   WsUtils.checkRequest(true, "Missing param: %s", "foo");
   // do not fail
 }