当前位置: 首页>>代码示例>>Java>>正文


Java MockHttpSession类代码示例

本文整理汇总了Java中org.springframework.mock.web.MockHttpSession的典型用法代码示例。如果您正苦于以下问题:Java MockHttpSession类的具体用法?Java MockHttpSession怎么用?Java MockHttpSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MockHttpSession类属于org.springframework.mock.web包,在下文中一共展示了MockHttpSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAddEventWithWebAuthenticationDetails

import org.springframework.mock.web.MockHttpSession; //导入依赖的package包/类
@Test
public void testAddEventWithWebAuthenticationDetails() {
    HttpSession session = new MockHttpSession(null, "test-session-id");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    request.setRemoteAddr("1.2.3.4");
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", details);
    AuditEvent event = new AuditEvent("test-user", "test-type", data);
    customAuditEventRepository.add(event);
    List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
    assertThat(persistentAuditEvents).hasSize(1);
    PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0);
    assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4");
    assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id");
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:18,代码来源:CustomAuditEventRepositoryIntTest.java

示例2: testLogout

import org.springframework.mock.web.MockHttpSession; //导入依赖的package包/类
@Test
public void testLogout() throws Exception {
    final MockHttpSession mockHttpSession = new MockHttpSession();
    testSignUp();
    mockMvc
            .perform(post("/v1/user/signin")
                    .session(mockHttpSession)
                    .contentType(MediaType.APPLICATION_JSON)
                    .content("{\"username\":\"n02\"," +
                            "\"password\":\"soHardPassword\"}"));
    mockMvc
            .perform(post("/v1/user/logout")
                    .session(mockHttpSession)
                    .contentType(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk());
}
 
开发者ID:java-park-mail-ru,项目名称:SpaceInvasion-09-2017,代码行数:17,代码来源:UserControllerTest.java

示例3: verifyStartAuthentication

import org.springframework.mock.web.MockHttpSession; //导入依赖的package包/类
@Test
public void verifyStartAuthentication() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setParameter(ThemeChangeInterceptor.DEFAULT_PARAM_NAME, MY_THEME);
    mockRequest.setParameter(LocaleChangeInterceptor.DEFAULT_PARAM_NAME, MY_LOCALE);
    mockRequest.setParameter(CasProtocolConstants.PARAMETER_METHOD, MY_METHOD);

    final MockHttpSession mockSession = new MockHttpSession();
    mockRequest.setSession(mockSession);

    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);

    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.setExternalContext(servletExternalContext);
    mockRequestContext.getFlowScope().put(CasProtocolConstants.PARAMETER_SERVICE,
            org.jasig.cas.services.TestUtils.getService(MY_SERVICE));

    final FacebookClient facebookClient = new FacebookClient(MY_KEY, MY_SECRET);
    final TwitterClient twitterClient = new TwitterClient(MY_KEY, MY_SECRET);
    final Clients clients = new Clients(MY_LOGIN_URL, facebookClient, twitterClient);
    final ClientAction action = new ClientAction();
    action.setCentralAuthenticationService(mock(CentralAuthenticationService.class));
    action.setClients(clients);

    final Event event = action.execute(mockRequestContext);
    assertEquals("error", event.getId());
    assertEquals(MY_THEME, mockSession.getAttribute(ThemeChangeInterceptor.DEFAULT_PARAM_NAME));
    assertEquals(MY_LOCALE, mockSession.getAttribute(LocaleChangeInterceptor.DEFAULT_PARAM_NAME));
    assertEquals(MY_METHOD, mockSession.getAttribute(CasProtocolConstants.PARAMETER_METHOD));
    final MutableAttributeMap flowScope = mockRequestContext.getFlowScope();
    final Map<String, String> urls = (Map<String, String>) flowScope.get(ClientAction.PAC4J_URLS);
    assertTrue((urls.get("Facebook"))
            .startsWith("https://www.facebook.com/v2.2/dialog/oauth?client_id=my_key&redirect_uri=http%3A%2F%2Fcasserver%2Flogin%3F"
                    + Clients.DEFAULT_CLIENT_NAME_PARAMETER + "%3DFacebookClient&state="));
    assertEquals(MY_LOGIN_URL + '?' + Clients.DEFAULT_CLIENT_NAME_PARAMETER
            + "=TwitterClient&needs_client_redirection=true", urls.get("Twitter"));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:39,代码来源:ClientActionTests.java

示例4: verifyOK

import org.springframework.mock.web.MockHttpSession; //导入依赖的package包/类
@Test
public void verifyOK() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest(
            "GET",
            CONTEXT
            + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockRequest.setSession(mockSession);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());
    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(REDIRECT_URI + '?' + OAuthConstants.CODE + '=' + SERVICE_TICKET, map.get("callbackUrl"));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:20,代码来源:OAuth20CallbackAuthorizeControllerTests.java

示例5: verifyOKWithState

import org.springframework.mock.web.MockHttpSession; //导入依赖的package包/类
@Test
public void verifyOKWithState() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest(
            "GET",
            CONTEXT
            + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE);
    mockRequest.setSession(mockSession);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());
    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(REDIRECT_URI + '?' + OAuthConstants.CODE + '=' + SERVICE_TICKET + '&' + OAuthConstants.STATE + '='
            + STATE, map.get("callbackUrl"));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:22,代码来源:OAuth20CallbackAuthorizeControllerTests.java

示例6: verifyOK

import org.springframework.mock.web.MockHttpSession; //导入依赖的package包/类
@Test
public void verifyOK() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest(
            "GET",
            CONTEXT
            + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockRequest.setSession(mockSession);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.afterPropertiesSet();
    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());
    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + SERVICE_TICKET, map.get("callbackUrl"));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:21,代码来源:OAuth20CallbackAuthorizeControllerTests.java

示例7: verifyOKWithState

import org.springframework.mock.web.MockHttpSession; //导入依赖的package包/类
@Test
public void verifyOKWithState() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest(
            "GET",
            CONTEXT
            + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE);
    mockRequest.setSession(mockSession);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.afterPropertiesSet();
    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());
    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + SERVICE_TICKET + "&" + OAuthConstants.STATE + "="
            + STATE, map.get("callbackUrl"));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:23,代码来源:OAuth20CallbackAuthorizeControllerTests.java

示例8: verifyCodeNoProfile

import org.springframework.mock.web.MockHttpSession; //导入依赖的package包/类
@Test
public void verifyCodeNoProfile() throws Exception {
    clearAllServices();

    final MockHttpServletRequest mockRequest = new MockHttpServletRequest(GET, CONTEXT + OAuth20Constants.AUTHORIZE_URL);
    mockRequest.setParameter(OAuth20Constants.CLIENT_ID, CLIENT_ID);
    mockRequest.setParameter(OAuth20Constants.REDIRECT_URI, REDIRECT_URI);
    mockRequest.setParameter(OAuth20Constants.RESPONSE_TYPE, OAuth20ResponseTypes.CODE.name().toLowerCase());
    mockRequest.setServerName(CAS_SERVER);
    mockRequest.setServerPort(CAS_PORT);
    mockRequest.setScheme(CAS_SCHEME);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    final OAuthRegisteredService service = getRegisteredService(REDIRECT_URI, SERVICE_NAME);
    service.setBypassApprovalPrompt(true);
    this.servicesManager.save(service);

    final MockHttpSession session = new MockHttpSession();
    mockRequest.setSession(session);

    final ModelAndView modelAndView = oAuth20AuthorizeEndpointController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuth20Constants.ERROR_VIEW, modelAndView.getViewName());
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:24,代码来源:OAuth20AuthorizeControllerTests.java

示例9: testSignIn

import org.springframework.mock.web.MockHttpSession; //导入依赖的package包/类
@Test
public void testSignIn() throws Exception {
    testSignUp();
    final MockHttpSession mockHttpSession = new MockHttpSession();
    mockMvc
            .perform(post("/v1/user/signin")
                    .session(mockHttpSession)
                    .contentType(MediaType.APPLICATION_JSON)
                    .content("{\"username\":\"n02\"," +
                            "\"password\":\"soHardPassword\"}"))
            .andExpect(status().isOk())
            .andExpect(jsonPath("username").value("n02"));
    assertEquals(
            ((Integer)mockHttpSession.getAttribute("user")),
            (Integer)userService.getUser("n02").getId());
}
 
开发者ID:java-park-mail-ru,项目名称:SpaceInvasion-09-2017,代码行数:17,代码来源:UserControllerTest.java

示例10: testOK

import org.springframework.mock.web.MockHttpSession; //导入依赖的package包/类
@Test
public void testOK() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest(
            "GET",
            CONTEXT
            + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockRequest.setSession(mockSession);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.afterPropertiesSet();
    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());
    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + SERVICE_TICKET, map.get("callbackUrl"));
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:21,代码来源:OAuth20CallbackAuthorizeControllerTests.java

示例11: testOKWithState

import org.springframework.mock.web.MockHttpSession; //导入依赖的package包/类
@Test
public void testOKWithState() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest(
            "GET",
            CONTEXT
            + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE);
    mockRequest.setSession(mockSession);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.afterPropertiesSet();
    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());
    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + SERVICE_TICKET + "&" + OAuthConstants.STATE + "="
            + STATE, map.get("callbackUrl"));
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:23,代码来源:OAuth20CallbackAuthorizeControllerTests.java

示例12: testMethodAll

import org.springframework.mock.web.MockHttpSession; //导入依赖的package包/类
@Test
public void testMethodAll() throws Exception
{
    MockHttpSession session = getSession( "ALL" );
    String endpoint = "/method/testAll";

    mvc.perform( get( endpoint ).session( session ) )
        .andExpect( status().isNotFound() );

    mvc.perform( get( "/26" + endpoint ).session( session ) )
        .andExpect( status().isNotFound() );

    mvc.perform( get( "/27" + endpoint ).session( session ) )
        .andExpect( status().isNotFound() );

    mvc.perform( get( "/26" + endpoint + "/a" ).session( session ) )
        .andExpect( status().isOk() );

    mvc.perform( get( "/27" + endpoint + "/b" ).session( session ) )
        .andExpect( status().isOk() );
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:22,代码来源:ApiVersionMethodTest.java

示例13: httpSession

import org.springframework.mock.web.MockHttpSession; //导入依赖的package包/类
private MockHttpSession httpSession(MockHttpServletRequest request, final String sessionid) {
	MockHttpSession session;
	synchronized (this.sessions) {
		session = this.sessions.get(sessionid);
		if (session == null) {
			session = new HtmlUnitMockHttpSession(request, sessionid);
			session.setNew(true);
			synchronized (this.sessions) {
				this.sessions.put(sessionid, session);
			}
			addSessionCookie(request, sessionid);
		}
		else {
			session.setNew(false);
		}
	}
	return session;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:HtmlUnitRequestBuilder.java

示例14: startGame_setsGameStarted

import org.springframework.mock.web.MockHttpSession; //导入依赖的package包/类
@Test
public void startGame_setsGameStarted() throws Exception {
    List<Player> players = Arrays.asList(new Player(), new Player());
    Game game = Game.builder().gameName("gamename").players(players).build();
    when(mockGameDataService.findGameByName("gamename")).thenReturn(game);
    List<Territory> territories = generateTerritoriesForTest();
    when(mockTerritoryDataService.getListOfTerritoriesOnMap()).thenReturn(territories);
    when(mockPlayerTerritoryDataService.getTerritoriesInGame("gamename")).thenReturn(playerTerritoriesForTest());

    MockHttpSession session = new MockHttpSession();
    session.setAttribute(PlayerController.SESSION_GAME_NAME_FIELD, "gamename");
    gameService.startGame(session);

    verify(mockGameDataService).saveGame(game);
    assertTrue(game.isStarted());
}
 
开发者ID:ChicagoOpenSourceTeam,项目名称:SupplyRaidServer,代码行数:17,代码来源:GameServiceTest.java

示例15: startGameRequest_callsMarkUnsuppliedThenSupplied_inSupplyService

import org.springframework.mock.web.MockHttpSession; //导入依赖的package包/类
@Test
public void startGameRequest_callsMarkUnsuppliedThenSupplied_inSupplyService() throws Exception {
    List<Player> players = Arrays.asList(Player.builder().playerId(10L).build(), Player.builder().playerId(20L).build());
    Game game = Game.builder().gameName("gamename").players(players).build();
    when(mockRepository.findOne("gamename")).thenReturn(game);
    List<Territory> territories = generateTerritoriesForTest();
    when(mockTerritoryRepository.findAll()).thenReturn(territories);
    MockHttpSession session = new MockHttpSession();
    session.setAttribute(PlayerController.SESSION_GAME_NAME_FIELD, "gamename");
    List<PlayerTerritory> playerTerritories = generatePlayerTerritoriesForTest();
    when(mockPlayerTerritoryRepository.findByGameName("gamename")).thenReturn(playerTerritories);

    mockMvc.perform(post("/game/start").contentType(MediaType.APPLICATION_JSON).session(session));

    InOrder inOrder = inOrder(mockSuppliedStatusService);
    inOrder.verify(mockSuppliedStatusService).markUnsupplied();
    ArgumentCaptor<List> listArgumentCaptor = ArgumentCaptor.forClass(List.class);
    inOrder.verify(mockSuppliedStatusService).markSupplied(listArgumentCaptor.capture(), eq(playerTerritories));

    List<PlayerTerritory> value = (List<PlayerTerritory>) listArgumentCaptor.getValue();
    assertThat(value
            .stream()
            .map(PlayerTerritory::getTerritoryId)
            .collect(Collectors.toList())).containsExactlyInAnyOrder(5L, 10L, 15L, 20L);
}
 
开发者ID:ChicagoOpenSourceTeam,项目名称:SupplyRaidServer,代码行数:26,代码来源:GameControllerTest.java


注:本文中的org.springframework.mock.web.MockHttpSession类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。