1 / 21

고급자바프로그래밍 (Advanced Java Programming)

고급자바프로그래밍 (Advanced Java Programming). 강원대학교 컴퓨터학부 2012 년 가을학기 담당교수 정충교. 5 장 서비스 추상화. 5.1 사용자 레벨 관리 기능 추가. package springbook.user.service ; public class UserService { public void upgradeLevels () private boolean canUpgradeLevel (User user) private void upgradeLevel (User user)

kirra
Download Presentation

고급자바프로그래밍 (Advanced Java Programming)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 고급자바프로그래밍(Advanced Java Programming) 강원대학교컴퓨터학부 2012년 가을학기 담당교수정충교

  2. 5장 서비스 추상화

  3. 5.1 사용자 레벨 관리 기능 추가 packagespringbook.user.service; publicclassUserService { public void upgradeLevels() private booleancanUpgradeLevel(User user) private void upgradeLevel(User user) public void add(User user) }

  4. UserDao package springbook.user.dao; public interface UserDao { void add(User user); User get(String user); List<User> getAll(); void deleteAll(); intgetCount(); void update(User user); }

  5. @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations="/test-applicationContext.xml") public class UserServiceTest { @AutowiredUserServiceuserService; @AutowiredUserDaouserDao; List<User> users; // test fixture @Before public void setUp() { users = Arrays.asList( new User("bumjin", "박범진", "p1", Level.BASIC, MIN_LOGCOUNT_FOR_SILVER-1, 0), new User("joytouch", "강명성", "p2", Level.BASIC, MIN_LOGCOUNT_FOR_SILVER, 0), new User("erwins", "신승한", "p3", Level.SILVER, 60, MIN_RECCOMEND_FOR_GOLD-1), new User("madnite1", "이상호", "p4", Level.SILVER, 60, MIN_RECCOMEND_FOR_GOLD), new User("green", "오민규", "p5", Level.GOLD, 100, Integer.MAX_VALUE) ); }

  6. @Test public void upgradeLevels() { userDao.deleteAll(); for(User user : users) userDao.add(user); userService.upgradeLevels(); checkLevelUpgraded(users.get(0), false); checkLevelUpgraded(users.get(1), true); checkLevelUpgraded(users.get(2), false); checkLevelUpgraded(users.get(3), true); checkLevelUpgraded(users.get(4), false); }

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

  8. @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)); }

  9. 5.2 트랜스액션 서비스 추상화

  10. JdbcTemplate의 기본 동작

  11. Transaction • 리스트 5-38

  12. Local Transaction • 리스트 5-41

  13. JdbcTemplate의 기능 • try/catch/finally 작업 흐름 지원 • SQLException예외 변환 • transaction

  14. Global Transaction

  15. 추상화 • 리스트 5-45

  16. 계층과 책임의 분리

  17. 메일서비스 추상화

  18. 테스트 환경

  19. 목 오브젝트를 이용한 테스트

More Related