On 29/11/2013 09:04, Jim Talbut wrote:
Hi,

In my JUnit tests I have two Spring-based tests that declare JAX-RS
providers (on different local ports)

The tests both work when run independently, but when I run them both
together (which will mean Spring keeps the contexts around after the
test finishes) I get this error:
08:58:12.285 [qtp842577946-28] ERROR u.c.s.s.a.s.CatchAllExceptionMapper
- Exception caught:
java.lang.NullPointerException: null
     at
org.apache.cxf.jaxrs.impl.tl.ThreadLocalProviders.getContextResolver(ThreadLocalProviders.java:50)
~[cxf-rt-frontend-jaxrs-2.7.7.jar:2.7.7]
     at
com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider._locateMapperViaProvider(JacksonJsonProvider.java:203)

Ahah!

Why do I always spend ages looking for a solution then find it soon after mailing this group? :) I found the answer courtesy of this: http://camel.465427.n5.nabble.com/Problem-using-unit-test-spring-cxf-td5725603.html

In my case clearing the bus worked sometimes, but some tests still failed, so I set it to the correct bus too. Putting the following in the base class that all the tests derive from makes the problem go away:

    @Autowired
    protected Bus cxf;

    @Before
    public void prepare() {
        BusFactory.setDefaultBus(cxf);
    }

    @After
    public void cleanup() {
        BusFactory.setDefaultBus(null);
    }

Jim

Reply via email to