Пример #1
0
  @Test
  public void delete() {
    UserMapper sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
    final User user = sut.find(2);
    assertThat(user.getId(), is(2));
    assertThat(user.getLoginName(), is("Bar"));
    assertThat(user.getHashedUserData(), is("043bd227eaa879d438e7c1dfea568bc9"));

    sut.delete(user);

    try {
      sut.find(2);
      fail("Expected exception not thrown!");
    } catch (DomainModelException ex) {
      assertThat(ex.getMessage(), is("There is no record set whith primary key '2'!"));
    }

    // avoid cache
    sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());

    try {
      sut.find(2);
      fail("Expected exception not thrown!");
    } catch (DomainModelException ex) {
      assertThat(ex.getMessage(), is("There is no record set whith primary key '2'!"));
    }
  }
Пример #2
0
  @Test
  public void findUserById() {
    final UserMapper sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
    User user = sut.find(1);
    assertThat(user.getId(), is(1));
    assertThat(user.getLoginName(), is("Foo"));
    assertThat(user.getHashedUserData(), is("b9f46238b289f23ba807973840655032"));

    user = sut.find(2);
    assertThat(user.getId(), is(2));
    assertThat(user.getLoginName(), is("Bar"));
    assertThat(user.getHashedUserData(), is("043bd227eaa879d438e7c1dfea568bc9"));
  }
Пример #3
0
  @Test
  public void testDynamicFind() {
    UserSearch search = new UserSearch();
    search.setFirstName("first_name_page");
    search.setLastName("last_name_page");
    search.setOrderBy("firstName");
    search.setSequance("desc");

    List<User> list = userMapper.find("dynamicFind", search);
    assertEquals(3, list.size());
  }
Пример #4
0
  @Test
  public void update() {
    UserMapper sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
    User user = sut.find(2);
    assertThat(user.getId(), is(2));
    assertThat(user.getLoginName(), is("Bar"));
    assertThat(user.getHashedUserData(), is("043bd227eaa879d438e7c1dfea568bc9"));

    user.setLoginName("snafu");
    user.setHashedUserData("snafupw");
    sut.update(user);

    user = sut.find(2); // get from cache
    assertThat(user.getId(), is(2));
    assertThat(user.getLoginName(), is("snafu"));
    assertThat(user.getHashedUserData(), is("snafupw"));

    sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
    user = sut.find(2);
    assertThat(user.getId(), is(2));
    assertThat(user.getLoginName(), is("snafu"));
    assertThat(user.getHashedUserData(), is("snafupw"));
  }
Пример #5
0
  @Test
  public void insert() {
    final String loginName = "snafu";
    final String hashedUserData = "snafupw";
    User user = new User(loginName, hashedUserData);
    UserMapper sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
    final int id = sut.insert(user);

    // avoid cache
    sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
    user = sut.find(id);
    assertThat(user.getLoginName(), is(loginName));
    assertThat(user.getHashedUserData(), is(hashedUserData));
  }
Пример #6
0
  @Test
  public void testFind() {
    User search = new User();
    search.setFirstName("first_name_page");
    search.setLastName("last_name_page");

    Example example = Example.create(search);
    DetachedCriteria dc = DetachedCriteria.forClass(User.class).add(example);
    OrderBy orderBy = new OrderBy();
    orderBy.setOrderBy("firstName");
    orderBy.setSequance("asc");

    List<User> find = userMapper.find(dc, orderBy);
    assertEquals(3, find.size());
  }
Пример #7
0
 @Test
 public void findUserById_caches() {
   final UserMapper sut = new UserMapper(dataSource(), new IntegerIdentityMap<User>());
   final User user = sut.find(1);
   assertThat(user, is(sameInstance(sut.find(1))));
 }