spec.log().all();
@Test public void testRequestWithHeaders() throws Exception { given() .log().everything() .accept(ContentType.TEXT) .when() .header("Authorization", "AUTH_HEADER") .get("/simple/apis") .then() .statusCode(equalTo(HttpUtil.HTTP_NO_CONTENT)); } }
.log().ifValidationFails() .header("Content-Type", format.getDefaultMIMEType()) .body(body.getBytes())
public static Response sendHttpGet(String contentType, String httpGetCommand, boolean responseLog) { if (responseLog) { return given() .contentType(contentType) .log().all() .expect() .log().all() .when() .get(httpGetCommand); } return given() .contentType(contentType) .log().all() .when() .get(httpGetCommand); }
/** * Should return the example from the specification when the script triggers an HTTP 201 Created status code. * * @throws Exception */ @Test public void testServeScriptedExample() throws Exception { given() .log().everything() // JSON content type in 'Accept' header matches specification example .accept(ContentType.JSON) .when() .put("/simple/apis") .then() .log().everything() .statusCode(HttpUtil.HTTP_CREATED) .body("result", equalTo("success")) .header("MyHeader","MyHeaderValue"); }
public static Response sendHttpGet(String contentType, String httpGetCommand, boolean responseLog) { if (responseLog) { return given() .contentType(contentType) .log().all() .expect() .log().all() .when() .get(httpGetCommand); } return given() .contentType(contentType) .log().all() .when() .get(httpGetCommand); }
/** * Should return the specification UI. * * @param testContext * @throws Exception */ @Test public void testGetSpecUi(TestContext testContext) throws Exception { final String body = given() .log().everything() .accept(ContentType.TEXT) .when() .get(OpenApiPluginImpl.SPECIFICATION_PATH + "/") .then() .log().everything() .statusCode(HttpUtil.HTTP_OK) .extract().asString(); testContext.assertTrue(body.contains("</html>")); }
/** * Should return a combined specification. * * @param testContext * @throws Exception */ @Test public void testGetCombinedSpec(TestContext testContext) throws Exception { final String body = given() .log().everything() .accept(ContentType.JSON) .when() .get(OpenApiPluginImpl.COMBINED_SPECIFICATION_PATH) .then() .log().everything() .statusCode(HttpUtil.HTTP_OK) .extract().asString(); testContext.assertNotNull(body); final Swagger combined = new SwaggerParser().parse(body); testContext.assertNotNull(combined.getInfo()); testContext.assertEquals("Imposter Mock APIs", combined.getInfo().getTitle()); // should contain combination of both specs' endpoints testContext.assertEquals(4, combined.getPaths().size()); testContext.assertTrue(combined.getPaths().keySet().contains("/simple/apis")); testContext.assertTrue(combined.getPaths().keySet().contains("/api/pets")); }
@Test public void testVersion() { given().log().all() .get("q2/version").then().statusCode(200).assertThat() .body("version", equalTo( String.format("jPOS %s %s/%s (%s)", Q2.getVersion(), Q2.getBranch(), Q2.getRevision(), Q2.getBuildTimestamp() ) )); }
/** * Should return the example from the specification for the default HTTP 200 status code, since the * content type in the 'Accept' matches that in the specification example. * * @param testContext * @throws Exception */ @Test public void testServeDefaultExampleMatchContentType(TestContext testContext) throws Exception { final String body = given() .log().everything() // JSON content type in 'Accept' header matches specification example .accept(ContentType.JSON) .when() .get("/simple/apis") .then() .log().everything() .statusCode(HttpUtil.HTTP_OK) .extract().asString(); assertBody(testContext, body); }
@Test public void testAll() { given().log().all() .get("q2").then().statusCode(200).assertThat() .body("version", equalTo( String.format("jPOS %s %s/%s (%s)", Q2.getVersion(), Q2.getBranch(), Q2.getRevision(), Q2.getBuildTimestamp() ) )); }
/** * Should return the example from the specification for the default HTTP 200 status code, even though the * content type in the 'Accept' header does not match that in the specification example. * * @param testContext * @throws Exception * @see OpenApiPluginConfig#isPickFirstIfNoneMatch() */ @Test public void testServeDefaultExampleNoExactMatch(TestContext testContext) throws Exception { final String body = given() .log().everything() // do not set JSON content type in 'Accept' header, to force mismatch against specification example .accept(ContentType.TEXT) .when() .get("/simple/apis") .then() .log().everything() .statusCode(HttpUtil.HTTP_OK) .extract().asString(); assertBody(testContext, body); }
public static Response sendHttpPost(String contentType, String payload, String httpPostCommand, boolean responseLog) { if (responseLog) { return given() .contentType(contentType) .body(payload) .log().all() .expect() .log().all() .when() .post(httpPostCommand); } return given() .contentType(contentType) .body(payload) // .log().all() .when() .post(httpPostCommand); }
@Test public void testPost() { given().and().body("{ \"test\": \"Test JSON\" }") .log().all().post("q2") .then().statusCode(200).assertThat() .body("version", equalTo( String.format("jPOS %s %s/%s (%s)", Q2.getVersion(), Q2.getBranch(), Q2.getRevision(), Q2.getBuildTimestamp() ) )); }
public static Response sendHttpPost(String contentType, String payload, String httpPostCommand, boolean responseLog) { if (responseLog) { return given() .contentType(contentType) .body(payload) .log().all() .expect() .log().all() .when() .post(httpPostCommand); } return given() .contentType(contentType) .body(payload) // .log().all() .when() .post(httpPostCommand); }
public static Response sendHttpPost(String contentType, Map<String, ?> parameters, String httpPostCommand, boolean responseLog) { if (responseLog) { return given() .contentType(contentType) .formParameters(parameters) .log().all() .expect() .log().all() .when() .post(httpPostCommand); } return given() .contentType(contentType) .formParameters(parameters) // .log().all() .when() .post(httpPostCommand); }
public static Response sendHttpPost(String contentType, Map<String, ?> parameters, String httpPostCommand, boolean responseLog) { if (responseLog) { return given() .contentType(contentType) .formParameters(parameters) .log().all() .expect() .log().all() .when() .post(httpPostCommand); } return given() .contentType(contentType) .formParameters(parameters) // .log().all() .when() .post(httpPostCommand); }