Search in sources :

Example 1 with MockParameterMap

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

the class CreateSavingsAccountTest method testSelectCustomerStep_CustomerSelected.

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

Example 2 with MockParameterMap

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

the class CreateSavingsAccountTest method testStartFlow_CustomerIdProvided.

@Test
public void testStartFlow_CustomerIdProvided() {
    Integer customerId = 1;
    MutableAttributeMap input = new LocalAttributeMap();
    MockParameterMap requestParameterMap = new MockParameterMap();
    requestParameterMap.put("customerId", customerId.toString());
    MockExternalContext context = new MockExternalContext();
    context.setRequestParameterMap(requestParameterMap);
    startFlow(input, context);
    assertCurrentStateEquals("selectProductOfferingStep");
    verify(controller).customerSelected(eq(customerId), any(CreateSavingsAccountFormBean.class));
    verify(controller).getProductOfferings(any(CreateSavingsAccountFormBean.class));
}
Also used : LocalAttributeMap(org.springframework.webflow.core.collection.LocalAttributeMap) MockExternalContext(org.springframework.webflow.test.MockExternalContext) MutableAttributeMap(org.springframework.webflow.core.collection.MutableAttributeMap) MockParameterMap(org.springframework.webflow.test.MockParameterMap) CreateSavingsAccountFormBean(org.mifos.ui.core.controller.CreateSavingsAccountFormBean) Test(org.junit.Test)

Example 3 with MockParameterMap

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

the class BaseAcceptableUsagePolicyRepositoryTests method verifyFetchingPolicy.

protected void verifyFetchingPolicy(final RegisteredService service, final Authentication authentication, final boolean expectPolicyFound) {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    val context = mock(RequestContext.class);
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getConversationScope()).thenReturn(new LocalAttributeMap<>());
    val flowDefn = mock(FlowDefinition.class);
    when(flowDefn.getApplicationContext()).thenReturn(applicationContext);
    when(context.getActiveFlow()).thenReturn(flowDefn);
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, response));
    WebUtils.putRegisteredService(context, service);
    WebUtils.putAuthentication(authentication, context);
    assertEquals(expectPolicyFound, getAcceptableUsagePolicyRepository().fetchPolicy(context).isPresent());
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) 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)

Example 4 with MockParameterMap

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

the class AuthyAuthenticationWebflowEventResolverTests method beforeAll.

@BeforeEach
public void beforeAll() {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getConversationScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getRequestScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getFlashScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    WebUtils.putCredential(context, new AuthyTokenCredential("token"));
}
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) AuthyTokenCredential(org.apereo.cas.adaptors.authy.AuthyTokenCredential) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with MockParameterMap

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

the class GenericCasWebflowExceptionHandlerTests method verifyOperation.

@Test
public void verifyOperation() {
    val errors = new LinkedHashSet<Class<? extends Throwable>>();
    errors.add(AccountLockedException.class);
    errors.add(CredentialExpiredException.class);
    errors.add(AccountExpiredException.class);
    val catalog = new DefaultCasWebflowExceptionCatalog();
    catalog.registerExceptions(errors);
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = mock(RequestContext.class);
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, response));
    val handler = new GenericCasWebflowExceptionHandler(catalog, MessageBundleProperties.DEFAULT_BUNDLE_PREFIX_AUTHN_FAILURE);
    assertTrue(handler.supports(new AccountExpiredException(), context));
    val event = handler.handle(new CredentialExpiredException(), context);
    assertNotNull(event);
    assertEquals(CasWebflowExceptionHandler.UNKNOWN, event.getId());
}
Also used : lombok.val(lombok.val) LinkedHashSet(java.util.LinkedHashSet) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) AccountExpiredException(javax.security.auth.login.AccountExpiredException) MockParameterMap(org.springframework.webflow.test.MockParameterMap) MessageContext(org.springframework.binding.message.MessageContext) CredentialExpiredException(javax.security.auth.login.CredentialExpiredException) 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