Ejemplo n.º 1
0
  @Test
  public void testTaskDeletion() throws Exception {
    Action.ActionResult result =
        action(
                new Invocation() {
                  @Override
                  public Result invoke() {
                    return controller.create("foo");
                  }
                })
            .invoke();

    assertThat(status(result)).isEqualTo(OK);
    assertThat(contentType(result)).isEqualTo(MimeTypes.JSON);
    assertThat(json(result).get("name").textValue()).isEqualTo("foo");
    assertThat(json(result).get("completed").booleanValue()).isFalse();

    final int id = json(result).get("id").intValue();
    result =
        Action.action(
                new Invocation() {
                  @Override
                  public Result invoke() {
                    return controller.delete(id);
                  }
                })
            .invoke();

    assertThat(status(result)).isEqualTo(OK);
  }
Ejemplo n.º 2
0
  @Test
  public void testTaskRetrieval() throws Exception {
    Action.ActionResult result =
        Action.action(
                new Invocation() {
                  @Override
                  public Result invoke() {
                    return controller.retrieve();
                  }
                })
            .invoke();

    assertThat(status(result)).isEqualTo(OK);
    assertThat(contentType(result)).isEqualTo(MimeTypes.JSON);
    assertThat(jsonarray(result).arrayNode().size()).isEqualTo(0);

    result =
        action(
                new Invocation() {
                  @Override
                  public Result invoke() {
                    return controller.create("foo");
                  }
                })
            .with()
            .attribute("name", "foo")
            .invoke();

    assertThat(status(result)).isEqualTo(OK);

    result =
        Action.action(
                new Invocation() {
                  @Override
                  public Result invoke() {
                    return controller.retrieve();
                  }
                })
            .invoke();

    assertThat(status(result)).isEqualTo(OK);
    assertThat(contentType(result)).isEqualTo(MimeTypes.JSON);
    assertThat(jsonarray(result).size()).isEqualTo(1);
  }