001    // Copyright 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.error;
016    
017    import static org.easymock.EasyMock.checkOrder;
018    import static org.easymock.EasyMock.expect;
019    import static org.easymock.EasyMock.expectLastCall;
020    
021    import org.apache.tapestry.BaseComponentTestCase;
022    import org.apache.tapestry.IPage;
023    import org.apache.tapestry.IRequestCycle;
024    import org.apache.tapestry.error.TestExceptionPresenter.ExceptionFixture;
025    import org.apache.tapestry.services.ResponseRenderer;
026    import org.apache.tapestry.test.Creator;
027    
028    /**
029     * Base class for tests of the various error reporting service implementations.
030     * 
031     * @author Howard M. Lewis Ship
032     * @since 4.0
033     */
034    public abstract class BaseErrorTestCase extends BaseComponentTestCase
035    {
036    
037        protected IPage newPage()
038        {
039            Creator c = new Creator();
040        
041            return (IPage) c.newInstance(ExceptionFixture.class);
042        }
043    
044        protected IRequestCycle newCycle(String pageName, IPage page)
045        {
046            IRequestCycle cycle = newCycle();
047            checkOrder(cycle, false);
048            
049            expect(cycle.getPage(pageName)).andReturn(page);
050        
051            return cycle;
052        }
053    
054        protected ResponseRenderer newRenderer(IRequestCycle cycle, Throwable throwable) throws Exception
055        {
056            ResponseRenderer renderer = newMock(ResponseRenderer.class);
057        
058            renderer.renderResponse(cycle);
059        
060            if (throwable != null)
061                expectLastCall().andThrow(throwable);
062        
063            return renderer;
064        }
065    
066        protected RequestExceptionReporter newReporter()
067        {
068            return newMock(RequestExceptionReporter.class);
069        }
070    
071    }