Search in sources :

Example 11 with MockParameterMap

use of org.springframework.webflow.test.MockParameterMap in project cas by apereo.

the class DefaultCasWebflowAuthenticationExceptionHandlerTests method setup.

@BeforeEach
public void setup() {
    val errors = new LinkedHashSet<Class<? extends Throwable>>();
    errors.add(UnauthorizedServiceForPrincipalException.class);
    errors.add(UnauthorizedAuthenticationException.class);
    val catalog = new DefaultCasWebflowExceptionCatalog();
    catalog.registerExceptions(errors);
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    this.context = mock(RequestContext.class);
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getFlashScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, response));
    this.handler = new DefaultCasWebflowAuthenticationExceptionHandler(catalog, MessageBundleProperties.DEFAULT_BUNDLE_PREFIX_AUTHN_FAILURE);
}
Also used : lombok.val(lombok.val) LinkedHashSet(java.util.LinkedHashSet) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockParameterMap(org.springframework.webflow.test.MockParameterMap) RequestContext(org.springframework.webflow.execution.RequestContext) MessageContext(org.springframework.binding.message.MessageContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with MockParameterMap

use of org.springframework.webflow.test.MockParameterMap in project cas by apereo.

the class DefaultCasWebflowAbstractTicketExceptionHandlerTests method setup.

@BeforeEach
public void setup() {
    val errors = new LinkedHashSet<Class<? extends Throwable>>();
    errors.add(InvalidTicketException.class);
    errors.add(InvalidProxyGrantingTicketForServiceTicketException.class);
    errors.add(UnauthorizedServiceTicketValidationException.class);
    val catalog = new DefaultCasWebflowExceptionCatalog();
    catalog.registerExceptions(errors);
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    this.context = mock(RequestContext.class);
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getFlashScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, response));
    this.handler = new DefaultCasWebflowAbstractTicketExceptionHandler(catalog, MessageBundleProperties.DEFAULT_BUNDLE_PREFIX_AUTHN_FAILURE);
}
Also used : lombok.val(lombok.val) LinkedHashSet(java.util.LinkedHashSet) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockParameterMap(org.springframework.webflow.test.MockParameterMap) RequestContext(org.springframework.webflow.execution.RequestContext) MessageContext(org.springframework.binding.message.MessageContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 13 with MockParameterMap

use of org.springframework.webflow.test.MockParameterMap in project cas by apereo.

the class DelegatedClientAuthenticationDynamicDiscoveryExecutionActionTests method verifyOperationWithoutClient.

@Test
public void verifyOperationWithoutClient() throws Exception {
    val context = mock(RequestContext.class);
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getRequestScope()).thenReturn(new LocalAttributeMap<>());
    val request = new MockHttpServletRequest();
    request.addParameter("username", "cas@test.org");
    val response = new MockHttpServletResponse();
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new org.springframework.mock.web.MockServletContext(), request, response));
    val result = delegatedAuthenticationDiscoveryAction.execute(context);
    assertNotNull(result);
    assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, result.getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockParameterMap(org.springframework.webflow.test.MockParameterMap) MessageContext(org.springframework.binding.message.MessageContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.apereo.cas.util.MockServletContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with MockParameterMap

use of org.springframework.webflow.test.MockParameterMap in project cas by apereo.

the class FinalizeAccountRegistrationActionTests method setup.

@BeforeEach
public void setup() {
    this.context = mock(RequestContext.class);
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getConversationScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
}
Also used : MockParameterMap(org.springframework.webflow.test.MockParameterMap) RequestContext(org.springframework.webflow.execution.RequestContext) MessageContext(org.springframework.binding.message.MessageContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 15 with MockParameterMap

use of org.springframework.webflow.test.MockParameterMap in project cas by apereo.

the class SubmitAccountRegistrationActionTests method verifyFailingOperation.

@Test
public void verifyFailingOperation() throws Exception {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = mock(RequestContext.class);
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getFlashScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val results = submitAccountRegistrationAction.execute(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, results.getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockParameterMap(org.springframework.webflow.test.MockParameterMap) MessageContext(org.springframework.binding.message.MessageContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Aggregations

MockParameterMap (org.springframework.webflow.test.MockParameterMap)20 MessageContext (org.springframework.binding.message.MessageContext)16 lombok.val (lombok.val)15 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)15 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)15 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)15 MockServletContext (org.springframework.mock.web.MockServletContext)14 Test (org.junit.jupiter.api.Test)9 BeforeEach (org.junit.jupiter.api.BeforeEach)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 Test (org.junit.Test)4 RequestContext (org.springframework.webflow.execution.RequestContext)4 MockExternalContext (org.springframework.webflow.test.MockExternalContext)4 LinkedHashSet (java.util.LinkedHashSet)3 Authentication (org.apereo.cas.authentication.Authentication)3 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)3 SwivelTokenCredential (org.apereo.cas.adaptors.swivel.SwivelTokenCredential)2 Flow (org.springframework.webflow.engine.Flow)2 MockFlowExecutionContext (org.springframework.webflow.test.MockFlowExecutionContext)2 MockFlowSession (org.springframework.webflow.test.MockFlowSession)2