Spring Framework MockPortletRequest - 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 MockPortletRequest 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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:addParameter
	public void testUnregisteredHandlerWithDefault() throws Exception {
		ParameterHandlerMapping hm = (ParameterHandlerMapping)pac.getBean("handlerMapping");
		Object defaultHandler = new Object();
		hm.setDefaultHandler(defaultHandler);
 
		MockPortletRequest request = new MockPortletRequest();
		request.addParameter("action", "modify");
 
		assertNotNull(hm.getHandler(request));
		assertEquals(defaultHandler, hm.getHandler(request).getHandler());
	} 
 
	public void testConfiguredParameterName() throws Exception {
		ParameterHandlerMapping hm = (ParameterHandlerMapping)pac.getBean("handlerMapping");
		hm.setParameterName("someParam");
 
		MockPortletRequest request = new MockPortletRequest();
		request.addParameter("someParam", "add");
 
		Object handler = hm.getHandler(request).getHandler();
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:addParameter
		} 
	} 
 
	@Test
	public void testBooleanParameter() throws PortletRequestBindingException {
		MockPortletRequest request = new MockPortletRequest();
		request.addParameter("param1", "true");
		request.addParameter("param2", "e");
		request.addParameter("param4", "yes");
		request.addParameter("param5", "1");
		request.addParameter("paramEmpty", "");
 
		assertTrue(PortletRequestUtils.getBooleanParameter(request, "param1").equals(Boolean.TRUE));
		assertTrue(PortletRequestUtils.getBooleanParameter(request, "param1", false));
		assertTrue(PortletRequestUtils.getRequiredBooleanParameter(request, "param1"));
 
		assertFalse(PortletRequestUtils.getBooleanParameter(request, "param2", true));
		assertFalse(PortletRequestUtils.getRequiredBooleanParameter(request, "param2"));
 
		assertTrue(PortletRequestUtils.getBooleanParameter(request, "param3") == null);

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
	private MockPortletRequest request;
 
	protected void setUp() throws Exception {
		super.setUp(); 
		this.request = new MockPortletRequest();
		this.requestMap = new SingleValueRequestPropertyMap(this.request);
	} 
 
	public void testSingleValueProperty() throws Exception {
		this.request.setProperty("key", "value");
		assertEquals("value", this.requestMap.getAttribute("key"));
	} 
 
	public void testMultiValuePropertyAsString() throws Exception {
		this.request.setProperty("key", "value");
		this.request.addProperty("key", "value2");
		Object actual = this.requestMap.getAttribute("key");
		assertEquals("value", actual);
	} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
	private MockPortletRequest request;
 
	protected void setUp() throws Exception {
		super.setUp(); 
		this.request = new MockPortletRequest();
		this.requestMap = new SingleValueRequestParameterMap(this.request);
	} 
 
	public void testSingleValueParameter() throws Exception {
		this.request.setParameter("key", "value");
		assertEquals("value", this.requestMap.getAttribute("key"));
	} 
 
	public void testMultiValueParameterAsString() throws Exception {
		this.request.setParameter("key", "value");
		this.request.addParameter("key", "value2");
		Object actual = this.requestMap.getAttribute("key");
		assertEquals("value", actual);
	} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
	private MockPortletRequest request;
 
	protected void setUp() throws Exception {
		super.setUp(); 
		this.request = new MockPortletRequest();
		this.requestMap = new MultiValueRequestPropertyMap(this.request);
	} 
 
	public void testMultiValueProperty() throws Exception {
		this.request.setProperty("key", "value");
		this.request.addProperty("key", "value2");
		Object actual = this.requestMap.getAttribute("key");
		assertEquals(2, ((String[]) actual).length);
		assertEquals("value", ((String[]) actual)[0]);
		assertEquals("value2", ((String[]) actual)[1]);
	} 
 
	public void testSingleValuePropertyAsArray() throws Exception {
		this.request.setProperty("key", "value");
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
	private MockPortletRequest request;
 
	protected void setUp() throws Exception {
		super.setUp(); 
		this.request = new MockPortletRequest();
		this.requestMap = new MultiValueRequestParameterMap(this.request);
	} 
 
	public void testMultiValueParameter() throws Exception {
		this.request.setParameter("key", "value");
		this.request.addParameter("key", "value2");
		Object actual = this.requestMap.getAttribute("key");
		assertTrue(actual.getClass().isArray());
		assertEquals(2, ((String[]) actual).length);
		assertEquals("value", ((String[]) actual)[0]);
		assertEquals("value2", ((String[]) actual)[1]);
	} 
 
	public void testSingleValueParameterAsArray() throws Exception {
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
	private MockPortletRequest request;
 
	protected void setUp() throws Exception {
		super.setUp(); 
		request = new MockPortletRequest();
		tested = new PortletRequestMap(request);
	} 
 
	protected void tearDown() throws Exception {
		super.tearDown(); 
		request = null;
		tested = null;
	} 
 
	public void testGetAttribute() { 
		request.setAttribute("Some key", "Some value");
		// perform test 
		Object result = tested.getAttribute("Some key");
		assertEquals("Some value", result);
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAttributeNames, setAttribute
        assertEquals(obj, "testValue1");
        assertEquals("testValue1", request.getAttribute("testAttribute"));
    } 
 
    public void testClear() { 
    	MockPortletRequest request = new MockPortletRequest();
    	request.setAttribute("testAttribute1", "testValue1");
    	request.setAttribute("testAttribute2", "testValue2");
 
 
        PortletRequestMap map = new PortletRequestMap(request);
        map.clear();
 
        assertFalse(request.getAttributeNames().hasMoreElements());
    } 
 
    public void testRemove() { 
        MockPortletRequest request = new MockPortletRequest();
        request.setAttribute("testAttribute1", "testValue1");
         
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
	private MockPortletRequest request;
 
	protected void setUp() throws Exception {
		super.setUp(); 
		request = new MockPortletRequest();
		tested = new PortletRequestParameterMap(request);
	} 
 
	protected void tearDown() throws Exception {
		super.tearDown(); 
		request = null;
		tested = null;
	} 
 
	public void testGetAttribute() { 
		request.setParameter("Some param", "Some value");
		// perform test 
		Object result = tested.getAttribute("Some param");
		assertEquals("Some value", result);
6
CodeRank
Experience pair programming with AI  Get Codota for Java