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());
}
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));
}
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);
}
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();
}
Aggregations