-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stub out passing explanation as JSON #3943
- Loading branch information
Showing
4 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/test/java/edu/harvard/iq/dataverse/api/RequestAccessIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package edu.harvard.iq.dataverse.api; | ||
|
||
import com.jayway.restassured.RestAssured; | ||
import com.jayway.restassured.path.json.JsonPath; | ||
import com.jayway.restassured.response.Response; | ||
import edu.harvard.iq.dataverse.authorization.DataverseRole; | ||
import java.util.logging.Logger; | ||
import javax.json.Json; | ||
import javax.json.JsonObjectBuilder; | ||
import static javax.ws.rs.core.Response.Status.CREATED; | ||
import static javax.ws.rs.core.Response.Status.OK; | ||
import static javax.ws.rs.core.Response.Status.UNAUTHORIZED; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class RequestAccessIT { | ||
|
||
private static final Logger logger = Logger.getLogger(DatasetsIT.class.getCanonicalName()); | ||
|
||
@BeforeClass | ||
public static void setUpClass() { | ||
RestAssured.baseURI = UtilIT.getRestAssuredBaseUri(); | ||
|
||
} | ||
|
||
@Test | ||
public void testRequestAccess() { | ||
Response createCurator = UtilIT.createRandomUser(); | ||
createCurator.prettyPrint(); | ||
createCurator.then().assertThat() | ||
.statusCode(OK.getStatusCode()); | ||
String curatorUsername = UtilIT.getUsernameFromResponse(createCurator); | ||
String curatorApiToken = UtilIT.getApiTokenFromResponse(createCurator); | ||
|
||
Response createDataverseResponse = UtilIT.createRandomDataverse(curatorApiToken); | ||
createDataverseResponse.prettyPrint(); | ||
createDataverseResponse.then().assertThat() | ||
.statusCode(CREATED.getStatusCode()); | ||
|
||
String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); | ||
|
||
Response createAuthor = UtilIT.createRandomUser(); | ||
createAuthor.prettyPrint(); | ||
createAuthor.then().assertThat() | ||
.statusCode(OK.getStatusCode()); | ||
String authorUsername = UtilIT.getUsernameFromResponse(createAuthor); | ||
String authorApiToken = UtilIT.getApiTokenFromResponse(createAuthor); | ||
|
||
// Whoops, the curator forgot to give the author permission to create a dataset. | ||
Response noPermToCreateDataset = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, authorApiToken); | ||
noPermToCreateDataset.prettyPrint(); | ||
noPermToCreateDataset.then().assertThat() | ||
.body("message", equalTo("User @" + authorUsername + " is not permitted to perform requested action.")) | ||
.statusCode(UNAUTHORIZED.getStatusCode()); | ||
|
||
Response grantAuthorAddDataset = UtilIT.grantRoleOnDataverse(dataverseAlias, DataverseRole.DS_CONTRIBUTOR.toString(), "@" + authorUsername, curatorApiToken); | ||
grantAuthorAddDataset.prettyPrint(); | ||
grantAuthorAddDataset.then().assertThat() | ||
.body("data.assignee", equalTo("@" + authorUsername)) | ||
.body("data._roleAlias", equalTo("dsContributor")) | ||
.statusCode(OK.getStatusCode()); | ||
|
||
Response createDataset = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, authorApiToken); | ||
createDataset.prettyPrint(); | ||
createDataset.then().assertThat() | ||
.statusCode(CREATED.getStatusCode()); | ||
|
||
Integer datasetId = UtilIT.getDatasetIdFromResponse(createDataset); | ||
|
||
// FIXME: have the initial create return the DOI or Handle to obviate the need for this call. | ||
Response getDatasetJsonBeforePublishing = UtilIT.nativeGet(datasetId, authorApiToken); | ||
getDatasetJsonBeforePublishing.prettyPrint(); | ||
String protocol = JsonPath.from(getDatasetJsonBeforePublishing.getBody().asString()).getString("data.protocol"); | ||
String authority = JsonPath.from(getDatasetJsonBeforePublishing.getBody().asString()).getString("data.authority"); | ||
String identifier = JsonPath.from(getDatasetJsonBeforePublishing.getBody().asString()).getString("data.identifier"); | ||
|
||
String datasetPersistentId = protocol + ":" + authority + "/" + identifier; | ||
System.out.println("datasetPersistentId: " + datasetPersistentId); | ||
|
||
// Whoops, the author tries to publish but isn't allowed. The curator will take a look. | ||
Response noPermToPublish = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", authorApiToken); | ||
noPermToPublish.prettyPrint(); | ||
noPermToPublish.then().assertThat() | ||
.body("message", equalTo("User @" + authorUsername + " is not permitted to perform requested action.")) | ||
.statusCode(UNAUTHORIZED.getStatusCode()); | ||
|
||
Response submitForReview = UtilIT.submitDatasetForReview(datasetPersistentId, authorApiToken); | ||
submitForReview.prettyPrint(); | ||
submitForReview.then().assertThat() | ||
.body("data.inReview", equalTo(true)) | ||
.statusCode(OK.getStatusCode()); | ||
|
||
String comments = "You forgot to upload your files."; | ||
JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder(); | ||
jsonObjectBuilder.add("comments", comments); | ||
Response returnToAuthor = UtilIT.returnDatasetToAuthor(datasetPersistentId, jsonObjectBuilder.build(), curatorApiToken); | ||
returnToAuthor.prettyPrint(); | ||
returnToAuthor.then().assertThat() | ||
.body("data.inReview", equalTo(false)) | ||
.statusCode(OK.getStatusCode()); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters