Skip to content

Commit 9e9edd3

Browse files
committed
Show values for controlled vocabulary, add tests #8944
With toArray().toString() we were getting something like this: [Ljava.lang.Object;@76d0a290
1 parent 80138ef commit 9e9edd3

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

src/main/java/edu/harvard/iq/dataverse/util/json/JsonPrinter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,11 @@ public static JsonObjectBuilder json(DatasetFieldType fld) {
555555
if (fld.isControlledVocabulary()) {
556556
// If the field has a controlled vocabulary,
557557
// add all values to the resulting JSON
558-
fieldsBld.add(
559-
"controlledVocabularyValues",
560-
fld.getControlledVocabularyValues().toArray().toString());
558+
JsonArrayBuilder jab = Json.createArrayBuilder();
559+
for (ControlledVocabularyValue cvv : fld.getControlledVocabularyValues()) {
560+
jab.add(cvv.getStrValue());
561+
}
562+
fieldsBld.add("controlledVocabularyValues", jab);
561563
}
562564
if (!fld.getChildDatasetFieldTypes().isEmpty()) {
563565
JsonObjectBuilder subFieldsBld = jsonObjectBuilder();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package edu.harvard.iq.dataverse.api;
2+
3+
import com.jayway.restassured.RestAssured;
4+
import com.jayway.restassured.response.Response;
5+
import static javax.ws.rs.core.Response.Status.OK;
6+
import org.hamcrest.CoreMatchers;
7+
import org.junit.BeforeClass;
8+
import org.junit.Test;
9+
10+
public class MetadataBlocksIT {
11+
12+
@BeforeClass
13+
public static void setUpClass() {
14+
RestAssured.baseURI = UtilIT.getRestAssuredBaseUri();
15+
}
16+
17+
@Test
18+
public void testGetCitationBlock() {
19+
Response getCitationBlock = UtilIT.getMetadataBlock("citation");
20+
getCitationBlock.prettyPrint();
21+
getCitationBlock.then().assertThat()
22+
.statusCode(OK.getStatusCode())
23+
.body("data.fields.subject.controlledVocabularyValues[0]", CoreMatchers.is("Agricultural Sciences"));
24+
}
25+
26+
}

src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,11 @@ static Response setMetadataBlocks(String dataverseAlias, JsonArrayBuilder blocks
567567
.post("/api/dataverses/" + dataverseAlias + "/metadatablocks");
568568
}
569569

570+
static Response getMetadataBlock(String block) {
571+
return given()
572+
.get("/api/metadatablocks/" + block);
573+
}
574+
570575
static private String getDatasetXml(String title, String author, String description) {
571576
String nullLicense = null;
572577
String nullRights = null;

tests/integration-tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
DataversesIT,DatasetsIT,SwordIT,AdminIT,BuiltinUsersIT,UsersIT,UtilIT,ConfirmEmailIT,FileMetadataIT,FilesIT,SearchIT,InReviewWorkflowIT,HarvestingServerIT,HarvestingClientsIT,MoveIT,MakeDataCountApiIT,FileTypeDetectionIT,EditDDIIT,ExternalToolsIT,AccessIT,DuplicateFilesIT,DownloadFilesIT,LinkIT,DeleteUsersIT,DeactivateUsersIT,AuxiliaryFilesIT,InvalidCharactersIT,LicensesIT,NotificationsIT,BagIT
1+
DataversesIT,DatasetsIT,SwordIT,AdminIT,BuiltinUsersIT,UsersIT,UtilIT,ConfirmEmailIT,FileMetadataIT,FilesIT,SearchIT,InReviewWorkflowIT,HarvestingServerIT,HarvestingClientsIT,MoveIT,MakeDataCountApiIT,FileTypeDetectionIT,EditDDIIT,ExternalToolsIT,AccessIT,DuplicateFilesIT,DownloadFilesIT,LinkIT,DeleteUsersIT,DeactivateUsersIT,AuxiliaryFilesIT,InvalidCharactersIT,LicensesIT,NotificationsIT,BagIT,MetadataBlocksIT

0 commit comments

Comments
 (0)