开发者

How to test that observer of org.jboss.seam.postInitialization works correctly

开发者 https://www.devze.com 2022-12-11 17:30 出处:网络
I\'ve created SEAM component which checks that at least one user with global admin rights exists and creates one if no.

I've created SEAM component which checks that at least one user with global admin rights exists and creates one if no.

@Name("installer")
@Stateless
public class InstallerBean implements Installer, Serializable{
   @Observer("org.jboss.seam.postInitialization")
   public void install() {
      ...
   }

   public boolean isInstalled() {
      ...
   }
}

Now I need to test that installer works correctly. I need to check that isInstalled() returns true and check that correct users and roles are exists in the database. However SeamTest.ComponentTest.testComponents() is running before my installation compleate. I can see in the log that last messages from my installer appears in the middle of second test execution so my tests randomly fails.

I'm trying to 开发者_高级运维test my installer in the following way:

public class InstallerTests extends SeamTest {
    @Test
    public void isInstalledTest() {
        new ComponentTest() {
            @Override
            protected void testComponents() {
               ...
            }
        }
    }

    ...
}

How can I make my test starting after my installation compleated?

I'm new to SEAM so maybe I'm doing all compleately wrong. Please tell me if there is a better way.


Maybe you already solved you problem. Do you call some methods asynchronously during the execution of install()? This could randomly delay completing the installation. A very pragmatic yet not the most clean solution is to use Thread.sleep(.) in your test case to wait for the installation to complete.

0

精彩评论

暂无评论...
验证码 换一张
取 消