Search in sources :

Example 1 with DefaultValidationContext

use of org.springframework.webflow.validation.DefaultValidationContext in project cas by apereo.

the class UsernamePasswordCredentialTests method verifyInvalidEvent.

@Test
public void verifyInvalidEvent() {
    ApplicationContextProvider.holdApplicationContext(applicationContext);
    val input = new UsernamePasswordCredential(null, "Mellon", StringUtils.EMPTY, Map.of());
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val validationContext = new DefaultValidationContext(context, "whatever", mock(MappingResults.class));
    input.validate(validationContext);
    assertFalse(context.getMessageContext().hasErrorMessages());
}
Also used : lombok.val(lombok.val) DefaultValidationContext(org.springframework.webflow.validation.DefaultValidationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) MappingResults(org.springframework.binding.mapping.MappingResults) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with DefaultValidationContext

use of org.springframework.webflow.validation.DefaultValidationContext in project cas by apereo.

the class UsernamePasswordCredentialTests method verifyOperation.

@Test
public void verifyOperation() {
    ApplicationContextProvider.holdApplicationContext(applicationContext);
    val input = new UsernamePasswordCredential("casuser", "Mellon", StringUtils.EMPTY, Map.of());
    assertTrue(input.isValid());
    assertEquals(UsernamePasswordCredential.class, input.getClass());
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val validationContext = new DefaultValidationContext(context, "submit", mock(MappingResults.class));
    input.validate(validationContext);
    assertTrue(context.getMessageContext().hasErrorMessages());
}
Also used : lombok.val(lombok.val) DefaultValidationContext(org.springframework.webflow.validation.DefaultValidationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) MappingResults(org.springframework.binding.mapping.MappingResults) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)2 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)2 Test (org.junit.jupiter.api.Test)2 MappingResults (org.springframework.binding.mapping.MappingResults)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 MockServletContext (org.springframework.mock.web.MockServletContext)2 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)2 MockRequestContext (org.springframework.webflow.test.MockRequestContext)2 DefaultValidationContext (org.springframework.webflow.validation.DefaultValidationContext)2