|
Hi,
I have a doubts regarding the under
mentioned scenarios:
Scenario 1:
import java.util.*;
import java.text.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.io.*; import junit.framework.*; import org.apache.cactus.*; import org.apache.cactus.util.*; import org.apache.cactus.util.log.*; // For Logging public class TestJspTestCase extends JspTestCase
{
public TestJspTestCase(String theName)
{
super(theName); } public static void main(String[] theArgs)
{
junit.ui.TestRunner.main(new String[] {TestJspTestCase.class.getName()}); } public static Test suite()
{
return new TestSuite(TestJspTestCase.class); } public void testOut() throws IOException, ServletException { logger.debug("Beginning of testHelloJSP()"); session.setAttribute("name" , "BLUE" ) ; pageContext.forward("/hello.jsp"); logger.debug("End of testHelloJSP()"); assertEquals("BLUE" , session.getAttribute("name")); } public void endOut(HttpURLConnection huc
)throws IOException , ServletException {
System.out.println( AssertUtils.getResponseAsString(huc) ); } } Hello.jsp
<html>
<body> <P>A Test Sample</P> <% out.println("This is the first sample test using CACTUS 1.2 "); out.print("Name: "); out.println( session.getAttribute("name").toString() ) ; %> </body> </html> When I run this test case, by saying 'java
TestJspTestCase' I get the following output on the java
console
<html>
<body> <P>A Test Sample</P> This is the first sample test using CACTUS 1.2 Name: BLUE
</body>
</html> This is correct and I am clear till this place.
Consider another scenario like this:
SCENARIO 2:
import java.util.*;
import java.text.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.io.*; import junit.framework.*; import org.apache.cactus.*; import org.apache.cactus.util.*; import org.apache.cactus.util.log.*; // For Logging public class TestJspTestCase3 extends JspTestCase
{
public TestJspTestCase3(String theName)
{
super(theName); } public static void main(String[] theArgs)
{
junit.ui.TestRunner.main(new String[] {TestJspTestCase3.class.getName()}); } public static Test suite()
{
return new TestSuite(TestJspTestCase3.class); } public void testHelloJSP() throws
IOException, ServletException {
logger.debug("Beginning of testHelloJSP()"); session.setAttribute("name" , "BLUE" ) ; pageContext.forward("/hello.jsp"); logger.debug("End of testHelloJSP()"); assertEquals("BLUE" , session.getAttribute("name")); } public void testTablesJSP() throws
IOException, ServletException {
logger.debug("Beginning of testTablesJSP()"); session.setAttribute("name" , "Dharnidhar Vemuri" ) ; session.setAttribute("age" , "16" ) ; pageContext.forward("/Tables.jsp"); logger.debug("End of testTablesJSP()"); assertEquals("Dharnidhar Vemuri" , session.getAttribute("name")); } public void testOut() throws IOException,
ServletException {
logger.debug("Beginning of testHelloJSP()"); session.setAttribute("name" , "BLUE" ) ; pageContext.forward("/hello.jsp"); logger.debug("End of testHelloJSP()"); assertEquals("BLUE" , session.getAttribute("name")); logger.debug("Beginning of
testTablesJSP()");
session.setAttribute("name" , "Dharnidhar Vemuri" ) ; session.setAttribute("age" , "16" ) ; pageContext.forward("/Tables.jsp"); logger.debug("End of testTablesJSP()"); assertEquals("Dharnidhar Vemuri" , session.getAttribute("name")); } public void endOut(HttpURLConnection huc
)throws IOException , ServletException {
System.out.println( AssertUtils.getResponseAsString(huc) ); } } The Hello.jsp is the same as above, the Tables.jsp
goes like this
<html><head><title>Hello
World</title></head>
<body> <tr><td> <% out.print("Name: "+ session.getAttribute("name").toString() ); %> </tr></td> <tr><td> <% out.print("Age: "+ session.getAttribute("age").toString() ); %> </tr></td> </body></html> Now I again try to run this by saying java
TestJspTestCase3, My test runs without errrors but I just don't get anything on
the java console.
Then I thought maybe because of the following lines
it is not coming. I commented the code and tried to run again. My test passes,
but again nothing
on the java console. What can be the
reason?
logger.debug("Beginning of
testTablesJSP()");
session.setAttribute("name" , "Dharnidhar Vemuri" ) ; session.setAttribute("age" , "16" ) ; pageContext.forward("/Tables.jsp"); logger.debug("End of testTablesJSP()"); assertEquals("Dharnidhar Vemuri" , session.getAttribute("name")); Regards
Dharnidhar
|
- Re: A doubt in one of the samples that is being used in ... Dharnidhar Vemuri
- Re: A doubt in one of the samples that is being use... Rakesh Bhalla
- Re: A doubt in one of the samples that is being... Dharnidhar Vemuri
- Re: A doubt in one of the samples that is b... Vincent Massol
- Re: A doubt in one of the samples that ... Karthik Kumar
