* Test deleting a gadget, then undeleting it.
*/
@Test
public void testDeleteThenUndelete()
{
Tab tab = jpaTabMapper.findById(fordsFirstTabId);
Gadget fordGadget1 = jpaGadgetMapper.findById(fordsFirstTabFirstGadgetId);
final int expectedGadgetCountAfterDeletingAndUndeleting = 3;
// delete the first gadget
try
{
jpaTabMapper.deleteGadget(fordGadget1);
}
catch (GadgetDeletionException e)
{
throw new RuntimeException(e);
}
jpaTabMapper.flush();
// clear the getEntityManager() so we can re-query the collection
getEntityManager().clear();
try
{
jpaTabMapper.undeleteGadget(fordsFirstTabFirstGadgetId);
}
catch (GadgetUndeletionException e)
{
throw new RuntimeException(e);
}
jpaTabMapper.flush();
// clear the getEntityManager() so we can re-query the collection
getEntityManager().clear();
// re-get and assert
tab = jpaTabMapper.findById(fordsFirstTabId);
assertEquals("Expected 3 gadgets in Ford's startPage after deleting and undeleting.",
expectedGadgetCountAfterDeletingAndUndeleting, tab.getGadgets().size());
assertEquals("Expected the undeleted gadget to be 1st again.", fordsFirstTabFirstGadgetId, tab.getGadgets()
.get(0).getId());
assertEquals("Expected the previously 1st gadget to be 2nd after deleting and undeleting the first",
fordsFirstTabSecondGadgetId, tab.getGadgets().get(1).getId());
assertEquals("Expected the previously 2nd gadget to be 3rd after deleting and undeleting the first",
fordsFirstTabThirdGadgetId, tab.getGadgets().get(2).getId());
}