Search in sources :

Example 1 with Task

use of org.jboss.as.quickstarts.tasksrs.model.Task in project quickstart by wildfly.

the class TaskDaoIT method taskDao_should_remove_task_from_detachedUser.

@Test
@InSequence(5)
public void taskDao_should_remove_task_from_detachedUser() {
    // given
    Task task = new Task();
    task.setId(1L);
    task.setOwner(detachedUser);
    assertEquals(2, taskDao.getAll(detachedUser).size());
    // when
    taskDao.deleteTask(task);
    // then
    assertEquals(1, taskDao.getAll(detachedUser).size());
}
Also used : Task(org.jboss.as.quickstarts.tasksrs.model.Task) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 2 with Task

use of org.jboss.as.quickstarts.tasksrs.model.Task in project quickstart by wildfly.

the class TaskDaoIT method user_should_be_created_with_one_task_attached.

@Test
@InSequence(1)
public void user_should_be_created_with_one_task_attached() throws Exception {
    // given
    User user = new User("New user");
    Task task = new Task("New task");
    // when
    em.persist(user);
    taskDao.createTask(user, task);
    List<Task> userTasks = em.createQuery("SELECT t FROM Task t WHERE t.owner = :owner", Task.class).setParameter("owner", user).getResultList();
    // then
    assertEquals(1, userTasks.size());
    assertEquals(task, userTasks.get(0));
}
Also used : Task(org.jboss.as.quickstarts.tasksrs.model.Task) User(org.jboss.as.quickstarts.tasksrs.model.User) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 3 with Task

use of org.jboss.as.quickstarts.tasksrs.model.Task in project quickstart by wildfly.

the class TaskResource method deleteTaskById.

@DELETE
@Path("tasks/id/{id}")
public void deleteTaskById(@Context SecurityContext context, @PathParam("id") Long id) {
    Task task = getTaskById(context, id);
    taskDao.deleteTask(task);
}
Also used : Task(org.jboss.as.quickstarts.tasksrs.model.Task) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 4 with Task

use of org.jboss.as.quickstarts.tasksrs.model.Task in project quickstart by wildfly.

the class TaskResource method createTask.

@POST
@Path("tasks/title/{title}")
public Response createTask(@Context UriInfo info, @Context SecurityContext context, @PathParam("title") @DefaultValue("task") String taskTitle) {
    User user = getUser(context);
    Task task = new Task(taskTitle);
    taskDao.createTask(user, task);
    // Construct the URI for the newly created resource and put in into the Location header of the response
    // (assumes that there is only one occurrence of the task title in the request)
    String rawPath = info.getAbsolutePath().getRawPath().replace("title/" + task.getTitle(), "id/" + task.getId().toString());
    UriBuilder uriBuilder = info.getAbsolutePathBuilder().replacePath(rawPath);
    URI uri = uriBuilder.build();
    return Response.created(uri).build();
}
Also used : Task(org.jboss.as.quickstarts.tasksrs.model.Task) User(org.jboss.as.quickstarts.tasksrs.model.User) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

Task (org.jboss.as.quickstarts.tasksrs.model.Task)4 Path (javax.ws.rs.Path)2 InSequence (org.jboss.arquillian.junit.InSequence)2 User (org.jboss.as.quickstarts.tasksrs.model.User)2 Test (org.junit.Test)2 URI (java.net.URI)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 UriBuilder (javax.ws.rs.core.UriBuilder)1