Java Reference
In-Depth Information
for
( PostInsertEventListener listener : postInsertListeners ) {
System.out.println("Listener: " + listener.getClass().getName() );
}
}
}
}
Finally, it's necessary to change the test case classes: first the infrastructure classes (as
shown in listing 18.16) and then the test methods themselves (listing 18.17).
Listing 18.16
Changes on
AbstractJpaDbUnitELTemplateTestCase
[...]
public abstract class
AbstractJpaDbUnitELTemplateTestCaseJUnit
extends
AbstractJpaDbUnitTestCase {
B
@Override
protected void
invokeTestMethod(Method method, RunNotifier notifier) {
context =
new
ELContextImpl();
ELFunctionMapperImpl.resetIds();
setupDataSet(method);
super
.invokeTestMethod(method, notifier);
assertDataSet(method);
}
}
C
B
Although not shown here, superclass
AbstractJpaDbUnitTestCase
also changed; it
doesn't need to keep track of the
ID
s anymore, so
id
and
phoneId
were removed.
This method now is also simpler than before. Instead of binding the
id
variable to
the
EL
context before and after invoking the test, it resets the
ID
's map before each
test is run.
C
Listing 18.17
New version of
EntitiesMappingTest
using JPA ID's integration
[...]
public class
EntitiesMappingTest
extends
AbstractJpaDbUnitELTemplateTestCase {
@Test
@DataSets(setUpDataSet="/user-with-telephone.xml")
public void
testLoadUserWithTelephone() {
beginTransaction();
long
id = ELFunctionMapperImpl.getId(User.
class
);
User user = em.find(User.
class
, id);
commitTransaction();
assertUser(user,true);
}
B
@Test
@DataSets(assertDataSet="/user-with-telephone.xml")
public void
testSaveUserWithTelephone()
throws
Exception {
User user = newUser(true);
beginTransaction();
em.persist(user);
C