Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-6939

Problems with testing form submission if dealing with multiple AJAX click behaviors

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Not A Problem
    • 8.7.0
    • None
    • wicket-core
    • None

    Description

      both wicketTester.executeAjaxEvent(..) aswell as  wicketTester.newFormTester(..).submit(..)
      cannot handle cases where multiple click behaviors are attached to the submitting component, i.e. a button, and the first behavior processed within BaseWicketTester.executeAjaxEvent(final Component component, final String event) is the non-submitting (i.e. not AjaxFormSubmitBehavior) behavior.
      This first behavoir creates a brand new request after being processed, and thus clears the uploadedFile added beforehand via tester.getRequest().addFile(..) needed when submission of the form is processed.

      In my case there is such a behavior (a loading indicator) that I had, as a workaround to this bug, first to remove in my test code in order to make my unit test work:

       

              final BeladungPage startedPage = this.tester.startPage(this.beladungPage);
      
              final File xmlFile = new File("src/test/resources/camunda.cfg.xml");
              final FormComponent<?> formComponent = (FormComponent<?>) tester.getComponentFromLastRenderedPage(
                      "upload:form:sections:sections:0:section:body:file:upload");
      
              // workaround for wicket bug in tester.executeAjaxEvent() / tester.newFormTester().submit() if dealing with multiple AJAX click behaviors
              final Button submitButton = (Button) this.tester.getComponentFromLastRenderedPage("upload:form:buttons:buttons:0:button");
              submitButton.remove(submitButton.getBehaviors(ClickAjaxEventBehavior.class).get(0));
      
              tester.getRequest().addFile(formComponent.getInputName(), xmlFile, "application/xml");
              tester.executeAjaxEvent("upload:form:buttons:buttons:0:button", "click");
              //        tester.newFormTester("upload:form", false).submit("buttons:buttons:0:button");
      
              final IFeedbackMessageFilter msgFilter = new ExactLevelFeedbackMessageFilter(FeedbackMessage.ERROR);
              final List<FeedbackMessage> feedbackMessages = this.tester.getFeedbackMessages(msgFilter);
              Assert.assertEquals(
                      "[[FeedbackMessage message = \"Ein Fehler ist aufgetreten! Die markierten Felder wurden unzureichend ausgefüllt.<br>Bitte überprüfen Sie Ihre Angaben.\", reporter = form, level = ERROR], [FeedbackMessage message = \"content-type 'application/xml' wird nicht unterstützt\", reporter = file, level = ERROR]]",
                      feedbackMessages.toString());

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            MarkusBohr Markus Bohr
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: