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 JUnit and Cactus using strutstestCase Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "JUnit and Cactus using strutstestCase" Watch "JUnit and Cactus using strutstestCase" New topic
Author

JUnit and Cactus using strutstestCase

Steve P Holmes
Greenhorn

Joined: Aug 19, 2004
Posts: 3
Hopefully there are some experts there. I've been working on this for days and am so frustrated I'm about to quit. Currently it is failing within the action class and throwing an exception. Please let me know what additional info I can give to make this more clear. Here is my test case:

package gov.wapa.snr.pbs.actionTests;

import servletunit.struts.CactusStrutsTestCase;
import gov.wapa.snr.pbs.actionForms.TypeTablesForm;

import java.util.ArrayList;

import org.apache.cactus.client.authentication.FormAuthentication;
import org.apache.cactus.WebRequest;

/**
* User: Holmes
* Date: Aug 13, 2004
* Time: 12:26:48 PM
* All software and source code property of WAPA/DOE
*/

public class TestTypeTablesAction extends CactusStrutsTestCase {

public void beginFormAuthentication(WebRequest theRequest) throws Exception {
theRequest.setAuthentication(new FormAuthentication("weblogic", "weblogic"));
}

public void testFormAuthentication() {
assertEquals("weblogic", request.getUserPrincipal().getName());
assertEquals("weblogic", request.getRemoteUser());
assertTrue("User not in 'PBSadmin' role", request.isUserInRole("PBSadmin"));
}

public void beginNoTypeTable(WebRequest theRequest) {

theRequest.setAuthentication(new FormAuthentication("weblogic", "weblogic"));
theRequest.addParameter("Menu2Load", "TabbedHome");
theRequest.addParameter("menuSelected2", "-1");
theRequest.addParameter("menuSelected", "3");
}

public void testNoTypeTable() {

/*setRequestPathInfo("/welcome.do");
actionPerform();*/

setConfigFile("/WEB-INF/struts-config.xml");
setRequestPathInfo("/systemTables_other.do");
actionPerform();
System.out.println("Actual forward in NoTypeTable: " + getActualForward());
TypeTablesForm form = (TypeTablesForm) getActionForm();
assertNotNull("typeTablesForm is null", form);
ArrayList methodNames = form.getSystemDelegateMethodNames();
assertNotNull("Method names in Form Bean is null", methodNames);
verifyTilesForward("failure", "systemTables_other");
verifyNoActionErrors();
}

public void beginWithTypeTable(WebRequest theRequest) {

theRequest.setAuthentication(new FormAuthentication("weblogic", "weblogic"));
theRequest.addParameter("Menu2Load", "TabbedHome");
theRequest.addParameter("menuSelected2", "-1");
theRequest.addParameter("menuSelected", "3");
}

public void testWithTypeTable() {

setConfigFile("/WEB-INF/struts-config.xml");
setRequestPathInfo("/systemTables_other.do");
addRequestParameter("typeTable", "AddressTypes");
actionPerform();
System.out.println("Actual forward in WithTypeTable: " + getActualForward());
TypeTablesForm form = (TypeTablesForm) getActionForm();
;
assertNotNull("typeTablesForm is null", form);
ArrayList methodNames = form.getSystemDelegateMethodNames();
assertNotNull("Method names in Form Bean is null", methodNames);
assertNotNull("typeTable is Null", form.getTypeTable());
assertNotNull("getAlign is Null", form.getAlign());
assertNotNull("ColumnNameOne is null", form.getColumnNameOne());
assertNotNull("columnNameTwo is null", form.getColumnNameTwo());
assertNotNull("columnOne is null", form.getColumnOne());
assertNotNull("columnTwo is null", form.getColumnTwo());
assertNotNull("tableType is null", form.getTypeTable());
verifyTilesForward("success", "systemTables_other");
verifyNoActionErrors();
}
}
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Hi Steve,

The exception stack trace would be nice (along with some kind of a pointer to which line in your test class the exception points to).


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Steve P Holmes
Greenhorn

Joined: Aug 19, 2004
Posts: 3
I figured out the problem. Turns out there was NOTHING wrong with my configuration and the tests were running fine. They were failing where they should have been there were some actual errors in the code.

But you could help me with something else. I can't seem to get the server side logging working. The client seems to be working fine but I'm getting:

log4j:WARN No appenders could be found for logger (org.apache.cactus.internal.server.ServerTestCaseCaller).
log4j:WARN Please initialize the log4j system properly.

I've got the logging_server.properties in the classes directory of WEB-INF on the server. Any thoughts?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Steve P Holmes:
I've got the logging_server.properties in the classes directory of WEB-INF on the server. Any thoughts?
Have you told your logging framework that it should read its configuration from WEB-INF/logging_server.properties?
Steve P Holmes
Greenhorn

Joined: Aug 19, 2004
Posts: 3
How do I do that?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Steve P Holmes:
How do I do that?

Try starting the server with -Dlog4j.configuration=/opt/foo/bar/WEB-INF/logging_server.properties
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Or, you could use a servlet to initialize the Log4J properties as described in the Log4J manual (search for "Initialization servlet" close to the bottom of the page).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JUnit and Cactus using strutstestCase