Dashboard > Struts University > Home > JPA Training Course > JPA Agenda > TestData-Notes
Added by Ted Husted, last edited by Ted Husted on Dec 08, 2007

Where JPA ends, Hibernate 3 begins.

Presentation - Building applications with Spring 2 Core and Java 5

The JPA helps us persist objects. Spring helps us create and manage objects. In this session, we overview the core of the Spring framework and look at what utility it provides applications.

  • Criteria Queries
  • Annotation Extensions
  • Validator
  • Search
  • Shards

Workshop - TestData

In the lab, we use Spring to create fully-formed objects that we can use with our persistence tests.

Story: Advanced tests require pre-existing data. Among other things, Spring Core provides an easy way to create fully-formed objects for testing.

  • Use Spring to setup background data for testing


  • Spring capabilities, including a spring.xml file.
  • Scaffolding for persistence tests (EntityTestCase, et al)


  • Add Spring capabilities to the project
  • Create Spring beans to declare bootstrap test data.
  • Create unit test to load bean factory, obtain test objects, and persist test data.

Hint code

<bean id="imap" class="entity.protocol.ProtocolImpl">
    <property name="description" value="IMAP Protocol" />
    <bean id="pop3" class="entity.protocol.ProtocolImpl">
    <property name="description" value="POP3 Protocol" />
    <bean id="user"
    <!-- ... -->
    <property name="subscriptions">
    <bean class="entity.subscription.SubscriptionImpl">
    <!-- ... -->
public class BootstrapDataTest extends EntityTestCase {
    protected BeanFactory factory;
    public void setUp() throws Exception {
    factory = new XmlBeanFactory(new ClassPathResource ("spring.xml"));
    public void tearDown() throws Exception {


  • Used Spring to setup background data for testing

Extra Credit

  • Create additional unit tests that make good use of the test data.
  • Add more test data, if needed.

Site running on a free Atlassian Confluence Open Source Project License granted to OSS. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.5 Build:#811 Jul 25, 2007) - Bug/feature request - Contact Administrators