Java Code Examples for org.springframework.mock.web.MockHttpServletResponse#flushBuffer()

The following examples show how to use org.springframework.mock.web.MockHttpServletResponse#flushBuffer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TmsControllerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void getVectorTile() throws Exception {
	MockHttpServletResponse response = new MockHttpServletResponse();
	tmsController.getVectorTile("layerBeansMultiPolygon", "layerBeansMultiPolygonStyleInfo", "EPSG:4326", 0, 0, 0,
			100.0 / 256.0, "-50,-50", 256, 256, true, false, null, response);
	response.flushBuffer();
	new ResponseAssert(response).assertEqualImage("layerBeansMultiPolygon-0-0-0.png", writeImages, DELTA);
}
 
Example 2
Source File: RestControllerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testEpsg() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setRequestURI("/rest/beans");
	request.setMethod("GET");
	MockHttpServletResponse response = new MockHttpServletResponse();
	// check attribute equality
	request.setParameter("queryable", "stringAttr");
	request.setParameter("stringAttr_eq", "bean1");
	request.setParameter("epsg", "900913");
	ModelAndView mav = adapter.handle(request, response, restController);
	view.render(mav.getModel(), request, response);
	response.flushBuffer();
	Object json = new JSONParser().parse(response.getContentAsString());
	Assert.assertTrue(json instanceof JSONObject);
	JSONObject jsonObject = (JSONObject) json;
	JSONArray features = (JSONArray) jsonObject.get("features");
	JSONObject feature = (JSONObject) features.get(0);
	JSONObject geometry = (JSONObject) feature.get("geometry");
	GeometryJSON g = new GeometryJSON(0);
	Geometry m = g.read(geometry.toJSONString());
	Envelope envelope = new Envelope(0, 1, 0, 1);
	Geometry orig = JTS.toGeometry(envelope);
	Geometry m2 = geoservice.transform(orig, "EPSG:4326", "EPSG:900913");
	// equality check on buffer, JTS equals does not do the trick !
	Assert.assertTrue(m.buffer(0.01).contains(m2));
	Assert.assertTrue(m2.buffer(0.01).contains(m));
}
 
Example 3
Source File: RestControllerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testReadOneFeature() throws Exception {

	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()));
}