Skip to content

Commit

Permalink
assert how "keywords" works, increase code coverage #4371
Browse files Browse the repository at this point in the history
from 41.16% to 42.94% for DatasetVersion
  • Loading branch information
pdurbin committed Oct 11, 2018
1 parent a6915d7 commit fe01e80
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ public void setUp() {
dsDescriptionType.setChildDatasetFieldTypes(dsDescriptionTypes);

DatasetFieldType keywordType = datasetFieldTypeSvc.add(new DatasetFieldType("keyword", DatasetFieldType.FieldType.TEXT, true));
Set<DatasetFieldType> keywordChildTypes = new HashSet<>();
keywordChildTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("keywordValue", DatasetFieldType.FieldType.TEXT, false)));
keywordChildTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("keywordVocabulary", DatasetFieldType.FieldType.TEXT, false)));
keywordChildTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("keywordVocabularyURI", DatasetFieldType.FieldType.TEXT, false)));
keywordType.setChildDatasetFieldTypes(keywordChildTypes);

DatasetFieldType topicClassificationType = datasetFieldTypeSvc.add(new DatasetFieldType("topicClassification", DatasetFieldType.FieldType.TEXT, true));
Set<DatasetFieldType> topicClassificationTypes = new HashSet<>();
topicClassificationTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("topicClassValue", DatasetFieldType.FieldType.TEXT, false)));
topicClassificationTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("topicClassVocab", DatasetFieldType.FieldType.TEXT, false)));
topicClassificationTypes.add(datasetFieldTypeSvc.add(new DatasetFieldType("topicClassVocabURI", DatasetFieldType.FieldType.TEXT, false)));
topicClassificationType.setChildDatasetFieldTypes(topicClassificationTypes);

DatasetFieldType descriptionType = datasetFieldTypeSvc.add(new DatasetFieldType("description", DatasetFieldType.FieldType.TEXTBOX, false));

DatasetFieldType subjectType = datasetFieldTypeSvc.add(new DatasetFieldType("subject", DatasetFieldType.FieldType.TEXT, true));
Expand Down Expand Up @@ -128,7 +141,7 @@ public void tearDown() {
@Test
public void testExportDataset() throws Exception {
System.out.println("exportDataset");
File datasetVersionJson = new File("src/test/resources/json/dataset-finch1.json");
File datasetVersionJson = new File("src/test/resources/json/dataset-finch2.json");
String datasetVersionAsJson = new String(Files.readAllBytes(Paths.get(datasetVersionJson.getAbsolutePath())));

JsonReader jsonReader1 = Json.createReader(new StringReader(datasetVersionAsJson));
Expand Down Expand Up @@ -168,6 +181,11 @@ public void testExportDataset() throws Exception {
assertEquals("1", json2.getString("version"));
assertEquals("Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds.", json2.getString("description"));
assertEquals("Medicine, Health and Life Sciences", json2.getJsonArray("keywords").getString(0));
assertEquals("tcTerm1", json2.getJsonArray("keywords").getString(1));
assertEquals("KeywordTerm1", json2.getJsonArray("keywords").getString(2));
assertEquals("KeywordTerm2", json2.getJsonArray("keywords").getString(3));
// This dataset, for example, has multiple keywords separated by commas: https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/24034&version=2.0
assertEquals("keywords, with, commas", json2.getJsonArray("keywords").getString(4));
assertEquals("https://schema.org/version/3.3", json2.getString("schemaVersion"));
assertEquals("DataCatalog", json2.getJsonObject("includedInDataCatalog").getString("@type"));
assertEquals("LibraScholar", json2.getJsonObject("includedInDataCatalog").getString("name"));
Expand Down
158 changes: 158 additions & 0 deletions src/test/resources/json/dataset-finch2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"datasetVersion": {
"metadataBlocks": {
"citation": {
"fields": [
{
"value": "Darwin's Finches",
"typeClass": "primitive",
"multiple": false,
"typeName": "title"
},
{
"value": [
{
"authorName": {
"value": "Finch, Fiona",
"typeClass": "primitive",
"multiple": false,
"typeName": "authorName"
},
"authorAffiliation": {
"value": "Birds Inc.",
"typeClass": "primitive",
"multiple": false,
"typeName": "authorAffiliation"
}
}
],
"typeClass": "compound",
"multiple": true,
"typeName": "author"
},
{
"value": [
{
"datasetContactEmail": {
"typeClass": "primitive",
"multiple": false,
"typeName": "datasetContactEmail",
"value": "[email protected]"
}
}
],
"typeClass": "compound",
"multiple": true,
"typeName": "datasetContact"
},
{
"value": [
{
"dsDescriptionValue": {
"value": "Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds.",
"multiple": false,
"typeClass": "primitive",
"typeName": "dsDescriptionValue"
}
}
],
"typeClass": "compound",
"multiple": true,
"typeName": "dsDescription"
},
{
"value": [
"Medicine, Health and Life Sciences"
],
"typeClass": "controlledVocabulary",
"multiple": true,
"typeName": "subject"
},
{
"typeName": "keyword",
"multiple": true,
"typeClass": "compound",
"value": [
{
"keywordValue": {
"typeName": "keywordValue",
"multiple": false,
"typeClass": "primitive",
"value": "KeywordTerm1"
},
"keywordVocabulary": {
"typeName": "keywordVocabulary",
"multiple": false,
"typeClass": "primitive",
"value": "KeywordVocabulary1"
},
"keywordVocabularyURI": {
"typeName": "keywordVocabularyURI",
"multiple": false,
"typeClass": "primitive",
"value": "http://KeywordVocabularyURL1.org"
}
},
{
"keywordValue": {
"typeName": "keywordValue",
"multiple": false,
"typeClass": "primitive",
"value": "KeywordTerm2"
},
"keywordVocabulary": {
"typeName": "keywordVocabulary",
"multiple": false,
"typeClass": "primitive",
"value": "KeywordVocabulary2"
},
"keywordVocabularyURI": {
"typeName": "keywordVocabularyURI",
"multiple": false,
"typeClass": "primitive",
"value": "http://KeywordVocabularyURL2.org"
}
},
{
"keywordValue": {
"typeName": "keywordValue",
"multiple": false,
"typeClass": "primitive",
"value": "keywords, with, commas"
}
}
]
},
{
"typeName": "topicClassification",
"multiple": true,
"typeClass": "compound",
"value": [
{
"topicClassValue": {
"typeName": "topicClassValue",
"multiple": false,
"typeClass": "primitive",
"value": "tcTerm1"
},
"topicClassVocab": {
"typeName": "topicClassVocab",
"multiple": false,
"typeClass": "primitive",
"value": "tcVocab1"
},
"topicClassVocabURI": {
"typeName": "topicClassVocabURI",
"multiple": false,
"typeClass": "primitive",
"value": "http://example.com/tcTerm1"
}
}
]
}
],
"displayName": "Citation Metadata"
}
}
}
}

0 comments on commit fe01e80

Please sign in to comment.