コード例 #1
0
  @Test
  public void executesMethodWithNamedParametersCorrectly() throws Exception {

    firstUser = userDao.save(firstUser);
    secondUser = userDao.save(secondUser);

    assertTrue(
        userDao
            .findByLastnameOrFirstname("Oliver", "Arrasz")
            .containsAll(Arrays.asList(firstUser, secondUser)));
  }
コード例 #2
0
  @Test
  public void savingEmptyCollectionIsNoOp() throws Exception {

    List<User> result = userDao.save(new ArrayList<User>());
    assertNotNull(result);
    assertTrue(result.isEmpty());
  }
コード例 #3
0
  @Test
  public void savingNullCollectionIsNoOp() throws Exception {

    List<User> result = userDao.save((Collection<User>) null);
    assertNotNull(result);
    assertTrue(result.isEmpty());
  }
コード例 #4
0
  @Test
  public void savesCollectionCorrectly() throws Exception {

    List<User> result = userDao.save(Arrays.asList(firstUser, secondUser, thirdUser));
    assertNotNull(result);
    assertThat(result.size(), is(3));
    assertThat(result, hasItems(firstUser, secondUser, thirdUser));
  }
コード例 #5
0
  /** Flushes test users to the database. */
  private void flushTestUsers() {

    firstUser = userDao.save(firstUser);
    secondUser = userDao.save(secondUser);
    thirdUser = userDao.save(thirdUser);

    userDao.flush();

    id = firstUser.getId();

    assertThat(id, is(notNullValue()));
    assertThat(secondUser.getId(), is(notNullValue()));
    assertThat(thirdUser.getId(), is(notNullValue()));

    assertThat(userDao.exists(id), is(true));
    assertThat(userDao.exists(secondUser.getId()), is(true));
    assertThat(userDao.exists(thirdUser.getId()), is(true));
  }
コード例 #6
0
  /** Tests, that the generic dao implements count correctly. */
  @Test
  public void testCountsCorrectly() {

    Long count = userDao.count();

    User user = new User();
    user.setEmailAddress("*****@*****.**");
    userDao.save(user);

    assertTrue(userDao.count().equals(count + 1));
  }
コード例 #7
0
  /** Tests cascading on {@literal merge} operation. */
  @Test
  public void testMergingCascadesCollegueas() {

    firstUser.addColleague(secondUser);
    flushTestUsers();

    firstUser.addColleague(new User("Florian", "Hopf", "*****@*****.**"));
    firstUser = userDao.save(firstUser);

    User reference = userDao.readByPrimaryKey(firstUser.getId());
    Set<User> colleagues = reference.getColleagues();

    assertNotNull(colleagues);
    assertEquals(2, colleagues.size());
  }