@Test
public void testBuildUrl() throws Exception {

	AutomaticDispatcherUrlService adus = new AutomaticDispatcherUrlService();
	// set mock request in context holder
	MockHttpServletRequest mockRequest = new MockHttpServletRequest();
	mockRequest.setScheme("http");
	mockRequest.setServerName("geomajas.org");
	mockRequest.setServerPort(80);
	mockRequest.setContextPath("/test");
	ServletRequestAttributes attributes = new ServletRequestAttributes(mockRequest);
	RequestContextHolder.setRequestAttributes(attributes);
	Assert.assertEquals("http://geomajas.org/test/d/", adus.getDispatcherUrl());
	mockRequest.setScheme("https");
	mockRequest.setServerName("secure.geomajas.org");
	mockRequest.setServerPort(8443);
	mockRequest.setContextPath(null);
	Assert.assertEquals("https://secure.geomajas.org:8443/d/", adus.getDispatcherUrl());
	// clean up
	RequestContextHolder.setRequestAttributes(null);
}