Search in sources :

Example 6 with MockParameterMap

use of org.springframework.webflow.test.MockParameterMap in project head by mifos.

the class CreateSavingsAccountTest method testEnterAccountDetailsStep_NewProductSelected.

@Test
public void testEnterAccountDetailsStep_NewProductSelected() {
    Integer productId = 1;
    setCurrentState("enterAccountDetailsStep");
    MockExternalContext context = new MockExternalContext();
    MockParameterMap requestParameterMap = new MockParameterMap();
    requestParameterMap.put("productId", productId.toString());
    context.setRequestParameterMap(requestParameterMap);
    context.setEventId("newProductSelected");
    resumeFlow(context);
    verify(controller).loadProduct(productId, formBean);
    assertCurrentStateEquals("enterAccountDetailsStep");
}
Also used : MockExternalContext(org.springframework.webflow.test.MockExternalContext) MockParameterMap(org.springframework.webflow.test.MockParameterMap) Test(org.junit.Test)

Example 7 with MockParameterMap

use of org.springframework.webflow.test.MockParameterMap in project head by mifos.

the class CreateSavingsAccountTest method testSelectProductOfferingStep_ProductSelected.

@Test
public void testSelectProductOfferingStep_ProductSelected() {
    Integer productId = 1;
    setCurrentState("selectProductOfferingStep");
    doNothing().when(controller).loadProduct(1, formBean);
    MockExternalContext context = new MockExternalContext();
    MockParameterMap requestParameterMap = new MockParameterMap();
    requestParameterMap.put("productId", productId.toString());
    context.setRequestParameterMap(requestParameterMap);
    context.setEventId("productSelected");
    resumeFlow(context);
    verify(controller).loadProduct(productId, formBean);
    assertCurrentStateEquals("enterAccountDetailsStep");
}
Also used : MockExternalContext(org.springframework.webflow.test.MockExternalContext) MockParameterMap(org.springframework.webflow.test.MockParameterMap) Test(org.junit.Test)

Example 8 with MockParameterMap

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

the class RadiusAuthenticationWebflowEventResolverFailureTests method initialize.

@BeforeEach
public void initialize() {
    this.context = mock(RequestContext.class);
    when(context.getConversationScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    val request = new MockHttpServletRequest();
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    when(context.getFlowExecutionContext()).thenReturn(new MockFlowExecutionContext(new MockFlowSession(new Flow("mockFlow"))));
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    val authentication = CoreAuthenticationTestUtils.getAuthentication();
    WebUtils.putAuthentication(authentication, context);
    val builder = mock(AuthenticationResultBuilder.class);
    when(builder.getInitialAuthentication()).thenReturn(Optional.of(authentication));
    when(builder.collect(any(Authentication.class))).thenReturn(builder);
    WebUtils.putAuthenticationResultBuilder(builder, context);
}
Also used : lombok.val(lombok.val) MockFlowSession(org.springframework.webflow.test.MockFlowSession) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockServletContext(org.springframework.mock.web.MockServletContext) Flow(org.springframework.webflow.engine.Flow) MockFlowExecutionContext(org.springframework.webflow.test.MockFlowExecutionContext) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Authentication(org.apereo.cas.authentication.Authentication) MockParameterMap(org.springframework.webflow.test.MockParameterMap) RequestContext(org.springframework.webflow.execution.RequestContext) MessageContext(org.springframework.binding.message.MessageContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with MockParameterMap

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

the class SendForgotUsernameInstructionsActionEmailMessageBodyTests method verifyOp.

@Test
public void verifyOp() 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.getRequestScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getConversationScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, response));
    request.setParameter("email", "casuser@apereo.org");
    var result = sendForgotUsernameInstructionsAction.execute(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, 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.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 10 with MockParameterMap

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

the class WebAuthnAuthenticationWebflowEventResolverTests method verifyOperation.

@Test
public void verifyOperation() {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = mock(RequestContext.class);
    when(context.getRequestScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getConversationScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    WebUtils.putCredential(context, RegisteredServiceTestUtils.getCredentialsWithDifferentUsernameAndPassword("casuser", "123456"));
    val event = webAuthnAuthenticationWebflowEventResolver.resolveSingle(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, event.getId());
    assertEquals(HttpStatus.UNAUTHORIZED.value(), response.getStatus());
    val support = new EventFactorySupport();
    assertTrue(event.getAttributes().contains(support.getExceptionAttributeName()));
}
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) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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