【发布时间】:2011-01-31 16:29:45
【问题描述】:
我有一个项目首先使用 EJB 2 编写,然后迁移到 Spring,最后迁移到 JBoss Seam 2.2.0(这是我正在处理的情况)。它将在 Tomcat 上运行,但现在它在 JBoss 4.2 上执行(尽管我相信这个事实无关紧要)。我的任务是运行上次迁移之前编写的所有测试。
经过大量的谷歌搜索,我写了这样的东西:
public class CustomUserDAOTest extends SeamTest {
@Test
public void f() throws Exception {
new ComponentTest() {
@Override
protected void testComponents() throws Exception {
CustomUserDAO customUserDAO = (CustomUserDAO) Component.getInstance(CustomUserDAOBean.class);
List<CustomUser> users = customUserDAO.getAll();
assertNotNull(users);
}
}.run();
}
}
这很好,因为我设法获得了 CustomUserDAOBean 的实例及其依赖项,但是当我运行测试时,我遇到了另一个问题:
java.lang.RuntimeException: exception invoking: getTransaction
at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:154)
at org.jboss.seam.Component.callComponentMethod(Component.java:2249)
at org.jboss.seam.Component.unwrap(Component.java:2275)
at org.jboss.seam.Component.getInstance(Component.java:2041)
[OMITTED]
at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
at br.com.visent.sicorp.server.dao.impl.CustomUserDAOBean_$$_javassist_seam_1.listAll(CustomUserDAOBean_$$_javassist_seam_1.java)
at br.com.visent.sicorp.server.dao.test.CustomUserDAOTest$1.testComponents(CustomUserDAOTest.java:24)
at org.jboss.seam.mock.AbstractSeamTest$ComponentTest.run(AbstractSeamTest.java:162)
[OMITTED]
at org.testng.TestNG.run(TestNG.java:856)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:110)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:174)
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
[OMITTED]
at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
... 45 more
我在网上找到了一些关于它的 cmets,但没有解决方案。我该怎么办?有人有什么想法吗?
提前致谢!
【问题讨论】:
-
你为什么不直接创建一个 seam-gen 项目,然后对比你的项目,看看是否有任何设置或你做错了什么?
-
Shervin,您的建议非常好!我在下面回答我自己的问题。谢谢!
标签: java seam integration-testing testng