我刚刚用jboss编写arquillian测试并在此处记录:
http://czetsuya-tech.blogspot.com/2014/11/rest-testing-with-arquillian-in-jboss.html#.VGQkCvmUeSk
但是我有一个问题,我们的其他网络服务使用过滤器保护:
@WSSecured
@Provider
public class RESTSecurityInterceptor implements ContainerRequestFilter,
ExceptionMapper<Exception> { //... }
如何在调用arquillian rest easy资源时添加用户名/密码令牌?
@RunAsClient
@Test
public void testCreate(
@ArquillianResteasyResource("api/rest") CountryWs countryWs) { }
答案 0 :(得分:1)
此问题的解决方案是创建一个生产者,该生产者将生成默认用户并将此类添加到测试战争中:
@Singleton
@Startup
public class DefaultUserProducer {
@Inject
private Logger log;
@Inject
private UserService userService;
private User currentUser;
@PostConstruct
public void init() {
try {
currentUser = userService.login("username", "password");
} catch (LoginException e) {
log.error("Failed to login. {}", e.getMessage());
}
}
@Produces
@RSUser
public User getCurrentUser() {
return currentUser;
}
}