|
|||||||||||||||||||
| 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 | |||||||||||||||
| JspTestCaller.java | 50% | 92.9% | 100% | 89.5% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* ========================================================================
|
|
| 3 |
*
|
|
| 4 |
* Copyright 2001-2003 The Apache Software Foundation.
|
|
| 5 |
*
|
|
| 6 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
| 7 |
* you may not use this file except in compliance with the License.
|
|
| 8 |
* You may obtain a copy of the License at
|
|
| 9 |
*
|
|
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
| 11 |
*
|
|
| 12 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 13 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 15 |
* See the License for the specific language governing permissions and
|
|
| 16 |
* limitations under the License.
|
|
| 17 |
*
|
|
| 18 |
* ========================================================================
|
|
| 19 |
*/
|
|
| 20 |
package org.apache.cactus.internal.server;
|
|
| 21 |
|
|
| 22 |
import java.io.IOException;
|
|
| 23 |
import java.io.Writer;
|
|
| 24 |
|
|
| 25 |
import java.lang.reflect.Field;
|
|
| 26 |
|
|
| 27 |
import javax.servlet.http.HttpServletRequest;
|
|
| 28 |
|
|
| 29 |
import junit.framework.TestCase;
|
|
| 30 |
|
|
| 31 |
import org.apache.cactus.JspTestCase;
|
|
| 32 |
import org.apache.cactus.ServletURL;
|
|
| 33 |
import org.apache.cactus.server.PageContextWrapper;
|
|
| 34 |
|
|
| 35 |
/**
|
|
| 36 |
* Call the test method on the server side after assigning the JSP implicit
|
|
| 37 |
* objects using reflection.
|
|
| 38 |
*
|
|
| 39 |
* @version $Id: JspTestCaller.java 238991 2004-05-22 11:34:50Z vmassol $
|
|
| 40 |
*/
|
|
| 41 |
public class JspTestCaller extends ServletTestCaller |
|
| 42 |
{
|
|
| 43 |
/**
|
|
| 44 |
* @param theObjects the implicit objects coming from the redirector
|
|
| 45 |
*/
|
|
| 46 | 10 |
public JspTestCaller(JspImplicitObjects theObjects)
|
| 47 |
{
|
|
| 48 | 10 |
super(theObjects);
|
| 49 |
} |
|
| 50 |
|
|
| 51 |
/**
|
|
| 52 |
* @see AbstractWebTestCaller#setTestCaseFields(TestCase)
|
|
| 53 |
*/
|
|
| 54 | 5 |
protected void setTestCaseFields(TestCase theTestInstance) |
| 55 |
throws Exception
|
|
| 56 |
{
|
|
| 57 | 5 |
if (!(theTestInstance instanceof JspTestCase)) |
| 58 |
{
|
|
| 59 | 0 |
return;
|
| 60 |
} |
|
| 61 |
|
|
| 62 | 5 |
JspTestCase jspInstance = (JspTestCase) theTestInstance; |
| 63 | 5 |
JspImplicitObjects jspImplicitObjects = |
| 64 |
(JspImplicitObjects) this.webImplicitObjects;
|
|
| 65 |
|
|
| 66 |
// Sets the Servlet-related implicit objects
|
|
| 67 |
// -----------------------------------------
|
|
| 68 | 5 |
super.setTestCaseFields(jspInstance);
|
| 69 |
|
|
| 70 |
// Set the page context field of the test case class
|
|
| 71 |
// -------------------------------------------------
|
|
| 72 |
// Extract from the HTTP request the URL to simulate (if any)
|
|
| 73 | 5 |
HttpServletRequest request = jspImplicitObjects.getHttpServletRequest(); |
| 74 |
|
|
| 75 | 5 |
ServletURL url = ServletURL.loadFromRequest(request); |
| 76 |
|
|
| 77 | 5 |
Field pageContextField = jspInstance.getClass().getField("pageContext");
|
| 78 |
|
|
| 79 | 5 |
pageContextField.set(jspInstance, |
| 80 |
new PageContextWrapper(jspImplicitObjects.getPageContext(), url));
|
|
| 81 |
|
|
| 82 |
// Set the JSP writer field of the test case class
|
|
| 83 |
// -----------------------------------------------
|
|
| 84 | 5 |
Field outField = jspInstance.getClass().getField("out");
|
| 85 |
|
|
| 86 | 5 |
outField.set(jspInstance, jspImplicitObjects.getJspWriter()); |
| 87 |
} |
|
| 88 |
|
|
| 89 |
/**
|
|
| 90 |
* @see AbstractWebTestCaller#getResponseWriter()
|
|
| 91 |
*/
|
|
| 92 | 5 |
protected Writer getResponseWriter() throws IOException |
| 93 |
{
|
|
| 94 | 5 |
JspImplicitObjects jspImplicitObjects = |
| 95 |
(JspImplicitObjects) this.webImplicitObjects;
|
|
| 96 |
|
|
| 97 | 5 |
return jspImplicitObjects.getJspWriter();
|
| 98 |
} |
|
| 99 |
} |
|
| 100 |
|
|
||||||||||