use of com.jayway.restassured.config.MatcherConfig in project graylog2-server by Graylog2.
the class RestAssuredSetupRule method before.
@Override
protected void before() throws Throwable {
final URI uri = IntegrationTestsConfig.getGlServerURL();
RestAssured.baseURI = uri.getScheme() + "://" + uri.getHost();
RestAssured.port = uri.getPort();
String[] userInfo = uri.getUserInfo().split(":");
authenticationScheme = preemptive().basic(userInfo[0], userInfo[1]);
// we want all the details for failed tests
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
// we want to be able to describe mismatches in a custom way.
final MatcherConfig matcherConfig = RestAssured.config().getMatcherConfig().errorDescriptionType(MatcherConfig.ErrorDescriptionType.HAMCREST);
RestAssured.config = RestAssured.config().matcherConfig(matcherConfig);
// we usually send and receive JSON, so we preconfigure for that.
RestAssured.requestSpecification = new RequestSpecBuilder().build().accept(JSON).contentType(JSON);
// immediately query the server for its version number, we need it to be able to process the RequireVersion annotations.
given().when().authentication().preemptive().basic(userInfo[0], userInfo[1]).get("/system").then().body("version", new BaseMatcher<Object>() {
@Override
public boolean matches(Object item) {
if (item instanceof String) {
String str = (String) item;
try {
// clean our slightly non-semver version number
str = str.replaceAll("\\(.*?\\)", "").trim();
serverUnderTestVersion = Version.valueOf(str);
return true;
} catch (RuntimeException e) {
return false;
}
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("parse the system under test's version number");
}
});
}
Aggregations