File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes How do I set value in my test case method for testing Action Class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "How do I set value in my test case method for testing Action Class?" Watch "How do I set value in my test case method for testing Action Class?" New topic
Author

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

thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29249
    
139

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?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
It's in the same project...
thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
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

Joined: Feb 01, 2003
Posts: 207
It's obvious that JUNIT is not able to find resource file.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29249
    
139

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

Joined: Feb 01, 2003
Posts: 207
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

Joined: Feb 01, 2003
Posts: 207
I am using the IDE provided by WSAD 5.1.2 for JUNIT..
thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29249
    
139

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

Joined: Feb 01, 2003
Posts: 207
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

Joined: Feb 01, 2003
Posts: 207
No Help!!!
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29249
    
139

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I set value in my test case method for testing Action Class?
 
Similar Threads
in Eclipse - web.xml not found
struts test case problem
JUnit problem with addRequestParameter . HELP * * *
junit Error - web.xml was not found
testing Action class through StrutsTestCase