seam test and transaction ovservers
freakwave10 Oct 15, 2009 5:15 PMHi all,
we have some component tests setup to create a simple organizational hierarchy:
1 |-11 |-12-121 ...
This hierarchy is displayed in a tree.
To ensure the tree is up to date, the setupOrgTree method is annotated with the TransactionSuccess event:
@Create
@Observer("org.jboss.seam.afterTransactionSuccess.Organization")
public void setupOrgTree()
{
...
From a test case, we create hundrets of organizations. The problem is this test takes really long, because each insert into the databasse will raise a org.jboss.seam.afterTransactionSuccess.Organization event and the tree will be rebuild many times.
Here is the test method:
@Test //(dependsOnMethods = { "test_check_organization" })
public void test_create_orgainization() throws Exception {
new FacesRequest(){
@Override
protected void invokeApplication() throws Exception {
Conversation.instance().begin();
//create root org
OrganizationHome organizationHome = (OrganizationHome) Component.getInstance("organizationHome", true);
organizationHome.getInstance().setName("WEBA");
Organization parentOrg = organizationHome.getInstance();
organizationHome.persist();
for (int i=0; i<3; i++) {
organizationHome.clearInstance();
organizationHome.getInstance().setName("Level1-" + i);
organizationHome.getInstance().setParentOrganization(parentOrg);
Organization level1org = organizationHome.getInstance();
organizationHome.persist();
for (int n=0; n<3; n++) {
organizationHome.clearInstance();
organizationHome.getInstance().setName("Level2-" + n);
organizationHome.getInstance().setParentOrganization(level1org);
Organization level2org = organizationHome.getInstance();
organizationHome.persist();
for (int m=0; m<=3; m++) {
organizationHome.clearInstance();
organizationHome.create();
organizationHome.getInstance().setName("Level3-" + m);
organizationHome.getInstance().setParentOrganization(level2org);
organizationHome.persist();
}
}
}
Conversation.instance().end();
}
}.run();
}What would be the best way to supress the setupOrgTree when running a test?
Of course I could raise my own event whenever an organization is updated/deleted/modified, but it has quite some charme to use the TransactionSuccess Events, since this is raised always (when using the home object to manage organizations).
Thanks for any suggestions.
Wolfgang