KickJava   Java API By Example, From Geeks To Geeks.

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


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.Tapestry;
19 import org.apache.tapestry.asset.AssetService;
20 import org.apache.tapestry.engine.ServiceEncoding;
21 import org.apache.tapestry.services.ServiceConstants;
22 import org.easymock.MockControl;
23
24 /**
25  * Tests for {@link org.apache.tapestry.engine.encoders.AssetEncoder}.
26  *
27  * @author Howard M. Lewis Ship
28  * @since 4.0
29  */

30 public class TestAssetEncoder extends HiveMindTestCase
31 {
32     public void testWrongService()
33     {
34         MockControl control = newControl(ServiceEncoding.class);
35         ServiceEncoding encoding = (ServiceEncoding) control.getMock();
36
37         encoding.getParameterValue(ServiceConstants.SERVICE);
38         control.setReturnValue("foo");
39
40         replayControls();
41
42         new AssetEncoder().encode(encoding);
43
44         verifyControls();
45     }
46
47     public void testWrongPath()
48     {
49         MockControl control = newControl(ServiceEncoding.class);
50         ServiceEncoding encoding = (ServiceEncoding) control.getMock();
51
52         encoding.getServletPath();
53         control.setReturnValue("/Home.page");
54
55         replayControls();
56
57         AssetEncoder encoder = new AssetEncoder();
58         encoder.setPath("/assets/");
59
60         encoder.decode(encoding);
61
62         verifyControls();
63     }
64
65     public void testEncode()
66     {
67         MockControl control = newControl(ServiceEncoding.class);
68         ServiceEncoding encoding = (ServiceEncoding) control.getMock();
69
70         encoding.getParameterValue(ServiceConstants.SERVICE);
71         control.setReturnValue(Tapestry.ASSET_SERVICE);
72
73         encoding.getParameterValue(AssetService.PATH);
74         control.setReturnValue("/foo/bar/Baz.gif");
75
76         encoding.getParameterValue(AssetService.DIGEST);
77         control.setReturnValue("12345");
78
79         encoding.setServletPath("/assets/12345/foo/bar/Baz.gif");
80         encoding.setParameterValue(AssetService.PATH, null);
81         encoding.setParameterValue(AssetService.DIGEST, null);
82         encoding.setParameterValue(ServiceConstants.SERVICE, null);
83         
84         replayControls();
85
86         AssetEncoder encoder = new AssetEncoder();
87         encoder.setPath("/assets/");
88
89         encoder.encode(encoding);
90
91         verifyControls();
92     }
93
94     public void testDecode()
95     {
96         MockControl control = newControl(ServiceEncoding.class);
97         ServiceEncoding encoding = (ServiceEncoding) control.getMock();
98
99         encoding.getServletPath();
100         control.setReturnValue("/assets/12345/foo/bar/Baz.gif");
101
102         encoding.setParameterValue(ServiceConstants.SERVICE, Tapestry.ASSET_SERVICE);
103         encoding.setParameterValue(AssetService.DIGEST, "12345");
104         encoding.setParameterValue(AssetService.PATH, "/foo/bar/Baz.gif");
105         
106         replayControls();
107
108         AssetEncoder encoder = new AssetEncoder();
109         encoder.setPath("/assets/");
110
111         encoder.decode(encoding);
112
113         verifyControls();
114     }
115 }
Popular Tags