|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
@Retention(value=RUNTIME) @Target(value=METHOD) public @interface Callback
The Callback
can be used for asynchronous HTTP tests that need a callback.
This means when the tested service needs to send something back within a separate request. At
this time the client needs to act as a service to accept the incoming request. See
this wiki for more information
about webhooks.
Please note, that the Callback
annotation only works in combination with the
annotation. This means it can't be used standalone and it
has the same prerequisites as the HttpTest
.HttpTest
Once a request has finished on an http test method and the method has a Callback
annotation attached, a sever will be started before the test code will be executed. On this
server a servlet will be registered on the port specified in the port
attribute
using the path specified in the path
attribute. After the test code finished the
server waits until the timeout
has reached or the callback was called. If the
callback was not done than the test method fails. In any case the server shuts itself down after
the test method execution.
Of course you want to test something when the callback arrives. Therefore you need to register
a resource using the resource
attribute. The value of this attributes has to be a
subclass of
. For convenience you can also subclass the
CallbackResource
which implements all methods and returns a default
response instead of sub classing the DefaultCallbackResource
directly.CallbackResource
A simple callback looks like this:
@RunWith( HttpJUnitRunner.class ) public class Example { @Rule public Destination destination = new Destination( "http://localhost" ); @Context private Response response; private class TestCallbackResource extends DefaultCallbackResource { @Override public Response post( Request request ) { assertNotNull( request.getHeaders().get( "some header" ).get( 0 ) ); return super.post( request ); } } @HttpTest( method = Method.GET, path = "/test" ) @Callback( port = 9090, path = "/callback", resource = TestCallbackResource.class, timeout = 10000 ) public void testMethod() { com.eclipsesource.restfuse.Assert.assertAccepted( response ); } }
CallbackResource
,
DefaultCallbackResource
,
HttpTest
,
Destination
Required Element Summary | |
---|---|
java.lang.String |
path
The path attribute specifies the path on which the callback will be reachable
during the test method execution. |
int |
port
The port attribute specifies the port on which the callback will be reachable
during the test method execution. |
java.lang.Class<? extends CallbackResource> |
resource
The resource attribute specifies the class that will be instantiated and
handles the incoming requests from a callback. |
int |
timeout
The timeout attribute specifies the milliseconds of the callback timeout. |
Element Detail |
---|
public abstract java.lang.String path
The path
attribute specifies the path on which the callback will be reachable
during the test method execution.
public abstract int port
The port
attribute specifies the port on which the callback will be reachable
during the test method execution.
public abstract java.lang.Class<? extends CallbackResource> resource
The resource
attribute specifies the class that will be instantiated and
handles the incoming requests from a callback. Instead of sub classing
directly you can also subclass
CallbackResource
which implements all methods and returns a
default response.DefaultCallbackResource
CallbackResource
,
DefaultCallbackResource
public abstract int timeout
The timeout
attribute specifies the milliseconds of the callback timeout. This
means, that if the callback was not called within the given time frame, the test method will
fail.
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |