Search in sources :

Example 21 with MockExternalContext

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

the class CreateSavingsAccountTest method testAnswerQuestionGroupStep_QuestionsAnswered.

@Test
public void testAnswerQuestionGroupStep_QuestionsAnswered() {
    List<QuestionGroupDetail> questionGroups = new ArrayList<QuestionGroupDetail>();
    doNothing().when(questionnaireServiceFacade).validateResponses(questionGroups);
    setCurrentState("answerQuestionGroupStep");
    MockExternalContext context = new MockExternalContext();
    context.setEventId("questionsAnswered");
    resumeFlow(context);
    assertCurrentStateEquals("previewStep");
}
Also used : MockExternalContext(org.springframework.webflow.test.MockExternalContext) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 22 with MockExternalContext

use of org.springframework.webflow.test.MockExternalContext 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 23 with MockExternalContext

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

the class FinalizeInterruptFlowActionTests method verifyFinalizedInterruptBlockedUnauthzUrl.

@Test
public void verifyFinalizedInterruptBlockedUnauthzUrl() throws Exception {
    val context = new MockRequestContext();
    context.setExternalContext(new MockExternalContext());
    val interrupt = InterruptResponse.interrupt();
    interrupt.setBlock(true);
    InterruptUtils.putInterruptIn(context, interrupt);
    val registeredService = RegisteredServiceTestUtils.getRegisteredService();
    val strategy = new DefaultRegisteredServiceAccessStrategy(true, true);
    strategy.setUnauthorizedRedirectUrl(new URI("https://www.github.com"));
    registeredService.setAccessStrategy(strategy);
    WebUtils.putRegisteredService(context, registeredService);
    val action = new FinalizeInterruptFlowAction(mock(CasCookieBuilder.class));
    val event = action.doExecute(context);
    assertEquals(event.getId(), CasWebflowConstants.TRANSITION_ID_STOP);
    assertTrue(context.getMockExternalContext().isResponseComplete());
    assertNotNull(context.getMockExternalContext().getExternalRedirectUrl());
}
Also used : lombok.val(lombok.val) MockExternalContext(org.springframework.webflow.test.MockExternalContext) CasCookieBuilder(org.apereo.cas.web.cookie.CasCookieBuilder) MockRequestContext(org.springframework.webflow.test.MockRequestContext) DefaultRegisteredServiceAccessStrategy(org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 24 with MockExternalContext

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

the class ClientFlowExecutionRepositoryTests method verifyLaunchAndResumeFlow.

@Test
public void verifyLaunchAndResumeFlow() {
    assertNotNull(flowExecutor);
    val launchResult = flowExecutor.launchExecution("test-flow", new LocalAttributeMap<>(), new MockExternalContext());
    assertNotNull(launchResult.getPausedKey());
    try {
        val key = ClientFlowExecutionKey.parse(launchResult.getPausedKey());
        assertEquals(key.toString(), launchResult.getPausedKey());
    } catch (final BadlyFormattedFlowExecutionKeyException e) {
        fail(() -> "Error parsing flow execution key: " + e.getMessage());
    }
    val context = new MockExternalContext();
    context.setEventId("submit");
    context.getRequestMap().put("vegan", "0");
    val resumeResult = flowExecutor.resumeExecution(launchResult.getPausedKey(), context);
    assertNotNull(resumeResult.getOutcome());
    assertEquals("lasagnaDinner", resumeResult.getOutcome().getId());
}
Also used : lombok.val(lombok.val) MockExternalContext(org.springframework.webflow.test.MockExternalContext) BadlyFormattedFlowExecutionKeyException(org.springframework.webflow.execution.repository.BadlyFormattedFlowExecutionKeyException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with MockExternalContext

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

the class GenericSuccessViewActionTests method verifyAuthn.

@Test
public void verifyAuthn() throws Exception {
    val cas = mock(CentralAuthenticationService.class);
    val servicesManager = mock(ServicesManager.class);
    val serviceFactory = mock(ServiceFactory.class);
    val service = RegisteredServiceTestUtils.getService("https://github.com/apereo/cas");
    when(serviceFactory.createService(anyString())).thenReturn(service);
    val registeredService = RegisteredServiceTestUtils.getRegisteredService();
    when(servicesManager.findServiceBy(any(Service.class))).thenReturn(registeredService);
    val action = new GenericSuccessViewAction(cas, servicesManager, serviceFactory, casProperties);
    val context = new MockRequestContext();
    context.setExternalContext(new MockExternalContext());
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val tgt = new MockTicketGrantingTicket(CoreAuthenticationTestUtils.getAuthentication());
    when(cas.getTicket(any(String.class), any())).thenReturn(tgt);
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    val result = action.execute(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, result.getId());
    assertNotNull(WebUtils.getAuthentication(context));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockExternalContext(org.springframework.webflow.test.MockExternalContext) GenericSuccessViewAction(org.apereo.cas.web.flow.login.GenericSuccessViewAction) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Service(org.apereo.cas.authentication.principal.Service) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.jupiter.api.Test)

Aggregations

MockExternalContext (org.springframework.webflow.test.MockExternalContext)26 Test (org.junit.Test)21 lombok.val (lombok.val)5 Test (org.junit.jupiter.api.Test)5 MockParameterMap (org.springframework.webflow.test.MockParameterMap)4 MockRequestContext (org.springframework.webflow.test.MockRequestContext)4 ArrayList (java.util.ArrayList)3 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)3 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)2 Service (org.apereo.cas.authentication.principal.Service)2 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)2 DefaultRegisteredServiceAccessStrategy (org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy)2 GenericSuccessViewAction (org.apereo.cas.web.flow.login.GenericSuccessViewAction)2 LocalAttributeMap (org.springframework.webflow.core.collection.LocalAttributeMap)2 MutableAttributeMap (org.springframework.webflow.core.collection.MutableAttributeMap)2 URI (java.net.URI)1 CasCookieBuilder (org.apereo.cas.web.cookie.CasCookieBuilder)1 CreateSavingsAccountFormBean (org.mifos.ui.core.controller.CreateSavingsAccountFormBean)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 BadlyFormattedFlowExecutionKeyException (org.springframework.webflow.execution.repository.BadlyFormattedFlowExecutionKeyException)1