8 Replies Latest reply on Nov 20, 2012 3:01 PM by Dan Allen

    Warp: alternative syntax

    Lukáš Fryč Master

      I was thinking about how we could make client/server interaction with Warp more pleasant:

       

      Sequence of methods:

      https://gist.github.com/3951243

       

      This would work only in case of ordering of methods ensured by JVM.

        • 1. Re: Warp: alternative syntax
          Karel Piwko Master

          I'm afraid there is no way how to ensure that. Maybe we can reuse @InSequence ?

          • 2. Re: Warp: alternative syntax
            Lukáš Fryč Master

            We could also do post-processing and add @InSequence automatically using APT (in case it will ensure ordering).

            • 3. Re: Warp: alternative syntax
              Aslak Knutsen Master

              hmm.. looks a bit confusing to me at first.

               

              It seems to force a new method when ever you want to 'move' to the container side.

              • 4. Re: Warp: alternative syntax
                Dan Allen Master

                I don't think annotated methods should be used for flow control. The @InSequence ensures order, but the dependency is on the system state not necessarily on sequential, handshake steps.

                 

                If you think you can find a way to make it work, then keep at it. I won't discourage you from experimenting. We should be careful to make the reader do too much wiring in his or her head, just something to keep in mind.

                • 5. Re: Warp: alternative syntax
                  Lukáš Fryč Master

                  +1 the proposed syntax is not really step forward

                   

                  The real problem which comes with anonymous classes is that some people does not like code structure it comes with it:

                  https://github.com/richfaces/components/blob/develop/misc/ui/src/test/integration/org/richfaces/component/focus/TestFocusValidationAware.java#L110

                   

                  Is it space where JSFUnit really excelled and what is the ideal we should try to achieve.

                  • 6. Re: Warp: alternative syntax
                    Aslak Knutsen Master

                    There is nothing that forces anyone to use annonymous classes tho. In some cases it's just a lazy shortcut.

                     

                     

                        @Test
                        public void testGlobalMessageIsIgnored() {
                            
                           // Warp.execute({ guardHttp(submitButton).click() })  Java8 closure?
                           Warp.execute(new GuardedClick(submitButton))
                                    .verify(new GlobalMessageBehavior());
                            
                            assertEquals(input3, getFocusedElement());
                        }
                        
                        private static class GlobalMessageBehavior() {
                                private static final long serialVersionUID = 1L;
                    
                    
                                @BeforePhase(Phase.RENDER_RESPONSE)
                                public void addGlobalMessage() {
                                    FacesContext context = FacesContext.getCurrentInstance();
                                    context.addMessage(null, new FacesMessage("global message"));
                                }
                                
                                @AfterPhase(Phase.RENDER_RESPONSE)
                                public void verifyGlobalMessageIsIgnored() {
                                    FacesContext context = FacesContext.getCurrentInstance();
                                    
                                    AbstractFocus component = bean.getComponent();
                                    FocusRendererBase renderer = bean.getRenderer();
                                    String candidates = renderer.getFocusCandidatesAsString(context, component);
                                    
                                    assertEquals("form", candidates);
                                }
                            }    
                    
                    

                     

                     

                    Maybe a WebDriver Warp Function lib would help some. Atleast for the ClientActions.

                     

                    Warp.execute(Client.clickGuarded(driver))

                    Warp.execute(Client.navigateTo(driver, indexPage))

                    • 7. Re: Warp: alternative syntax
                      Lukáš Fryč Master

                      The integration with WebDriver is tempting:

                       

                      public class Warp {
                          public static <T> T guard(T target) { ...}
                      }
                      

                       

                      guard(driver).get(url);
                      verify(new ServerAssertion() { ... });
                      
                      guard(button).click();
                      verify(new ServerAssertion() { ... });
                      

                       

                      We should definitely make the API Java8 / closures compatible.

                      • 8. Re: Warp: alternative syntax
                        Dan Allen Master

                        Now you are on to something. Having the option to separate the chaining of verify seems to reduce some of the clutter.

                         

                        Personally, the nested classes don't throw me off...but perhaps it's because I'm used to it from the old days of SeamTest (which, btw, Warp leaves in the dust!)

                         

                        Another alternative is to use Groovy for tests. Recall that Groovy now has a type-safe mode, so you get the best of both worlds: closures today and the feeling of type-safe Java. It's defintiely something worth looking into. Tests like this lend itself very well to a more flexible language.

                         

                        But again, keep poking at it and see if you come up with an alternative that works well in pure Java.