[Httpunit-develop] Problem finding resource bundle when running servlet in ServletRunner
Brought to you by:
russgold
|
From: Simmons, J. D. <jim...@wa...> - 2012-03-14 19:05:06
|
I am trying to test our servlet development framework with ServletUnit. I am using the code below as a starting point:
package walgreens.test.bounce;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import javax.servlet.ServletException;
import org.xml.sax.SAXException;
import com.meterware.httpunit.PostMethodWebRequest;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import com.meterware.servletunit.InvocationContext;
import com.meterware.servletunit.ServletRunner;
import com.meterware.servletunit.ServletUnitClient;
public class TestValidation {
@org.junit.Test
public void testRequiredField() {
File webXml = new File("WebContent/WEB-INF/web.xml");
try {
ServletRunner sr = new ServletRunner(webXml, "/bOunceFrameworkTest");
ServletUnitClient sc = sr.newClient();
WebRequest request = new PostMethodWebRequest(
"http://test.walgreens.com/bOunceFrameworkTest/StandardProxy");
InvocationContext ic = sc.newInvocation(request);
ic.service();
WebResponse response = ic.getServletResponse();
System.out.println(response.getText());
assertTrue(response.getTitle()
.equals("Test Server Side Validation"));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ServletException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Now this code runs our StandardProxy servlet just fine *except* for one thing. This code in the init() method of the servlet:
applicationResources = ResourceBundle
.getBundle("/ApplicationResources");
*cannot* find the file named ApplicationResources.properties. When I run the application under WebSphere or Tomcat there is no such problem and never has been. The file in question is in the root of the source directory for the application, just as it would be in Struts 2. It is only when using ServletRunner that there is a problem.
I have tried copying the file to various places (root of the project, root of WebContent) but the file just will not be found. Is there some way to work around this problem?
James Simmons
|