Пример #1
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()));
   }
 }
Пример #2
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));
  }
Пример #3
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);
  }
Пример #4
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()));
   }
 }
Пример #5
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());
 }
Пример #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);
   }
 }
Пример #7
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	
    }
  }
Пример #8
0
 private void checkUserAndLevel(User updated, String expectedId, Level expectedLevel) {
   assertThat(updated.getId(), is(expectedId));
   assertThat(updated.getLevel(), is(expectedLevel));
 }
Пример #9
0
 public void add(User user) {
   if (user.getLevel() == null) {
     user.setLevel(Level.BASIC);
   }
   userDao.add(user);
 }