001    // Copyright 2004, 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.engine;
016    
017    import java.util.HashMap;
018    import java.util.Map;
019    
020    import org.apache.tapestry.IRequestCycle;
021    import org.apache.tapestry.services.LinkFactory;
022    import org.apache.tapestry.services.ResponseRenderer;
023    import org.apache.tapestry.services.ServiceConstants;
024    import org.testng.annotations.Test;
025    
026    /**
027     * @author Howard M. Lewis Ship
028     * @since 4.0
029     */
030    @Test
031    public class PageServiceTest extends ServiceTestCase
032    {
033        public void testGetLink()
034        {
035            LinkFactory lf = newLinkFactory();
036            ILink link = newLink();
037    
038            Map parameters = new HashMap();
039            parameters.put(ServiceConstants.PAGE, "TargetPage");
040    
041            PageService ps = new PageService();
042            ps.setLinkFactory(lf);
043    
044            trainConstructLink(lf, ps, false, parameters, true, link);
045    
046            replay();
047    
048            assertSame(link, ps.getLink(false, "TargetPage"));
049    
050            verify();
051        }
052    
053        public void testService() throws Exception
054        {
055            IRequestCycle cycle = newCycle();
056            ResponseRenderer rr = newResponseRenderer();
057    
058            trainGetParameter(cycle, ServiceConstants.PAGE, "TargetPage");
059    
060            cycle.activate("TargetPage");
061    
062            rr.renderResponse(cycle);
063    
064            replay();
065    
066            PageService ps = new PageService();
067            ps.setResponseRenderer(rr);
068    
069            ps.service(cycle);
070    
071            verify();
072        }
073    }