Search in sources :

Example 6 with ErrorCodeEscape

use of com.github.bordertech.wcomponents.ErrorCodeEscape in project wcomponents by BorderTech.

the class TargetableErrorInterceptor_Test method testHandleActionTargetableError.

@Test
public void testHandleActionTargetableError() throws IOException {
    final TargetableIdException excp = new TargetableIdException("Simulate target id error");
    // Throw targetid exception in chain
    InterceptorComponent chain = new InterceptorComponent() {

        @Override
        public void serviceRequest(final Request request) {
            throw excp;
        }
    };
    // Setup interceptor
    TargetableErrorInterceptor targetable = new TargetableErrorInterceptor();
    targetable.setBackingComponent(chain);
    // Process Action
    try {
        targetable.serviceRequest(new MockRequest());
        Assert.fail("Target id exception not handled correctly");
    } catch (ErrorCodeEscape e) {
        Assert.assertTrue("Incorrect target id exception message", e.getMessage().contains(CONTENT_ERROR));
        Assert.assertEquals("Incorrect escape code for target id exception", HttpServletResponse.SC_BAD_REQUEST, e.getCode());
        Assert.assertEquals("Cause should be the original target id exception", excp, e.getCause());
    }
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Request(com.github.bordertech.wcomponents.Request) ErrorCodeEscape(com.github.bordertech.wcomponents.ErrorCodeEscape) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 7 with ErrorCodeEscape

use of com.github.bordertech.wcomponents.ErrorCodeEscape in project wcomponents by BorderTech.

the class TargetableErrorInterceptor_Test method testHandleActionSessionToken.

@Test
public void testHandleActionSessionToken() throws IOException {
    final SessionTokenException excp = new SessionTokenException("Simulate session error");
    // Throw session exception in chain
    InterceptorComponent chain = new InterceptorComponent() {

        @Override
        public void serviceRequest(final Request request) {
            throw excp;
        }
    };
    // Setup interceptor
    TargetableErrorInterceptor interceptor = new TargetableErrorInterceptor();
    interceptor.setBackingComponent(chain);
    // Process Action
    try {
        interceptor.serviceRequest(new MockRequest());
        Assert.fail("Session exception not handled correctly");
    } catch (ErrorCodeEscape e) {
        Assert.assertTrue("Incorrect session exception message", e.getMessage().contains(SESSION_ERROR));
        Assert.assertEquals("Incorrect escape code for session exception", HttpServletResponse.SC_BAD_REQUEST, e.getCode());
        Assert.assertEquals("Cause should be the original session exception", excp, e.getCause());
    }
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Request(com.github.bordertech.wcomponents.Request) ErrorCodeEscape(com.github.bordertech.wcomponents.ErrorCodeEscape) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 8 with ErrorCodeEscape

use of com.github.bordertech.wcomponents.ErrorCodeEscape in project wcomponents by BorderTech.

the class AjaxErrorInterceptor_Test method testHandleActionSystemError.

@Test
public void testHandleActionSystemError() throws IOException {
    final SystemException excp = new SystemException("Simulate action phase system error");
    // Throw system exception in chain
    InterceptorComponent chain = new InterceptorComponent() {

        @Override
        public void serviceRequest(final Request request) {
            throw excp;
        }
    };
    // Setup interceptor
    AjaxErrorInterceptor ajax = new AjaxErrorInterceptor();
    ajax.setBackingComponent(chain);
    // Process Action
    try {
        ajax.serviceRequest(new MockRequest());
        Assert.fail("System exception not handled correctly");
    } catch (ErrorCodeEscape e) {
        Assert.assertTrue("Incorrect system exception message", e.getMessage().contains(AJAX_ERROR));
        Assert.assertEquals("Incorrect escape code for system exception", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getCode());
        Assert.assertEquals("Cause should be the original system exception", excp, e.getCause());
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Request(com.github.bordertech.wcomponents.Request) ErrorCodeEscape(com.github.bordertech.wcomponents.ErrorCodeEscape) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 9 with ErrorCodeEscape

use of com.github.bordertech.wcomponents.ErrorCodeEscape in project wcomponents by BorderTech.

the class AjaxErrorInterceptor_Test method testHandlePreparePaintSystemError.

@Test
public void testHandlePreparePaintSystemError() throws IOException {
    final SystemException excp = new SystemException("Simulate prepare paint system error");
    // Throw system exception in chain
    InterceptorComponent chain = new InterceptorComponent() {

        @Override
        public void preparePaint(final Request request) {
            throw excp;
        }
    };
    // Setup interceptor
    AjaxErrorInterceptor ajax = new AjaxErrorInterceptor();
    ajax.setBackingComponent(chain);
    // Process Action
    try {
        ajax.preparePaint(new MockRequest());
        Assert.fail("System exception not handled correctly in prepare paint");
    } catch (ErrorCodeEscape e) {
        Assert.assertTrue("Incorrect system exception message in prepare paint", e.getMessage().contains(AJAX_ERROR));
        Assert.assertEquals("Incorrect escape code for system exception in prepare paint", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getCode());
        Assert.assertEquals("Cause should be the original system exception in prepare paint", excp, e.getCause());
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Request(com.github.bordertech.wcomponents.Request) ErrorCodeEscape(com.github.bordertech.wcomponents.ErrorCodeEscape) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Aggregations

ErrorCodeEscape (com.github.bordertech.wcomponents.ErrorCodeEscape)9 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)9 Request (com.github.bordertech.wcomponents.Request)8 Test (org.junit.Test)8 SystemException (com.github.bordertech.wcomponents.util.SystemException)4 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)1 ContentEscape (com.github.bordertech.wcomponents.ContentEscape)1 UIContext (com.github.bordertech.wcomponents.UIContext)1 WServlet (com.github.bordertech.wcomponents.servlet.WServlet)1 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)1 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)1 IOException (java.io.IOException)1