Search in sources :

Example 1 with User

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);
}
Also used : User(org.jboss.as.quickstarts.tasksrs.model.User) Test(org.junit.Test)

Example 2 with User

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);
}
Also used : User(org.jboss.as.quickstarts.tasksrs.model.User) Test(org.junit.Test)

Example 3 with User

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));
}
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 4 with User

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());
}
Also used : User(org.jboss.as.quickstarts.tasksrs.model.User) Test(org.junit.Test)

Example 5 with User

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

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