1 15 package org.apache.tapestry.error; 16 17 import org.apache.hivemind.ApplicationRuntimeException; 18 import org.apache.hivemind.test.HiveMindTestCase; 19 import org.apache.tapestry.IPage; 20 import org.apache.tapestry.IRequestCycle; 21 import org.apache.tapestry.error.ExceptionPresenterImpl; 22 import org.apache.tapestry.html.BasePage; 23 import org.apache.tapestry.services.ResponseRenderer; 24 25 31 public class TestExceptionPresenter extends BaseErrorTestCase 32 { 33 public abstract static class ExceptionFixture extends BasePage 34 { 35 public abstract void setException(Throwable exception); 36 } 37 38 public void testSuccess() throws Exception 39 { 40 Throwable cause = new IllegalArgumentException (); 41 IPage page = newPage(); 42 43 IRequestCycle cycle = newCycle("Exception", page); 44 ResponseRenderer renderer = newRenderer(cycle, null); 45 46 cycle.activate(page); 47 48 replayControls(); 49 50 ExceptionPresenterImpl ep = new ExceptionPresenterImpl(); 51 ep.setExceptionPageName("Exception"); 52 ep.setResponseRenderer(renderer); 53 54 ep.presentException(cycle, cause); 55 56 verifyControls(); 57 58 assertSame(cause, page.getProperty("exception")); 59 } 60 61 public void testFailure() throws Exception 62 { 63 Throwable cause = new IllegalArgumentException (); 64 Throwable renderCause = new ApplicationRuntimeException("Some failure."); 65 66 IPage page = newPage(); 67 68 IRequestCycle cycle = newCycle("Exception", page); 69 ResponseRenderer renderer = newRenderer(cycle, renderCause); 70 RequestExceptionReporter reporter = newReporter(); 71 72 cycle.activate(page); 73 74 reporter.reportRequestException(ErrorMessages.unableToProcessClientRequest(cause), cause); 75 reporter.reportRequestException( 76 ErrorMessages.unableToPresentExceptionPage(renderCause), 77 renderCause); 78 79 replayControls(); 80 81 ExceptionPresenterImpl ep = new ExceptionPresenterImpl(); 82 ep.setExceptionPageName("Exception"); 83 ep.setResponseRenderer(renderer); 84 ep.setRequestExceptionReporter(reporter); 85 86 try 87 { 88 ep.presentException(cycle, cause); 89 unreachable(); 90 } 91 catch (ApplicationRuntimeException ex) 92 { 93 assertSame(renderCause, ex.getRootCause()); 94 } 95 96 verifyControls(); 97 98 assertSame(cause, page.getProperty("exception")); 99 } 100 } | Popular Tags |