3 Replies Latest reply on Apr 29, 2008 9:10 AM by JB Arnoux

    SeamTest, simulate JSF actions with error

    JB Arnoux Newbie

      i write a second post for a second question about my problem for Integration test with SeamTest

      i have the same EJB Seam to test, and would simulate JSF Actions;

      this is my EJB Seam

      public class EJBSeam implements
              EJBSeamLocale {
          private static final Logger aLogger =
          @PersistenceContext(type = PersistenceContextType.EXTENDED, unitName = "MyUnitName")
          private EntityManager em;
          @In(required = false)
          @Out(required = false)
          private APojo myPojoWichContainsEJBEntity;
          private AnInterfaceLocal MyEJBActions;
          private Boolean actionPossible;
          private String errorMessage;

      This is part of the xhtml Page

      <h:inputText id="name" value="#{myPojoWichContainsEJBEntity.entityBean.name}" /><br />

      and this is my SeamTest extended class

      public class TestSeamEJB extends SeamTest {
       public void testAddCF() throws Exception {
      new FacesRequest() {
                  protected void updateModelValues() throws Exception
                      APojo myPojoInstance = (APojo) Component.getInstance("myPojoWichContainsEJBEntity");
                assert myPojoInstance!=null;

      I obtain this ful stack trace error:

      FAILED: testAddCF
           at test.integration.formation.TestGestionCFA$1.updateModelValues(TestGestionCFA.java:50)
           at org.jboss.seam.mock.SeamTest$Request.run(SeamTest.java:476)
           at test.integration.formation.TestGestionCFA.testAddCF(TestGestionCFA.java:59)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:585)
           at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580)
           at org.testng.internal.Invoker.invokeMethod(Invoker.java:478)
           at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:607)
           at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:874)
           at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
           at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
           at org.testng.TestRunner.runWorkers(TestRunner.java:689)
           at org.testng.TestRunner.privateRun(TestRunner.java:566)
           at org.testng.TestRunner.run(TestRunner.java:466)
           at org.testng.SuiteRunner.runTest(SuiteRunner.java:301)
           at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:296)
           at org.testng.SuiteRunner.privateRun(SuiteRunner.java:276)
           at org.testng.SuiteRunner.run(SuiteRunner.java:191)
           at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:808)
           at org.testng.TestNG.runSuitesLocally(TestNG.java:776)
           at org.testng.TestNG.run(TestNG.java:701)
           at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
           at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)

      I have Seam 1.2.1GA, TestNG5.7 with eclipse plugin, and move the embedded.jar files in first position in classpath for this test class.

      I don't understand what do i do to test this JSF interacitons.
      If anyone could help me or just give me indication, or example, or anything else.
      I read books and tutorials about seam, and seam manual without finding how to solve this problem.
      Thanks in advance

        • 1. Re: SeamTest, simulate JSF actions with error
          JB Arnoux Newbie

          could you tell me if i gave you enough information?

          Is my problem so trivial that i could find the answer alone? (in this case, could you just give me an indication, or a link because since one week, i didn't find any answer.

          Thanks in advance.

          • 2. Re: SeamTest, simulate JSF actions with error
            Matt Drees Master

            It's not real clear what behavior you'd like to have.

            myPojoWichContainsEJBEntity is an outjected field, so if you expect it to be available in your test, you must trigger the outjection somehow.  I imagine you'll want to set up a @Factory method for this.  Read the docs on how to use @Factory with @Out.

            • 3. Re: SeamTest, simulate JSF actions with error
              JB Arnoux Newbie

              Thanks for your reply,

              In fact, myPojoWichContainsEJBEntity is a java class wich contains all fields manipulate by forms.

              My Seam class does control and give the information contained by myPojoWichContainsEJBEntity to the MyEJBActions to get results.

              I factorized all fields because my form manipulate more than just one entity mapped by EntityBean. That is why is myPojoWichContainsEJBEntity @in and @out annotated. It's @In because i need it for my initialisation's controls, and @Out, because it's needed by the other form to complete my scenarios.

              I was able to do unit test, and i would try to simulate JSF actions with seamTest.

              In examples and books (P307) , they said : In a seam test case, we can retrieve any Seam component by its name via the static component.getInstance() method.
              That's what i tried, but it didn't work.

              Pending, I will follow your advice and read about @Factory.