Package org.apache.wicket.util.tester

Examples of org.apache.wicket.util.tester.BaseWicketTester$TestPageManagerProvider


  @Test
  public void testWithServlet30() throws MalformedURLException
  {
    MockApplication application = new MockApplication();
    MockServletContext servletContext = new MockServletContext(application, "/");
    BaseWicketTester tester = new BaseWicketTester(application, servletContext);

    MetaInfStaticResourceReference metaRes = new MetaInfStaticResourceReference(getClass(),
      STATIC_RESOURCE_NAME);
    PackageResourceReference packRes = new PackageResourceReference(getClass(),
      STATIC_RESOURCE_NAME);

    Url packUrl = tester.getRequestCycle().mapUrlFor(packRes, null);
    Url metaUrl = tester.getRequestCycle().mapUrlFor(metaRes, null);

    Assert.assertNotNull(metaUrl);
    Assert.assertNotNull(packUrl);
    Assert.assertFalse(
      "Meta and pack resource should not map to the same url under servlet 3.0.",
      metaUrl.equals(packUrl));

    String metaUrlStr = metaUrl.toString();
    if (metaUrlStr.charAt(1) != '/')
    {
      metaUrlStr = "/" + metaUrlStr;
    }

    // meta resource is served by the servlet container under 3.0
    URL metaNetUrl = servletContext.getResource(metaUrlStr);

    Assert.assertNotNull("Meta resource is not found by the 3.0 servlet container.", metaNetUrl);

    MockWebRequest request = new MockWebRequest(packUrl);

    IRequestHandler requestHandler = tester.getApplication()
      .getRootRequestMapper()
      .mapRequest(request);

    // the pack resource is still served by wicket
    Assert.assertNotNull(requestHandler);
View Full Code Here


  public void testDecorateResponse() throws Exception
  {
    Duration defaultDuration = Duration.minutes(60);

    // setup RequestCycle
    BaseWicketTester tester = new BaseWicketTester();
    RequestCycle requestCycle = ThreadContext.getRequestCycle();
    Application.get().getResourceSettings().setDefaultCacheDuration(defaultDuration);

    try
    {
      // version match
      requestCycle.setMetaData(IResourceCachingStrategy.URL_VERSION, TEST_RESOURCE_VERSION);

      AbstractResource.ResourceResponse response = new AbstractResource.ResourceResponse();
      strategy.decorateResponse(response, new TestResource());

      assertEquals(WebResponse.MAX_CACHE_DURATION, response.getCacheDuration());
      assertEquals(WebResponse.CacheScope.PUBLIC, response.getCacheScope());

      // version mismatch
      requestCycle.setMetaData(IResourceCachingStrategy.URL_VERSION, "foo");

      response = new AbstractResource.ResourceResponse();
      strategy.decorateResponse(response, new TestResource());

      assertEquals(defaultDuration, response.getCacheDuration());
      assertEquals(WebResponse.CacheScope.PRIVATE, response.getCacheScope());
    }
    finally
    {
      tester.destroy();
    }
  }
View Full Code Here

  public void testDecorateResponse() throws Exception
  {
    Duration defaultDuration = Duration.minutes(60);

    // setup RequestCycle
    BaseWicketTester tester = new BaseWicketTester();
    RequestCycle requestCycle = ThreadContext.getRequestCycle();
    Application.get().getResourceSettings().setDefaultCacheDuration(defaultDuration);

    try
    {
      // version match
      requestCycle.setMetaData(IResourceCachingStrategy.URL_VERSION, TEST_RESOURCE_VERSION);

      AbstractResource.ResourceResponse response = new AbstractResource.ResourceResponse();
      strategy.decorateResponse(response, new TestResource());

      assertEquals(WebResponse.MAX_CACHE_DURATION, response.getCacheDuration());
      assertEquals(WebResponse.CacheScope.PUBLIC, response.getCacheScope());

      // version mismatch
      requestCycle.setMetaData(IResourceCachingStrategy.URL_VERSION, "foo");

      response = new AbstractResource.ResourceResponse();
      strategy.decorateResponse(response, new TestResource());

      assertEquals(defaultDuration, response.getCacheDuration());
      assertEquals(WebResponse.CacheScope.PRIVATE, response.getCacheScope());
    }
    finally
    {
      tester.destroy();
    }
  }
View Full Code Here

  public void testDecorateResponse() throws Exception
  {
    Duration defaultDuration = Duration.minutes(60);

    // setup RequestCycle
    BaseWicketTester tester = new BaseWicketTester();
    RequestCycle requestCycle = ThreadContext.getRequestCycle();
    Application.get().getResourceSettings().setDefaultCacheDuration(defaultDuration);

    try
    {
      // version match
      requestCycle.setMetaData(IResourceCachingStrategy.URL_VERSION, TEST_RESOURCE_VERSION);

      AbstractResource.ResourceResponse response = new AbstractResource.ResourceResponse();
      strategy.decorateResponse(response, new TestResource());

      assertEquals(WebResponse.MAX_CACHE_DURATION, response.getCacheDuration());
      assertEquals(WebResponse.CacheScope.PUBLIC, response.getCacheScope());

      // version mismatch
      requestCycle.setMetaData(IResourceCachingStrategy.URL_VERSION, "foo");

      response = new AbstractResource.ResourceResponse();
      strategy.decorateResponse(response, new TestResource());

      assertEquals(defaultDuration, response.getCacheDuration());
      assertEquals(WebResponse.CacheScope.PRIVATE, response.getCacheScope());
    }
    finally
    {
      tester.destroy();
    }
  }
View Full Code Here

  public void testDecorateResponse() throws Exception
  {
    Duration defaultDuration = Duration.minutes(60);

    // setup RequestCycle
    BaseWicketTester tester = new BaseWicketTester();
    RequestCycle requestCycle = ThreadContext.getRequestCycle();
    Application.get().getResourceSettings().setDefaultCacheDuration(defaultDuration);

    try
    {
      // version match
      requestCycle.setMetaData(IResourceCachingStrategy.URL_VERSION, TEST_RESOURCE_VERSION);

      AbstractResource.ResourceResponse response = new AbstractResource.ResourceResponse();
      strategy.decorateResponse(response, new TestResource());

      assertEquals(WebResponse.MAX_CACHE_DURATION, response.getCacheDuration());
      assertEquals(WebResponse.CacheScope.PUBLIC, response.getCacheScope());

      // version mismatch
      requestCycle.setMetaData(IResourceCachingStrategy.URL_VERSION, "foo");

      response = new AbstractResource.ResourceResponse();
      strategy.decorateResponse(response, new TestResource());

      assertEquals(defaultDuration, response.getCacheDuration());
      assertEquals(WebResponse.CacheScope.PRIVATE, response.getCacheScope());
    }
    finally
    {
      tester.destroy();
    }
  }
View Full Code Here

   * Test with Servlet 2.5 container
   */
  @Test
  public void testWithServlet25()
  {
    BaseWicketTester tester = new BaseWicketTester();

    MetaInfStaticResourceReference metaRes = new MetaInfStaticResourceReference(getClass(),
      STATIC_RESOURCE_NAME);
    PackageResourceReference packRes = new PackageResourceReference(getClass(),
      STATIC_RESOURCE_NAME);

    Url packUrl = tester.getRequestCycle().mapUrlFor(packRes, null);
    Url metaUrl = tester.getRequestCycle().mapUrlFor(metaRes, null);

    Assert.assertNotNull(metaUrl);

    // under 2.5 there should not be any difference between meta and pack resource urls
    Assert.assertEquals(metaUrl, packUrl);

    MockWebRequest request = new MockWebRequest(metaUrl);

    IRequestHandler requestHandler = tester.getApplication()
      .getRootRequestMapper()
      .mapRequest(request);

    // meta resource is served by wicket under 2.5
    Assert.assertNotNull(requestHandler);
View Full Code Here

  @Test
  public void testWithServlet30() throws MalformedURLException
  {
    MockApplication application = new MockApplication();
    MockServletContext servletContext = new MockServletContext30(application, null);
    BaseWicketTester tester = new BaseWicketTester(application, servletContext);

    MetaInfStaticResourceReference metaRes = new MetaInfStaticResourceReference(getClass(),
      STATIC_RESOURCE_NAME);
    PackageResourceReference packRes = new PackageResourceReference(getClass(),
      STATIC_RESOURCE_NAME);

    Url packUrl = tester.getRequestCycle().mapUrlFor(packRes, null);
    Url metaUrl = tester.getRequestCycle().mapUrlFor(metaRes, null);

    Assert.assertNotNull(metaUrl);
    Assert.assertNotNull(packUrl);
    Assert.assertFalse(
      "Meta and pack resource should not map to the same url under servlet 3.0.",
      metaUrl.equals(packUrl));

    String metaUrlStr = metaUrl.toString();
    if (!metaUrlStr.startsWith("/"))
    {
      metaUrlStr = "/" + metaUrlStr;
    }

    // meta resource is served by the servlet container under 3.0
    URL metaNetUrl = servletContext.getResource(metaUrlStr);

    Assert.assertNotNull("Meta resource is not found by the 3.0 servlet container.", metaNetUrl);

    MockWebRequest request = new MockWebRequest(packUrl);

    IRequestHandler requestHandler = tester.getApplication()
      .getRootRequestMapper()
      .mapRequest(request);

    // the pack resource is still served by wicket
    Assert.assertNotNull(requestHandler);
View Full Code Here

TOP

Related Classes of org.apache.wicket.util.tester.BaseWicketTester$TestPageManagerProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.