|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
MockRequestDispatcher.java | 0% | 0% | 0% | 0% |
|
1 |
// Copyright 2004, 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.test.mock;
|
|
16 |
|
|
17 |
import java.io.FileInputStream;
|
|
18 |
import java.io.IOException;
|
|
19 |
import java.io.InputStream;
|
|
20 |
import java.io.OutputStream;
|
|
21 |
|
|
22 |
import javax.servlet.RequestDispatcher;
|
|
23 |
import javax.servlet.ServletException;
|
|
24 |
import javax.servlet.ServletRequest;
|
|
25 |
import javax.servlet.ServletResponse;
|
|
26 |
|
|
27 |
/**
|
|
28 |
* Used to enable mock testing of internal request forwarding.
|
|
29 |
*
|
|
30 |
* @author Howard Lewis Ship
|
|
31 |
* @since 4.0
|
|
32 |
*/
|
|
33 |
public class MockRequestDispatcher implements RequestDispatcher |
|
34 |
{ |
|
35 |
private String _resourcePath;
|
|
36 |
|
|
37 | 0 |
public MockRequestDispatcher(String resourcePath)
|
38 |
{ |
|
39 | 0 |
_resourcePath = resourcePath; |
40 |
} |
|
41 |
|
|
42 | 0 |
public void forward(ServletRequest request, ServletResponse response) |
43 |
throws ServletException, IOException
|
|
44 |
{ |
|
45 | 0 |
if (_resourcePath.endsWith("/FAIL_SERVLET")) |
46 | 0 |
throw new ServletException("Test-directed ServletException from RequestDispatcher forward()."); |
47 |
|
|
48 |
// For testing purposes, assume we only forward to static HTML files.
|
|
49 |
|
|
50 |
|
|
51 | 0 |
InputStream in = new FileInputStream(_resourcePath);
|
52 |
|
|
53 | 0 |
response.setContentType("test/html");
|
54 |
|
|
55 | 0 |
OutputStream out = response.getOutputStream(); |
56 |
|
|
57 |
|
|
58 | 0 |
byte[] buffer = new byte[1000]; |
59 |
|
|
60 | 0 |
while (true) |
61 |
{ |
|
62 | 0 |
int length = in.read(buffer);
|
63 |
|
|
64 | 0 |
if (length < 0)
|
65 | 0 |
break;
|
66 |
|
|
67 | 0 |
out.write(buffer, 0, length); |
68 |
} |
|
69 |
|
|
70 | 0 |
in.close(); |
71 | 0 |
out.close(); |
72 |
} |
|
73 |
|
|
74 | 0 |
public void include(ServletRequest request, ServletResponse response) |
75 |
throws ServletException, IOException
|
|
76 |
{ |
|
77 | 0 |
throw new ServletException("MockRequestDispatcher.include() not supported."); |
78 |
} |
|
79 |
|
|
80 |
} |
|
81 |
|
|