use of org.jboss.as.quickstarts.tasksrs.model.User in project quickstart by wildfly.
the class UserDaoIT method userDao_should_return_null_when_searching_for_non_existent_user.
@Test
public void userDao_should_return_null_when_searching_for_non_existent_user() {
// given
String nonExistent = "nonExistent";
// when
User retrieved = userDao.getForUsername(nonExistent);
// then
assertNull(retrieved);
}
use of org.jboss.as.quickstarts.tasksrs.model.User in project quickstart by wildfly.
the class UserDaoIT method userDao_should_create_user_so_it_could_be_retrieved_from_userDao_by_username.
@Test
public void userDao_should_create_user_so_it_could_be_retrieved_from_userDao_by_username() {
// given
User created = new User("username1");
// when
userDao.createUser(created);
User retrieved = userDao.getForUsername("username1");
// then
assertTrue(em.contains(created));
assertTrue(em.contains(retrieved));
Assert.assertEquals(created, retrieved);
}
use of org.jboss.as.quickstarts.tasksrs.model.User 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.User in project quickstart by wildfly.
the class UserDaoIT method user_should_be_retrievable_from_userDao_by_username.
@Test
public void user_should_be_retrievable_from_userDao_by_username() {
// given
String username = "jdoe";
// when
User retrieved = userDao.getForUsername(username);
// then
Assert.assertEquals(username, retrieved.getUsername());
}
use of org.jboss.as.quickstarts.tasksrs.model.User 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