daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Jan 20th, 2017 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.thoughtforge.dao.jpa;
  2.  
  3. import junit.framework.Assert;
  4. import net.thoughtforge.dao.UserDao;
  5. import net.thoughtforge.model.User;
  6. import org.junit.Before;
  7. import org.junit.Test;
  8. import org.junit.runner.RunWith;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.test.context.ContextConfiguration;
  11. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  12. import org.springframework.test.context.transaction.TransactionConfiguration;
  13. import org.springframework.transaction.annotation.Transactional;
  14.  
  15. @RunWith(SpringJUnit4ClassRunner.class)
  16. @ContextConfiguration(locations = {
  17.         "classpath:applicationContext/applicationContext-*.xml"})
  18. @TransactionConfiguration(transactionManager="transactionManager", defaultRollback=true)
  19. @Transactional
  20. public class UserDaoImplTest {
  21.  
  22.     private static final String FIRST_NAME = "joe";
  23.     private static final String LAST_NAME = "bloggs";
  24.     private static final String PASSWORD = "password";
  25.     private static final String USERNAME = "joe.bloggs";
  26.  
  27.     @Autowired
  28.     private UserDao userDao;
  29.  
  30.     @Before
  31.     public void before() {
  32.         User user = new User();
  33.         user.setFirstName(FIRST_NAME);
  34.         user.setLastName(LAST_NAME);
  35.         user.setPassword(PASSWORD);
  36.         user.setUsername(USERNAME);
  37.         userDao.save(user);
  38.     }
  39.  
  40.     @Test
  41.     public void findByUserName() {
  42.         User user = userDao.findByUsername(USERNAME);
  43.         Assert.assertNotNull(user);
  44.         Assert.assertEquals(USERNAME, user.getUsername());
  45.     }
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top