Example usage for org.hibernate PropertyAccessException PropertyAccessException

List of usage examples for org.hibernate PropertyAccessException PropertyAccessException

Introduction

In this page you can find the example usage for org.hibernate PropertyAccessException PropertyAccessException.

Prototype

public PropertyAccessException(Throwable cause, String message, boolean wasSetter, Class persistentClass,
        String propertyName) 

Source Link

Document

Constructs a PropertyAccessException using the specified information.

Usage

From source file:org.apereo.portal.spring.security.preauth.PortalPreAuthenticatedProcessingFilterTest.java

License:Apache License

/**
 * Test that when firing a profile selection event arising from personal profile selection, an
 * exception thrown by the event handler is handled by the
 * PortalPreAuthenticatedProcessingFilter such that it does not propagate and thereby prevent
 * user login. That is, failure to register the user profile selection is better than failure to
 * log in at all./*from   ww w. j a  v  a 2s .  c  o m*/
 *
 * @throws IOException
 * @throws ServletException
 */
@Test
public void testHandlesExceptionFromFiringProfileSelectionEvent() throws IOException, ServletException {
    SecurityContextHolder.createEmptyContext();
    SecurityContextHolder.getContext().setAuthentication(auth);
    when(request.getServletPath()).thenReturn("/Login");
    when(request.getParameter(LoginController.REQUESTED_PROFILE_KEY)).thenReturn("someProfileKey");

    final ProfileSelectionEvent expectedEvent = new ProfileSelectionEvent(filter, "someProfileKey", person,
            request);

    final RuntimeException rootCause = new RuntimeException();
    final PropertyAccessException propertyAccessException = new PropertyAccessException(rootCause,
            "String message", false, PortalPreAuthenticatedProcessingFilterTest.class, "somePropertyName");

    // test that the specific observed exception type is handled
    doThrow(propertyAccessException).when(this.eventPublisher).publishEvent(expectedEvent);

    filter.doFilter(request, response, filterChain);

    // test that exceptions generally are handled
    doThrow(rootCause).when(this.eventPublisher).publishEvent(expectedEvent);

    filter.doFilter(request, response, filterChain);
}

From source file:org.apereo.portal.spring.security.preauth.PortalPreAuthenticatedProcessingFilterTest.java

License:Apache License

/**
 * Test that when firing a profile selection event arising from swapped profile selection, an
 * exception thrown by the event handler is handled by the
 * PortalPreAuthenticatedProcessingFilter such that it does not propagate and thereby prevent
 * (swapped) user login. That is, failure to register the user profile selection and therefore
 * swapping as potentially the wrong profile is better than failing to swap at all.
 *
 * @throws IOException//  w  w  w  .j  a va 2  s  .  c  o  m
 * @throws ServletException
 */
@Test
public void testHandlesExceptionFromFiringSwappedProfileSelectionEvent() throws IOException, ServletException {

    SecurityContextHolder.createEmptyContext();
    SecurityContextHolder.getContext().setAuthentication(auth);
    when(request.getServletPath()).thenReturn("/Login");
    when(request.isRequestedSessionIdValid()).thenReturn(true);

    when(identitySwapperManager.getTargetProfile(session)).thenReturn("targetProfileKey");
    when(identitySwapperManager.getOriginalUsername(session)).thenReturn(null);
    when(identitySwapperManager.getTargetUsername(session)).thenReturn("targetUsername");

    final ProfileSelectionEvent expectedEvent = new ProfileSelectionEvent(filter, "targetProfileKey", person,
            request);

    final RuntimeException rootCause = new RuntimeException();
    final PropertyAccessException propertyAccessException = new PropertyAccessException(rootCause,
            "String message", false, PortalPreAuthenticatedProcessingFilterTest.class, "somePropertyName");

    // test that the specific observed exception type is handled
    doThrow(propertyAccessException).when(this.eventPublisher).publishEvent(expectedEvent);

    filter.doFilter(request, response, filterChain);

    // test that exceptions generally are handled
    doThrow(rootCause).when(this.eventPublisher).publishEvent(expectedEvent);

    filter.doFilter(request, response, filterChain);
}