List of usage examples for org.springframework.mock.web MockHttpServletRequest getRequestURL
@Override
public StringBuffer getRequestURL()
From source file:fi.okm.mpass.idp.authn.impl.ValidateOIDCAuthenticationResponseTest.java
/** * Helper method for initializing servlet request with state and error parameters. * @param state/*from www .java 2 s.c o m*/ * @param errorCode * @param errorDesc * @return */ protected MockHttpServletRequest getHttpServletRequest(final String state, final String errorCode, final String errorDesc) { final MockHttpServletRequest httpRequest = Mockito.mock(MockHttpServletRequest.class); Mockito.when(httpRequest.getRequestURL()).thenReturn(new StringBuffer("https://example.org/mock")); if (state == null) { Mockito.when(httpRequest.getQueryString()).thenReturn(null); return httpRequest; } if (errorCode == null) { Mockito.when(httpRequest.getQueryString()).thenReturn("state=" + state); } else { Mockito.when(httpRequest.getQueryString()) .thenReturn("state=" + state + "&error=" + errorCode + "&error_description=" + errorDesc); } return httpRequest; }
From source file:fi.okm.mpass.idp.authn.impl.AbstractSpringSocialOAuth2IdentityTest.java
protected MockHttpServletRequest initHttpRequestWithState() { MockHttpServletRequest httpRequest = Mockito.mock(MockHttpServletRequest.class); final String sessionId = "mockSessionId"; HttpSession httpSession = Mockito.mock(HttpSession.class); Mockito.when(httpSession.getId()).thenReturn(sessionId); Mockito.when(httpRequest.getSession()).thenReturn(httpSession); Mockito.when(httpRequest.getParameter("code")).thenReturn("mockCode"); Mockito.when(httpRequest.getParameter("state")) .thenReturn(AbstractSpringSocialOAuth2Identity.calculateHash(sessionId)); Mockito.when(httpRequest.getRequestURL()).thenReturn(new StringBuffer()); return httpRequest; }
From source file:fi.okm.mpass.idp.authn.impl.OpenIdConnectIdentityTest.java
@Test public void successGetRedirect() throws Exception { MockHttpServletRequest mockHttpServletRequest = getRequest(); openIdConnectIdentity.setAuthorizationEndpoint(authorize_endpoint); String redirectUrl = openIdConnectIdentity.getRedirectUrl(mockHttpServletRequest); Assert.assertNotNull(redirectUrl);//from w ww. j a va 2s.co m Assert.assertEquals(verifyUrl(redirectUrl), true); List<NameValuePair> params = URLEncodedUtils.parse(new URI(redirectUrl), "UTF-8"); Assert.assertNotNull(params.contains("scope")); Assert.assertNotNull(params.contains("response_type")); Assert.assertNotNull(params.contains("client_id")); Assert.assertNotNull(params.contains("redirect_uri")); Assert.assertNotNull(params.contains("state")); for (NameValuePair param : params) { if (param.getName().equals("scope")) { Assert.assertTrue(param.getValue().contains("openid")); } if (param.getName().equals("response_type")) { Assert.assertEquals(param.getValue(), "code"); } if (param.getName().equals("client_id")) { Assert.assertEquals(param.getValue(), client_id); } if (param.getName().equals("redirect_uri")) { Assert.assertEquals(param.getValue(), mockHttpServletRequest.getRequestURL().toString()); } } }
From source file:org.jtalks.jcommune.web.exception.PrettyLogExceptionResolverTest.java
@Test public void testLogExceptionWithIncomingNotFoundException() throws Exception { Log mockLog = replaceLoggerWithMock(prettyLogExceptionResolver); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); NotFoundException notFoundException = new NotFoundException("Entity not found"); String logMessage = String.format("[%s][%s][%s][%s]", request.getMethod(), request.getRequestURL().toString(), request.getHeader("Cookie"), "Entity not found"); request.setContent("".getBytes()); prettyLogExceptionResolver.logException(notFoundException, request); verify(mockLog).info(logMessage);/*from ww w . j a v a2 s . c o m*/ }
From source file:org.jtalks.jcommune.web.exception.PrettyLogExceptionResolverTest.java
@Test public void testLogExceptionWithIncomingTypeMismatchException() throws Exception { Log mockLog = replaceLoggerWithMock(prettyLogExceptionResolver); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); TypeMismatchException typeMismatchException = new TypeMismatchException("Not a number", Number.class); String logMessage = String.format("[%s][%s][%s][%s]", request.getMethod(), request.getRequestURL().toString(), request.getHeader("Cookie"), typeMismatchException.getMessage()); request.setContent("".getBytes()); prettyLogExceptionResolver.logException(typeMismatchException, request); verify(mockLog).info(logMessage);//from ww w .j av a 2 s . co m }