Search in sources :

Example 6 with MockRequestContext

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

the class ServiceAuthorizationCheckTests method authorizedServiceProvided.

@Test
public void authorizedServiceProvided() throws Exception {
    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.getFlowScope().put("service", this.authorizedService);
    final Event event = this.serviceAuthorizationCheck.doExecute(mockRequestContext);
    assertEquals("success", event.getId());
}
Also used : Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.Test)

Example 7 with MockRequestContext

use of org.springframework.webflow.test.MockRequestContext in project opennms by OpenNMS.

the class DefaultSchedulerServiceIT method testScheduleBadCronExpression.

@Test
public void testScheduleBadCronExpression() {
    expect(m_reportWrapperService.validate(m_criteria, REPORT_ID)).andReturn(true);
    replay(m_reportWrapperService);
    MockRequestContext context = new MockRequestContext();
    DeliveryOptions deliveryOptions = new DeliveryOptions();
    deliveryOptions.setInstanceId("testScheduleBadCronExpressionTrigger");
    assertEquals("error", m_schedulerService.addCronTrigger(REPORT_ID, m_criteria, deliveryOptions, "bad expression", context));
    verify(m_reportWrapperService);
}
Also used : MockRequestContext(org.springframework.webflow.test.MockRequestContext) DeliveryOptions(org.opennms.reporting.core.DeliveryOptions) Test(org.junit.Test)

Example 8 with MockRequestContext

use of org.springframework.webflow.test.MockRequestContext in project opennms by OpenNMS.

the class DefaultSchedulerServiceIT method testScheduleAndRun.

@Test
public void testScheduleAndRun() throws SchedulerException, InterruptedException {
    DeliveryOptions deliveryOptions = new DeliveryOptions();
    deliveryOptions.setInstanceId("testScheduleAndRunTrigger");
    expect(m_reportWrapperService.validate(m_criteria, REPORT_ID)).andReturn(true);
    m_reportWrapperService.run(m_criteria, ReportMode.SCHEDULED, deliveryOptions, REPORT_ID);
    replay(m_reportWrapperService);
    MockRequestContext context = new MockRequestContext();
    assertEquals("success", m_schedulerService.addCronTrigger(REPORT_ID, m_criteria, deliveryOptions, CRON_EXPRESSION, context));
    // give the trigger a chance to fire (one minute)
    Thread.sleep(61000);
    m_schedulerService.removeTrigger("testScheduleAndRunTrigger");
    verify(m_reportWrapperService);
    m_schedulerService.removeTrigger("testScheduleAndRunTrigger");
    assertEquals(0, m_scheduler.getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(TRIGGER_GROUP)).size());
}
Also used : MockRequestContext(org.springframework.webflow.test.MockRequestContext) DeliveryOptions(org.opennms.reporting.core.DeliveryOptions) Test(org.junit.Test)

Example 9 with MockRequestContext

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

the class DelegatedClientAuthenticationActionTests method verifyStartAuthentication.

@Test
public void verifyStartAuthentication() throws Exception {
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setParameter(ThemeChangeInterceptor.DEFAULT_PARAM_NAME, MY_THEME);
    mockRequest.setParameter(LocaleChangeInterceptor.DEFAULT_PARAM_NAME, MY_LOCALE);
    mockRequest.setParameter(CasProtocolConstants.PARAMETER_METHOD, MY_METHOD);
    final MockHttpSession mockSession = new MockHttpSession();
    mockRequest.setSession(mockSession);
    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);
    when(servletExternalContext.getNativeResponse()).thenReturn(mockResponse);
    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.setExternalContext(servletExternalContext);
    mockRequestContext.getFlowScope().put(CasProtocolConstants.PARAMETER_SERVICE, RegisteredServiceTestUtils.getService(MY_SERVICE));
    final FacebookClient facebookClient = new FacebookClient(MY_KEY, MY_SECRET);
    final TwitterClient twitterClient = new TwitterClient("3nJPbVTVRZWAyUgoUKQ8UA", "h6LZyZJmcW46Vu8R47MYfeXTSYGI30EqnWaSwVhFkbA");
    final Clients clients = new Clients(MY_LOGIN_URL, facebookClient, twitterClient);
    final DelegatedClientAuthenticationAction action = new DelegatedClientAuthenticationAction(clients, null, mock(CentralAuthenticationService.class), "theme", "locale", false);
    final Event event = action.execute(mockRequestContext);
    assertEquals("error", event.getId());
    assertEquals(MY_THEME, mockSession.getAttribute(ThemeChangeInterceptor.DEFAULT_PARAM_NAME));
    assertEquals(MY_LOCALE, mockSession.getAttribute(LocaleChangeInterceptor.DEFAULT_PARAM_NAME));
    assertEquals(MY_METHOD, mockSession.getAttribute(CasProtocolConstants.PARAMETER_METHOD));
    final MutableAttributeMap flowScope = mockRequestContext.getFlowScope();
    final Set<DelegatedClientAuthenticationAction.ProviderLoginPageConfiguration> urls = (Set<DelegatedClientAuthenticationAction.ProviderLoginPageConfiguration>) flowScope.get(DelegatedClientAuthenticationAction.PAC4J_URLS);
    assertFalse(urls.isEmpty());
    assertSame(2, urls.size());
}
Also used : TwitterClient(org.pac4j.oauth.client.TwitterClient) Set(java.util.Set) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) FacebookClient(org.pac4j.oauth.client.FacebookClient) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Clients(org.pac4j.core.client.Clients) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MutableAttributeMap(org.springframework.webflow.core.collection.MutableAttributeMap) MockHttpSession(org.springframework.mock.web.MockHttpSession) Event(org.springframework.webflow.execution.Event) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 10 with MockRequestContext

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

the class X509CertificateCredentialsNonInteractiveActionTests method verifyNoCredentialsResultsInError.

@Test
public void verifyNoCredentialsResultsInError() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse()));
    assertEquals("error", this.action.execute(context).getId());
}
Also used : ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

MockRequestContext (org.springframework.webflow.test.MockRequestContext)73 Test (org.junit.Test)68 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)53 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)53 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)50 MockServletContext (org.springframework.mock.web.MockServletContext)46 Event (org.springframework.webflow.execution.Event)34 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)14 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)10 DeliveryOptions (org.opennms.reporting.core.DeliveryOptions)8 Credential (org.apereo.cas.authentication.Credential)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)5 Service (org.apereo.cas.authentication.principal.Service)5 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)4 Clients (org.pac4j.core.client.Clients)4 FacebookClient (org.pac4j.oauth.client.FacebookClient)4 MutableAttributeMap (org.springframework.webflow.core.collection.MutableAttributeMap)4 Authentication (org.apereo.cas.authentication.Authentication)3 SamlMetadataUIInfo (org.apereo.cas.support.saml.mdui.SamlMetadataUIInfo)3