我使用IBM Rational Application Developer 9.0创建了一个简单的portlet(JSR-286)。我想写一个junit测试用例。我已按照链接中提供的步骤进行操作:http://www.ibm.com/developerworks/opensource/library/wa-portletunit/index.html 但我无法成功,获得空指针异常。 以下是代码段:
public void testdoViewOfGenericBookmarkWithPortletUnit() throws Exception
{
PortletRunner runner = getPortletRunner();
PortletUser user = new GenericPortletUser();
runner.setUser(user);
WebResponse bookmarkResponse=runner.getResponse();
WebLink[] links=bookmarkResponse.getLinks();
assertEquals(links.length,1);
assertEquals(links[0].getText(),"IBM");
}
private PortletRunner getPortletRunner() throws Exception {
File webInfDir=new File("/home/akshay/rad_workspace/MyPortal/WebContent");
Class portletClass = MyPortalPortlet.class;
PortletRunner runner = PortletRunner.createPortletRunner(portletClass,webInfDir,
"MyPortal");
return runner;
}
问题在于我们在getPortletRunner方法中获取PortletRunner实例,错误堆栈跟踪如下所示
java.lang.NullPointerException
at org.apache.pluto.portalImpl.services.config.Config.getParameters(Config.java:40)
at net.sf.portletunit.servlet.PortletUnitServlet.init(PortletUnitServlet.java:115)
at com.meterware.servletunit.WebApplication$ServletConfiguration.getServlet(WebApplication.java:587)
at com.meterware.servletunit.WebApplication$ServletRequestImpl.getServlet(WebApplication.java:775)
at com.meterware.servletunit.InvocationContextImpl$ExecutionContext.getServlet(InvocationContextImpl.java:251)
at com.meterware.servletunit.InvocationContextImpl.getServlet(InvocationContextImpl.java:89)
at net.sf.portletunit.PortletRunner.initializePluto(PortletRunner.java:258)
at net.sf.portletunit.PortletRunner.<init>(PortletRunner.java:91)
at net.sf.portletunit.PortletRunner.createPortletRunner(PortletRunner.java:296)
at com.ibm.portletunit.bookmarktest.test.BookmarkExampletest.getPortletRunner(BookmarkExampletest.java:92)
at com.ibm.portletunit.bookmarktest.test.BookmarkExampletest.testdoViewOfGenericBookmarkWithPortletUnit(BookmarkExampletest.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:613)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
拜托,有谁可以帮助我。我怀疑portletunit不支持JSR-286。 还有哪些其他库可用于使用IBM Rational Application Developer 9.0构建portlet(JSR-286)的junit测试