1 2 Previous Next 21 Replies Latest reply on Jun 27, 2007 8:45 AM by knisterpeter Go to original post
      • 15. Re: UnitTesting and jBPM pageflow
        knisterpeter

         

        String id = new NonFacesRequest("/public/register.xhtml") {
        
         @Override
         protected void renderResponse() throws Exception {
         Contexts.getSessionContext().set("person", new Person());
         invokeMethod("#{register.begin}"); // <-- This is my pageflow start method annoted with @Begin(...)
         Pageflow pageflow = Pageflow.instance();
         assertEquals("register", pageflow.getNode().getName());
         assertTrue(isLongRunningConversation());
         assertEquals("/public/register.xhtml", getRenderedViewId());
         }
        
         }.run();
        
        ... next FacesRequest...
        
         @Override
         protected void invokeApplication() throws Exception {
         Pageflow pageflow = Pageflow.instance();
         pageflow.navigate(getFacesContext(), "next");
         assertEquals("confirm", pageflow.getNode().getName());
         }
        
        
        


        As you can see, I'll never start the pageflow directly. I'm using the annotations to start Converstation and seam automatically start my pageflow.
        As you further can see in subsequent requests I'll to the transition from node to node with calling pageflow.navigate(...) with my transition name I want to trigger.

        I hope this does help you.

        • 16. Re: UnitTesting and jBPM pageflow
          trekker880

          hi
          Can we do this unit testing using simple public static void main(). ?

          • 17. Re: UnitTesting and jBPM pageflow
            knisterpeter

            Do use TestNG or JUnit for testing.

            • 18. Re: UnitTesting and jBPM pageflow
              trekker880

              Ok.
              Let me clear my requirement for this pageflow.
              Here is somewhat i am trying to do.

              public class Test{
              
              public test() throws Exception{
              
              
              PageFlow pageflow = PageFlow.Instance(); <---Start the pageflow here--->
              
              And using this pageflow object i want to extract the view id of the current page and the next page to it.
              }
              
              public static void main(String[] args){
              Test test1= new Test();
              test1.test();
              }
              


              this is the idea..Whatever the pageflow is defined in the pageflow-definition.xml , I am able to find out the current page,current view id and all the related info. in a java file so that the method in it is accessible to the other class...In short i want this java class as a utility to fit into my application.

              Thanx,

              • 19. Re: UnitTesting and jBPM pageflow
                knisterpeter

                I have no idea what your use case is and no idea how to you solve your problem, but it does not sound like a unit test to me.
                If you want to create a unit test, extend your testclass from SeamTest which will boostrap an embedded container and the seam environment. Then do as I posted above and you have your pageflow running.

                With just Pageflow.instance() you don't start any pageflow.

                • 20. Re: UnitTesting and jBPM pageflow
                  trekker880

                  OK.
                  You had put a comment on the pageflow-defintion.xml as it's not legal.
                  I am using start-page to start my pageflow. So where i need to put the start node. I am starting my pageflow using the page rather than the start-state.

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


                  Also there is one concern.
                  As i am moving from the page2 to page 3. Say the conversation id it shows is 1 but when it is on page3 the conversation-id changed to 2 and it remains the same for the subsequent flow.
                  If i am on a same pageflow the conversation id should remain the same for back-forth flow navigation.But it gets changed when it moves from page2 to page3.

                  <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="pageflow1">
                  
                   <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="page5" name="yes"></transition>
                   <transition name="back" to="page3"></transition>
                   </page>
                   <page name="page5" view-id="/page5.jspx" back="enabled">
                   <redirect/>
                   <transition to="start" name="yes"></transition>
                   <transition name="back" to="page4"></transition>
                   </page>
                  
                   <page view-id="/login.jspx" name="start" >
                   </page>
                  
                  </pageflow-definition>
                  


                  Also there are method in the Jbpm class in the seam.

                  getPageflowDefinitionFromResource(String resourceName)
                  getPageflowDefinitionFromXml(String pageflowDefinition)
                  getPageflowProcessDefinition(String pageflowName)
                  getProcessDefinitionFromResource(String resourceName)
                  


                  How to get the pageflow definition.xml using these methods. I tried these methods but in vain. May be i m following the wrong path. Do you have any idea?

                  Can you post your bean where you used the @Begin annotated method to start the pageflow ?

                  Thanx

                  • 21. Re: UnitTesting and jBPM pageflow
                    knisterpeter

                    This is the part of my bean:

                    @Name("register")
                    @Stateful
                    @Scope(ScopeType.CONVERSATION)
                    public class RegisterBean extends Controller implements IRegister {
                    
                     private static final long serialVersionUID = 7559006461204534425L;
                    
                     @PersistenceContext(type = PersistenceContextType.EXTENDED)
                     private EntityManager em;
                    
                     /**
                     * @see de.llynch.kingpin.IRegister#begin()
                     */
                     @Begin(join = true, pageflow = "register")
                     public void begin() {
                     }
                    
                    ....

                    This is the testcase (I'm using JUnit):
                    /**
                     * @throws Exception
                     */
                     @Test
                     @SuppressWarnings("synthetic-access")
                     public void testRegister() throws Exception {
                     String id = new NonFacesRequest("/public/register.xhtml") {
                    
                     @Override
                     protected void renderResponse() throws Exception {
                     invokeMethod("#{register.begin}");
                     Pageflow pageflow = Pageflow.instance();
                     assertEquals("register", pageflow.getNode().getName());
                     assertTrue(isLongRunningConversation());
                     assertEquals("/public/register.xhtml", getRenderedViewId());
                     }
                    
                     }.run();
                    
                     id = new FacesRequest("/public/register.xhtml", id) {
                    
                     @Override
                     protected void invokeApplication() throws Exception {
                     Pageflow pageflow = Pageflow.instance();
                     pageflow.navigate(getFacesContext(), "next");
                     assertEquals("confirm", pageflow.getNode().getName());
                     }
                    
                     @Override
                     protected void renderResponse() throws Exception {
                     assertEquals("/public/confirm.xhtml", getViewId());
                     assertTrue(isLongRunningConversation());
                     }
                    
                     }.run();
                    
                     id = new FacesRequest("/public/confirm.xhtml", id) {
                    
                     @Override
                     protected void invokeApplication() throws Exception {
                     Pageflow pageflow = Pageflow.instance();
                     assertTrue(pageflow.isInProcess());
                     assertEquals("confirm", pageflow.getNode().getName());
                     pageflow.navigate(getFacesContext(), "next");
                     assertEquals("invite", pageflow.getNode().getName());
                     }
                    
                     @Override
                     protected void renderResponse() throws Exception {
                     assertEquals("/public/secure/invite.xhtml", getViewId());
                     assertFalse(isLongRunningConversation());
                     }
                    
                     }.run();
                     }
                    
                    



                    1 2 Previous Next