|
package com.kendelong.integration.user; |
|
|
|
import static junit.framework.Assert.assertEquals; |
|
import static junit.framework.Assert.assertNotNull; |
|
import static junit.framework.Assert.assertNotSame; |
|
import static junit.framework.Assert.assertNull; |
|
import static junit.framework.Assert.assertTrue; |
|
|
|
import org.dbunit.DatabaseUnitException; |
|
import org.dbunit.database.DatabaseConnection; |
|
import org.dbunit.database.IDatabaseConnection; |
|
import org.dbunit.dataset.IDataSet; |
|
import org.dbunit.operation.DatabaseOperation; |
|
import org.hibernate.SessionFactory; |
|
import org.hibernate.jdbc.Work; |
|
import org.junit.Before; |
|
import org.junit.runner.RunWith; |
|
|
|
import java.util.Date; |
|
|
|
import org.apache.solr.client.solrj.impl.XMLResponseParser.KnownType; |
|
import org.junit.Ignore; |
|
import org.junit.Test; |
|
import org.junit.runner.RunWith; |
|
import org.springframework.beans.factory.annotation.Autowired; |
|
import org.springframework.test.context.ContextConfiguration; |
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
|
import org.springframework.transaction.annotation.Transactional; |
|
import org.springframework.beans.factory.annotation.Qualifier; |
|
import org.springframework.test.context.transaction.TransactionConfiguration; |
|
|
|
|
|
@RunWith(SpringJUnit4ClassRunner.class) |
|
@ContextConfiguration({"classpath:database-test-context.xml"}) |
|
@TransactionConfiguration(defaultRollback=true) |
|
@Transactional |
|
public class UserIntegrationTest |
|
{ |
|
private final Integer KNOWN_USER_ID = 2001; |
|
|
|
@Autowired |
|
private SessionFactory sessionFactory; |
|
|
|
private IDatabaseConnection con; |
|
private IDataSet dataset; |
|
|
|
private List data; |
|
|
|
|
|
{ |
|
data = [ |
|
[table: 'user', id: 2001, legacy_id: 2001, first_name: 'Sarah',last_name:'Connor', email: '[email protected]', screen_name: 'AScreenName', create_date:'2010-11-02'], |
|
[table: 'baby', id: 5000, legacy_id: 5000, name: 'baby1', birth_date: '2011-05-12', user_id: 2001, gender: 'F', create_date:'2010-11-02'], |
|
[table: 'baby', id: 5001, legacy_id: 5001, name: 'baby2', birth_date: '2011-05-12', user_id: 2001, gender: 'F', create_date:'2010-11-02'], |
|
] ; |
|
} |
|
|
|
@Autowired |
|
private IProfileService profileService; |
|
|
|
@Before |
|
public void doData() throws DatabaseUnitException, SQLException |
|
{ |
|
sessionFactory.getCurrentSession().doWork(new Work() |
|
{ |
|
@Override |
|
public void execute(Connection connection) throws SQLException |
|
{ |
|
try |
|
{ |
|
con = new DatabaseConnection(connection); |
|
dataset = new GroovyDataset(data); |
|
DatabaseOperation.REFRESH.execute(con, dataset); |
|
} |
|
catch(DatabaseUnitException e) |
|
{ |
|
throw new SQLException(e); |
|
} |
|
} |
|
}); |
|
} |
|
|
|
@Test |
|
public void testLoadUser() |
|
{ |
|
User user = this.profileDao.loadUserById(KNOWN_USER_ID, false, false); |
|
assertNotNull(user); |
|
assertEquals("Sarah", user.getFirstName()); |
|
assertEquals("Connor", user.getLastName()) |
|
} |
|
|
|
@Test |
|
public void testBabiesLoadedProperly() |
|
{ |
|
User user = this.profileDao.loadUserById(KNOWN_USER_ID, true, false); |
|
assertTrue(user.hasBabies()); |
|
assertEquals(2, user.babies.size()) |
|
} |
|
|
|
} |