@Test
  public void define_remove_action() throws Exception {
    WebService.Controller controller = tester.controller("api/permissions");

    WebService.Action action = controller.action("remove");
    assertThat(action).isNotNull();
    assertThat(action.handler()).isInstanceOf(RailsHandler.INSTANCE.getClass());
    assertThat(action.params()).hasSize(5);
  }
Exemplo n.º 2
0
  @Test
  public void define_close_action() throws Exception {
    WebService.Controller controller = tester.controller("api/action_plans");

    WebService.Action action = controller.action("close");
    assertThat(action).isNotNull();
    assertThat(action.handler()).isInstanceOf(RailsHandler.class);
    assertThat(action.params()).hasSize(2);
  }
Exemplo n.º 3
0
  @Test
  public void define_search_action() throws Exception {
    WebService.Controller controller = tester.controller("api/action_plans");

    WebService.Action action = controller.action("search");
    assertThat(action).isNotNull();
    assertThat(action.handler()).isInstanceOf(RailsHandler.class);
    assertThat(action.responseExampleAsString()).isNotEmpty();
    assertThat(action.params()).hasSize(2);
  }
Exemplo n.º 4
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");
   }
 }
Exemplo n.º 5
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();
  }
Exemplo n.º 6
0
  public void execute(
      InternalRequest request, ServletResponse response, String controllerPath, String actionKey) {
    try {
      WebService.Action action = getAction(controllerPath, actionKey);
      request.setAction(action);
      verifyRequest(action, request);
      action.handler().handle(request, response);

    } catch (IllegalArgumentException e) {
      // TODO replace by BadRequestException in Request#requiredParam()
      sendError(400, e.getMessage(), response);

    } catch (ServerException e) {
      // TODO support ServerException l10n messages
      sendError(e.httpCode(), e.getMessage(), response);

    } catch (Exception e) {
      // TODO implement Request.toString()
      LoggerFactory.getLogger(getClass()).error("Fail to process request " + request, e);
      sendError(500, e.getMessage(), response);
    }
  }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
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();
  }
Exemplo n.º 9
0
 @Test
 public void define() throws Exception {
   WebService.Action def = tester.getDef();
   assertThat(def.params()).isEmpty();
 }