|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
@Retention(value=RUNTIME) @Target(value=METHOD) public @interface HttpTest
The HttpTest
annotation tells JUnit that the public void
method
to which it is attached can be run as an http test case when it's coupled with a Test
annotation. Before the test method will be executed an request will be send to the service
configured via the Destination
rule and the annotation's parameters.
Please keep in mind that an HttpTest
only works when a
Rule exists in the TestCase.Destination
If the request fails, the test fails. When the request succeeds, the Response
will be injected into the TestCase Object. The injection looks for a field of the type
which is annotated with the Response
annotation. The response object can also be pulled using the Context
getRespone()
method
on the
rule.Destination
You don't have to combine the
and Test
HttpTest
annotation when you are using the
. This runner detects all
HttpJUnitRunner
HttpTest
annotated methods and executes them as test methods.
To run the method, JUnit first constructs a fresh instance of the class. Then the request will be executed and JUnit invokes the annotated method afterwards. Any exceptions thrown by the test will be reported by JUnit as a failure. If no exceptions are thrown, the test is assumed to have succeeded.
A simple http test looks like this:
@RunWith( HttpJUnitRunner.class ) public class Example { @Rule public Destination destination = new Destination( "http://localhost" ); @Context private Response response; @HttpTest( method = Method.GET, path = "/test" ) public void testMethod() { com.eclipsesource.restfuse.Assert.assertAccepted( response ); } }
Required Element Summary | |
---|---|
Method |
method
The method attribute tells the request which Http Method should be used. |
java.lang.String |
path
The path attribute will be attached to the base url of the
rule. |
Optional Element Summary | |
---|---|
Authentication[] |
authentications
PROVISIONAL API, MAY CHANGE OR VANISH IN FUTURE |
java.lang.String |
content
When the request can have an entity like POST or PUT requests the content can be set by the content attribute. |
java.lang.String |
file
When the request can have an entity like POST or PUT requests the content can be set by the file attribute. |
Header[] |
headers
With the headers the request headers can be set. |
int |
order
Order of test in case tests need to be executed in certain order. |
MediaType |
type
The type attribute tells the request which "Content-Type" header it should send. |
Element Detail |
---|
public abstract Method method
The method attribute tells the request which Http Method should be used.
Method
public abstract java.lang.String path
The path attribute will be attached to the base url of the
rule. This enables the creation of many http test method within one TestCase using different
url paths for the same host.Destination
public abstract Authentication[] authentications
The
will be used to transmit authentication data.
Currently only BASIC and DIGEST authentication is supported.AuthenticationInfo
AuthenticationInfo
,
AuthenticationType
public abstract java.lang.String content
When the request can have an entity like POST or PUT requests the content can be set by the
content
attribute. An alternative can be to use the file
attribute.
If both are defined the file
attribute wins.
public abstract java.lang.String file
When the request can have an entity like POST or PUT requests the content can be set by the
file
attribute. The file has to be on the classpath of the TestCase. An
alternative can be to use the content
attribute. If both are defined the
file
attribute wins.
public abstract Header[] headers
With the headers
the request headers can be set.
Header
public abstract int order
Order of test in case tests need to be executed in certain order. 1 = first, 2 = second, ... By default order is set to 0
public abstract MediaType type
The type attribute tells the request which "Content-Type" header it should send. The default value is the wildcard type.
MediaType
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |