Skip to content

Commit

Permalink
adds test to check that directory labels with leading or trailing sep…
Browse files Browse the repository at this point in the history
…arators fail
  • Loading branch information
bmckinney committed Oct 24, 2016
1 parent 903f4ff commit 8e4b749
Show file tree
Hide file tree
Showing 3 changed files with 229 additions and 5 deletions.
20 changes: 17 additions & 3 deletions src/test/java/edu/harvard/iq/dataverse/api/FileMetadataIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.jayway.restassured.RestAssured;
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.response.Response;
import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.AfterClass;
Expand All @@ -36,6 +37,8 @@

/**
* FileMetadata Integration Tests
*
* @author bmckinney
*/
public class FileMetadataIT {

Expand Down Expand Up @@ -133,6 +136,17 @@ public void tearDownDataverse() {
@Test
public void testJsonParserWithDirectoryLabels() {
try {

// try to create a dataset with directory labels that contain both leading and trailing file separators
Response resp = given()
.header(keyString, token)
.body(IOUtils.toString(classLoader.getResourceAsStream(
"json/complete-dataset-with-files-invalid-directory-labels.json")))
.contentType("application/json")
.post("/api/dataverses/" + testName + "/datasets");
// this request should fail since a @Pattern constraint exists in FileMetadata to prevent this
assertEquals(resp.getStatusCode(), 500);

// create dataset and set id
dsId = given()
.header(keyString, token)
Expand All @@ -148,20 +162,20 @@ public void testJsonParserWithDirectoryLabels() {
.then().assertThat().statusCode(200)
.extract().jsonPath().getString("data.latestVersion.files[0].directoryLabel");
System.out.println("directoryLabel 1: " + dirLabel1);
assertEquals("data/subdir1/", dirLabel1);
assertEquals("data/subdir1", dirLabel1);
String dirLabel2 = given()
.header(keyString, token)
.get("/api/datasets/" + dsId)
.then().assertThat().statusCode(200)
.extract().jsonPath().getString("data.latestVersion.files[1].directoryLabel");
System.out.println("directoryLabel 2: " + dirLabel2);
assertEquals("data/subdir2/", dirLabel2);
assertEquals("data/subdir2", dirLabel2);

} catch (Exception e) {
System.out.println("Error testJsonParserWithDirectoryLabels: " + e.getMessage());
e.printStackTrace();
fail();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
{
"datasetVersion": {
"metadataBlocks": {
"citation": {
"displayName": "Citation Metadata",
"fields": [
{
"typeName": "title",
"multiple": false,
"typeClass": "primitive",
"value": "X-Ray Diffraction data from Lin28/let-7d microRNA complex, source of 3TRZ structure"
},
{
"typeName": "author",
"multiple": true,
"typeClass": "compound",
"value": [
{
"authorName": {
"typeName": "authorName",
"multiple": false,
"typeClass": "primitive",
"value": "Sliz, Piotr"
},
"authorAffiliation": {
"typeName": "authorAffiliation",
"multiple": false,
"typeClass": "primitive",
"value": "Harvard Medical School"
},
"authorIdentifierScheme": {
"typeName": "authorIdentifierScheme",
"multiple": false,
"typeClass": "controlledVocabulary",
"value": "ORCID"
},
"authorIdentifier": {
"typeName": "authorIdentifier",
"multiple": false,
"typeClass": "primitive",
"value": "0000-0002-6522-0835"
}
}
]
},
{
"typeName": "datasetContact",
"multiple": true,
"typeClass": "compound",
"value": [
{
"datasetContactName": {
"typeName": "datasetContactName",
"multiple": false,
"typeClass": "primitive",
"value": "Admin, Dataverse"
},
"datasetContactAffiliation": {
"typeName": "datasetContactAffiliation",
"multiple": false,
"typeClass": "primitive",
"value": "sbgrid.org / SBDG"
},
"datasetContactEmail": {
"typeName": "datasetContactEmail",
"multiple": false,
"typeClass": "primitive",
"value": "generic@mailinator.com"
}
}
]
},
{
"typeName": "dsDescription",
"multiple": true,
"typeClass": "compound",
"value": [
{
"dsDescriptionValue": {
"typeName": "dsDescriptionValue",
"multiple": false,
"typeClass": "primitive",
"value": "Native dataset"
}
}
]
},
{
"typeName": "subject",
"multiple": true,
"typeClass": "controlledVocabulary",
"value": [
"Medicine, Health and Life Sciences",
"Other"
]
},
{
"typeName": "publication",
"multiple": true,
"typeClass": "compound",
"value": [
{
"publicationIDType": {
"typeName": "publicationIDType",
"multiple": false,
"typeClass": "controlledVocabulary",
"value": "doi"
},
"publicationIDNumber": {
"typeName": "publicationIDNumber",
"multiple": false,
"typeClass": "primitive",
"value": "10.1016/ j.cell.2011.10.020"
},
"publicationURL": {
"typeName": "publicationURL",
"multiple": false,
"typeClass": "primitive",
"value": "http://dx.doi.org/10.1016/j.cell.2011.10.020"
}
}
]
},
{
"typeName": "contributor",
"multiple": true,
"typeClass": "compound",
"value": [
{
"contributorType": {
"typeName": "contributorType",
"multiple": false,
"typeClass": "controlledVocabulary",
"value": "Data Collector"
},
"contributorName": {
"typeName": "contributorName",
"multiple": false,
"typeClass": "primitive",
"value": "Nam, Yunsun"
}
}
]
},
{
"typeName": "depositor",
"multiple": false,
"typeClass": "primitive",
"value": "Sliz, Piotr"
},
{
"typeName": "dateOfDeposit",
"multiple": false,
"typeClass": "primitive",
"value": "2015-04-13T18:14:17Z"
},
{
"typeName": "relatedDatasets",
"multiple": true,
"typeClass": "primitive",
"value": [
"<a href=\"https://dv.sbgrid.org/dataset.xhtml?persistentId=doi:10.15785/SBGRID/3\" target=\"_blank\">doi:10.15785/SBGRID/3</a>"
]
}
]
}
},

"files": [
{
"description": "",
"label": "yn152_4_001.img",
"directoryLabel": "data/subdir1/",
"version": 1,
"datasetVersionId": 2,
"dataFile": {
"id": 424,
"filename": "yn152_4_001.img",
"contentType": "application/octet-stream",
"storageIdentifier": "data/subdir/yn152_4_001.img",
"originalFormatLabel": "UNKNOWN",
"checksum": {
"type": "MD5",
"value": "fc4ac06da6fd84785ed1b79cab9b714a73621ac7"
},
"description": ""
}
},
{
"description": "",
"label": "yn152_4_002.img",
"directoryLabel": "/data/subdir2",
"version": 1,
"datasetVersionId": 2,
"dataFile": {
"id": 425,
"filename": "yn152_4_002.img",
"contentType": "application/octet-stream",
"storageIdentifier": "data/subdir/yn152_4_002.img",
"originalFormatLabel": "UNKNOWN",
"checksum": {
"type": "MD5",
"value": "756c1963e34eb6dd8bb5b48333c4f20ce64a0307"
},
"description": ""
}
}
]
}
}
4 changes: 2 additions & 2 deletions src/test/resources/json/complete-dataset-with-files.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
{
"description": "",
"label": "yn152_4_001.img",
"directoryLabel": "data/subdir1/",
"directoryLabel": "data/subdir1",
"version": 1,
"datasetVersionId": 2,
"dataFile": {
Expand All @@ -189,7 +189,7 @@
{
"description": "",
"label": "yn152_4_002.img",
"directoryLabel": "data/subdir2/",
"directoryLabel": "data/subdir2",
"version": 1,
"datasetVersionId": 2,
"dataFile": {
Expand Down

0 comments on commit 8e4b749

Please sign in to comment.