You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by senthu <se...@gmail.com> on 2010/06/16 08:06:29 UTC

Unable to inject @context from junit test case

Hi,

I am working on a API to expose service using CXF. The strange problem
facing here is, when we deploy as a web-app the UriInfo getting injected and
everything is working fine.

When we run the Junit test cases, UriBuilder throws NullPointerException as
the UriInfo holds null. It happens only when we keep the @Context UriInfo in
an abstract class field or a bean property.

The unit test cases work fine when the UriInfo is been given as a method
param to the APIs we expose.

In Junit test case, we are instantiating JAXRSServerFactoryBean and adding
the resource provider as the service interface. Please help getting through
this issue.

Thanks,
SK
-- 
View this message in context: http://old.nabble.com/Unable-to-inject-%40context-from-junit-test-case-tp28899148p28899148.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Unable to inject @context from junit test case

Posted by DonDiego761 <ro...@capgemini.com>.
Hi,

I have the same problem with my JUnit test case. The uriInfo variable is
null. And I don't understand the solution of Sergey. Could you explain with
details the solution please?

My config:
The interface IRestService et the implementation RestServiceImpl where
uriInfo is initialized by the annotation @Context.
And I use JAXRSServerFactoryBean object to start my rest server.

Regards,
-- 
View this message in context: http://cxf.547215.n5.nabble.com/Unable-to-inject-context-from-junit-test-case-tp567410p3265454.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Unable to inject @context from junit test case

Posted by Sergey Beryozkin <sb...@gmail.com>.
Looks like similar to what Jason has reported.
here is my theory : Spring uses JDK proxies but CXF SpringAopHelper is not
initialized in the test case so may be the test class should just implement
an interface with a method

@Context
public void setUriInfo(UriInfo ui);

cheers, Sergey

On Wed, Jun 16, 2010 at 7:03 PM, Daniel Kulp <dk...@apache.org> wrote:

>
> Is this something you can create a small test case for?  That would be a
> help.
>
> Dan
>
> On Wednesday 16 June 2010 2:06:29 am senthu wrote:
> > Hi,
> >
> > I am working on a API to expose service using CXF. The strange problem
> > facing here is, when we deploy as a web-app the UriInfo getting injected
> > and everything is working fine.
> >
> > When we run the Junit test cases, UriBuilder throws NullPointerException
> as
> > the UriInfo holds null. It happens only when we keep the @Context UriInfo
> > in an abstract class field or a bean property.
> >
> > The unit test cases work fine when the UriInfo is been given as a method
> > param to the APIs we expose.
> >
> > In Junit test case, we are instantiating JAXRSServerFactoryBean and
> adding
> > the resource provider as the service interface. Please help getting
> through
> > this issue.
> >
> > Thanks,
> > SK
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
>

Re: Unable to inject @context from junit test case

Posted by Daniel Kulp <dk...@apache.org>.
Is this something you can create a small test case for?  That would be a help.

Dan

On Wednesday 16 June 2010 2:06:29 am senthu wrote:
> Hi,
> 
> I am working on a API to expose service using CXF. The strange problem
> facing here is, when we deploy as a web-app the UriInfo getting injected
> and everything is working fine.
> 
> When we run the Junit test cases, UriBuilder throws NullPointerException as
> the UriInfo holds null. It happens only when we keep the @Context UriInfo
> in an abstract class field or a bean property.
> 
> The unit test cases work fine when the UriInfo is been given as a method
> param to the APIs we expose.
> 
> In Junit test case, we are instantiating JAXRSServerFactoryBean and adding
> the resource provider as the service interface. Please help getting through
> this issue.
> 
> Thanks,
> SK

-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog