用 cactus 测试 ejb,如何运行测试代码?

JcLing 2003-10-20 06:23:27
我参照 cactus的文档,写好测试代码代码后,编译也通过了,
ejb也正确的部署,并且可以正常的运行,但是,不知道如何运行 测试代码?

cactus的文档上面说这样来运行:
junit.swingui.TestRunner.main [test case class]

我在命令行输入:
junit.swingui.TestRunner.main ConverterTest

报错:
'junit.swingui.TestRunner.main' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

我这样来测试:
java junit.swingui.TestRunner ConverterTest

运行报错: Failure !!!

cactus的文档上还说的实在没看懂,谁来教教我?

---------------------------------------------------------
cactus 文档上关于如何编写测试代码:
(http://jakarta.apache.org/cactus/writing/howto_ejb_j2eeri.html)

cactus 文档上关于如何运行测试代码:
http://jakarta.apache.org/cactus/integration/index.html

---------------------------------------------------------
ejb 和 cactus 测试代码:
//ConverterTest.java --> 测试代码
//Converter.java --> ejb 的 Remote 接口
//ConverterHome.java --> ejb 的 Home 的接口
//ConverterBean.java --> ejb 的具体实现

//测试代码:ConverterTest.java
import javax.naming.*;
import javax.rmi.*;
import junit.framework.*;
import java.math.*;
import org.apache.cactus.*;

public class ConverterTest extends ServletTestCase
{
private Converter converter;

public ConverterTest(String name)
{
super(name);
}

public static Test suite()
{
return new TestSuite(ConverterTest.class);
}

public void setUp()
{
try
{
Context ctx = new InitialContext();
ConverterHome home = (ConverterHome)PortableRemoteObject.narrow(ctx.lookup("java:comp/ejb/Converter"), ConverterHome.class);
this.converter = home.create();
}
catch ( Exception e )
{};

}

public void testConvert() throws Exception
{
BigDecimal dollar = converter.dollarToYen(new BigDecimal(100.00));
assertEquals("dollar", 1.0, dollar.doubleValue(), 0.01);
}
}

//Converter.java --> ejb 的Remote 接口

import javax.ejb.EJBObject;
import java.rmi.RemoteException;
import java.math.*;
import java.lang.*;

public interface Converter extends EJBObject
{
public BigDecimal dollarToYen(BigDecimal dollars) throws RemoteException;
public BigDecimal yenToEuro(BigDecimal yen) throws RemoteException;
}

//ConverterHome.java --> ejb 的Home 接口
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;

public interface ConverterHome extends EJBHome
{
Converter create() throws RemoteException, CreateException;
}

//ConverterBean.java --> ejb 的具体实现
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.math.*;

public class ConverterBean implements SessionBean
{
BigDecimal yenRate = new BigDecimal("2.0000");
BigDecimal euroRate = new BigDecimal("0.0002");

public BigDecimal dollarToYen(BigDecimal dollars)
{
BigDecimal result = dollars.multiply(yenRate);
return result.setScale(2,BigDecimal.ROUND_UP);
}

public BigDecimal yenToEuro(BigDecimal yen) {

BigDecimal result = yen.multiply(euroRate);
return result.setScale(2,BigDecimal.ROUND_UP);
}

public ConverterBean() {}
public void ejbCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}

}

...全文
143 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
JcLing 2003-10-21
  • 打赏
  • 举报
回复
??
JcLing 2003-10-20
  • 打赏
  • 举报
回复
?

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧