Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I set value in my test case method for testing Action Class?

 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am testing my application using JUNIT and my application is based on struts.
I am getting an NullPointerException ,while testing using JUNIT

Code snippet from PAAction.javs

NullPointerException is due to the following line of code:
StrPageSize = getResources (req).getMessage ("pricing.pageSize");

I am setting the page size using properties file (ApplicationResources.properties) which I have stored in the dcomm-ui/JavaSource/com/sbc/dcomm/ui/resources /

Code snippet from ApplicationResources.properties
pricing.pageSize=5

If web server executes action class for the application, it will not throw any exception; it takes value from the properties file and executes the method properly.

How do I set this value in my test case method for testing it using JUNIT?
How do I fix this problem by setting pagesize in my test case method?


My Test case method is as follows:
public void testApplyChanges()
{
UserProfile profile=SessionDAOFactory.getUserProfile(request);
setRequestPathInfo("/pricingMain");
PAActionForm nPopUpForm = new PAActionForm();
setActionForm(nPopUpForm);
addRequestParameter("method","applyChanges");
addRequestParameter("id","2863");
addRequestParameter("cartSiteId","-1");
addRequestParameter("page","1");



nPopUpForm.setEditableField("textCostPrice");
nPopUpForm.setEditValues("2320.0,2320.0,352.0,352.0,0.0");
nPopUpForm.setPromoCode("12");
nPopUpForm.setPromoDesc("2356");
nPopUpForm.setId(2863);
nPopUpForm.setCartSiteId("-1");
actionPerform();
verifyForward("success");
verifyForwardPath("/cart/pa/paMain.jsp");
verifyNoActionErrors();


}

Expecting your solution ..
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thomas,
It sounds like the test cannot find resource. It it in the same project or a different one? If it's a different one, it it in the classpath?
 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's in the same project...
 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If web server executes action class for the application, it will not throw any exception; it takes value from the properties file and executes the method properly


I am able to get the page size from properties while I am using the same application from browser window.Web Server takes value from property file and executes for the application.

JUNIT is not able to take the value from the properties file and execute it for unit testing.It throws NullPonterException.
 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's obvious that JUNIT is not able to find resource file.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First thing is to double check that there is a file in WEB-INF/classes/com/sbc/dcomm/ui/resources/ApplicationResources.properties. If not, the file can't be found because it isn't there.

Otherwise, it is a classpath issue. What IDE are you using? Are you running the JUnit test through Ant, the IDE or the command line?
 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using WSAD 5.1.2 and it comes with JUNIT tool.I am testing my application using this tool.

My application,server,IDE,junit are on the same location.

How do I set classpath SPECIFICALLY for properties file ?
 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the IDE provided by WSAD 5.1.2 for JUNIT..
 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dcomm-ui\JavaSource
dcomm-ui\JUnit are on the path.These paths are mentioned in JAVA BUILD PATH.
Could you please tell me ,do I need to set class path for properties for seperately?

The properties file is placed on \dcomm-ui\WebContent\WEB-INF\classes\com\sbc\dcomm\ui\resources\.

While running the application,how does it pick up this file and execute?
This problem arises only when we test it using JUNIT.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From a WSAD point of view, everything should be fine since it is the same project. One more question: are you using any tools like Cactus or just plain junit?
 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am extending the class named CactusStrutsTestCase and this comes along with WSAD 5.1.2

Eg : public class PAActionTest extends CactusStrutsTestCase
 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No Help!!!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Out of ideas. Sorry! You might want to try posting the classpart part of this question in WebSphere. It does look like a configuration issue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic