001 // Copyright 2007, 2008, 2009, 2010, 2011 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.tapestry5.internal.test; 016 017 import org.apache.tapestry5.internal.services.CookieSink; 018 import org.apache.tapestry5.internal.services.CookieSource; 019 import org.apache.tapestry5.ioc.MappedConfiguration; 020 import org.apache.tapestry5.ioc.OrderedConfiguration; 021 import org.apache.tapestry5.ioc.ServiceBinder; 022 import org.apache.tapestry5.ioc.annotations.Contribute; 023 import org.apache.tapestry5.ioc.annotations.Local; 024 import org.apache.tapestry5.ioc.services.ServiceOverride; 025 import org.apache.tapestry5.services.MarkupRendererFilter; 026 import org.apache.tapestry5.services.Request; 027 import org.apache.tapestry5.services.RequestFilter; 028 import org.apache.tapestry5.services.Response; 029 import org.apache.tapestry5.test.PageTester; 030 031 /** 032 * Used in conjunction with {@link PageTester} to mock up and/or stub out portions of Tapestry that 033 * need to be handled differently when testing. 034 */ 035 @SuppressWarnings("rawtypes") 036 public class PageTesterModule 037 { 038 public static final String TEST_MODE = "test"; 039 040 public static void bind(ServiceBinder binder) 041 { 042 binder.bind(TestableRequest.class, TestableRequestImpl.class); 043 binder.bind(TestableResponse.class, TestableResponseImpl.class); 044 } 045 046 @Contribute(ServiceOverride.class) 047 public static void setupTestableOverrides(MappedConfiguration<Class, Object> configuration, @Local 048 TestableRequest request, @Local 049 TestableResponse response) 050 { 051 configuration.add(Request.class, request); 052 configuration.add(Response.class, response); 053 054 TestableCookieSinkSource cookies = new TestableCookieSinkSource(); 055 056 configuration.add(CookieSink.class, cookies); 057 configuration.add(CookieSource.class, cookies); 058 } 059 060 public static void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration) 061 { 062 configuration.addInstance("EndOfRequestCleanup", EndOfRequestCleanupFilter.class, "before:StaticFiles"); 063 } 064 065 public static void contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter> configuration) 066 { 067 configuration.addInstance("CaptureRenderedDocument", CaptureRenderedDocument.class, "before:DocumentLinker"); 068 } 069 }