|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.kuali.student.common.test.spring.AbstractTransactionalDaoTest
@ContextConfiguration(locations="classpath:META-INF/default-dao-context-test.xml") @TestExecutionListeners(value={org.springframework.test.context.transaction.TransactionalTestExecutionListener.class,DaoTestDependencyInjectorListener.class,org.springframework.test.context.support.DirtiesContextTestExecutionListener.class}) @Transactional @TransactionConfiguration(transactionManager="JtaTxManager") public abstract class AbstractTransactionalDaoTest
This test class will load your dao and gives you access to the shared entityManager em. Also passes the @Dao and @PersistenceFileLocation to system properties from the annotations.
Extend this class and set the
@PersistenceFileLocation defines the persistence.xml location if it is named something else.
@Dao defines the Dao implementation class, and an optional application context that contains a list of beans that should be persisted. The list bean should be called "persistList". SQL files that should be loaded can also be defined here with the testSqlFile parameter. This should be an SQL file.
This test class is @Transactional, so all tests will be rolled back. That means the data you load will be in the same state for each test.
Example:
@PersistenceFileLocation("classpath:META-INF/custom-persistence.xml") public class DaoCommonTest extends AbstractTransactionalDaoTest { @Dao(value = "org.kuali.student.MyDaoImpl", testDataFile = "classpath:META-INF/pretest-data-beans-1.xml,pretest-data-beans-2.xml") public MyDao myDao; @Test public void test1() { MyObject a = myDao.foo(); MyObject b = em.find(MyObject.class,1); assertEquals(a.id,b.id); } }Example of application context for preloading data:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="persistList" class="org.springframework.beans.factory.config.ListFactoryBean"> <property name="sourceList"> <list> <ref bean="value1" /> <ref bean="value2" /> </list> </property> </bean> <bean id="value1" class="org.kuali.student.Value"> <property name="value" value="Value Number One" /> </bean> <bean id="value2" class="org.kuali.student.Value"> <property name="value" value="Value Number Two" /> </bean> </beans>
Field Summary | |
---|---|
protected EntityManager |
em
|
Constructor Summary | |
---|---|
AbstractTransactionalDaoTest()
Passes some variables so they can be used in the application context |
Method Summary | |
---|---|
void |
preLoadBeans()
Loads the application context defined in the @Dao testDataFile attribute. |
void |
preLoadData()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected EntityManager em
Constructor Detail |
---|
public AbstractTransactionalDaoTest()
Method Detail |
---|
public void preLoadBeans()
@BeforeTransaction public void preLoadData() throws IOException
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |