use of io.restassured.specification.ResponseSpecification in project knox by apache.
the class GatewayBasicFuncTest method getYarnRmProxyData.
private void getYarnRmProxyData(String encryptedQuery, String path, String resource, ContentType contentType, Map<String, Matcher<?>> contentMatchers) throws Exception {
String username = "hdfs";
String password = "hdfs-password";
String gatewayPath = driver.getUrl("RESOURCEMANAGER") + path + "?" + encryptedQuery + (driver.isUseGateway() ? "" : "&user.name=" + username);
switch(contentType) {
case JSON:
resource += ".json";
break;
case XML:
resource += ".xml";
break;
default:
break;
}
driver.getMock("RESOURCEMANAGER").expect().method("GET").pathInfo(path).queryParam("user.name", username).respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes(resource)).contentType(contentType.toString());
ResponseSpecification responseSpecification = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").then().statusCode(HttpStatus.SC_OK).contentType(contentType);
if (contentMatchers != null) {
for (Entry<String, Matcher<?>> matcher : contentMatchers.entrySet()) {
responseSpecification.body(matcher.getKey(), matcher.getValue());
}
}
Response response = responseSpecification.when().get(gatewayPath);
if (contentMatchers == null || contentMatchers.isEmpty()) {
switch(contentType) {
case JSON:
MatcherAssert.assertThat(response.getBody().asString(), sameJSONAs(driver.getResourceString(resource, UTF8)));
break;
case XML:
MatcherAssert.assertThat(the(response.getBody().asString()), isEquivalentTo(the(driver.getResourceString(resource, UTF8))));
break;
default:
break;
}
}
driver.assertComplete();
}
use of io.restassured.specification.ResponseSpecification in project knox by apache.
the class GatewayBasicFuncTest method getYarnRmApp.
private void getYarnRmApp(ContentType contentType, boolean running) throws Exception {
String username = "hdfs";
String password = "hdfs-password";
String path = "/v1/cluster/apps/application_1399541193872_0033/";
String resource;
if (running) {
resource = "/yarn/app_running";
} else {
resource = "/yarn/app_succeeded";
}
switch(contentType) {
case JSON:
resource += ".json";
break;
case XML:
resource += ".xml";
break;
default:
break;
}
String gatewayPath = driver.getUrl("RESOURCEMANAGER") + path + (driver.isUseGateway() ? "" : "?user.name=" + username);
InetSocketAddress gatewayAddress = driver.gateway.getAddresses()[0];
String gatewayHostName = gatewayAddress.getHostName();
String gatewayAddrName = InetAddress.getByName(gatewayHostName).getHostAddress();
VelocityEngine velocity = new VelocityEngine();
velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.NullLogSystem");
velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
velocity.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
velocity.init();
VelocityContext context = new VelocityContext();
context.put("proxy_address", driver.getRealUrl("RESOURCEMANAGER"));
String name = TestUtils.getResourceName(this.getClass(), resource);
Template template = velocity.getTemplate(name);
StringWriter sw = new StringWriter();
template.merge(context, sw);
String request = sw.toString();
driver.getMock("RESOURCEMANAGER").expect().method("GET").pathInfo(path).queryParam("user.name", username).respond().status(HttpStatus.SC_OK).content(request.getBytes()).contentType(contentType.toString());
ResponseSpecification response = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").then().statusCode(HttpStatus.SC_OK).contentType(contentType);
if (running) {
response.body("app.trackingUrl", anyOf(startsWith("http://" + gatewayHostName + ":" + gatewayAddress.getPort() + "/"), startsWith("http://" + gatewayAddrName + ":" + gatewayAddress.getPort() + "/")));
} else {
response.body("app.trackingUrl", isEmptyString());
}
response.body("app.amContainerLogs", isEmptyString()).body("app.amHostHttpAddress", isEmptyString()).when().get(gatewayPath);
driver.assertComplete();
}
use of io.restassured.specification.ResponseSpecification in project rest-assured by rest-assured.
the class SpecificationBuilderITest method expectingSpecMergesTheCurrentSpecificationWithTheSuppliedOne.
@Test
public void expectingSpecMergesTheCurrentSpecificationWithTheSuppliedOne() throws Exception {
final ResponseSpecBuilder builder = new ResponseSpecBuilder();
builder.expectBody("store.book.size()", is(4)).expectStatusCode(200);
final ResponseSpecification responseSpecification = builder.build();
expect().spec(responseSpecification).body("store.book[0].author", equalTo("Nigel Rees")).when().get("/jsonStore");
}
use of io.restassured.specification.ResponseSpecification in project rest-assured by rest-assured.
the class SpecificationBuilderITest method responseSpecificationCanExpectContentWithArgs.
@Test
public void responseSpecificationCanExpectContentWithArgs() throws Exception {
final ResponseSpecification spec = new ResponseSpecBuilder().rootPath("store.book[%d]").expectContent("author", withArgs(0), equalTo("Nigel Rees")).build();
expect().spec(spec).content("title", withArgs(1), equalTo("Sword of Honour")).when().get("/jsonStore");
}
use of io.restassured.specification.ResponseSpecification in project rest-assured by rest-assured.
the class SpecificationBuilderITest method responseSpecificationCanExpectBodyWithArgs.
@Test
public void responseSpecificationCanExpectBodyWithArgs() throws Exception {
final ResponseSpecification spec = new ResponseSpecBuilder().rootPath("store.book[%d]").expectBody("author", withArgs(0), equalTo("Nigel Rees")).build();
expect().spec(spec).body("title", withArgs(1), equalTo("Sword of Honour")).when().get("/jsonStore");
}
Aggregations