Search in sources :

Example 1 with TestMapperContext

use of org.apache.wicket.core.request.mapper.TestMapperContext in project wicket by apache.

the class PageProviderTest method ignorePageFoundByIdIfItsClassDoesntMatch.

/**
 * https://issues.apache.org/jira/browse/WICKET-4488
 *
 * There is a stored page with id = 0 and class Page1.
 * A following request to page2?0 should not use the stored page with id=0 because
 * the requested and the found page classes do not match.
 */
@Test
public void ignorePageFoundByIdIfItsClassDoesntMatch() {
    TestMapperContext mapperContext = new TestMapperContext();
    Page page = new TestPage();
    mapperContext.getPageManager().touchPage(page);
    mapperContext.getPageManager().commitRequest();
    // by cleaning session cache we make sure of not being testing the same in-memory instance
    mapperContext.cleanSessionCache();
    PageProvider provider = new PageProvider(page.getPageId(), MockPageWithLink.class, 0);
    assertFalse(provider.hasPageInstance());
    assertEquals(MockPageWithLink.class, provider.getPageClass());
    assertTrue(provider.doesProvideNewPage());
}
Also used : PageProvider(org.apache.wicket.core.request.handler.PageProvider) MockPage(org.apache.wicket.MockPage) Page(org.apache.wicket.Page) WebPage(org.apache.wicket.markup.html.WebPage) TestMapperContext(org.apache.wicket.core.request.mapper.TestMapperContext) Test(org.junit.Test)

Example 2 with TestMapperContext

use of org.apache.wicket.core.request.mapper.TestMapperContext in project wicket by apache.

the class PageProviderTest method pageProviderDontDeserializeOnePageTwice.

/**
 * <a href="https://issues.apache.org/jira/browse/WICKET-4046">WICKET-4046</a>
 */
@Test
public void pageProviderDontDeserializeOnePageTwice() {
    int oldState = 0;
    int newState = 1;
    StatefullMockPage testPage = new StatefullMockPage();
    testPage.state = oldState;
    // storing test page
    TestMapperContext mapperContext = new TestMapperContext();
    mapperContext.getPageManager().touchPage(testPage);
    mapperContext.getPageManager().commitRequest();
    // by cleaning session cache we make sure of not being testing the same in-memory instance
    mapperContext.cleanSessionCache();
    PageProvider pageProvider = mapperContext.new TestPageProvider(testPage.getPageId(), 0);
    // simulation an test call to isNewPageInstance
    boolean isNewPageInstance = pageProvider.isNewPageInstance();
    assertFalse("test page is already stored", isNewPageInstance);
    // changing some sate
    StatefullMockPage providedPage = (StatefullMockPage) pageProvider.getPageInstance();
    providedPage.state = newState;
    mapperContext.getPageManager().touchPage(providedPage);
    mapperContext.getPageManager().commitRequest();
    mapperContext.cleanSessionCache();
    StatefullMockPage restauredPageAfterStateChage = (StatefullMockPage) mapperContext.getPageInstance(testPage.getPageId());
    // OK, if the correct page got touched/stores its change will be visible now
    assertEquals(newState, restauredPageAfterStateChage.state);
}
Also used : PageProvider(org.apache.wicket.core.request.handler.PageProvider) TestMapperContext(org.apache.wicket.core.request.mapper.TestMapperContext) Test(org.junit.Test)

Example 3 with TestMapperContext

use of org.apache.wicket.core.request.mapper.TestMapperContext in project wicket by apache.

the class PageProviderTest method testPageProperties_stored.

@Test
public void testPageProperties_stored() {
    TestMapperContext mapperContext = new TestMapperContext();
    Page page = new TestPage();
    mapperContext.getPageManager().touchPage(page);
    mapperContext.getPageManager().commitRequest();
    // by cleaning session cache we make sure of not being testing the same in-memory instance
    mapperContext.cleanSessionCache();
    PageProvider provider = mapperContext.new TestPageProvider(page.getPageId(), 0);
    assertTrue(provider.hasPageInstance());
    assertFalse(provider.doesProvideNewPage());
}
Also used : PageProvider(org.apache.wicket.core.request.handler.PageProvider) MockPage(org.apache.wicket.MockPage) Page(org.apache.wicket.Page) WebPage(org.apache.wicket.markup.html.WebPage) TestMapperContext(org.apache.wicket.core.request.mapper.TestMapperContext) Test(org.junit.Test)

Example 4 with TestMapperContext

use of org.apache.wicket.core.request.mapper.TestMapperContext in project wicket by apache.

the class PageProviderTest method pageProviderIsSerializeble.

@Test
public void pageProviderIsSerializeble() throws Exception {
    TestMapperContext mapperContext = new TestMapperContext();
    Page page = new TestPage();
    mapperContext.getPageManager().touchPage(page);
    mapperContext.getPageManager().commitRequest();
    PageProvider pageProvider = new PageProvider(page.getPageId(), page.getRenderCount());
    JavaSerializer javaSerializer = new JavaSerializer("app");
    byte[] serialized = javaSerializer.serialize(pageProvider);
    PageProvider deserialized = (PageProvider) javaSerializer.deserialize(serialized);
    deserialized.setPageSource(mapperContext);
    assertThat(deserialized.getPageInstance(), is(page));
}
Also used : PageProvider(org.apache.wicket.core.request.handler.PageProvider) MockPage(org.apache.wicket.MockPage) Page(org.apache.wicket.Page) WebPage(org.apache.wicket.markup.html.WebPage) TestMapperContext(org.apache.wicket.core.request.mapper.TestMapperContext) JavaSerializer(org.apache.wicket.serialize.java.JavaSerializer) Test(org.junit.Test)

Aggregations

PageProvider (org.apache.wicket.core.request.handler.PageProvider)4 TestMapperContext (org.apache.wicket.core.request.mapper.TestMapperContext)4 Test (org.junit.Test)4 MockPage (org.apache.wicket.MockPage)3 Page (org.apache.wicket.Page)3 WebPage (org.apache.wicket.markup.html.WebPage)3 JavaSerializer (org.apache.wicket.serialize.java.JavaSerializer)1