Search in sources :

Example 6 with MockPageWithLink

use of org.apache.wicket.MockPageWithLink in project wicket by apache.

the class AbstractLinkTest method testRenderUsingGetBody.

/**
 * Tests that the {@link AbstractLink} uses the {@link AbstractLink#getBody()} to get its body. This
 * method can be overridden to provide a dynamic model.
 */
@Test
public void testRenderUsingGetBody() {
    final AtomicInteger counter = new AtomicInteger(0);
    MockPageWithLink mockPageWithLink = new MockPageWithLink();
    AbstractLink link = new AbstractLink("link") {

        private static final long serialVersionUID = 1L;

        @Override
        public IModel<?> getBody() {
            return Model.of(counter.getAndIncrement());
        }
    };
    link.setMarkupId("link");
    mockPageWithLink.add(link);
    tester.startPage(mockPageWithLink);
    TagTester tagTester = tester.getTagById("link");
    Assert.assertEquals("0", tagTester.getValue());
    tester.startPage(mockPageWithLink);
    tagTester = tester.getTagById("link");
    Assert.assertEquals("1", tagTester.getValue());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TagTester(org.apache.wicket.util.tester.TagTester) MockPageWithLink(org.apache.wicket.MockPageWithLink) Test(org.junit.Test)

Example 7 with MockPageWithLink

use of org.apache.wicket.MockPageWithLink in project wicket by apache.

the class ISecuritySettingsTest method enforceMounts.

/**
 * https://issues.apache.org/jira/browse/WICKET-3849
 */
@Test
public void enforceMounts() {
    MockPageWithLink pageWithLink = new MockPageWithLink();
    pageWithLink.add(new Link<Void>(MockPageWithLink.LINK_ID) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            throw new RedirectToUrlException("/wicket/bookmarkable/" + UnknownPage.class.getName());
        }
    });
    tester.startPage(pageWithLink);
    tester.assertRenderedPage(MockPageWithLink.class);
    tester.clickLink(MockPageWithLink.LINK_ID);
    tester.assertRenderedPage(UnknownPage.class);
    tester.getApplication().getSecuritySettings().setEnforceMounts(true);
    tester.startPage(pageWithLink);
    tester.assertRenderedPage(MockPageWithLink.class);
    tester.clickLink(MockPageWithLink.LINK_ID);
    Assert.assertNull(tester.getLastRenderedPage());
    /*
		 * Test that mounts are enforced when the root compound mapper does not directly contain the mounted mapper.
		 */
    tester.getApplication().setRootRequestMapper(new HttpsMapper(tester.getApplication().getRootRequestMapper(), new HttpsConfig()));
    tester.startPage(pageWithLink);
    tester.assertRenderedPage(MockPageWithLink.class);
    tester.clickLink(MockPageWithLink.LINK_ID);
    Assert.assertNull(tester.getLastRenderedPage());
}
Also used : HttpsMapper(org.apache.wicket.protocol.https.HttpsMapper) RedirectToUrlException(org.apache.wicket.request.flow.RedirectToUrlException) HttpsConfig(org.apache.wicket.protocol.https.HttpsConfig) MockPageWithLink(org.apache.wicket.MockPageWithLink) Test(org.junit.Test)

Example 8 with MockPageWithLink

use of org.apache.wicket.MockPageWithLink in project wicket by apache.

the class DebugSettingsTest method setComponentPathAttributeName.

/**
 * https://issues.apache.org/jira/browse/WICKET-5498
 */
@Test
public void setComponentPathAttributeName() {
    String attributeName = "data-wicket-path";
    tester.getApplication().getDebugSettings().setComponentPathAttributeName(attributeName);
    MockPageWithLink page = new MockPageWithLink();
    Component link = new Link<Void>(MockPageWithLink.LINK_ID) {

        @Override
        public void onClick() {
        }
    }.setMarkupId(MockPageWithLink.LINK_ID);
    page.add(link);
    tester.startPage(page);
    TagTester tagTester = tester.getTagById(MockPageWithLink.LINK_ID);
    String wicketPath = tagTester.getAttribute(attributeName);
    assertEquals(link.getPageRelativePath(), wicketPath);
}
Also used : Component(org.apache.wicket.Component) TagTester(org.apache.wicket.util.tester.TagTester) MockPageWithLink(org.apache.wicket.MockPageWithLink) Test(org.junit.Test)

Example 9 with MockPageWithLink

use of org.apache.wicket.MockPageWithLink in project wicket by apache.

the class DifferentPageCheckerTest method serializingAnotherPage.

/**
 * https://issues.apache.org/jira/browse/WICKET-5634
 *
 * Tests that the serialization fails when a checking ObjectOutputStream is
 * used with DifferentPageChecker and there is a component in the object tree that
 * keeps a reference to a page which is not component.getPage()..
 */
@Test
public void serializingAnotherPage() {
    JavaSerializer serializer = new JavaSerializer("JavaSerializerTest") {

        @Override
        protected ObjectOutputStream newObjectOutputStream(OutputStream out) throws IOException {
            IObjectChecker checker = new DifferentPageChecker();
            return new CheckingObjectOutputStream(out, checker);
        }
    };
    WebComponent component = new ComponentThatKeepsAReferenceToAnotherPage(MockPageWithLink.LINK_ID);
    MockPageWithLink rootPage = new MockPageWithLink();
    rootPage.add(component);
    byte[] serialized = serializer.serialize(rootPage);
    assertNull("The produced byte[] must be null if there was an error", serialized);
}
Also used : WebComponent(org.apache.wicket.markup.html.WebComponent) OutputStream(java.io.OutputStream) ObjectOutputStream(java.io.ObjectOutputStream) JavaSerializer(org.apache.wicket.serialize.java.JavaSerializer) MockPageWithLink(org.apache.wicket.MockPageWithLink) Test(org.junit.Test)

Aggregations

MockPageWithLink (org.apache.wicket.MockPageWithLink)9 Test (org.junit.Test)9 ResourceLink (org.apache.wicket.markup.html.link.ResourceLink)3 TagTester (org.apache.wicket.util.tester.TagTester)3 ByteArrayResource (org.apache.wicket.request.resource.ByteArrayResource)2 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Component (org.apache.wicket.Component)1 MockPanelWithLink (org.apache.wicket.MockPanelWithLink)1 Page (org.apache.wicket.Page)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)1 WebComponent (org.apache.wicket.markup.html.WebComponent)1 WebPage (org.apache.wicket.markup.html.WebPage)1 ExternalLink (org.apache.wicket.markup.html.link.ExternalLink)1 Link (org.apache.wicket.markup.html.link.Link)1 AccessDeniedPage (org.apache.wicket.markup.html.pages.AccessDeniedPage)1 HttpsConfig (org.apache.wicket.protocol.https.HttpsConfig)1 HttpsMapper (org.apache.wicket.protocol.https.HttpsMapper)1