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.engine.encoders;
016    
017    import static org.easymock.EasyMock.expect;
018    
019    import org.apache.tapestry.BaseComponentTestCase;
020    import org.apache.tapestry.engine.ServiceEncoding;
021    import org.apache.tapestry.services.ServiceConstants;
022    import org.testng.annotations.Test;
023    
024    /**
025     * Tests {@link org.apache.tapestry.engine.encoders.ServiceExtensionEncoder}.
026     * 
027     * @author Howard M. Lewis Ship
028     * @since 4.0
029     */
030    @Test
031    public class TestServiceExtensionEncoder extends BaseComponentTestCase
032    {
033        public void testEncode()
034        {
035            ServiceEncoding sec = newMock(ServiceEncoding.class);
036    
037            expect(sec.getParameterValue(ServiceConstants.SERVICE)).andReturn("heavy");
038    
039            sec.setServletPath("/heavy.svc");
040            sec.setParameterValue(ServiceConstants.SERVICE, null);
041    
042            replay();
043    
044            ServiceExtensionEncoder e = new ServiceExtensionEncoder();
045            e.setExtension("svc");
046    
047            e.encode(sec);
048    
049            verify();
050        }
051    
052        public void testDecodeWrongExtension()
053        {
054            ServiceEncoding sec = newMock(ServiceEncoding.class);
055    
056            expect(sec.getServletPath()).andReturn("/foo/bar/baz.direct");
057    
058            replay();
059    
060            ServiceExtensionEncoder e = new ServiceExtensionEncoder();
061            e.setExtension("svc");
062    
063            e.decode(sec);
064    
065            verify();
066        }
067        
068        public void testDecode()
069        {
070            ServiceEncoding sec = newMock(ServiceEncoding.class);
071    
072            expect(sec.getServletPath()).andReturn("/hitter.svc");
073    
074            sec.setParameterValue(ServiceConstants.SERVICE, "hitter");
075            
076            replay();
077    
078            ServiceExtensionEncoder e = new ServiceExtensionEncoder();
079            e.setExtension("svc");
080    
081            e.decode(sec);
082    
083            verify();     
084        }
085    }