jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dinesh N" <gnavs...@india.com>
Subject RE: Assesrtion Failed Error while JSP Testing
Date Wed, 11 Feb 2004 04:14:24 GMT
Hi Vincent,
 
 With bellow JSP i will show you my test case. Which allready including JSP.
Is is:

public class StringArrayJSPTest extends JspTestCase
{

	/**
	 * Constructor for StringArrayJSPTest.
	 * @param arg0
	 */
	
	private static final String TARGET_PAGE = "/StringArrayJSP.jsp";
	
	public StringArrayJSPTest(String arg0)
		{
			super(arg0);
		}
	
	
	
	
	public void setUp(){
		// check pre-process condition
		StringArray str1 = (StringArray)pageContext.getAttribute("stringArray1",
								   PageContext.PAGE_SCOPE);
		StringArray str2 = (StringArray)pageContext.getAttribute("stringArray2",
								   PageContext.SESSION_SCOPE);
		String str3 = (String)pageContext.getAttribute("stringArray3Count",
								   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("stringArray2",
	    PageContext.SESSION_SCOPE);
		pageContext.removeAttribute("stringArray3Count",
	    PageContext.APPLICATION_SCOPE);
		}

		
	

	public void teststringArray3() throws Exception
	{
//		process the target JSP
		 pageContext.include(TARGET_PAGE);

		 // check the result(s)
		 StringArray str1 = (StringArray)pageContext.getAttribute("stringArray1",
									PageContext.PAGE_SCOPE);
		 StringArray str2 = (StringArray)pageContext.getAttribute("stringArray2",
									PageContext.SESSION_SCOPE);
		 String str3 = (String)pageContext.getAttribute("stringArray3Count",
									PageContext.APPLICATION_SCOPE);

		 //assertNull("How did you set the attribute of this page-context?",str1);
		 //only one element is aded to stringArray1 so its cout should be 1 so compared with 1
		 assertEquals("stringArray1",1,str1.count());
		 assertEquals("stringArray3Count", str3);

//		 System.out.println("Value is "+session.getServletContext().getAttribute("stringArray3Count"));
//		 assertSame("This should be same","1",session.getServletContext().getAttribute("stringArray3Count"));
//		
	}

}


But it Shows result for test case as null. Dont knowe why?
CAn you tell me what may be the problem ?

----- Original Message -----
From: "Vincent Massol" <vmassol@pivolis.com>
Date: Tue, 10 Feb 2004 15:04:12 +0100
To: "'Cactus Users List'" <cactus-user@jakarta.apache.org>
Subject: RE: Assesrtion Failed Error while JSP Testing

> Hi Dinesh,
> 
> You need to call this JSP somewhere in your test! :-)
> 
> -Vincent
> 
> > -----Original Message-----
> > From: Dinesh N [mailto:gnavsupe@india.com]
> > Sent: 10 February 2004 08:10
> > To: Cactus Users List
> > Subject: RE: Assesrtion Failed Error while JSP Testing
> > 
> > 
> > Hi Vincent,
> >           I will give you  my JSP which i want to test.
> > 
> > It is:
> > 
> >   <%@page import="com.arraytest.StringArray"%>
> > 
> > <%
> >   StringArray stringArray1 = new StringArray();
> >   stringArray1.add("itemForStringArray1");
> >   pageContext.setAttribute("stringArray1",
> >   stringArray1);
> > StringArray stringArray2 = new StringArray();
> > stringArray2.add("itemForStringArray2");
> > stringArray2.delete(0);
> > pageContext.setAttribute("stringArray2", stringArray2,
> > PageContext.SESSION_SCOPE);
> > StringArray stringArray3 = new StringArray();
> > stringArray3.add("itemForStringArray3");
> > pageContext.setAttribute("stringArray3Count",
> > String.valueOf(stringArray3.count()), PageContext.APPLICATION_SCOPE);
> > %>
> > 
> > This is JSP wich is doing some StringList Inser add delete operation.
> And
> > this "itemForStringArray3Count" and infact all others also i want to
> > access in TestClass which i mentioned in previous mail.
> > 
> > In this TestStringArray3() -- I want to test the correct value is
> returned
> > and asdet in JSP.
> > Thats all. Its just preliminary level.
> > 
> > If you could help me i will be very happy.
> > 
> > ----- Original Message -----
> > From: "Vincent Massol" <vmassol@pivolis.com>
> > Date: Mon, 9 Feb 2004 21:09:19 +0100
> > To: "'Cactus Users List'" <cactus-user@jakarta.apache.org>
> > Subject: RE: Assesrtion Failed Error while JSP Testing
> > 
> > > Hi Dinesh,
> > >
> > > Can you please show us your test case? The teststringArray3() method
> > > does not call anything that sets your stringArrya3Count attribute in
> the
> > > servlet context. Where is that set?
> > >
> > > Thanks
> > > -Vincent
> > >
> > > > -----Original Message-----
> > > > From: Dinesh N [mailto:gnavsupe@india.com]
> > > > Sent: 09 February 2004 08:06
> > > > To: cactus-user@jakarta.apache.org
> > > > Subject: Assesrtion Failed Error while JSP Testing
> > > >
> > > > Hi Friends,
> > > >     I am new to this technology. I am testing a jsp page which do
> some
> > > > operation on java compiled class.
> > > >
> > > > Now i have created some test case like:
> > > >
> > > > public void teststringArray3()
> > > > 	{
> > > > 		 System.out.println("Value is
> > > > "+session.getServletContext().getAttribute("stringArray3Count"));
> > > > 		 assertSame("This should be
> > > >
> > >
> same","1",session.getServletContext().getAttribute("stringArray3Count"))
> > > ;
> > > >
> > > > 	}
> > > >
> > > > ****stringArray3Count is an veriable which is set to proper value
> in
> > > JSP
> > > > Page.
> > > >
> > > > But i am not able to access the Value in Test class. It is
> returning
> > > NULL.
> > > > CAn anybody help me...?
> > > > Please let me know where is problem in my Code or what..?
> > > >
> > > > I also tried with. pageContext.include("/test.jsp");
> > > > and then pageContext.getAttribute(stringArray3Count());
> > > > But still it returns null.
> > > >
> > > > After running the Result is:
> > > >
> > > >    This should be same expected same:<1> was not:<null>
> > > >
> > > > junit.framework.AssertionFailedError: This should be same expected
> > > > same:<1> was not:<null>
> > > > at:
> > > > arraytest.StringArrayJSPTest.teststringArray3
> > > >
> > > > CAn anybody tell me what is the problem ?
> > > >
> > > > Thanking You,
> > > >
> > > > Ragards,
> > > > Dinesh N.
> > > >
> > > > --
> > > > India.com free e-mail - www.india.com.
> > > > Check out our value-added Premium features, such as an extra 20MB
> for
> > > mail
> > > > storage, POP3, e-mail forwarding, and ads-free mailboxes!
> > > >
> > > > Powered by Outblaze
> > > >
> > > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail:
> cactus-user-help@jakarta.apache.org
> > >
> > >
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> > >
> > 
> > 
> > 
> > Thanking You,
> > 
> > Ragards,
> > Dinesh N.
> > 
> > --
> > India.com free e-mail - www.india.com.
> > Check out our value-added Premium features, such as an extra 20MB for
> mail
> > storage, POP3, e-mail forwarding, and ads-free mailboxes!
> > 
> > Powered by Outblaze
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> 



Thanking You,

Ragards,
Dinesh N.

-- 
India.com free e-mail - www.india.com. 
Check out our value-added Premium features, such as an extra 20MB for mail storage, POP3,
e-mail forwarding, and ads-free mailboxes!

Powered by Outblaze

Mime
View raw message