Coverage Report - org.apache.tapestry5.internal.test.PageTesterModule
 
Classes in this File Line Coverage Branch Coverage Complexity
PageTesterModule
95%
21/22
N/A
0
 
 1  
 // Copyright 2007, 2008, 2009 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry5.internal.test;
 16  
 
 17  
 import org.apache.tapestry5.SymbolConstants;
 18  
 import org.apache.tapestry5.internal.services.CookieSink;
 19  
 import org.apache.tapestry5.internal.services.CookieSource;
 20  
 import org.apache.tapestry5.ioc.*;
 21  
 import org.apache.tapestry5.services.*;
 22  
 import org.apache.tapestry5.test.PageTester;
 23  
 
 24  
 /**
 25  
  * Used in conjuction with {@link PageTester} to mock up and/or stub out portions of Tapestry that need to be handled
 26  
  * differently when testing.
 27  
  */
 28  0
 public class PageTesterModule
 29  
 {
 30  
     public static final String TEST_MODE = "test";
 31  
 
 32  
     public static void bind(ServiceBinder binder)
 33  
     {
 34  46
         binder.bind(TestableRequest.class, TestableRequestImpl.class);
 35  46
         binder.bind(TestableResponse.class, TestableResponseImpl.class);
 36  46
     }
 37  
 
 38  
     public static void contributeAlias(Configuration<AliasContribution> configuration, ObjectLocator locator)
 39  
     {
 40  46
         alias(configuration, locator, Request.class, "TestableRequest");
 41  46
         alias(configuration, locator, Response.class, "TestableResponse");
 42  
 
 43  46
         TestableCookieSinkSource cookies = new TestableCookieSinkSource();
 44  
 
 45  46
         alias(configuration, CookieSink.class, cookies);
 46  46
         alias(configuration, CookieSource.class, cookies);
 47  46
     }
 48  
 
 49  
     private static <T> void alias(Configuration<AliasContribution> configuration, ObjectLocator locator,
 50  
                                   Class<T> serviceClass, String serviceId)
 51  
     {
 52  92
         T service = locator.getService(serviceId, serviceClass);
 53  
 
 54  92
         alias(configuration, serviceClass, service);
 55  92
     }
 56  
 
 57  
     private static <T> void alias(Configuration<AliasContribution> configuration, Class<T> serviceClass, T service)
 58  
     {
 59  184
         AliasContribution<T> contribution = AliasContribution.create(serviceClass, TEST_MODE, service);
 60  
 
 61  184
         configuration.add(contribution);
 62  184
     }
 63  
 
 64  
     public static void contributeFactoryDefaults(MappedConfiguration<String, String> configuration)
 65  
     {
 66  46
         configuration.override(SymbolConstants.FORCE_ABSOLUTE_URIS, "true");
 67  46
     }
 68  
 
 69  
     public static void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration)
 70  
     {
 71  46
         configuration.addInstance("EndOfRequestCleanup", EndOfRequestCleanupFilter.class, "before:StaticFiles");
 72  46
     }
 73  
 
 74  
     public static void contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter> configuration)
 75  
     {
 76  46
         configuration.addInstance("CaptureRenderedDocument", CaptureRenderedDocument.class, "before:DocumentLinker");
 77  46
     }
 78  
 }