You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Rice Yeh <ri...@gmail.com> on 2010/07/23 04:08:20 UTC
Is there easy way to test JAX-RS?
Hi,
I move my implementation of JAX-RS from RestEasy to CXF. One feature in
RestEasy I like is that it provides a very simple way to test my resources.
Its test code is like below:
this.dispatcher = MockDispatcherFactory.createDispatcher();
this.dispatcher.getRegistry().addResourceFactory(new
POJOResourceFactory(organization.class), "hr");
this.dispatcher.getRegistry().addResourceFactory(new
POJOResourceFactory(bureaucracy.class), "hr");
MockHttpRequest request = MockHttpRequest.get("/hr/bureaucracy/" +
oid(b) + "/organization/" + oid(finance) +"/children");
MockHttpResponse response = new MockHttpResponse();
this.dispatcher.invoke(request, response);
System.out.println(response.getContentAsString());
assert response.getStatus() == 200;
That is, I don't need to startup http (jetty) server. All (server and
client) are done in memory and in one thread. Is there similar way to do
this in CXF?
Regards,
Rice
Re: Is there easy way to test JAX-RS?
Posted by Rice Yeh <ri...@gmail.com>.
Yes, this is the way I am doing now. However, what I want is NO need to have
a http server started but directly call a dispatcher to run my resources
like in resteasy. In CXF's JAX-WS, we can use local transport. However,
local transport is not supported by CXF's JAX-RS.
Regards,
Rice
On Fri, Jul 23, 2010 at 1:15 PM, KARR, DAVID (ATTSI) <dk...@att.com> wrote:
> > -----Original Message-----
> > From: Rice Yeh [mailto:riceyeh@gmail.com]
> > Sent: Thursday, July 22, 2010 7:08 PM
> > To: users@cxf.apache.org
> > Subject: Is there easy way to test JAX-RS?
> >
> > Hi,
> > I move my implementation of JAX-RS from RestEasy to CXF. One feature
> > in
> > RestEasy I like is that it provides a very simple way to test my
> > resources.
> > Its test code is like below:
> >
> > this.dispatcher = MockDispatcherFactory.createDispatcher();
> > this.dispatcher.getRegistry().addResourceFactory(new
> > POJOResourceFactory(organization.class), "hr");
> > this.dispatcher.getRegistry().addResourceFactory(new
> > POJOResourceFactory(bureaucracy.class), "hr");
> >
> > MockHttpRequest request =
> > MockHttpRequest.get("/hr/bureaucracy/" +
> > oid(b) + "/organization/" + oid(finance) +"/children");
> > MockHttpResponse response = new MockHttpResponse();
> > this.dispatcher.invoke(request, response);
> > System.out.println(response.getContentAsString());
> > assert response.getStatus() == 200;
> >
> > That is, I don't need to startup http (jetty) server. All (server and
> > client) are done in memory and in one thread. Is there similar way to
> > do
> > this in CXF?
>
> Here are two links to tutorials on this (and other subjects), both of
> which were mentioned on this list a while ago:
>
> < http://confluence.highsource.org/x/r4BM >.
> < http://aruld.info/cxf-22-in-action-services-design-simplified/ >.
>
> It does require starting up an "embedded" Jetty instance, but it's all
> managed internally.
>
RE: Is there easy way to test JAX-RS?
Posted by "KARR, DAVID (ATTSI)" <dk...@att.com>.
> -----Original Message-----
> From: Rice Yeh [mailto:riceyeh@gmail.com]
> Sent: Thursday, July 22, 2010 7:08 PM
> To: users@cxf.apache.org
> Subject: Is there easy way to test JAX-RS?
>
> Hi,
> I move my implementation of JAX-RS from RestEasy to CXF. One feature
> in
> RestEasy I like is that it provides a very simple way to test my
> resources.
> Its test code is like below:
>
> this.dispatcher = MockDispatcherFactory.createDispatcher();
> this.dispatcher.getRegistry().addResourceFactory(new
> POJOResourceFactory(organization.class), "hr");
> this.dispatcher.getRegistry().addResourceFactory(new
> POJOResourceFactory(bureaucracy.class), "hr");
>
> MockHttpRequest request =
> MockHttpRequest.get("/hr/bureaucracy/" +
> oid(b) + "/organization/" + oid(finance) +"/children");
> MockHttpResponse response = new MockHttpResponse();
> this.dispatcher.invoke(request, response);
> System.out.println(response.getContentAsString());
> assert response.getStatus() == 200;
>
> That is, I don't need to startup http (jetty) server. All (server and
> client) are done in memory and in one thread. Is there similar way to
> do
> this in CXF?
Here are two links to tutorials on this (and other subjects), both of
which were mentioned on this list a while ago:
< http://confluence.highsource.org/x/r4BM >.
< http://aruld.info/cxf-22-in-action-services-design-simplified/ >.
It does require starting up an "embedded" Jetty instance, but it's all
managed internally.