/** Test InlineEnclosure */
  @Test
  public void autos6() {
    TestPage p = new TestPage();
    p.setPageMarkup(
        "<div wicket:enclosure='a'><div wicket:id='a'></div><div wicket:id='b'></div></div>");
    A a = new A();
    B b = new B();
    p.queue(a, b);
    tester.startPage(p);

    assertTrue(a.getParent() instanceof Enclosure);
    assertTrue(b.getParent() instanceof Enclosure);

    // A is visible, enclosure renders

    assertEquals(
        "<div wicket:enclosure=\"a\" id=\"wicket__InlineEnclosure_01\"><div wicket:id=\"a\"></div><div wicket:id=\"b\"></div></div>",
        tester.getLastResponseAsString());

    // A is not visible, inline enclosure render only itself (the placeholder tag)

    a.setVisible(false);
    tester.startPage(p);
    assertEquals(
        "<div id=\"wicket__InlineEnclosure_01\" style=\"display:none\"></div>",
        tester.getLastResponseAsString());
  }
  @Test
  public void border_nested() {
    MarkupContainer a = new A(), b = new B(), c = new C(), d = new D(), r = new R(), s = new S();

    Border outerBorder = new OuterBorder("outerBorder");

    Border innerBorder = new InnerBorder("innerBorder");

    outerBorder.queueToBorder(r, innerBorder);

    innerBorder.queueToBorder(c, d);

    outerBorder.queueToBorder(s);

    TestPage p = new TestPage();
    p.setPageMarkup("<p wicket:id='a'><p wicket:id='outerBorder'><p wicket:id='b'></p></p></p>");

    p.queue(b, outerBorder, a);

    tester.startPage(p);

    assertThat(
        p,
        hasPath(new Path(a, outerBorder, r, innerBorder, c, d, innerBorder.getBodyContainer(), s)));
    assertThat(p, hasPath(new Path(a, outerBorder, r, outerBorder.getBodyContainer(), b)));
  }
  @Test
  public void autos5() {
    TestPage p = new TestPage();
    p.setPageMarkup(
        "<wicket:enclosure child='a'><div wicket:id='a'></div><div wicket:id='b'></div></wicket:enclosure>");
    A a = new A();
    B b = new B();
    p.queue(a);
    p.add(b);
    tester.startPage(p);

    assertTrue(a.getParent() instanceof Enclosure);
    assertTrue(b.getParent() instanceof TestPage);

    // A is visible, enclosure renders

    assertEquals(
        "<wicket:enclosure child=\"a\"><div wicket:id=\"a\"></div><div wicket:id=\"b\"></div></wicket:enclosure>",
        tester.getLastResponseAsString());

    // A is not visible, enclosure does not render

    a.setVisible(false);
    tester.startPage(p);
    assertEquals("", tester.getLastResponseAsString());
  }
  /** repeater with a panel inside */
  @Test
  public void repeater3() {
    TestPage p = new TestPage();
    p.setPageMarkup(
        "<p wicket:id='a'><p wicket:id='lv'><p wicket:id='b'><p wicket:id='q'></p></p></p></p>");

    MarkupContainer a = new A();
    LV l =
        new LV(3) {
          @Override
          protected void populateItem(ListItem<Integer> item) {
            TestPanel q = new TestPanel("q");
            q.setPanelMarkup(
                "<wicket:panel><p wicket:id='r'><p wicket:id='s'></p></p></wicket:panel>");
            q.queue(new R(), new S());

            item.queue(q, new B());
          }
        };

    p.queue(a, l);

    tester.startPage(p);

    assertThat(l.size(), is(3));
    for (Component item : l) {
      assertThat(p, hasPath(new Path(a, l, item, new B()).add("q").add(new R(), new S())));
    }
  }
  /** {@code [a,b,c] -> [a[b[c]]] } */
  @Test
  public void dequeue1() {
    TestPage p = new TestPage();
    p.setPageMarkup("<p wicket:id='a'><p wicket:id='b'><p wicket:id='c'></p></p></p>");
    MarkupContainer a = new A(), b = new B(), c = new C();

    p.queue(b, c, a);
    assertThat(p, hasPath(a, b, c));
    tester.startPage(p);
  }
  @Test
  public void containerTag1() {
    MarkupContainer a = new A(), b = new B();

    TestPage page = new TestPage();
    page.setPageMarkup("<wicket:container wicket:id='a'><b wicket:id='b'></b></wicket:container>");

    page.queue(a, b);

    assertThat(page, hasPath(new Path(a, b)));
  }
  /**
   * WICKET-3470
   *
   * <p>Tests that a page already put in the session (in SessionEntry) can be serialized and later
   * deserialized without the need of {@link IPageStore}
   *
   * @throws ClassNotFoundException
   * @throws IOException
   */
  @Test
  public void serializationOutsideWicketLifecyle() throws IOException, ClassNotFoundException {
    // make sure no leaked threadlocals are present
    ThreadContext.detach();

    // create IPageManager (with IPageStore) and store a page instance
    IPageManager pageManager = newPersistentPageManager(APP_NAME);
    TestPage toSerializePage = new TestPage();
    pageManager.touchPage(toSerializePage);
    pageManager.commitRequest();

    // get the stored SessionEntry
    Serializable sessionEntry = pageManager.getContext().getSessionAttribute(null);

    // destroy the manager and the store
    pageManager.destroy();

    // simulate persisting of the http sessions initiated by the web container
    byte[] serializedSessionEntry = new JavaSerializer(APP_NAME).serialize(sessionEntry);
    assertNotNull("Wicket needs to be able to serialize the session entry", serializedSessionEntry);

    // simulate loading of the persisted http session initiated by the web container
    // when starting an application
    ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(serializedSessionEntry));

    // WicketFilter is not initialized so there is no Application available yet
    Assert.assertFalse(
        "Worker thread should be unaware of Wicket application", Application.exists());

    assertEquals(APP_NAME, in.readObject());

    // without available IPageStore the read SessionEntry holds
    // the IManageablePage itself, not SerializedPage
    Serializable loadedSessionEntry = (Serializable) in.readObject();
    assertNotNull(
        "Wicket needs to be able to deserialize the session entry regardless the application availability",
        loadedSessionEntry);

    // provide new IPageStore which will read IManageablePage's or SerializedPage's
    // from the SessionEntry's
    IPageManager newPageManager = newPersistentPageManager(APP_NAME);
    newPageManager.getContext().setSessionAttribute(null, loadedSessionEntry);

    TestPage deserializedPage = (TestPage) newPageManager.getPage(toSerializePage.getPageId());
    assertNotNull(deserializedPage);
    assertEquals(toSerializePage.instanceID, deserializedPage.instanceID);

    newPageManager.destroy();
  }
  @Test
  public void startingNewTestShouldStartTimeMeasurementAndNotifyListener() throws Exception {
    List<WikiPage> testPagesToRun = mock(List.class);
    TestPage page = new TestPage(mock(WikiPage.class));
    FitNesseContext fitNesseContext = mock(FitNesseContext.class);
    ResultsListener resultsListener = mock(ResultsListener.class);

    MultipleTestsRunner runner =
        new MultipleTestsRunner(
            testPagesToRun, fitNesseContext, page.getSourcePage(), resultsListener);

    runner.startingNewTest(page);
    verify(resultsListener).newTestStarted(same(page), same(runner.currentTestTime));
    assertThat(runner.currentTestTime, isAStartedTimeMeasurement());
  }
  @Test
  public void fragment_doesNotDequeueAcrossRegion() {
    MarkupContainer a = new A();

    TestPage page = new TestPage();
    page.setPageMarkup(
        "<f wicket:id='fragment'></f><wicket:fragment wicket:id='f'><a wicket:id='a'></a></wicket:fragment>");

    Fragment fragment = new Fragment("fragment", "f", page);

    page.queue(a, fragment);

    assertThat(page, hasPath(new Path(fragment)));
    assertThat(a.getParent(), is(nullValue()));
  }
  /** {@code [a,c[b]] ->| [a[b[c]]] } */
  @Test
  public void dequeueError1() {
    TestPage p = new TestPage();
    p.setPageMarkup("<p wicket:id='a'><p wicket:id='b'><p wicket:id='c'></p></p></p>");
    MarkupContainer a = new A(), b = new B(), c = new C();

    p.queue(b, c);
    c.queue(a);

    try {
      tester.startPage(p);
      Assert.fail();
    } catch (WicketRuntimeException e) {
      // expected
    }
  }
  /** panel has leading markup */
  @Test
  public void panel2() {
    MarkupContainer r = new R();

    TestPanel q = new TestPanel("q");
    q.setPanelMarkup(
        "<html><body><wicket:panel><p wicket:id='r'></p></wicket:panel></body></html>");
    q.queue(r);

    TestPage p = new TestPage();
    p.setPageMarkup("<p wicket:id='q'></p>");
    p.queue(q);

    tester.startPage(p);

    assertThat(p, hasPath(new Path(q, r)));
  }
  /** {@code [a,q[r,s]] - > [a[q[r[s]]]] } */
  @Test
  public void panel1() {
    MarkupContainer a = new A(), r = new R(), s = new S();

    TestPanel q = new TestPanel("q");
    q.setPanelMarkup("<wicket:panel><p wicket:id='r'><p wicket:id='s'></p></p></wicket:panel>");
    q.queue(r, s);

    TestPage p = new TestPage();
    p.setPageMarkup("<p wicket:id='a'><p wicket:id='q'></p></p>");

    p.queue(a, q);

    tester.startPage(p);

    assertThat(p, hasPath(new Path(a, q, r, s)));
  }
  /** dequeue, then rerender the page instance after a callback is executed */
  @Test
  public void callback() {
    TestPage p = new TestPage();
    p.setPageMarkup("<p wicket:id='a'><a wicket:id='l'><p wicket:id='b'></p></a></p>");
    MarkupContainer a = new A(), b = new B();
    L l = new L();
    p.queue(a, b, l);

    tester.startPage(p);

    assertThat(p, hasPath(new Path(a, l, b)));
    assertThat(l.isClicked(), is(false));

    tester.clickLink(l);

    assertThat(l.isClicked(), is(true));
  }
  @Test
  public void fragment1() {
    MarkupContainer a = new A(), b = new B(), r = new R(), s = new S();

    TestPage page = new TestPage();
    page.setPageMarkup(
        "<a wicket:id='a'></a><f wicket:id='fragment'></f><b wicket:id='b'></b>"
            + "<wicket:fragment wicket:id='f'><r wicket:id='r'></r><s wicket:id='s'></s></wicket:fragment>");

    Fragment fragment = new Fragment("fragment", "f", page);

    fragment.queue(r, s);
    page.queue(a, b, fragment);

    assertThat(page, hasPath(new Path(a)));
    assertThat(page, hasPath(new Path(b)));
    assertThat(page, hasPath(new Path(fragment, r)));
    assertThat(page, hasPath(new Path(fragment, s)));
  }
  /** panel with a static header section */
  @Test
  public void panel3() {
    MarkupContainer r = new R();

    TestPanel q = new TestPanel("q");
    q.setPanelMarkup(
        "<html><head><wicket:head><meta/></wicket:head></head>"
            + "<body><wicket:panel><p wicket:id='r'></p></wicket:panel></body></html>");
    q.queue(r);

    TestPage p = new TestPage();
    p.setPageMarkup("<html><head></head><body><p wicket:id='q'></p></body></html>");
    p.queue(q);

    tester.startPage(p);

    assertThat(p, hasPath(new Path(q, r)));
    tester.assertContains("<meta/>"); // contributed by <wicket:head>
  }
  @Test
  public void border1() {
    MarkupContainer a = new A(), b = new B(), r = new R(), s = new S();

    TestBorder border = new TestBorder("border");
    border.setBorderMarkup(
        "<wicket:border><b1 wicket:id='r'><b2 wicket:id='s'>"
            + "<wicket:body/></b2></b1></wicket:border>");
    border.queueToBorder(r, s);

    TestPage p = new TestPage();
    p.setPageMarkup(
        "<out1 wicket:id='a'><p wicket:id='border'><in1 wicket:id='b'></in1></p></out1>");

    p.queue(a, border, b);

    tester.startPage(p);

    assertThat(p, hasPath(new Path(a, border, r, s, border.getBodyContainer(), b)));
  }
  @Test
  public void testCompleteShouldRemoveHeadOfQueueAndNotifyListener() throws Exception {
    List<WikiPage> testPagesToRun = mock(List.class);
    TestPage page = new TestPage(mock(WikiPage.class));
    FitNesseContext fitNesseContext = mock(FitNesseContext.class);
    ResultsListener resultsListener = mock(ResultsListener.class);

    MultipleTestsRunner runner =
        new MultipleTestsRunner(
            testPagesToRun, fitNesseContext, page.getSourcePage(), resultsListener);
    runner.addToProcessingQueue(page);

    TestSummary testSummary = mock(TestSummary.class);

    runner.startingNewTest(page);
    runner.testComplete(testSummary);
    verify(resultsListener)
        .testComplete(same(page), same(testSummary), same(runner.currentTestTime));
    assertThat(runner.currentTestTime, isAStoppedTimeMeasurement());
  }
  /** Issue https://github.com/l0rdn1kk0n/wicket-bootstrap/issues/316 */
  @Test
  public void hasActiveButton() {

    TestPage page = new TestPage();
    final NavbarButton<?> buttonUnderTest =
        new NavbarButton<Object>(TestPage.class, GlyphIconType.adjust);
    page.add(buttonUnderTest);

    List<AbstractLink> buttons = new ArrayList<AbstractLink>();
    DropDownButton dropDownButton1 =
        new DropDownButton("dropDown", Model.of("")) {
          @Override
          protected List<AbstractLink> newSubMenuButtons(String buttonMarkupId) {
            return Collections.<AbstractLink>singletonList(buttonUnderTest);
          }
        };
    buttons.add(dropDownButton1);
    ButtonList buttonList = new ButtonList("id", buttons);

    assertTrue(buttonList.hasActiveButton(buttonUnderTest));
  }
  /** {a[b{e}[d,f{g}]],c} -> [a[b[c,d[e],f[g]]]] */
  @Test
  public void dequeue7() {
    TestPage p = new TestPage();

    // @formatter:off
    p.setPageMarkup(
        "  <p wicket:id='a'>"
            + "  <p wicket:id='b'>"
            + "    <p wicket:id='c'></p>"
            + "    <p wicket:id='d'>"
            + "      <p wicket:id='e'></p>"
            + "    </p>"
            + "    <p wicket:id='f'>"
            + "      <p wicket:id='g'></p>"
            + "    </p>"
            + "  </p>"
            + "</p>");
    // @formatter:on

    MarkupContainer a = new A(),
        b = new B(),
        c = new C(),
        d = new D(),
        e = new E(),
        f = new F(),
        g = new G();

    a.add(b);
    b.queue(e);
    p.queue(a, c);
    b.add(d);
    f.queue(g);
    b.add(f);

    tester.startPage(p);

    assertThat(p, hasPath(new Path(a, b, c)));
    assertThat(p, hasPath(new Path(a, b, d, e)));
    assertThat(p, hasPath(new Path(a, b, f, g)));
  }
  @Test
  public void repeater1() {
    TestPage p = new TestPage();
    p.setPageMarkup("<p wicket:id='lv'><p wicket:id='b'><p wicket:id='c'></p></p></p>");

    LV l =
        new LV(3) {
          @Override
          protected void populateItem(ListItem<Integer> item) {
            item.queue(new B(), new C());
          }
        };

    p.queue(l);

    tester.startPage(p);

    assertThat(l.size(), is(3));
    for (Component item : l) {
      assertThat(p, hasPath(new Path(l, item, new B(), new C())));
    }
  }
  /** test with inner panels */
  @Test
  public void nestedPanels() {
    MarkupContainer r = new R(), s = new S();

    Panel innerPanel = new InnerPanel("inner");
    innerPanel.queue(s);

    Panel outerPanel = new OuterPanel("outer");

    outerPanel.queue(r, innerPanel);

    TestPage p = new TestPage();
    p.setPageMarkup("<html><head></head><body><p wicket:id='outer'></p></body></html>");
    p.queue(outerPanel);

    tester.startPage(p);

    assertThat(p, hasPath(new Path(outerPanel, r)));
    assertThat(p, hasPath(new Path(outerPanel, innerPanel, s)));
    tester.assertContains("<meta/>"); // contributed by <wicket:head> in outer
    tester.assertContains("<meta2/>"); // contributed by <wicket:head> in inner
  }
  @Test
  public void formatsNumberAccordingToTheSettings() {
    final IModel<BigDecimal> valueModel = Model.of(BigDecimal.TEN);

    TestPage page =
        new TestPage() {
          @Override
          protected MonetaryTextField<? extends Number> createMonetaryField(String id) {
            return new MonetaryTextField<BigDecimal>(id, valueModel, BigDecimal.class);
          }
        };
    tester.startPage(page);
    tester.assertRenderedPage(TestPage.class);

    MockHttpServletResponse response = tester.getLastResponse();
    assertThat(
        response.getDocument(),
        containsString("$('#" + page.getAmountMarkupId() + "').autoNumeric('init');"));

    tester.newFormTester("form").setValue("amount", "11").submit();

    tester.assertNoErrorMessage();
    assertThat(valueModel.getObject().compareTo(BigDecimal.valueOf(11)), is(0));
  }