Package org.springframework.mock.web

Examples of org.springframework.mock.web.MockHttpServletResponse$ResponsePrintWriter


    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setServletPath("/foo/secure/super/somefile.html");
    request.setContextPath("/");

    MockHttpServletResponse response = new MockHttpServletResponse();

    filterChainProxy.doFilter(request, response, new MockFilterChain());
    assertTrue(filter.isInitialized());
    assertTrue(filter.isDoFiltered());
    assertFalse(filter.isDestroyed());
View Full Code Here


  }

  public void testText() throws Exception {
    Map<String, Object> datas = CollectUtils.newHashMap();
    datas.put("b", new BeangleTagLibrary(ActionContext.getContext().getValueStack(),
        new MockHttpServletRequest(), new MockHttpServletResponse()));
    datas.put("s", new StrutsModels(ActionContext.getContext().getValueStack(),
        new MockHttpServletRequest(), new MockHttpServletResponse()));
    datas.put("watch", new StopWatch());
    StringWriter writer = new StringWriter();
    Template template = cfg.getTemplate("comp.ftl");
    // template.process(datas, writer);
  }
View Full Code Here

  StreamDownloader streamDownloader = new SplitStreamDownloader(new MimeTypeProvider());

  public void download() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    URL testDoc = DefaultStreamDownloaderTest.class.getResource("/download.txt");
    streamDownloader.download(request, response, testDoc, null);
    Assert.assertEquals(response.getStatus(), 200);
    Assert.assertEquals(response.getHeader("Accept-Ranges"), "bytes");

    Assert.assertEquals(response.getContentLength(), 59);

    File file = new File(testDoc.toURI());
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    request.addHeader("Range", "bytes=5-12");
    streamDownloader.download(request, response, testDoc, null);
    Assert.assertEquals(response.getStatus(), 206);
    Assert.assertEquals(response.getHeader("Content-Range"), "bytes 5-12/" + file.length());
    String content = response.getContentAsString();
    Assert.assertEquals(content, "document");
  }
View Full Code Here

  StreamDownloader streamDownloader = new DefaultStreamDownloader(new MimeTypeProvider());

  public void download() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    URL testDoc = DefaultStreamDownloaderTest.class.getResource("/download.txt");
    streamDownloader.download(request, response, testDoc, null);
  }
View Full Code Here

  @Test
  @DirtiesContext // changing the controller
  public void testDoSomething() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    wmsController.setHttpService(new MockHttpService());

    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("SERVICE", "WMS");
    parameters.put("layers", "bluemarble");
    parameters.put("WIDTH", "512");
    parameters.put("HEIGHT", "512");
    parameters.put("bbox", "-52.01245495052001,-28.207099921352835,11.947593278789554,35.75294830795673");
    parameters.put("format", "image/jpeg");
    parameters.put("version", "1.1.1");
    parameters.put("srs", "EPSG:4326");
    parameters.put("styles", "");
    parameters.put("request", "GetMap");
    request.setParameters(parameters);
    request.setRequestURI("d/wms/proxyBlue/");
    request.setQueryString("SERVICE=WMS&layers=bluemarble&" +
        "WIDTH=512&HEIGHT=512&bbox=-52.01245495052001,-28.207099921352835,11.947593278789554," +
        "35.75294830795673&format=image/jpeg&version=1.1.1&srs=EPSG:4326&styles=&request=GetMap");
    request.setMethod("GET");
    wmsController.getWms(request, response);
    Assert.assertEquals(TEST_VALUE, new String(response.getContentAsByteArray(), "UTF-8"));
  }
View Full Code Here

  }

  @Test
  public void testReadImage() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();

    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("SERVICE", "WMS");
    parameters.put("layers", "bluemarble");
    parameters.put("WIDTH", "512");
View Full Code Here

    Assert.assertTrue(url.startsWith("http://test/rasterizing/layer/beans/"));
    Assert.assertTrue(url.contains("?"));
    String key = url.substring("http://test/rasterizing/layer/beans/".length(), url.indexOf(".png"));
    Object o = cacheManager.get(layerBeans, CacheCategory.REBUILD, key);
    Assert.assertNotNull("Missing rebuild data in cache", o);
    MockHttpServletResponse response = new MockHttpServletResponse();
    recorder.clear();
    controller.getImage(layerBeans.getId(), key, response);
    Assert.assertEquals("", recorder.matches(CacheCategory.RASTER, "Rasterization success", "Put item in cache"));
    new ServletResponseAssert(response).assertEqualImage("beans-4-8-8.png", writeImages, DELTA);
    cacheManager.drop(layerBeans);
View Full Code Here

    Assert.assertNull("Unexpected raster in cache", o);
    Assert.assertEquals("", recorder.matches(CacheCategory.REBUILD, "Put item in cache"));

    // clear to test without security context
    securityManager.clearSecurityContext();
    MockHttpServletResponse response = new MockHttpServletResponse();
    recorder.clear();
    controller.getImage(layerBeansPoint.getId(), key, response);
    Assert.assertEquals("", recorder.matches(CacheCategory.REBUILD, "Got rebuild info from cache"));
    new ServletResponseAssert(response).assertEqualImage("beansPoint-4-8-8.png", writeImages, DELTA);
    cacheManager.drop(layerBeansPoint);
View Full Code Here

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/rest/beans/1.json");
    request.setMethod("GET");

    MockHttpServletResponse response = new MockHttpServletResponse();
    ModelAndView mav = adapter.handle(request, response, restController);

    Object o = mav.getModel().get(RestController.FEATURE_COLLECTION);
    Assert.assertTrue(o instanceof InternalFeature);
    InternalFeature feature = (InternalFeature) o;

    Assert.assertEquals("bean1", feature.getAttributes().get("stringAttr").getValue());
    Assert.assertEquals(true, feature.getAttributes().get("booleanAttr").getValue());
    Assert.assertEquals("100,23", feature.getAttributes().get("currencyAttr").getValue());
    Calendar c = Calendar.getInstance();
    c.set(2010, 1, 23, 0, 0, 0);
    c.set(Calendar.MILLISECOND, 0);
    Assert.assertEquals(c.getTime(), feature.getAttributes().get("dateAttr").getValue());
    Assert.assertEquals(123.456, feature.getAttributes().get("doubleAttr").getValue());
    Assert.assertEquals(456.789F, feature.getAttributes().get("floatAttr").getValue());
    Assert.assertEquals("http://www.geomajas.org/image1",
        fixSlash(feature.getAttributes().get("imageUrlAttr").getValue().toString()));
    Assert.assertEquals(789, feature.getAttributes().get("integerAttr").getValue());
    Assert.assertEquals(123456789L, feature.getAttributes().get("longAttr").getValue());
    Assert.assertEquals((short) 123, feature.getAttributes().get("shortAttr").getValue());
    Assert.assertEquals("http://www.geomajas.org/url1",
        fixSlash(feature.getAttributes().get("urlAttr").getValue().toString()));

    view.render(mav.getModel(), request, response);
    response.flushBuffer();
    Object json = new JSONParser().parse(response.getContentAsString());
    String isodate = GeoJSONUtil.DATE_FORMAT.format(c.getTime());
    Assert.assertTrue(json instanceof JSONObject);
    Assert.assertEquals("{\"type\":\"Feature\"," + "\"geometry\":{\"type\":\"MultiPolygon\","
        + "\"coordinates\":[[[[0.0,0.0],[1,0.0],[1,1],[0.0,1],[0.0,0.0]]]]}," + "\"properties\":{"
        + "\"stringAttr\":\"bean1\"," + "\"booleanAttr\":true," + "\"currencyAttr\":\"100,23\","
        + "\"dateAttr\":\"" + isodate + "\"," + "\"doubleAttr\":123.456,\"floatAttr\":456.789,"
        + "\"imageUrlAttr\":\"http://www.geomajas.org/image1\","
        + "\"integerAttr\":789,\"longAttr\":123456789," + "\"shortAttr\":123,"
        + "\"urlAttr\":\"http://www.geomajas.org/url1\"}," + "\"id\":\"1\"}",
        fixSlash(response.getContentAsString()));
  }
View Full Code Here

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/rest/beans");
    request.addParameter("bbox", "4,6,0,3");
    request.setMethod("GET");

    MockHttpServletResponse response = new MockHttpServletResponse();
    ModelAndView mav = adapter.handle(request, response, restController);
    Object o = mav.getModel().get(RestController.FEATURE_COLLECTION);
    Assert.assertTrue(o instanceof List<?>);
    for (Object f : (List<?>) o) {
      Assert.assertTrue(f instanceof InternalFeature);
View Full Code Here

TOP

Related Classes of org.springframework.mock.web.MockHttpServletResponse$ResponsePrintWriter

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.