Search in sources :

Example 76 with MockRequestContext

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

the class TerminateSessionActionTests method verifyTerminateActionByCookie.

@Test
public void verifyTerminateActionByCookie() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.setCookies(new Cookie("TGC", "TGT-123456-something"));
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, action.execute(context).getId());
    assertNotNull(WebUtils.getLogoutRequests(context));
}
Also used : lombok.val(lombok.val) Cookie(javax.servlet.http.Cookie) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 77 with MockRequestContext

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

the class TicketGrantingTicketCheckActionTests method verifyValidTicket.

@Test
public void verifyValidTicket() throws Exception {
    val ctx = new MockRequestContext();
    val ctxAuthN = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport());
    val tgt = getCentralAuthenticationService().createTicketGrantingTicket(ctxAuthN);
    WebUtils.putTicketGrantingTicketInScopes(ctx, tgt);
    val action = new TicketGrantingTicketCheckAction(getCentralAuthenticationService());
    val event = action.execute(ctx);
    assertEquals(CasWebflowConstants.TRANSITION_ID_TICKET_GRANTING_TICKET_VALID, event.getId());
}
Also used : lombok.val(lombok.val) MockRequestContext(org.springframework.webflow.test.MockRequestContext) TicketGrantingTicketCheckAction(org.apereo.cas.web.flow.login.TicketGrantingTicketCheckAction) Test(org.junit.jupiter.api.Test)

Example 78 with MockRequestContext

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

the class TicketGrantingTicketCheckActionTests method verifyNullTicket.

@Test
public void verifyNullTicket() throws Exception {
    val ctx = new MockRequestContext();
    val action = new TicketGrantingTicketCheckAction(getCentralAuthenticationService());
    val event = action.execute(ctx);
    assertEquals(CasWebflowConstants.TRANSITION_ID_TICKET_GRANTING_TICKET_NOT_EXISTS, event.getId());
}
Also used : lombok.val(lombok.val) MockRequestContext(org.springframework.webflow.test.MockRequestContext) TicketGrantingTicketCheckAction(org.apereo.cas.web.flow.login.TicketGrantingTicketCheckAction) Test(org.junit.jupiter.api.Test)

Example 79 with MockRequestContext

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

the class TicketGrantingTicketCheckActionTests method verifyInvalidTicket.

@Test
public void verifyInvalidTicket() throws Exception {
    val ctx = new MockRequestContext();
    val tgt = new MockTicketGrantingTicket("user");
    WebUtils.putTicketGrantingTicketInScopes(ctx, tgt);
    val action = new TicketGrantingTicketCheckAction(getCentralAuthenticationService());
    val event = action.execute(ctx);
    assertEquals(CasWebflowConstants.TRANSITION_ID_TICKET_GRANTING_TICKET_INVALID, event.getId());
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockRequestContext(org.springframework.webflow.test.MockRequestContext) TicketGrantingTicketCheckAction(org.apereo.cas.web.flow.login.TicketGrantingTicketCheckAction) Test(org.junit.jupiter.api.Test)

Example 80 with MockRequestContext

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

the class RenderLoginActionTests method verifyNoRender.

@Test
public void verifyNoRender() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    val properties = new CasConfigurationProperties();
    val action = new RenderLoginAction(getServicesManager(), properties, applicationContext);
    assertNull(action.execute(context));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) RenderLoginAction(org.apereo.cas.web.flow.login.RenderLoginAction) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Aggregations

MockRequestContext (org.springframework.webflow.test.MockRequestContext)517 lombok.val (lombok.val)483 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)466 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)458 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)454 Test (org.junit.jupiter.api.Test)450 MockServletContext (org.springframework.mock.web.MockServletContext)404 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)132 MockServletContext (org.apereo.cas.util.MockServletContext)46 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)43 MockWebServer (org.apereo.cas.util.MockWebServer)36 ByteArrayResource (org.springframework.core.io.ByteArrayResource)36 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)35 Test (org.junit.Test)29 Event (org.springframework.webflow.execution.Event)26 Transition (org.springframework.webflow.engine.Transition)25 LiteralExpression (org.springframework.binding.expression.support.LiteralExpression)23 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)23 DefaultTargetStateResolver (org.springframework.webflow.engine.support.DefaultTargetStateResolver)23 DefaultTransitionCriteria (org.springframework.webflow.engine.support.DefaultTransitionCriteria)23