/** * Perform a POST request to a <code>path</code>. Normally the path doesn't have to be fully-qualified e.g. you don't need to * specify the path as <tt>http://localhost:8080/path</tt>. In this case it's enough to use <tt>/path</tt>. * * @param path The path to send the request to. * @param pathParams The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can do <code>post("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);</code>. * @return The response of the request. */ public static Response post(String path, Object... pathParams) { return given().post(path, pathParams); }
/** * Perform a POST request to a <code>path</code>. Normally the path doesn't have to be fully-qualified e.g. you don't need to * specify the path as <tt>http://localhost:8080/path</tt>. In this case it's enough to use <tt>/path</tt>. * * @param path The path to send the request to. * @param pathParams The path parameters. * @return The response of the request. */ public static Response post(String path, Map<String, ?> pathParams) { return given().post(path, pathParams); }
/** * Perform a POST request to a <code>uri</code>. * * @param uri The uri to send the request to. * @return The response of the request. */ public static Response post(URI uri) { return given().post(uri); }
/** * Perform a POST request to a <code>url</code>. * * @param url The url to send the request to. * @return The response of the request. */ public static Response post(URL url) { return given().post(url); }
/** * Perform a POST request to the statically configured path (by default <code>http://localhost:8080</code>). * * @return The response of the request. */ public static Response post() { return given().post(); }
public static OAuth2AccessToken getClientCredentialsAccessToken(String clientId, String clientSecret) { return given() .parameters("grant_type", "client_credentials") .auth() .preemptive() .basic(clientId, clientSecret) .when() .post("/oauth/token") .as(OAuth2AccessToken.class); }
public static OAuth2AccessToken getPasswordGrantAccessToken(String username, String password) { return given() .when() .contentType(APPLICATION_FORM_URLENCODED_VALUE) .formParam("grant_type", "password") .formParam("username", username) .formParam("password", password) .formParam("client_id", CLIENT_ID_ADMIN) .formParam("client_secret", CLIENT_SECRET_ADMIN) .post("/oauth/token") .as(OAuth2AccessToken.class); }
@Test public void createChildNonRootable() { String request = jsonParser.getJson("/ResourceIT/createChildNonRootable.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .post("/child") .then() .statusCode(HttpStatus.SC_NOT_FOUND); }
@Test(priority = 34) public void testPostToRecord() { String createRoot = jsonParser.getJson("/ResourceIT/createOneToOneRoot.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(createRoot) .post("/oneToOneRoot/1") .then() .statusCode(HttpStatus.SC_BAD_REQUEST); }
@Test public void assignedIdWithoutProvidedId() { String request = jsonParser.getJson("/ResourceIT/assignedIdWithoutId.req.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .post("/assignedIdString") .then() .statusCode(HttpStatus.SC_BAD_REQUEST); }
@Test public void createParentBadUri() { String request = jsonParser.getJson("/ResourceIT/createParentBadUri.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .post("/parent/678") .then() .statusCode(HttpStatus.SC_NOT_FOUND); }
@Test(priority = 41) public void testPostInvalidRelationship() { // Note: This tests the correct response when POSTing a resource with a not "include" relationship. The server // should returns UnknownEntityException rather than NPE. String createRoot = jsonParser.getJson("/ResourceIT/testPostWithInvalidRelationship.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(createRoot) .post("resourceWithInvalidRelationship") .then() .statusCode(HttpStatus.SC_BAD_REQUEST); }
@Test public void createParentList() { String request = jsonParser.getJson("/ResourceIT/createParentList.req.json"); String expected = "{\"errors\":[\"InvalidEntityBodyException: Bad Request Body"; given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .post("/parent") .then() .statusCode(HttpStatus.SC_BAD_REQUEST) .body(startsWith(expected)); }
@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() ) )); }
@Test public void testValidateProperties() throws Exception { ObjectNode validationResult = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with() // .content(buildTestDataStoreFormData()) // .contentType(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/validate").as(ObjectNode.class); assertNotNull(validationResult); assertEquals("OK", validationResult.get("status").textValue()); }
@Test public void testValidatePropertiesJsonio() throws Exception { ObjectNode validationResult = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with() // .content(buildTestDataStoreSerProps()) // .contentType(ServiceConstants.JSONIO_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/validate").as(ObjectNode.class); assertNotNull(validationResult); assertEquals("OK", validationResult.get("status").textValue()); }
@Test(priority = 2) public void createParentWithRels() { String request = jsonParser.getJson("/ResourceIT/createParentWithRels.req.json"); String expected = jsonParser.getJson("/ResourceIT/createParentWithRels.json"); String actual = given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .post("/parent") .then() .statusCode(HttpStatus.SC_CREATED) .extract().body().asString(); assertEqualDocuments(actual, expected); }
@Test public void testGetDatasetPropertiesFromSer() throws Exception { given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with() // .content(buildTestDataStoreSerProps()) // .contentType(ServiceConstants.JSONIO_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/dataset"); }
@Test public void testGetDatasetPropertiesFromUiSpecs() throws Exception { given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with() // .content(buildTestDataStoreFormData()) // .contentType(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/dataset"); }
@Test public void testInitializePropertiesUiSpecs() throws Exception { Response response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with() // .content(buildTestDataSetFormData()) // .contentType(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/uispec"); assertNotNull(response); String content = response.asString(); assertEquals(getMockDatasetMainFormUISpecs(), content); }