I have an interface :
@Produces(MediaType.APPLICATION_XML)
public interface IService {
@GET
@Path("{id}")
Response getObjects(@PathParam(value = "id") final String id);
}
Its implementation:
public class ServiceImpl {
@Context
private UriInfo uriInfo = null;
@Override
public final Response getObjects(@PathParam(value = "id") final String
id)
{
.....
}
}
And in my Junit test case :
public class Test {
@Test
public void getElementsNominal() {
startRestServer(...);
.....
}
private Server startRestServer(final String urlServeur, final String
restServicePath) {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(IService.class);
sf.getInInterceptors().add(new LoggingInInterceptor());
sf.getOutInterceptors().add(new LoggingOutInterceptor());
ServiceImpl service = new ServiceImpl ();
sf.setResourceProvider(IService.class, new
SingletonResourceProvider(service));
sf.setAddress(urlServeur + restServicePath);
Server server = sf.create();
LOGGER.info("Rest Server started @ " + sf.getAddress());
return server;
}
}
I used JUnit 4 and cxf v2.2.6.
The problem is the variable uriInfo (in the ServiceImpl class) is null when
I call a service via my JUnit test.
I hope I was clear.
--
View this message in context:
http://cxf.547215.n5.nabble.com/Unable-to-inject-context-from-junit-test-case-tp3269105p3269186.html
Sent from the cxf-user mailing list archive at Nabble.com.