1 2 Previous Next 21 Replies Latest reply on Jun 27, 2007 8:45 AM by knisterpeter

    UnitTesting and jBPM pageflow

    knisterpeter

      Hi,
      I want to write a testcase for each of my use cases. I have some use cases realized witz jBPM and now I'm wondering how to create a test case for a condition node in my pageflow. Any hint on that?

        • 1. Re: UnitTesting and jBPM pageflow
          stu2

          It's definitely possible, but I don't know how to make it pretty. Here's an example from one of my tests:

          log.info("Begin testing initial mapping");
           setViewId(MappingViewId.APPLICABLE_FIELDS.id);
           invokeMethod("#{catalogMapping.beginForInitialMapping()}");
          
           Pageflow pageFlow = Pageflow.instance();
           assert pageFlow.getNode().getName().equals(MappingViewId.APPLICABLE_FIELDS.node)
           : "found " + pageFlow.getNode().getName();
           log.info("current view-id is #0, nodename is #1", pageFlow.getPageViewId(), pageFlow.getNode().getName());
           pageFlow.navigate(getFacesContext(), "continue");
           assert pageFlow.getNode().getName().equals(MappingViewId.SELECT_FILE.node)
           : "found " + pageFlow.getNode().getName();
           setViewId(MappingViewId.SELECT_FILE.id);
           log.info("current view-id is #0, nodename is #1", pageFlow.getPageViewId(), pageFlow.getNode().getName());
          
           setValue("#{catalogMapping.uploadFileInputStream}", new ByteArrayInputStream(CsvData.SMALL.getBytes()));
           setValue("#{catalogMapping.uploadFileName}", "master.csv");
          
           // Verify that the merchant is there
           Merchant merchant = (Merchant) lookup("merchant");
           assert merchant != null: "no merchant!";
          
           pageFlow.navigate(getFacesContext(), "submit");
           // the #{catalogMapping.initForInitialMapping()} should now take place in the pageflow
          



          • 2. Re: UnitTesting and jBPM pageflow
            knisterpeter

            Thanks for your help. I'll give that all a try on monday. :)

            • 3. Re: UnitTesting and jBPM pageflow
              stu2

              It does work, but you really have to carefully simulate the browser to make it work. Note that those methods are all in SeamTest (now no doubt in BaseSeamTest). You'll find methods there to set request parameters and other things that simulate the browser.

              • 4. Re: UnitTesting and jBPM pageflow
                denis-karpov

                I think there is bug in testing(mock) environment (propagation of conversations with pageflow does not work)

                http://jira.jboss.org/jira/browse/JBSEAM-1000

                • 5. Re: UnitTesting and jBPM pageflow
                  knisterpeter

                  The pageflow testing does not work for me. On subsequent requests the pageflow is lost and set to null.
                  Below is my code. Anyone can give me a hint on how to do this the correct way? There are no examples in seam releases or even cvs.

                  String id = new NonFacesRequest("/public/register.xhtml") {
                  
                   @Override
                   protected void beforeRequest() {
                   setParameter("c", "1");
                   }
                  
                   @Override
                   protected void renderResponse() throws Exception {
                   Contexts.getSessionContext().set("person", new Person());
                   Contexts.getSessionContext().set(
                   "soapMailingJobCollectionAccess",
                   mailingJobCollectionAccess);
                   Contexts.getSessionContext().set("soapMailingJob", mailingJob);
                   // setValue("#{campaign.id}", 1);
                  
                   Pageflow pageflow = Pageflow.instance(); //<-- Here the process instance is null (correct)
                   pageflow.begin("register"); //<-- Here the process instance is 'register' (correct)
                   assertEquals("register", pageflow.getNode().getName());
                  
                   assertEquals("/public/register.xhtml", getRenderedViewId());
                   }
                  
                   }.run();
                  
                   id = new FacesRequest("/public/register.xhtml", id) {
                  
                   @Override
                   protected void processValidations() throws Exception {
                   assertTrue(validateValue("#{person.id.email}", email));
                   assertTrue(validateValue("#{person.salutation}", "MR"));
                   assertTrue(validateValue("#{person.mobile}", mobile));
                   assertFalse(isValidationFailure());
                   }
                  
                   @Override
                   protected void updateModelValues() throws Exception {
                   setValue("#{person.id.email}", email);
                   setValue("#{person.salutation}", Salutation.MR);
                   setValue("#{person.mobile}", mobile);
                   }
                  
                   @Override
                   protected void invokeApplication() throws Exception {
                   Pageflow pageflow = Pageflow.instance(); //<-- Here the process instance is null (WRONG!!!)
                   pageflow.navigate(getFacesContext(), "next");
                   assertEquals("confirm", pageflow.getNode().getName());
                   }
                  
                   @Override
                   protected void renderResponse() throws Exception {
                   assertEquals("Test Campaign",
                   getValue("#{person.id.campaign.name}"));
                   // XXX: (JBSEAM-1529) Gives NPE
                   // assertTrue(FacesMessages.instance().getCurrentGlobalMessages()
                   // .isEmpty());
                  
                   Iterator<FacesMessage> messages = FacesContext
                   .getCurrentInstance().getMessages();
                   assertTrue(messages.hasNext());
                   assertEquals("msgPasswordSend", messages.next().getSummary());
                   assertEquals("/public/confirm.xhtml", getViewId());
                   assertTrue(isLongRunningConversation());
                   }
                  
                   }.run();
                  
                  


                  • 6. Re: UnitTesting and jBPM pageflow
                    knisterpeter

                    BTW: Here is my pageflow definition:

                    <?xml version="1.0" encoding="UTF-8"?>
                    <pageflow-definition xmlns="http://jboss.com/products/seam/pageflow"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://jboss.com/products/seam/pageflow pageflow-1.2.xsd"
                     name="register">
                    
                     <start-page name="register" view-id="/public/register.xhtml">
                     <transition name="next" to="personRegistered">
                     <action expression="#{register.register}" />
                     </transition>
                     </start-page>
                    
                     <decision name="personRegistered"
                     expression="#{register.registered}">
                     <transition name="true" to="login" />
                     <transition name="false" to="confirm">
                     <action expression="#{register.sendCode}" />
                     </transition>
                     </decision>
                    
                     <page name="confirm" view-id="/public/confirm.xhtml">
                     <redirect />
                     <transition name="next" to="isCodeCorrect" />
                     </page>
                    
                     <decision name="isCodeCorrect"
                     expression="#{register.codeCorrect}">
                     <transition name="true" to="invite">
                     <action expression="#{register.complete}" />
                     </transition>
                     <transition name="false" to="confirm" />
                     </decision>
                    
                     <page name="invite" view-id="/public/secure/invite.xhtml">
                     <redirect />
                     <end-conversation />
                     </page>
                    
                     <page name="login" view-id="/public/login.xhtml">
                     <redirect />
                     <end-conversation />
                     </page>
                    
                    </pageflow-definition>
                    


                    • 7. Re: UnitTesting and jBPM pageflow
                      pmuir

                      If, as Denis says, that bug exists, then it's not going to work!

                      • 8. Re: UnitTesting and jBPM pageflow
                        knisterpeter

                        Since JBSEAM-1000 does not allow be to post a comment on this I'll do this here:

                        Here is a part of my logfile related to this problem:

                        [DEBUG] 15:43:42.965 jsf.SeamPhaseListener - after phase: RESTORE_VIEW 1
                        [DEBUG] 15:43:42.965 core.Events - Processing event:org.jboss.seam.afterPhase
                        [DEBUG] 15:43:42.966 core.Manager - No stored conversation, or concurrent call to the stored conversation
                        [DEBUG] 15:43:42.968 core.Events - Processing event:org.jboss.seam.preSetVariable.org.jboss.seam.core.pageflow
                        


                        • 9. Re: UnitTesting and jBPM pageflow
                          knisterpeter

                          Possibly this is caused by missing AbstractSeamJsfListener or ContextFilter, since test cases are not executing inside of a webapp. But both classes above call 'handleConversationPropagation' where the pageflow is validated and the conversation is restored (but I'm a noob to seam).

                          • 10. Re: UnitTesting and jBPM pageflow
                            knisterpeter

                            Nope, the phase listener is registered and called, but I don't see the method call to afterRestoreView().

                            • 11. [SOLVED] Re: UnitTesting and jBPM pageflow
                              knisterpeter

                              Ok, got it running! :)
                              I have to call a method on my component annotated with @Begin(join=true, pageflow="name") to start the pageflow AND converstation as long running.
                              The problem when calling the Pageflow.instance().begin() is that there is no long-running conversation, at least in my case. I have set the pageflow start directive in my pages.xml which does reside in another project for unit tests and is only available when deployed in a container environment.

                              Hope this does help anyone having problems.

                              • 12. Re: UnitTesting and jBPM pageflow
                                trekker880

                                @ knisterPeter

                                hi
                                i am getting the same problem. I'm also making a test class for the pageflow.Its a simple pageflow-definition

                                Code :
                                <pageflow-definition xmlns="http://jboss.com/products/seam/pageflow"
                                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                xsi:schemaLocation=
                                "http://jboss.com/products/seam/pageflow http://jboss.com/products/seam/pageflow-1.2.xsd"
                                name="submit2">

                                <start-page name="page2" view-id="/page2.jspx" >




                                </start-page>

                                <page name="page3" view-id="/page3.jspx" back="enabled">





                                <page name="page4" view-id="/page4.jspx" back="enabled">





                                <page view-id="/login.jspx" name="start" >


                                </pageflow-definition>

                                Here is pages.xml

                                Code:

                                <!DOCTYPE pages PUBLIC
                                "-//JBoss/Seam Pages Configuration DTD 1.2//EN"
                                "http://jboss.com/products/seam/pages-1.2.dtd">


                                <page view-id="/numberGuess.jspx">
                                <begin-conversation join="true" pageflow="numberGuess"/>

                                <page view-id="/confirm.jspx">
                                <begin-conversation nested="true" pageflow="cheat"/>

                                <page view-id="/page2.jspx">
                                <begin-conversation nested="true" pageflow="submit2"/>



                                I'm getting the error while doing the Pageflow.instance().begin()

                                My converstaion gets start when i am on page3.jspx while i am starting the pageflow from the page.jspx.

                                I am only making the simple java file rather than the junit test case.
                                My purpose is to extract the CurrentPage and the NextPage.

                                Could you provide the sample test code for this pageflow.

                                Thanks,

                                • 13. Re: UnitTesting and jBPM pageflow
                                  trekker880

                                  Sorry for the last post as the code isn't displayed properly.

                                  Here it is submit2.jpdl.xml

                                  
                                  <pageflow-definition xmlns="http://jboss.com/products/seam/pageflow"
                                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                   xsi:schemaLocation=
                                   "http://jboss.com/products/seam/pageflow http://jboss.com/products/seam/pageflow-1.2.xsd"
                                   name="submit2">
                                  
                                   <start-page name="page2" view-id="/page2.jspx" >
                                   <transition name="yes" to="page3">
                                   </transition>
                                  
                                   <transition name="back" to="start"></transition>
                                   </start-page>
                                  
                                   <page name="page3" view-id="/page3.jspx" back="enabled">
                                   <redirect/>
                                   <transition name="back" to="page2"></transition>
                                   <transition name="yes" to="page4"/>
                                   </page>
                                  
                                   <page name="page4" view-id="/page4.jspx" back="enabled">
                                   <redirect/>
                                   <transition to="start" name="yes"></transition>
                                   <transition name="back" to="page3"></transition>
                                   </page>
                                  
                                   <page view-id="/login.jspx" name="start" >
                                   </page>
                                  
                                  </pageflow-definition>
                                  
                                  


                                  Can you tell me how to read this xml . Is it read internally by the seam?

                                  I had made the entry in pages.xml

                                  
                                  <!DOCTYPE pages PUBLIC
                                   "-//JBoss/Seam Pages Configuration DTD 1.2//EN"
                                   "http://jboss.com/products/seam/pages-1.2.dtd">
                                  
                                  <pages>
                                   <page view-id="/numberGuess.jspx">
                                   <begin-conversation join="true" pageflow="numberGuess"/>
                                   </page>
                                   <page view-id="/confirm.jspx">
                                   <begin-conversation nested="true" pageflow="cheat"/>
                                   </page>
                                   <page view-id="/page2.jspx">
                                   <begin-conversation nested="true" pageflow="submit2"/>
                                   </page>
                                  </pages>
                                  
                                  


                                  Can you provide the sample test code for this submit2.jpdl.xml

                                  Here i need to find out the current page,current node and the next page.
                                  I tried like the jbpm way to read the submit2.jpdl.xml but with no result.

                                  
                                  ProcessDefinition pageflowDefinition =Jbpm.instance().getPageflowProcessDefinition("submit2");
                                  
                                  


                                  Can anybody provide the sample test code for that. i m in urgency..

                                  thanks,

                                  • 14. Re: UnitTesting and jBPM pageflow
                                    knisterpeter

                                    I would think as for me your pages.xml isn't processed. Therefore you need a method in your beans annotated with @Begin(join=true, pageflow="name").
                                    This method should be called when you start your unit test in a NonFacesRequest instance.
                                    That should be all to get you running. I'll post my code later on when I'm at office.

                                    BTW:

                                    <start-page name="page2" view-id="/page2.jspx" >
                                     <transition name="yes" to="page3">
                                     </transition>
                                    
                                     <transition name="back" to="start"></transition>
                                     </start-page>

                                    This does not look leagal to be, since you do not define a node 'start' in your jpdl.

                                    1 2 Previous Next