Example #1
0
  @Test
  public void updateTask() throws Exception {
    // update existing task
    Task t = new Task();
    Long id = PermanentUserData.tasks.get(0).getId();
    t.setName("updated");
    t.setRole(new Role(PermanentUserData.tasks.get(0).getRole().getId()));
    given()
        .contentType("application/json")
        .filter(sessionFilter)
        .body(om.writeValueAsString(t))
        .put("/web/" + id.toString())
        .then()
        .statusCode(204);

    // delete it
    given()
        .header(PermanentUserData.tokenHeader)
        .delete("/m/" + PermanentUserData.tasks.get(0).getId())
        .then()
        .statusCode(204);

    // test if is recreated with correct values
    t.setNote("note");
    LocalTime moment = LocalTime.now();
    int minutes = moment.getMinute();
    int hours = moment.getHour();
    t.setTime(moment);
    given()
        .contentType("application/json")
        .header(PermanentUserData.tokenHeader)
        .body(om.writeValueAsString(t))
        .put("/m/" + id.toString())
        .then()
        .statusCode(204);
    try (Connection conn = ds.getConnection();
        PreparedStatement ps = conn.prepareStatement("select * from task where name = ?"); ) {
      ps.setString(1, "updated");
      try (ResultSet rs = ps.executeQuery(); ) {
        rs.next();
        assertThat(rs.getString("name"), equalTo("updated"));
        assertThat(rs.getString("note"), equalTo("note"));
        assertThat(rs.getTime("time").getMinutes(), equalTo(minutes));
        assertThat(rs.getTime("time").getHours(), equalTo(hours));
        // rest was set to default
        assertThat(rs.getBoolean("finished"), equalTo(false));
        assertThat(rs.getBoolean("important"), equalTo(false));
        assertThat(rs.getBoolean("finished"), equalTo(false));
        assertThat(rs.getDate("date"), equalTo(null));
        assertThat(rs.getDate("firstDate"), equalTo(null));
      }
    }
  }
Example #2
0
 @Test
 public void createTask() throws Exception {
   Task t = new Task("newtask", new Role(PermanentUserData.role1.getId()));
   given()
       .contentType("application/json")
       .filter(sessionFilter)
       .body(om.writeValueAsString(t))
       .post("/web")
       .then()
       .body("id", greaterThan(0))
       .statusCode(200);
   t.setNote("note");
   given()
       .contentType("application/json")
       .header(PermanentUserData.tokenHeader)
       .body(om.writeValueAsString(t))
       .post("/m")
       .then()
       .body("id", greaterThan(0))
       .statusCode(200);
 }