Spring Framework MockRenderRequest - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework MockRenderRequest class.

This code example shows how to use the following methods:addUserRole, isUserInRole
	public void testAuthorizedUserWithMultipleRoles() throws Exception {
		UserRoleAuthorizationInterceptor interceptor = new UserRoleAuthorizationInterceptor();
		String validRole1 = "allowed1";
		String validRole2 = "allowed2";
		interceptor.setAuthorizedRoles(new String[] {validRole1, validRole2});
		MockRenderRequest request = new MockRenderRequest();
		MockRenderResponse response = new MockRenderResponse();
		Object handler = new Object();
		request.addUserRole(validRole2);
		request.addUserRole("someOtherRole");
		assertFalse(request.isUserInRole(validRole1));
		assertTrue(request.isUserInRole(validRole2));
		boolean shouldProceed = interceptor.preHandle(request, response, handler);
		assertTrue(shouldProceed);
	} 
 
	public void testUnauthorizedUser() throws Exception {
		UserRoleAuthorizationInterceptor interceptor = new UserRoleAuthorizationInterceptor();
		String validRole = "allowed";
		interceptor.setAuthorizedRoles(new String[] {validRole});
8
CodeRank
This code example shows how to use the following methods:
 
	public void testRenderRequestWithViewNameSet() throws Exception {
		ParameterizableViewController controller = new ParameterizableViewController();
		String viewName = "testView";
		controller.setViewName(viewName);
		RenderRequest request = new MockRenderRequest();
		RenderResponse response = new MockRenderResponse();
		ModelAndView mav = controller.handleRenderRequest(request, response);
		assertEquals(viewName, mav.getViewName());
	} 
 
	public void testInitApplicationContextWithNoViewNameSet() throws Exception {
		ParameterizableViewController controller = new ParameterizableViewController();
		try { 
			controller.setApplicationContext(new StaticPortletApplicationContext());
			fail("should have thrown IllegalArgumentException");
		} 
		catch (IllegalArgumentException ex) {
			// expected 
		} 
6
CodeRank
This code example shows how to use the following methods:getPortletSession
		urlHandler.setFlowExecutionRenderParameter("12345", actionResponse); 
		assertEquals("12345", actionResponse.getRenderParameter("execution")); 
	} 
 
	public void testSetFlowExecutionInSession() { 
		urlHandler.setFlowExecutionInSession("12345", renderRequest); 
		assertEquals("12345", renderRequest.getPortletSession().getAttribute("execution")); 
	} 
 
	public void testSessionFlowExecutionRemoval() { 
		urlHandler.setFlowExecutionInSession("12345", renderRequest); 
		assertEquals("12345", urlHandler.getFlowExecutionKey(renderRequest)); 
		actionRequest.setParameter("execution", "12345"); 
		assertEquals("12345", urlHandler.getFlowExecutionKey(actionRequest)); 
		assertNull(actionRequest.getPortletSession().getAttribute("execution")); 
	} 
 
	public void testCreateFlowExecutionUrl() { 
		String url = urlHandler.createFlowExecutionUrl("foo", "12345", renderResponse); 
		assertEquals("http://localhost/mockportlet?urlType=action;param_execution=12345", url); 
6
CodeRank
This code example shows how to use the following methods:
 
 
	@Before 
	public void setUp() { 
		exceptionResolver = new AnnotationMethodHandlerExceptionResolver();
		request = new MockRenderRequest();
		response = new MockRenderResponse();
	} 
 
	@Test
	public void simpleWithIOException() { 
		IOException ex = new IOException();
		SimpleController controller = new SimpleController();
		ModelAndView mav = exceptionResolver.resolveException(request, response, controller, ex);
		assertNotNull("No ModelAndView returned", mav);
		assertEquals("Invalid view name returned", "X:IOException", mav.getViewName());
	} 
 
	@Test
	public void simpleWithSocketException() { 
5
CodeRank
This code example shows how to use the following methods:
	protected void setUp() { 
		portletContext = new MockPortletContext();
		request = new MockActionRequest();
		response = new MockActionResponse();
		context = new PortletExternalContext(portletContext, request, response);
		renderRequest = new MockRenderRequest();
		renderResponse = new MockRenderResponse();
		renderContext = new PortletExternalContext(portletContext, renderRequest, renderResponse);
	} 
 
	public void testGetContextPath() { 
		request.setContextPath("/foo");
		assertEquals("/foo", request.getContextPath());
	} 
 
	public void testRequestParameters() { 
		assertTrue(context.getRequestParameterMap().isEmpty());
	} 
 
	public void testGetNativeObjects() { 
5
CodeRank