Package ro.bjug.todo.api

Examples of ro.bjug.todo.api.Todo


    assertThat(dao.findAll()).isEmpty();
  }

  @Test
  public void testCRUD() {
    final Todo todo = Todo.newBuilder()
        .id(UUID.randomUUID().toString())
        .email("john@example.com")
        .build();

    dao.createTableIfNotExists();
    dao.insert(todo);

    assertThat(dao.exists(todo.getId())).isTrue();
    assertThat(dao.exists("dummy-missing-id")).isFalse();

    assertThat(dao.findAll()).contains(todo);
    assertThat(dao.findById(todo.getId())).isEqualTo(todo);

    final Item item = Item.newBuilder()
        .title("Something")
        .created(new Date())
        .build();

    Todo updated = todo.toBuilder().item(item).build();
    dao.update(updated);

    assertThat(dao.findById(updated.getId())).isEqualTo(updated);

    dao.delete(updated.getId());
    assertThat(dao.findAll()).isEmpty();
  }
View Full Code Here


    assertThat(dao.findById("dummy")).isNull();
  }

  @Test
  public void testInsertSameElementTwice() {
    final Todo todo = Todo.newBuilder()
        .id(UUID.randomUUID().toString())
        .email("john@example.com")
        .build();
    dao.createTableIfNotExists();
View Full Code Here

    assertThat(response.getStatus()).isEqualTo(Response.Status.CREATED.getStatusCode());

    List<Todo> all = dao.findAll();
    assertThat(all).hasSize(1);

    Todo todo = all.get(0);
    assertThat(response.getLocation().toASCIIString()).endsWith(todo.getId());
    assertThat(todo.getEmail()).isNullOrEmpty();
  }
View Full Code Here

    ClientResponse response = client().resource("/todos")
        .type(MediaType.APPLICATION_FORM_URLENCODED)
        .post(ClientResponse.class, arguments);
    assertThat(response.getStatus()).isEqualTo(Response.Status.CREATED.getStatusCode());

    Todo todo = dao.findAll().get(0);
    assertThat(todo.getEmail()).isEqualTo(EMAIL);
  }
View Full Code Here

  }

  @Test
  public void testRetrieveExistingTodoList() {
    final String id = UUID.randomUUID().toString();
    final Todo todo = Todo.newBuilder().id(id).created(new Date()).build();
    dao.insert(todo);

    Todo stored = client().resource("/todos/" + id).get(Todo.class);
    assertThat(stored).isEqualTo(todo);
  }
View Full Code Here

  }

  @Test
  public void testAddItemToExistingTodo() {
    final String id = UUID.randomUUID().toString();
    final Todo todo = Todo.newBuilder().id(id).created(new Date()).build();
    dao.insert(todo);

    final Item item = Item.newBuilder().title("Something").created(new Date()).build();
    Todo updated = todo.toBuilder().item(item).build();

    Todo response = client().resource("/todos/" + id)
        .type(MediaType.APPLICATION_JSON).put(Todo.class, updated);
    assertThat(response).isEqualTo(updated);
  }
View Full Code Here

  }

  @Test
  public void testDeleteTodo() {
    final String id = UUID.randomUUID().toString();
    final Todo todo = Todo.newBuilder().id(id).created(new Date()).build();
    dao.insert(todo);

    ClientResponse response = client().resource("/todos/" + id).delete(ClientResponse.class);
    assertThat(response.getStatus()).isEqualTo(Response.Status.NO_CONTENT.getStatusCode());
View Full Code Here

  }

  @Test
  public void testDeleteAll() {
    final String id = UUID.randomUUID().toString();
    final Todo todo = Todo.newBuilder().id(id).created(new Date()).build();

    dao.insert(todo);
    dao.insert(todo.toBuilder().id("dummy").build());
    assertThat(dao.findAll()).hasSize(2);

    ClientResponse response = client().resource("/todos").delete(ClientResponse.class);
    assertThat(response.getStatus()).isEqualTo(Response.Status.NO_CONTENT.getStatusCode());
    assertThat(dao.findAll()).isEmpty();
View Full Code Here

  }

  @GET
  @Path("{id}")
  public Todo get(@PathParam("id") String id) {
    Todo todo = dao.findById(id);
    if (todo == null) {
      throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
    return todo;
  }
View Full Code Here

TOP

Related Classes of ro.bjug.todo.api.Todo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.