Spring Framework MockHttpSession - 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 MockHttpSession class.

This code example shows how to use the following methods:setAttribute
    private MockHttpSession session;
    private HttpSessionDestroyedEvent destroyedEvent;
 
    @Before 
    public void setUp() { 
        session = new MockHttpSession();
        session.setAttribute("notcontext", "notcontext");
        session.setAttribute("null", null);
        session.setAttribute("context", new SecurityContextImpl());
        destroyedEvent = new HttpSessionDestroyedEvent(session);
    } 
 
    // SEC-1870 
    @Test
    public void getSecurityContexts() { 
        List<SecurityContext> securityContexts = destroyedEvent.getSecurityContexts();
        assertEquals(1,securityContexts.size());
        assertSame(session.getAttribute("context"), securityContexts.get(0));
    } 
 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 */ 
public class ProgressTrackerTest { 
 
	@Before 
	public void setUp() throws Exception {
		_mockHttpSession = new MockHttpSession();
 
		_mockInstallProcess = new MockInstallProcess(_mockHttpSession);
	} 
 
	@After 
	public void tearDown() throws Exception {
		_mockInstallProcess.finish();
	} 
 
	@Test
	public void testGetMessage() throws Exception {
		_mockInstallProcess.initialize();
 
		ProgressTracker progressTracker = getAttribute(ProgressTracker.PERCENT);
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
    // SEC-2599 
    @Test(expected=IllegalStateException.class) 
    public void sessionCreatedNullApplicationContext() { 
        HttpSessionEventPublisher publisher = new HttpSessionEventPublisher(); 
        MockServletContext servletContext = new MockServletContext(); 
        MockHttpSession session = new MockHttpSession(servletContext); 
        HttpSessionEvent event = new HttpSessionEvent(session); 
 
        publisher.sessionCreated(event); 
    } 
 
    // SEC-2599 
    @Test(expected=IllegalStateException.class) 
    public void sessionDestroyedNullApplicationContext() { 
        HttpSessionEventPublisher publisher = new HttpSessionEventPublisher(); 
        MockServletContext servletContext = new MockServletContext(); 
        MockHttpSession session = new MockHttpSession(servletContext); 
        HttpSessionEvent event = new HttpSessionEvent(session); 
 
        publisher.sessionDestroyed(event); 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isInvalid
    public void backChannelLogoutFailsIfMultipart() { 
        final String logoutMessage = LogoutMessageGenerator.generateBackChannelLogoutMessage(TICKET); 
        request.setParameter(LOGOUT_PARAMETER_NAME, logoutMessage); 
        request.setMethod("POST"); 
        request.setContentType("multipart/form-data"); 
        final MockHttpSession session = new MockHttpSession(); 
        handler.getSessionMappingStorage().addSessionById(TICKET, session); 
        assertTrue(handler.process(request, response)); 
        assertFalse(session.isInvalid()); 
    } 
 
    @Test 
    public void backChannelLogoutFailsIfNoSessionIndex() { 
        final String logoutMessage = LogoutMessageGenerator.generateBackChannelLogoutMessage(""); 
        request.setParameter(LOGOUT_PARAMETER_NAME, logoutMessage); 
        request.setMethod("POST"); 
        final MockHttpSession session = new MockHttpSession(); 
        handler.getSessionMappingStorage().addSessionById(TICKET, session); 
        assertFalse(handler.process(request, response)); 
        assertFalse(session.isInvalid()); 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
		UserFormController controller = new UserFormController(); 
		WebRequest request = new ServletWebRequest(new MockHttpServletRequest()); 
		User user = controller.formBackingObject(request, null); 
		user.addName(new PersonName("This", "is", "Test")); 
		user.getPerson().setGender("F"); 
		controller.handleSubmission(request, new MockHttpSession(), new ModelMap(), "Save User", "pass123", "pass123", null, 
		    null, null, new String[0], "true", user, new BindException(user, "user")); 
	} 
	 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
    private SessionStatisticListener listener; 
    private HttpSessionEvent event; 
 
    @BeforeMethod 
    public void initMethod() { 
        event = new HttpSessionEvent(new MockHttpSession()); 
        listener = new SessionStatisticListener(); 
    } 
 
    @Test 
    public void confirmIncrementSessionCountTest() { 
        listener.sessionCreated(event); 
 
        assertEquals(listener.getTotalActiveSessions(), 1); 
    } 
 
    @Test 
    public void confirmDeletingSessionInformationTest() { 
        listener.sessionCreated(event); 
        assertEquals(listener.getTotalActiveSessions(), 1); 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
public class HttpSessionOAuthRememberMeServicesTests { 
 
	@Test 
	public void testEmptySession() { 
 
		MockHttpSession mockHttpSession = new MockHttpSession(); 
		MockHttpServletRequest request = new MockHttpServletRequest(); 
		MockHttpServletResponse response = new MockHttpServletResponse(); 
 
		request.setSession(mockHttpSession); 
 
		HttpSessionOAuthRememberMeServices oAuthRememberMeService = new HttpSessionOAuthRememberMeServices(); 
 
		Map<String, OAuthConsumerToken> tokens = oAuthRememberMeService.loadRememberedTokens(request, response); 
 
		Assert.assertNull(tokens); 
 
	} 
 
	@Test 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
    MockHttpSession session;
     
    @Before 
    public void setUp() { 
 
        session = new MockHttpSession();
 
        MockitoAnnotations.initMocks(this);
        when(request.getSession(false)).thenReturn(session);
 
        mapper.setAttributeName("key");
         
        Map<String,String> mappings = new HashMap<String,String>();
        mappings.put("key1", "fname1");
        mappings.put("key2", "fname2");
        mapper.setMappings(mappings);
 
        // intentionally does not  mapper.setDefaultProfileName("profile"); 
        // so that can test the no-default-set case 
    } 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
		List<PersonAttributeType> allTypes = Context.getPersonService().getAllPersonAttributeTypes();
		Assert.assertEquals(1, allTypes.get(0).getId().intValue());
		 
		// the test 
		Integer[] ids = new Integer[] { 1 };
		new PersonAttributeTypeListController().moveDown(ids, new MockHttpSession());
		allTypes = Context.getPersonService().getAllPersonAttributeTypes();
		Assert.assertEquals("The types didn't move correctly", 8, allTypes.get(0).getId().intValue());
	} 
	 
	/** 
	 * @see PersonAttributeTypeListController#moveDown(null,HttpSession) 
	 */ 
	@Test
	@Verifies(value = "should not fail if given last id", method = "moveDown(null,HttpSession)") 
	public void moveDown_shouldNotFailIfGivenLastId() throws Exception {
		// sanity check 
		List<PersonAttributeType> allTypes = Context.getPersonService().getAllPersonAttributeTypes();
		Assert.assertEquals(2, allTypes.get(allTypes.size() - 1).getId().intValue());
		 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getId
    } 
     
    @Test 
    public void read_method_should_return_correct_cart_Json_object () throws Exception { 
		//Arrange 
        this.mockMvc.perform(put("/rest/cart/add/P1234").session(session)) 
        			.andExpect(status().is(204)); 
         
        //Act 
        this.mockMvc.perform(get("/rest/cart/"+ session.getId()).session(session)) 
        			.andExpect(status().isOk()) 
        			.andExpect(jsonPath("$.cartItems.P1234.product.productId").value("P1234")); 
    } 
 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java