Skip to content

Commit

Permalink
add API tests for DataCite #3845
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Aug 11, 2017
1 parent e93d6b3 commit b7c9cad
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
79 changes: 79 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/DataCiteIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package edu.harvard.iq.dataverse.api;

import com.jayway.restassured.response.Response;
import static junit.framework.Assert.assertEquals;
import org.junit.Test;

/**
* These tests will only work if you are using "DataCite" rather than "EZID" for
* your :DoiProvider and have done all the other related setup to switch from
* EZID, including setting JVM options. Look for DataCite in the dev guide for
* more tips.
*/
public class DataCiteIT {

@Test
public void testCreateAndPublishDataset() {

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);

String title = "myTitle";
String description = "myDescription";
Response createDataset = UtilIT.createDatasetViaSwordApi(dataverseAlias, title, description, apiToken);
createDataset.prettyPrint();
String datasetPersistentId = UtilIT.getDatasetPersistentIdFromResponse(createDataset);

Response publishDataverse = UtilIT.publishDataverseViaSword(dataverseAlias, apiToken);
assertEquals(200, publishDataverse.getStatusCode());

Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken);
publishDataset.prettyPrint();
assertEquals(200, publishDataset.getStatusCode());

}

@Test
public void testCreateAndPublishDatasetHtmlInDescription() {

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);

String title = "myTitle";
// TODO: exercise https://github.com/IQSS/dataverse/issues/3845 by putting HTML in dataset description
String description = "BEGIN<br></br>END";
if (true) {
return;
}
Response createDataset = UtilIT.createDatasetViaSwordApi(dataverseAlias, title, description, apiToken);
createDataset.prettyPrint();
String datasetPersistentId = UtilIT.getDatasetPersistentIdFromResponse(createDataset);

Response publishDataverse = UtilIT.publishDataverseViaSword(dataverseAlias, apiToken);
assertEquals(200, publishDataverse.getStatusCode());

Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken);
publishDataset.prettyPrint();
assertEquals(200, publishDataset.getStatusCode());

}

}
5 changes: 5 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ static Response createDatasetViaSwordApi(String dataverseToCreateDatasetIn, Stri
return createDatasetViaSwordApiFromXML(dataverseToCreateDatasetIn, xmlIn, apiToken);
}

static Response createDatasetViaSwordApi(String dataverseToCreateDatasetIn, String title, String description, String apiToken) {
String xmlIn = getDatasetXml(title, "Lastname, Firstname", description);
return createDatasetViaSwordApiFromXML(dataverseToCreateDatasetIn, xmlIn, apiToken);
}

private static Response createDatasetViaSwordApiFromXML(String dataverseToCreateDatasetIn, String xmlIn, String apiToken) {
Response createDatasetResponse = given()
.auth().basic(apiToken, EMPTY_STRING)
Expand Down

0 comments on commit b7c9cad

Please sign in to comment.