Transactional Test Data
Here is an excerpt from
PetStoreImplTransactionTest.xml
,
which holds the data values used for the test.
PetStoreImplTransactionTest.xml (excerpt)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<import resource="classpath:AccountData.xml"/>
<import resource="classpath:ItemData.xml"/>
<import resource="classpath:LineItemData.xml"/>
<import resource="classpath:ProductData.xml"/>
<import resource="classpath:serviceContext.xml"/>
<bean id="petStoreImplTransactionTest" class="org.springunit.framework.SpringUnitContext">
<property name="data">
<map>
<entry key="testInsertOrder">
<map>
<entry key="lineItems">
<list>
<ref bean="lineItem1"/>
<ref bean="lineItem2"/>
<ref bean="lineItem3"/>
</list>
</entry>
<entry key="order">
<ref bean="order101"/>
</entry>
<entry key="expectedTotalPrice">
<value type="double">81.00</value>
</entry>
<entry key="prepopulated">
<map>
<entry key="products">
<list>
<ref bean="product101"/>
<ref bean="product102"/>
<ref bean="product103"/>
<ref bean="product104"/>
<ref bean="product105"/>
<ref bean="product106"/>
<ref bean="product107"/>
</list>
</entry>
<entry key="categories">
<list>
<ref bean="category101"/>
<ref bean="category102"/>
<ref bean="category103"/>
<ref bean="category104"/>
</list>
</entry>
<entry key="items">
<list>
<ref bean="item101"/>
<ref bean="item102"/>
<ref bean="item103"/>
<ref bean="item104"/>
</list>
</entry>
</map>
</entry>
</map>
</entry>
<!-- other entries omitted -->
</map>
</property>
</bean>
</beans>
As we have seen in many examples, the test makes use of reused
test data values, such as
Product
s,
Item
s,
and
Category
s.
The data values that comprise the
"prepopulated"
entry
are inserted (transactionally) into the database before calling
insertOrder
.
How that is done will be shown next.
Before going on, a subtle point worth noting is that the implementation
of
PetStoreFacade
used by the test
is among the beans imported by
serviceContext.xml
.
Remember that that class is configured with transactional
behavior using Spring's AOP capability.
The same is true for the
AdministrationService
.