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.resolver;
016    
017    import static org.easymock.EasyMock.expect;
018    
019    import java.net.URL;
020    
021    import org.apache.commons.logging.Log;
022    import org.apache.hivemind.Resource;
023    import org.apache.hivemind.util.URLResource;
024    import org.apache.tapestry.BaseComponentTestCase;
025    import org.apache.tapestry.INamespace;
026    import org.apache.tapestry.IRequestCycle;
027    import org.apache.tapestry.engine.ISpecificationSource;
028    import org.apache.tapestry.spec.IComponentSpecification;
029    
030    /**
031     * Base class for testing specification resolvers.
032     * 
033     * @author Howard M. Lewis Ship
034     * @since 4.0
035     */
036    public abstract class AbstractSpecificationResolverTestCase extends BaseComponentTestCase
037    {
038    
039        protected IComponentSpecification newSpecification()
040        {
041            return newMock(IComponentSpecification.class);
042        }
043    
044        protected IRequestCycle newCycle()
045        {
046            return newMock(IRequestCycle.class);
047        }
048    
049        protected URL newURL(String file)
050        {
051            return getClass().getResource(file);
052        }
053    
054        protected Resource newResource(URL url)
055        {
056            Resource resource = newMock(Resource.class);
057    
058            expect(resource.getResourceURL()).andReturn(url);
059    
060            return resource;
061        }
062    
063        protected Resource newResource(String path)
064        {
065            return new URLResource(newURL(path));
066        }
067    
068        protected void train(Log log, String message)
069        {
070            expect(log.isDebugEnabled()).andReturn(true);
071    
072            log.debug(message);
073        }
074    
075        protected Log newLog()
076        {
077            return newMock(Log.class);
078        }
079    
080        protected INamespace newNamespace()
081        {
082            return newMock(INamespace.class);
083        }
084    
085        protected ISpecificationSource newSource()
086        {
087            return newMock(ISpecificationSource.class);
088        }
089    
090        protected void trainContainsPage(INamespace namespace, String pageName, boolean containsPage)
091        {
092            expect(namespace.containsPage(pageName)).andReturn(containsPage);
093        }
094    
095        protected void trainFindPageSpecification(ISpecificationResolverDelegate delegate, IRequestCycle cycle, INamespace application, String pageName, IComponentSpecification spec)
096        {
097            expect(delegate.findPageSpecification(cycle, application, pageName)).andReturn(spec);
098        }
099    
100        protected void trainGetApplicationNamespace(ISpecificationSource source, INamespace application)
101        {
102            expect(source.getApplicationNamespace()).andReturn(application);
103        }
104    
105        protected void trainGetChildNamespace(INamespace child, String name, INamespace application)
106        {
107            expect(application.getChildNamespace(name)).andReturn(child);
108        }
109    
110        protected void trainGetFrameworkNamespace(ISpecificationSource source, INamespace framework)
111        {
112            expect(source.getFrameworkNamespace()).andReturn(framework);
113        }
114    
115        protected void trainGetNamespaceId(INamespace namespace, String namespaceId)
116        {
117            expect(namespace.getNamespaceId()).andReturn(namespaceId);
118        }
119    
120        protected void trainGetSpecificationLocation(INamespace namespace, Resource resource)
121        {
122            expect(namespace.getSpecificationLocation()).andReturn(resource);
123        }
124    
125        protected void trainGetSpecificationLocation(INamespace namespace, Resource root, String path)
126        {
127            expect(namespace.getSpecificationLocation()).andReturn(root.getRelativeResource(path));
128        }
129    
130        protected void trainIsApplicationNamespace(INamespace namespace, boolean isApplicationNamespace)
131        {
132            expect(namespace.isApplicationNamespace()).andReturn(isApplicationNamespace);
133        }
134    
135        protected void trainIsDebugEnabled(Log log, boolean isDebugEnabled)
136        {
137            expect(log.isDebugEnabled()).andReturn(isDebugEnabled);
138        }
139    
140    }