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());
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations