1 Reply Latest reply on Mar 1, 2010 9:46 PM by allenc

    Events in unit test

    allenc

      I added generation of a seam event to an existing method which causes this error in my unit test:


      No event context active
      
      org.jboss.seam.ScopeType.getContext(ScopeType.java:121) 
      at org.jboss.seam.Component.getInstance(Component.java:1999) 
      at org.jboss.seam.Component.getInstance(Component.java:1994) 
      at org.jboss.seam.Component.getInstance(Component.java:1967) 
      at org.jboss.seam.Component.getInstance(Component.java:1962) 
      at org.jboss.seam.core.Events.instance(Events.java:157) 
      at com.ols.cms.sas.SAS.icredit(SAS.java:50)
      



      Here is the code that generates the event:


      Events.instance().raiseEvent("transactionEvent", h.card, r);
      



      I am using Seam 2.2.0.GA. The code works fine when I run it in JBoss-5.1.0.GA. It works fine in unit test when I exclude the event generation.


      Do I need to do something to initialize the Event component or Context within a unit test?


      Allen


        • 1. Re: Events in unit test
          allenc

          It turns out what I really needed was to just disable event generation in unit tests. It is easy enough to call the observer from the test code. So I added this:


          '
          if (Events.exists()) Events.instance().raiseEvent(...
          '


          Problem solved.