Exemplo n.º 1
0
 public void add(final User user) {
   this.jdbcTemplate.update(
       "insert into users(id, name, password) values(?,?,?)",
       user.getId(),
       user.getName(),
       user.getPassword());
 }
Exemplo n.º 2
0
 public User mapRow(ResultSet rs, int i) throws SQLException {
   User user = new User();
   user.setId(rs.getString("id"));
   user.setName(rs.getString("name"));
   user.setPassword(rs.getString("password"));
   return user;
 }
Exemplo n.º 3
0
 @Test(expected = IllegalStateException.class)
 public void cannotUpgradeLevel() {
   Level[] levels = Level.values();
   for (Level level : levels) {
     if (level.nextLevel() != null) continue;
     user.setLevel(level);
     user.upgradeLevel();
   }
 }
Exemplo n.º 4
0
  private void sendUpgradeEMail(User user) {
    SimpleMailMessage mailMessage = new SimpleMailMessage();
    mailMessage.setTo(user.getEmail());
    mailMessage.setFrom("*****@*****.**");
    mailMessage.setSubject("Upgrade 안내");
    mailMessage.setText("사용자님의 등급이 " + user.getLevel().name());

    this.mailSender.send(mailMessage);
  }
Exemplo n.º 5
0
 @Test
 public void upgradeLevel() {
   Level[] levels = Level.values();
   for (Level level : levels) {
     if (level.nextLevel() == null) continue;
     user.setLevel(level);
     user.upgradeLevel();
     assertThat(user.getLevel(), is(level.nextLevel()));
   }
 }
Exemplo n.º 6
0
 private boolean canUpgradeLevel(User user) {
   Level currentLevel = user.getLevel();
   switch (currentLevel) {
     case BASIC:
       return (user.getLogin() >= MIN_LOGCOUNT_FOR_SILVER);
     case SILVER:
       return (user.getRecommend() >= MIN_RECCOMEND_FOR_GOLD);
     case GOLD:
       return false;
     default:
       throw new IllegalArgumentException("Unknown Level: " + currentLevel);
   }
 }
Exemplo n.º 7
0
  @Test
  public void add() {
    userDao.deleteAll();

    User userWithLevel = users.get(4); // GOLD 레벨
    User userWithoutLevel = users.get(0);
    userWithoutLevel.setLevel(null);

    userService.add(userWithLevel);
    userService.add(userWithoutLevel);

    User userWithLevelRead = userDao.get(userWithLevel.getId());
    User userWithoutLevelRead = userDao.get(userWithoutLevel.getId());

    assertThat(userWithLevelRead.getLevel(), is(userWithLevel.getLevel()));
    assertThat(userWithoutLevelRead.getLevel(), is(Level.BASIC));
  }
Exemplo n.º 8
0
 public User mapRow(ResultSet rs, int rowNum) throws SQLException {
   User user = new User();
   user.setId(rs.getString("id"));
   user.setName(rs.getString("name"));
   user.setPassword(rs.getString("password"));
   user.setLevel(Level.valueOf(rs.getInt("level")));
   user.setLogin(rs.getInt("login"));
   user.setRecommend(rs.getInt("recommend"));
   user.setEmail(rs.getString("email"));
   return user;
 }
Exemplo n.º 9
0
 public void update(User user) {
   this.jdbcTemplate.update(
       this.sqlService.getSql("userUpdate"),
       user.getName(),
       user.getPassword(),
       user.getLevel().intValue(),
       user.getLogin(),
       user.getRecommend(),
       user.getEmail(),
       user.getId());
 }
Exemplo n.º 10
0
 private void checkLevelUpgraded(User user, boolean upgraded) {
   User userUpdate = userDao.get(user.getId());
   if (upgraded) {
     assertThat(userUpdate.getLevel(), is(user.getLevel().nextLevel()));
   } else {
     assertThat(userUpdate.getLevel(), is(user.getLevel()));
   }
 }
Exemplo n.º 11
0
  public void add(final User user) throws DuplicateUserIdException {
    try {
      this.jdbcTemplate.update(
          this.sqlService.getSql("userAdd"),
          user.getId(),
          user.getName(),
          user.getPassword(),
          user.getLevel().intValue(),
          user.getLogin(),
          user.getRecommend(),
          user.getEmail());

    } catch (DuplicateKeyException e) {

      throw new DuplicateUserIdException(e); // Wrapping of Exception	
    }
  }
Exemplo n.º 12
0
  @Test
  public void andAndGet() throws SQLException {

    dao.deleteAll();
    assertThat(dao.getCount(), is(0));

    dao.add(user1);
    dao.add(user2);
    assertThat(dao.getCount(), is(2));

    User userget1 = dao.get(user1.getId());
    assertThat(userget1.getName(), is(user1.getName()));
    assertThat(userget1.getPassword(), is(user1.getPassword()));

    User userget2 = dao.get(user2.getId());
    assertThat(userget2.getName(), is(user2.getName()));
    assertThat(userget2.getPassword(), is(user2.getPassword()));
  }
Exemplo n.º 13
0
 protected void upgradeLevel(User user) {
   if (user.getId().equals(this.id)) throw new TestUserServiceException();
   super.upgradeLevel(user);
 }
Exemplo n.º 14
0
 private void checkUserAndLevel(User updated, String expectedId, Level expectedLevel) {
   assertThat(updated.getId(), is(expectedId));
   assertThat(updated.getLevel(), is(expectedLevel));
 }
Exemplo n.º 15
0
 public void add(User user) {
   if (user.getLevel() == null) {
     user.setLevel(Level.BASIC);
   }
   userDao.add(user);
 }
Exemplo n.º 16
0
 protected void upgradeLevel(User user) {
   user.upgradeLevel();
   userDao.update(user);
   sendUpgradeEMail(user);
 }
Exemplo n.º 17
0
 private void checkSameUser(User user1, User user2) {
   assertThat(user1.getId(), is(user2.getId()));
   assertThat(user1.getName(), is(user2.getName()));
   assertThat(user1.getPassword(), is(user2.getPassword()));
 }
Exemplo n.º 18
0
  public static void main(String[] args) throws ClassNotFoundException, SQLException {
    ApplicationContext context = new GenericXmlApplicationContext("applicationContext.xml");
    //		ApplicationContext context = new AnnotationConfigApplicationContext(DaoFactory.class);

    UserDaoJdbc dao = context.getBean("userDao", UserDaoJdbc.class);
    User user = new User();
    user.setId("whiteship2");
    user.setName("백기선2");
    user.setPassword("married");

    dao.add(user);

    System.out.println(user.getId() + "등록성공");

    User user2 = dao.get(user.getId());

    if (!user.getName().equals(user2.getName())) {
      System.out.println("테스트 실패 (name)");
    } else if (!user.getPassword().equals(user2.getPassword())) {
      System.out.println("테스트 실패 (password)");
    } else {
      System.out.println("조회 테스트 성공");
    }
  }