protected Response postNonRDFSource(String slug, String file, String mimeType) throws IOException { // Make sure we can post binary resources return buildBaseRequestSpecification() .header(SLUG, slug) .body(IOUtils.toByteArray(getClass().getResourceAsStream("/" + file))) .contentType(mimeType) .expect() .statusCode(HttpStatus.SC_CREATED) .header(LOCATION, HeaderMatchers.headerPresent()) .when() .post(container); }
protected static void assertCreateUser(User user){ given() .contentType("application/json;charset=UTF-8") .accept("application/json") .body(user) .expect().log().ifError() .statusCode(HttpStatus.SC_CREATED) .when() .post(getHost() + CONTEXT_PATH + "/users"); }
@Override public void perform() { given(). then(). statusCode(Status.OK.getStatusCode()). when(). post(testURL.toExternalForm()); } }).inspect(new SetupAuth(new User("testuser")));
@Override public void perform() { given(). then(). statusCode(Status.UNAUTHORIZED.getStatusCode()). when(). post(testURL.toExternalForm()); } }).inspect(new SetupAuth(null));
private String post(Model content, String slug) { RequestSpecification spec = buildBaseRequestSpecification().contentType(TEXT_TURTLE); if (slug != null) { spec.header(SLUG, slug); } Response post = spec.body(content, new RdfObjectMapper()).expect() .statusCode(HttpStatus.SC_CREATED).when() .post(getResourceUri()); String location = post.getHeader(LOCATION); assertNotNull(location, MSG_LOC_NOTFOUND); return location; }
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); }
@Test public void shouldReturnBadRequestOnMisingResourceWhenPOSTSession() throws Exception { given(). contentType(getBaseMediaType()). content(createSessionRepresentation()). then(). statusCode(Response.Status.BAD_REQUEST.getStatusCode()). when(). post(createRootURL() + "/{id}/session", "MISSING"); } }
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 @InSequence(1) public void shouldBeAbleToCreateUser() throws Exception { // User is not a top level resource, so in the test we hardcode the known location uri_user = new URL(base, "api/user").toExternalForm(); UserType conf = getCreateUser(); uri_userInstance = given(). contentType(USER_MEDIA_TYPE). body(conf). then(). statusCode(Status.CREATED.getStatusCode()). when(). post(uri_user). header("Location"); }
@Test @InSequence(1) public void shouldBeAbleToCreateAttachment() throws Exception { // Attachment is not a top level resource, so in the test we hardcode the known location uri_attachment = new URL(base, "api/attachment").toExternalForm(); AttachmentType conf = getCreateAttachment(); uri_attachmentInstance = given(). contentType(ATTACHMENT_MEDIA_TYPE). body(conf). then(). statusCode(Status.CREATED.getStatusCode()). when(). post(uri_attachment). header("Location"); }
@Test @InSequence(1) public void shouldBeAbleToCreateConference() throws Exception { assertNotNull("Previous step failed", uri_conference); ConferenceType conf = getCreateConference(); uri_conferenceInstance = given(). contentType(CONFERENCE_MEDIA_TYPE). body(conf). then(). statusCode(Status.CREATED.getStatusCode()). when(). post(uri_conference). header("Location"); }
@Test @InSequence(5) public void shouldBeAbleToCreateSession() throws Exception { assertNotNull("Previous step failed", uri_session); SessionType session = getCreateSession(); uri_sessionInstance = given(). contentType(SESSION_MEDIA_TYPE). body(session). then(). statusCode(Status.CREATED.getStatusCode()). when(). post(uri_session). header("Location"); }
@Test( groups = {MUST}, description = "LDP servers MUST accept a request entity body with a " + "request header of Content-Type with value of text/turtle [turtle].") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-post-turtle", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED) public void testAcceptTurtle() { skipIfMethodNotAllowed(HttpMethod.POST); Model model = postContent(); Response postResponse = buildBaseRequestSpecification().contentType(TEXT_TURTLE) .body(model, new RdfObjectMapper()).expect() .statusCode(HttpStatus.SC_CREATED).when() .post(getResourceUri()); // Delete the resource to clean up. String location = postResponse.getHeader(LOCATION); if (location != null) { buildBaseRequestSpecification().delete(location); } }
@Test( groups = {MUST}, description = "If the resource was created successfully, LDP servers MUST " + "respond with status code 201 (Created) and the Location " + "header set to the new resource’s URL. Clients shall not " + "expect any representation in the response entity body on " + "a 201 (Created) response.") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-post-created201", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED) public void testPostResponseStatusAndLocation() throws URISyntaxException { skipIfMethodNotAllowed(HttpMethod.POST); String location = null; try { Model model = postContent(); Response postResponse = buildBaseRequestSpecification().contentType(TEXT_TURTLE) .body(model, new RdfObjectMapper()).expect() .statusCode(HttpStatus.SC_CREATED).when() .post(getResourceUri()); location = postResponse.getHeader(LOCATION); assertNotNull(location, MSG_LOC_NOTFOUND); } finally { buildBaseRequestSpecification().delete(location); } }
@Test( groups = {SHOULD}, description = "LDP servers SHOULD assign the URI for the resource to be created " + "using server application specific rules in the absence of a client hint.") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-post-serverassignuri", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED) public void testPostNoSlug() { skipIfMethodNotAllowed(HttpMethod.POST); // POST content with no Slug and see if the server assigns a URI. Model model = postContent(); Response postResponse = buildBaseRequestSpecification() .contentType(TEXT_TURTLE) .body(model, new RdfObjectMapper()) .expect() .statusCode(HttpStatus.SC_CREATED) .header(LOCATION, HeaderMatchers.headerPresent()) .when() .post(getResourceUri()); // Delete the resource to clean up. buildBaseRequestSpecification().delete(postResponse.getHeader(LOCATION)); }
@Test public void testAfterDatastoreCalled() throws java.io.IOException { SerPropertiesDto serPropertiesDto = createDatasetDatastoreSerPropertiesDto(); given().content(serPropertiesDto).contentType(ServiceConstants.JSONIO_CONTENT_TYPE) // .accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect().statusCode(200).log().ifError() // .when()// .post(getVersionPrefix() + "/properties/uispec")// .then()// .body("jsonSchema", notNullValue())// .body("properties", notNullValue())// .body("uiSchema", notNullValue())// .body("properties.testAfterDatastoreTrigger", equalTo("bar"))// ; }
@Test public void initializeFullExampleDatasetProperties() throws java.io.IOException { SerPropertiesDto serPropertiesDto = createDatasetDatastoreSerPropertiesDto(); given().content(serPropertiesDto).contentType(ServiceConstants.JSONIO_CONTENT_TYPE) // .accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect().statusCode(200).log().ifError() // .when()// .post(getVersionPrefix() + "/properties/uispec")// .then()// .body("jsonSchema", notNullValue())// .body("properties", notNullValue())// .body("uiSchema", notNullValue())// .body("properties.@definitionName", equalTo("FullExampleDataset"))// .body("uiSchema.moduleName.'ui:widget'", equalTo("hidden"))// .body("uiSchema.query.'ui:widget'", equalTo("textarea"))// ; }
@Test( groups = {SHOULD}, description = "LDP servers SHOULD allow clients to create new resources without " + "requiring detailed knowledge of application-specific constraints. This " + "is a consequence of the requirement to enable simple creation and " + "modification of LDPRs. LDP servers expose these application-specific " + "constraints as described in section 4.2.1 General.") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-post-mincontraints", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED) public void testCreateWithoutConstraints() throws URISyntaxException { skipIfMethodNotAllowed(HttpMethod.POST); // Create a resource with one statement (dcterms:title). Model requestModel = ModelFactory.createDefaultModel(); Resource resource = requestModel.createResource(""); resource.addProperty(DCTerms.title, "Created by the LDP test suite"); Response postResponse = buildBaseRequestSpecification() .contentType(TEXT_TURTLE) .body(requestModel, new RdfObjectMapper()) .expect() .statusCode(HttpStatus.SC_CREATED) .when() .post(getResourceUri()); // Delete the resource to clean up. String location = postResponse.getHeader(LOCATION); if (location != null) { buildBaseRequestSpecification().delete(location); } }