Package org.opencastproject.test.rest
Class RestServiceTestEnv
java.lang.Object
org.opencastproject.test.rest.RestServiceTestEnv
Helper environment for creating REST service unit tests.
The REST endpoint to test needs a no-arg constructor in order to be created by the framework.
Write REST unit tests using rest assured.
Example Usage
import static com.jayway.restassured.RestAssured.*;
import static com.jayway.restassured.matcher.RestAssuredMatchers.*;
import static org.hamcrest.Matchers.*;
import static org.opencastproject.rest.RestServiceTestEnv.*
public class RestEndpointTest {
// create a local environment running on some random port
// use rt.host("/path/to/service") to wrap all URL creations for HTTP request methods
private static final RestServiceTestEnv rt = testEnvScanAllPackages(localhostRandomPort());
\@BeforeClass public static void oneTimeSetUp() {
env.setUpServer();
}
\@AfterClass public static void oneTimeTearDown() {
env.tearDownServer();
}
}
Add the following dependencies to your pom
<dependency> <groupId>com.jayway.restassured</groupId> <artifactId>rest-assured</artifactId> <version>1.7.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>4.2.4</version> <scope>test</scope> </dependency>
-
Method Summary
Modifier and TypeMethodDescriptionCreate a URL suitable for rest-assured's post(), get() e.al. methods.voidReturn the base URL of the HTTP server.voidCall in @AfterClass annotated method.static RestServiceTestEnvtestEnvForClasses(Class<?>... restServices)
-
Method Details
-
testEnvForClasses
-
host
Create a URL suitable for rest-assured's post(), get() e.al. methods. -
setUpServer
public void setUpServer()Return the base URL of the HTTP server.http://host:portpublic URL getBaseUrl() { return baseUrl; } Call in @BeforeClass annotated method. -
tearDownServer
public void tearDownServer()Call in @AfterClass annotated method.
-