com.eclipsesource.restfuse.annotation
Annotation Type HttpTest


@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 Destination Rule exists in the TestCase.

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 Response which is annotated with the Context annotation. The response object can also be pulled using the getRespone() method on the Destination rule.

You don't have to combine the Test and HttpTest annotation when you are using the HttpJUnitRunner. This runner detects all 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 Destination 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.
 MediaType type
          The type attribute tells the request which "Content-Type" header it should send.
 

Element Detail

method

public abstract Method method

The method attribute tells the request which Http Method should be used.

See Also:
Method

path

public abstract java.lang.String path

The path attribute will be attached to the base url of the Destination rule. This enables the creation of many http test method within one TestCase using different url paths for the same host.

authentications

public abstract Authentication[] authentications
PROVISIONAL API, MAY CHANGE OR VANISH IN FUTURE

The AuthenticationInfo will be used to transmit authentication data. Currently only BASIC and DIGEST authentication is supported.

See Also:
AuthenticationInfo, AuthenticationType
Default:
{}

content

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.

Default:
""

file

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.

Default:
""

headers

public abstract Header[] headers

With the headers the request headers can be set.

See Also:
Header
Default:
{}

type

public abstract MediaType type

The type attribute tells the request which "Content-Type" header it should send. The default value is the wildcard type.

See Also:
MediaType
Default:
com.eclipsesource.restfuse.MediaType.WILDCARD