Wicket
  1. Wicket
  2. WICKET-4507

wicktTester.getLastResponseAsString() returns wrong result after starting a Component

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.5
    • Fix Version/s: 1.5.6, 6.0.0-beta2
    • Component/s: wicket
    • Labels:
      None

      Description

      > This following test :

      @Test
      public void test() throws Exception {
      WicketTester tester=new WicketTester();
      tester.startComponentInPage(new Label("lableId", "content") {
      @Override
      protected void onComponentTag(ComponentTag tag)

      { super.onComponentTag(tag); tag.put("test","123"); }

      });
      tester.assertResultPage("icket:id=\"lableId\" test=\"123\">content");
      assertEquals("icket:id=\"lableId\" test=\"123
      \">content",tester.getLastResponseAsString());
      assertEquals("",tester.getResponse().getDocument());
      }

      exposes the wrong behaviour of test.getLastResponseAsString() after starting a component.

      It should return something such as "<span> .... </span>", bit it returns a string "cut in the middle" : cket:id=\"lableId\" test=\"123\">content

      see attached quickstart

      1. WICKET-4507.patch
        5 kB
        Christoph Leiter
      2. quickstart.tgz
        6 kB
        Carsten Behring

        Activity

        Martin Grigorov made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.5.6 [ 12319053 ]
        Fix Version/s 6.0.0-RC1 [ 12320343 ]
        Resolution Fixed [ 1 ]
        Martin Grigorov made changes -
        Assignee Martin Grigorov [ mgrigorov ]
        Hide
        Carsten Behring added a comment -

        I just tried the patch and wanted to confirm, that it would fix the problem for me.

        Show
        Carsten Behring added a comment - I just tried the patch and wanted to confirm, that it would fix the problem for me.
        Christoph Leiter made changes -
        Attachment WICKET-4507.patch [ 12523681 ]
        Hide
        Christoph Leiter added a comment -

        The current implementation of BaseWicketTester#getLastResponseAsString() returns just the body of a component if startComponentInPage() has been used. The surrounding markup of the page and the tag of the component get removed. Testing for attributes can't work that when only the body is rendered.

        The JavaDoc of getLastResponseAsString isn't exactly clear what the intended behaviour is: "In case the processed component was not a Page then the automatically created page markup gets removed". I think the tag of the component itself shouldn't be removed.

        I'll attach a patch which does just that.

        Show
        Christoph Leiter added a comment - The current implementation of BaseWicketTester#getLastResponseAsString() returns just the body of a component if startComponentInPage() has been used. The surrounding markup of the page and the tag of the component get removed. Testing for attributes can't work that when only the body is rendered. The JavaDoc of getLastResponseAsString isn't exactly clear what the intended behaviour is: "In case the processed component was not a Page then the automatically created page markup gets removed". I think the tag of the component itself shouldn't be removed. I'll attach a patch which does just that.
        Carsten Behring made changes -
        Description > This following test :

         @Test
         public void test() throws Exception {
          WicketTester tester=new WicketTester();
          tester.startComponentInPage(new Label("lableId", "content") {
                @Override
                protected void onComponentTag(ComponentTag tag) {
                    super.onComponentTag(tag);
                    tag.put("test","123");
                }
             });
          tester.assertResultPage("icket:id=\"lableId\" test=\"123\">content");
          assertEquals("icket:id=\"lableId\" test=\"123
         \">content",tester.getLastResponseAsString());
          assertEquals("",tester.getResponse().getDocument());
        }


        see attached quickstart
        > This following test :

         @Test
         public void test() throws Exception {
          WicketTester tester=new WicketTester();
          tester.startComponentInPage(new Label("lableId", "content") {
                @Override
                protected void onComponentTag(ComponentTag tag) {
                    super.onComponentTag(tag);
                    tag.put("test","123");
                }
             });
          tester.assertResultPage("icket:id=\"lableId\" test=\"123\">content");
          assertEquals("icket:id=\"lableId\" test=\"123
         \">content",tester.getLastResponseAsString());
          assertEquals("",tester.getResponse().getDocument());
        }

        exposes the wrong behaviour of test.getLastResponseAsString() after starting a component.

        It should return something such as "<span> .... </span>", bit it returns a string "cut in the middle" : cket:id=\"lableId\" test=\"123\">content


        see attached quickstart
        Carsten Behring made changes -
        Field Original Value New Value
        Attachment quickstart.tgz [ 12523342 ]
        Carsten Behring created issue -

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Carsten Behring
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development