Ejemplo n.º 1
0
 public static void verifyRequest(WebService.Action action, Request request) {
   // verify the HTTP verb
   if (action.isPost() && !"POST".equals(request.method())) {
     throw new ServerException(
         HttpServletResponse.SC_METHOD_NOT_ALLOWED, "HTTP method POST is required");
   }
 }
Ejemplo n.º 2
0
 @Test
 public void define_suggestions_action() throws Exception {
   WebService.Action action = controller.action("suggestions");
   assertThat(action).isNotNull();
   assertThat(action.isInternal()).isTrue();
   assertThat(action.isPost()).isFalse();
   assertThat(action.handler()).isInstanceOf(RailsHandler.class);
   assertThat(action.responseExampleAsString()).isNotEmpty();
   assertThat(action.params()).hasSize(2);
 }
Ejemplo n.º 3
0
  @Test
  public void action_pending_is_defined() {
    WsTester wsTester = new WsTester();
    WebService.NewController newController =
        wsTester.context().createController(DUMMY_CONTROLLER_KEY);

    underTest.define(newController);
    newController.done();

    WebService.Controller controller = wsTester.controller(DUMMY_CONTROLLER_KEY);
    assertThat(controller.actions()).extracting("key").containsExactly("pending");

    WebService.Action action = controller.actions().iterator().next();
    assertThat(action.isPost()).isFalse();
    assertThat(action.description()).isNotEmpty();
    assertThat(action.responseExample()).isNotNull();
  }
Ejemplo n.º 4
0
  @Test
  public void action_update_is_defined() {
    WsTester wsTester = new WsTester();
    WebService.NewController newController =
        wsTester.context().createController(DUMMY_CONTROLLER_KEY);

    underTest.define(newController);
    newController.done();

    WebService.Controller controller = wsTester.controller(DUMMY_CONTROLLER_KEY);
    assertThat(controller.actions()).extracting("key").containsExactly(ACTION_KEY);

    WebService.Action action = controller.actions().iterator().next();
    assertThat(action.isPost()).isTrue();
    assertThat(action.description()).isNotEmpty();
    assertThat(action.responseExample()).isNull();

    assertThat(action.params()).hasSize(1);
    WebService.Param key = action.param(KEY_PARAM);
    assertThat(key).isNotNull();
    assertThat(key.isRequired()).isTrue();
    assertThat(key.description()).isNotNull();
  }