【发布时间】:2009-11-09 00:56:31
【问题描述】:
这是我的previous question 的后续问题。
我正在尝试为我的 ServiceLocator 类编写测试用例,但它给了我以下错误:
com/iplanet/ias/admin/common/ASException
java.lang.NoClassDefFoundError: com/iplanet/ias/admin/common/ASException
at java.lang.ClassLoader.defineClass1(Native Method)
我的测试用例:
public void testServiceLocator () throws UivException, NamingException
{
DataSource ds = ServiceLocator.getInstance().getDataSource("jdbc/RSRC/my/mydb");
//I have not put any assert statements because i know above line is failing
}
上述代码在getInstance() 方法上失败,如下所示:
static public ServiceLocator getInstance() throws UivException {
try {
if (me == null) {
synchronized(ServiceLocator.class) {
me = new ServiceLocator();
}
}
return me;
}
catch (UivException e) {
throw new UivException(ErrorCode.SERVICE_LOCATOR_ERROR,
ErrorCode.SERVICE_LOCATOR_LOOKUP_ERROR,
e.getMessage());
}
}
我知道这个ServiceLocator 工作正常,因为当我从前端测试我的应用程序时没有问题。我写这个测试用例的唯一原因是因为我想测试我的DAO。而我要测试我的 DAO ServiceLocator 必须工作(来自 JUnit)。
我不知道如何处理错误消息。有没有人想建议一些我可以尝试但希望能奏效的东西?
编辑:ServiceLocator 构造函数
private ServiceLocator() throws UivException {
try {
ic = new InitialContext();
// System.out.println("Created the Initial Context");
cache = Collections.synchronizedMap(new HashMap());
}
catch (NamingException ne) {
throw new UivException(ErrorCode.SERVICE_LOCATOR_ERROR,
0, ne.getMessage());
}
catch (NullPointerException e) {
throw new UivException(ErrorCode.SERVICE_LOCATOR_ERROR,
0, e.getMessage());
}
}
【问题讨论】:
标签: java junit jndi service-locator