Search in sources :

Example 1 with Enclosure

use of org.apache.wicket.markup.html.internal.Enclosure in project wicket by apache.

the class ComponentQueueingTest method autosInsideNotQueueRegion.

/**
 * Test autocomponent inside not-queue region
 */
@Test
public void autosInsideNotQueueRegion() {
    TestPage p = new TestPage();
    p.setPageMarkup("<div wicket:id='outerContainer'><wicket:enclosure><div wicket:id='a'></div></wicket:enclosure></div>");
    Label a = new Label("a", "a");
    WebMarkupContainer outer;
    p.add(outer = new WebMarkupContainer("outerContainer"));
    outer.queue(a);
    tester.startPage(p);
    assertTrue(a.getParent() instanceof Enclosure);
}
Also used : Label(org.apache.wicket.markup.html.basic.Label) Enclosure(org.apache.wicket.markup.html.internal.Enclosure) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) TransparentWebMarkupContainer(org.apache.wicket.markup.html.TransparentWebMarkupContainer) Test(org.junit.Test)

Example 2 with Enclosure

use of org.apache.wicket.markup.html.internal.Enclosure in project wicket by apache.

the class BaseWicketTester method isComponentOnAjaxResponse.

/**
 * Tests that a <code>Component</code> has been added to a <code>AjaxRequestTarget</code>, using
 * {@link org.apache.wicket.ajax.AjaxRequestTarget#add(org.apache.wicket.Component...)}. This
 * method actually tests that a <code>Component</code> is on the Ajax response sent back to the
 * client.
 * <p>
 * PLEASE NOTE! This method doesn't actually insert the <code>Component</code> in the client DOM
 * tree, using JavaScript. But it shouldn't be needed because you have to trust that the Wicket
 * Ajax JavaScript just works.
 *
 * @param component
 *            the <code>Component</code> to test
 * @return a <code>Result</code>
 */
public Result isComponentOnAjaxResponse(final Component component) {
    String failMessage = "A component which is null could not have been added to the AJAX response";
    notNull(failMessage, component);
    Result result;
    // test that the component renders the placeholder tag if it's not visible
    String componentInfo = component.toString();
    if (!component.isVisible()) {
        failMessage = "A component which is invisible and doesn't render a placeholder tag" + " will not be rendered at all and thus won't be accessible for subsequent AJAX interaction. " + componentInfo;
        result = isTrue(failMessage, component.getOutputMarkupPlaceholderTag());
        if (result.wasFailed()) {
            return result;
        }
    }
    // Get the AJAX response
    String ajaxResponse = getLastResponseAsString();
    // Test that the previous response was actually a AJAX response
    failMessage = "The previous response was not an AJAX response. " + "You need to execute an AJAX event, using #clickLink() or " + "#executeAjaxEvent(), before using this assertion method";
    boolean isAjaxResponse = Pattern.compile("^<\\?xml version=\"1.0\" encoding=\".*?\"\\?><ajax-response>").matcher(ajaxResponse).find();
    result = isTrue(failMessage, isAjaxResponse);
    if (result.wasFailed()) {
        return result;
    }
    // See if the component has a markup id
    String markupId = component.getMarkupId();
    failMessage = "The component doesn't have a markup id, " + "which means that it can't have been added to the AJAX response. " + componentInfo;
    result = isTrue(failMessage, !Strings.isEmpty(markupId));
    if (result.wasFailed()) {
        return result;
    }
    // Look for that the component is on the response, using the markup id
    boolean isComponentInAjaxResponse = ajaxResponse.matches("(?s).*<component id=\"" + markupId + "\"[^>]*?>.*");
    failMessage = "Component wasn't found in the AJAX response. " + componentInfo;
    result = isTrue(failMessage, isComponentInAjaxResponse);
    if (!result.wasFailed()) {
        return result;
    }
    // Check if the component has been included as part of an enclosure render
    Enclosure enclosure = getLastRenderedPage().visitChildren(Enclosure.class, (Enclosure enc, IVisit<Enclosure> visit) -> {
        if (AjaxEnclosureListener.isControllerOfEnclosure(component, enc)) {
            visit.stop(enc);
        }
    });
    if (enclosure == null) {
        return result;
    }
    failMessage = "Component's enclosure was not found in the AJAX response. " + enclosure;
    boolean isEnclosureInAjaxResponse = !isComponentOnAjaxResponse(enclosure).wasFailed();
    return isTrue(failMessage, isEnclosureInAjaxResponse);
}
Also used : Enclosure(org.apache.wicket.markup.html.internal.Enclosure) IVisit(org.apache.wicket.util.visit.IVisit)

Aggregations

Enclosure (org.apache.wicket.markup.html.internal.Enclosure)2 TransparentWebMarkupContainer (org.apache.wicket.markup.html.TransparentWebMarkupContainer)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 Label (org.apache.wicket.markup.html.basic.Label)1 IVisit (org.apache.wicket.util.visit.IVisit)1 Test (org.junit.Test)1