diff --git a/src/test/java/edu/harvard/iq/dataverse/api/TermsOfUseIT.java b/src/test/java/edu/harvard/iq/dataverse/api/TermsOfUseIT.java new file mode 100644 index 00000000000..37640a57f63 --- /dev/null +++ b/src/test/java/edu/harvard/iq/dataverse/api/TermsOfUseIT.java @@ -0,0 +1,107 @@ +package edu.harvard.iq.dataverse.api; + +import com.jayway.restassured.RestAssured; +import static com.jayway.restassured.RestAssured.given; +import com.jayway.restassured.response.Response; +import edu.harvard.iq.dataverse.api.datadeposit.SwordConfigurationImpl; +import java.util.logging.Logger; +import static junit.framework.Assert.assertEquals; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TermsOfUseIT { + + private static final Logger logger = Logger.getLogger(DatasetsIT.class.getCanonicalName()); + private static final String EMPTY_STRING = ""; + private static SwordConfigurationImpl swordConfiguration = new SwordConfigurationImpl(); + + @BeforeClass + public static void setUpClass() { + RestAssured.baseURI = UtilIT.getRestAssuredBaseUri(); + } + + @Test + public void testTermsOfUseFileDownload() { + + Response createUser = UtilIT.createRandomUser(); + createUser.prettyPrint(); + assertEquals(200, createUser.getStatusCode()); + String username = UtilIT.getUsernameFromResponse(createUser); + String apiToken = UtilIT.getApiTokenFromResponse(createUser); + Response makeSuperUser = UtilIT.makeSuperUser(username); + assertEquals(200, makeSuperUser.getStatusCode()); + + Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); + createDataverseResponse.prettyPrint(); + String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); + + // This is the example XML from http://guides.dataverse.org/en/4.17/api/sword.html#create-a-dataset-with-an-atom-entry + String xmlIn = "\n" + + "\n" + + " \n" + + " Roasting at Home\n" + + " Peets, John\n" + + " Stumptown, Jane\n" + + " \n" + + " Chemistry\n" + + " \n" + + " coffee\n" + + " beverage\n" + + " caffeine\n" + + " Considerations before you start roasting your own coffee at home.\n" + + " \n" + + " Coffee Bean State University\n" + + " CaffeineForAll\n" + + " \n" + + " 2013-07-11\n" + + " \n" + + " aggregate data\n" + + " \n" + + " Stumptown, Jane. 2011. Home Roasting. Coffeemill Press.\n" + + " \n" + + " Peets, John. 2010. Roasting Coffee at the Coffee Shop. Coffeemill Press\n" + + " \n" + + " United States\n" + + " Canada\n" + + " \n" + + " NONE\n" + + " Downloader will not use the Materials in any way prohibited by applicable laws.\n" + + " \n" + + " Peets, J., & Stumptown, J. (2013). Roasting at Home. New England Journal of Coffee, 3(1), 22-34.\n" + + ""; + + Response createDataset = given() + .auth().basic(apiToken, EMPTY_STRING) + .body(xmlIn) + .contentType("application/atom+xml") + .post(swordConfiguration.getBaseUrlPathCurrent() + "/collection/dataverse/" + dataverseAlias); + + createDataset.prettyPrint(); + String datasetPersistentId = UtilIT.getDatasetPersistentIdFromSwordResponse(createDataset); + + Response uploadFile = UtilIT.uploadRandomFile(datasetPersistentId, apiToken); + uploadFile.then().assertThat() + .statusCode(201); + + Response publishDataverse = UtilIT.publishDataverseViaSword(dataverseAlias, apiToken); + assertEquals(200, publishDataverse.getStatusCode()); + + Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); + publishDataset.prettyPrint(); + assertEquals(200, publishDataset.getStatusCode()); + + Response swordStatement = UtilIT.getSwordStatement(datasetPersistentId, apiToken); + + Integer fileId = UtilIT.getFileIdFromSwordStatementResponse(swordStatement); + + Response downloadFile = UtilIT.downloadFile(fileId); + downloadFile.then().assertThat() + // TODO: When we fix https://github.com/IQSS/dataverse/issues/2911 + // change this to a non 200 response. A download should not be possible + // because the following terms of use are in place: + // "Downloader will not use the Materials in any way prohibited by applicable laws." + .statusCode(200); + } + +}