KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > engine > encoders > TestServiceExtensionEncoder


1 // Copyright 2005 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.tapestry.engine.encoders;
16
17 import org.apache.hivemind.test.HiveMindTestCase;
18 import org.apache.tapestry.engine.ServiceEncoding;
19 import org.apache.tapestry.services.ServiceConstants;
20 import org.easymock.MockControl;
21
22 /**
23  * Tests {@link org.apache.tapestry.engine.encoders.ServiceExtensionEncoder}.
24  *
25  * @author Howard M. Lewis Ship
26  * @since 4.0
27  */

28 public class TestServiceExtensionEncoder extends HiveMindTestCase
29 {
30     public void testEncode()
31     {
32         MockControl c = newControl(ServiceEncoding.class);
33         ServiceEncoding sec = (ServiceEncoding) c.getMock();
34
35         sec.getParameterValue(ServiceConstants.SERVICE);
36         c.setReturnValue("heavy");
37
38         sec.setServletPath("/heavy.svc");
39         sec.setParameterValue(ServiceConstants.SERVICE, null);
40
41         replayControls();
42
43         ServiceExtensionEncoder e = new ServiceExtensionEncoder();
44         e.setExtension("svc");
45
46         e.encode(sec);
47
48         verifyControls();
49     }
50
51     public void testDecodeWrongExtension()
52     {
53         MockControl c = newControl(ServiceEncoding.class);
54         ServiceEncoding sec = (ServiceEncoding) c.getMock();
55
56         sec.getServletPath();
57         c.setReturnValue("/foo/bar/baz.direct");
58
59         replayControls();
60
61         ServiceExtensionEncoder e = new ServiceExtensionEncoder();
62         e.setExtension("svc");
63
64         e.decode(sec);
65
66         verifyControls();
67     }
68     
69     public void testDecode()
70     {
71         MockControl c = newControl(ServiceEncoding.class);
72         ServiceEncoding sec = (ServiceEncoding) c.getMock();
73
74         sec.getServletPath();
75         c.setReturnValue("/hitter.svc");
76
77         sec.setParameterValue(ServiceConstants.SERVICE, "hitter");
78         
79         replayControls();
80
81         ServiceExtensionEncoder e = new ServiceExtensionEncoder();
82         e.setExtension("svc");
83
84         e.decode(sec);
85
86         verifyControls();
87     }
88 }
Popular Tags