我创建了一个 REST webservice,它使用UriInfo:
class Endpoint implements Resource {
@Context
private UriInfo uriInfo;
@Override
public Response doMagic() {
// do magic
}
}
部署到我的容器中,这很好用,但我也有一个 Arquillian 测试:
@Test
public void test(@ArquillianResteasyResource Resource api) throws Exception {
try (final Response response = api.doMagic()) {
// test magic
}
}
抛出以下异常:
javax.ejb.EJBException: org.jboss.resteasy.spi.LoggableFailure: RESTEASY003880: Unable to find contextual data of type: javax.ws.rs.core.UriInfo
at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:186)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:330)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:238)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:509)
例外是有道理的,Arquillian 测试不测试实际的 REST web 服务,而是测试 bean。所以当然没有 webservice 上下文,其中包括UriInfo.
我想要解决这个问题,我必须以UriInfo某种方式嘲笑。但是我不知道如何模拟注入了@Context. 我怎么做?
一只萌萌小番薯
相关分类