Package ch.entwine.weblounge.common.impl.testing

Examples of ch.entwine.weblounge.common.impl.testing.MockHttpServletResponse


      request.setAttribute(WebloungeRequest.COMPOSER, composer);
      request.setAttribute(WebloungeRequest.PAGELET, pagelet);
      request.setPathInfo(pathInfo);
      request.setRequestURI(UrlUtils.concat(httpContextURI, pathInfo));

      MockHttpServletResponse response = new MockHttpServletResponse();
      servlet.service(request, response);
      return response.getContentAsString();
    } else {
      InputStream is = null;
      try {
        is = rendererURL.openStream();
        return IOUtils.toString(is, "utf-8");
View Full Code Here


      request.setAttribute(WebloungeRequest.COMPOSER, composer);
      request.setAttribute(WebloungeRequest.PAGELET, pagelet);
      request.setPathInfo(pathInfo);
      request.setRequestURI(UrlUtils.concat(httpContextURI, pathInfo));

      MockHttpServletResponse response = new MockHttpServletResponse();
      servlet.service(request, response);
      return response.getContentAsString();
    } else {
      InputStream is = null;
      try {
        is = rendererURL.openStream();
        return IOUtils.toString(is, "utf-8");
View Full Code Here

  /**
   * Test method for {@link ch.entwine.weblounge.cache.impl.CacheableHttpServletResponseHeaders#apply(javax.servlet.http.HttpServletResponse)}.
   */
  @Test
  public void testApply() {
    HttpServletResponse response = new MockHttpServletResponse();
    headers.apply(response);
    assertTrue(response.containsHeader(headerName));
    assertTrue(response.containsHeader(multivalueHeaderName));
    assertFalse(response.containsHeader("Non-Existing-Header"));
  }
View Full Code Here

  public void setUp() throws Exception {
    tags.add(tag);
    tags.add(otherTag);
    handle = new TaggedCacheHandle(tags.getTags(), expirationTime, recheckTime);
   
    response = new CacheableHttpServletResponse(new MockHttpServletResponse());
    transaction = response.startTransaction(handle, filter);
  }
View Full Code Here

      logger.info("Precompiling java server pages for '{}'", site);
      int errorCount = 0;
      Iterator<URL> rendererIterator = rendererUrls.iterator();
      while (keepGoing && rendererIterator.hasNext()) {
        MockHttpServletResponse response = new MockHttpServletResponse();
        URL entry = rendererIterator.next();
        String path = entry.getPath();
        String pathInfo = path.substring(path.indexOf(site.getIdentifier()) + site.getIdentifier().length());
        request.setPathInfo(pathInfo);
        request.setRequestURI(pathInfo);
        request.setAttribute(WebloungeRequest.PAGE, page);
        request.setAttribute(WebloungeRequest.COMPOSER, page.getComposer(PageTemplate.DEFAULT_STAGE));
        if (pagelet != null)
          request.setAttribute(WebloungeRequest.PAGELET, pagelet);

        try {
          logger.debug("Precompiling {}:/{}", site, pathInfo);
          servlet.service(request, response);
          switch (response.getStatus()) {
            case HttpServletResponse.SC_OK:
              logger.debug("Precompilation of {}:/{} finished", site, pathInfo);
              break;
            case SC_NOT_FOUND:
              logger.error("Precompilation failed: {}:/{}: not found", site, pathInfo);
              break;
            default:
              logger.debug("Precompilation of {}:/{} failed with status {}", new Object[] {
                  site,
                  pathInfo,
                  response.getStatus() });
              break;
          }
        } catch (Throwable t) {
          while (t != t.getCause() && t.getCause() != null)
            t = t.getCause();
View Full Code Here

  /**
   * @throws java.lang.Exception
   */
  @Before
  public void setUp() throws Exception {
    response = new CacheableHttpServletResponse(new MockHttpServletResponse());
  }
View Full Code Here

      request.setMethod(site.getHostname(environment).getURL().getProtocol());
      request.setAttribute(WebloungeRequest.LANGUAGE, language);
      request.setPathInfo(pathInfo);
      request.setRequestURI(UrlUtils.concat(httpContextURI, pathInfo));

      MockHttpServletResponse response = new MockHttpServletResponse();
      servlet.service(request, response);
      return response.getContentAsString();
    } else {
      HttpClient httpClient = new DefaultHttpClient();
      httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
      try {
        if (version == Resource.WORK) {
          rendererURL = new URL(UrlUtils.concat(rendererURL.toExternalForm(), "work_" + language.getIdentifier() + ".html"));
        } else {
          rendererURL = new URL(UrlUtils.concat(rendererURL.toExternalForm(), "index_" + language.getIdentifier() + ".html"));
        }
        HttpGet getRequest = new HttpGet(rendererURL.toExternalForm());
        getRequest.addHeader(new BasicHeader("X-Weblounge-Special", "Page-Preview"));
        HttpResponse response = httpClient.execute(getRequest);
        if (response.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK)
          return null;
        String responseText = EntityUtils.toString(response.getEntity(), "utf-8");
        return responseText;
      } finally {
        httpClient.getConnectionManager().shutdown();
      }
    }
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.impl.testing.MockHttpServletResponse

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.