我有一个项目,我们使用JNDI来查询DNS记录。这个项目本身工作得很好,但是我找不到一种简单而独立的方法来使用jUnit测试依赖于JNDI的组件。
该代码远不是火箭科学,看起来非常像典型的普通JNDI DNS请求。
目前,我将测试单元指向公共DNS记录(A,MX,TXT记录),但这是不可行的。
...
Hashtable env = new Hashtable();
env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
env.put("com.sun.jndi.dns.timeout.initial", timeOut);
env.put("com.sun.jndi.dns.timeout.retries", retries);
env.put("java.naming.provider.url", dns:);
}
Attributes attrs;
try {
DirContext ictx = new InitialDirContext(env);
attrs = ictx.getAttributes(queryInput, new String[]{queryType});
return attrs;
} catch ( NameNotFoundException e) {
getLogger().debug("Resolution for domain {} failed due to {}", new Object[]{queryInput, e});
attrs = new BasicAttributes(queryType, "NXDOMAIN",true);
return attrs;有没有办法将TXT和A响应注入到JNDI中?
https://stackoverflow.com/questions/38423134
复制相似问题