本文整理匯總了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");
}
示例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());
}
示例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"));
}
示例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());
}
示例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());
}
示例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"));
}
示例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"));
}
示例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() );
}
示例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;
}
示例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());
}
示例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);
}