Hi Dinesh,
In article <[EMAIL PROTECTED]>,
Mon, 09 Feb 2004 15:05:59 +0800,
"Dinesh N" <[EMAIL PROTECTED]> wrote:
gnavsupe> I am new to this technology. I am testing a jsp page which do some operation
on java compiled class.
gnavsupe>
gnavsupe> Now i have created some test case like:
gnavsupe>
gnavsupe> public void teststringArray3()
gnavsupe> {
gnavsupe> System.out.println("Value is
"+session.getServletContext().getAttribute("stringArray3Count"));
gnavsupe> assertSame("This should be
same","1",session.getServletContext().getAttribute("stringArray3Count"));
gnavsupe>
gnavsupe> }
It should have pageContext.include("/test.jsp"), as you had tried.
Also, you should use assertEquals, as Rainsberger noticed.
gnavsupe> I also tried with. pageContext.include("/test.jsp");
gnavsupe> and then pageContext.getAttribute(stringArray3Count());
gnavsupe> But still it returns null.
I believe that the stringArray3Count() should be "stringArray3Count".
In article <[EMAIL PROTECTED]>,
Tue, 10 Feb 2004 15:09:37 +0800,
"Dinesh N" <[EMAIL PROTECTED]> wrote:
gnavsupe> I will give you my JSP which i want to test.
gnavsupe> It is:
gnavsupe> <[EMAIL PROTECTED] import="com.arraytest.StringArray"%>
I wrote (and tested) a sample JSP with JspTestCase.
It uses java.lang.String for attributes, however,
I believe that you can find out what you have to do
for your com.arraytest.StringArray.
I hope this will helps you.
----
Kazuhito SUGURI
mailto:[EMAIL PROTECTED]
<%
String str1 = "string #1";
pageContext.setAttribute("attr1", str1);
String str2 = "string #2";
pageContext.setAttribute("attr2", str2, PageContext.SESSION_SCOPE);
String str3 = "string #3";
pageContext.setAttribute("attr3", str3, PageContext.APPLICATION_SCOPE);
%>
<%= pageContext.getAttribute("attr1") %>
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.cactus.JspTestCase;
import org.apache.cactus.WebResponse;
public class SampleJspTest
extends JspTestCase
{
private static final String TARGET_PAGE = "/sample.jsp";
public SampleJspTest(String name){
super(name);
}
public void setUp(){
// check pre-process condition
String str1 = (String)pageContext.getAttribute("attr1",
pageContext.PAGE_SCOPE);
String str2 = (String)pageContext.getAttribute("attr2",
pageContext.SESSION_SCOPE);
String str3 = (String)pageContext.getAttribute("attr3",
pageContext.APPLICATION_SCOPE);
assertNull("pre-process condition fails for attr1", str1);
assertNull("pre-process condition fails for attr2", str2);
assertNull("pre-process condition fails for attr3", str3);
}
public void tearDown(){
// clear attribute(s) for the next test
pageContext.removeAttribute("attr2", pageContext.SESSION_SCOPE);
pageContext.removeAttribute("attr3", pageContext.APPLICATION_SCOPE);
}
public void testSample()
throws Exception
{
// process the target JSP
pageContext.include(TARGET_PAGE);
// check the result(s)
String str1 = (String)pageContext.getAttribute("attr1",
pageContext.PAGE_SCOPE);
String str2 = (String)pageContext.getAttribute("attr2",
pageContext.SESSION_SCOPE);
String str3 = (String)pageContext.getAttribute("attr3",
pageContext.APPLICATION_SCOPE);
assertNull("How did you set the attribute of this page-context?",
str1);
assertEquals("string #2", str2);
assertEquals("string #3", str3);
}
public void endSample(WebResponse theResponse){
assertEquals("string #1", theResponse.getText().trim());
}
public static Test suite(){
return new TestSuite(SampleJspTest.class);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]