Skip to content

Commit

Permalink
load codemeta metadata block in docker dev persona #10519
Browse files Browse the repository at this point in the history
It's used in API tests.
  • Loading branch information
pdurbin committed Nov 8, 2024
1 parent e7652db commit 5afad8e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 28 deletions.
2 changes: 2 additions & 0 deletions doc/release-notes/10519-dataset-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ This will have the following effects for the APIs used by the new Dataverse UI (
- The list of fields shown when creating a dataset will include fields marked as "displayoncreate" (in the tsv/database) for metadata blocks (e.g. "CodeMeta") that are linked to the dataset type (e.g. "software") that is passed to the API.
- The metadata blocks shown when editing a dataset will include metadata blocks (e.g. "CodeMeta") that are linked to the dataset type (e.g. "software") that is passed to the API.

The CodeMeta metadata block is now available in the Dockerized development environment.

For more information, see the guides and #10519.
2 changes: 2 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ services:
- dev
networks:
- dataverse
volumes:
- ./docker-dev-volumes/solr/data:/var/solr

dev_dv_initializer:
container_name: "dev_dv_initializer"
Expand Down
9 changes: 9 additions & 0 deletions modules/container-configbaker/scripts/bootstrap/dev/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ export API_TOKEN
# ${ENV_OUT} comes from bootstrap.sh and will expose the saved information back to the host if enabled.
echo "API_TOKEN=${API_TOKEN}" >> "${ENV_OUT}"

echo "Loading CodeMeta metadata block (needed for API tests)..."
curl "${DATAVERSE_URL}/api/admin/datasetfield/load" -X POST --data-binary @/scripts/bootstrap/base/data/metadatablocks/codemeta.tsv -H "Content-type: text/tab-separated-values"

echo "Fetching Solr schema from Dataverse and running update-fields.sh..."
curl "${DATAVERSE_URL}/api/admin/index/solr/schema" | /scripts/update-fields.sh /var/solr/data/collection1/conf/schema.xml

echo "Reloading Solr..."
curl "http://solr:8983/solr/admin/cores?action=RELOAD&core=collection1"

echo "Publishing root dataverse..."
curl -H "X-Dataverse-key:$API_TOKEN" -X POST "${DATAVERSE_URL}/api/dataverses/:root/actions/:publish"

Expand Down
18 changes: 0 additions & 18 deletions src/test/java/edu/harvard/iq/dataverse/api/DatasetTypesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import static jakarta.ws.rs.core.Response.Status.CREATED;
import static jakarta.ws.rs.core.Response.Status.FORBIDDEN;
import static jakarta.ws.rs.core.Response.Status.OK;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.UUID;
import org.hamcrest.CoreMatchers;
import static org.hamcrest.CoreMatchers.equalTo;
Expand Down Expand Up @@ -409,22 +407,6 @@ public void testUpdateDatasetTypeLinksWithMetadataBlocks() {

@Test
public void testLinkSoftwareToCodemeta() {
Response listBlocksAvailable = UtilIT.listMetadataBlocks(false, false);
listBlocksAvailable.then().assertThat().statusCode(OK.getStatusCode());
String blocksAsString = JsonPath.from(listBlocksAvailable.getBody().asString()).getString("data");
System.out.println("blocks: " + blocksAsString);
if (!blocksAsString.contains("codeMeta20")) {
System.out.println("CodeMeta hasn't been added. Adding it...");
byte[] codemetaTsv = null;
try {
codemetaTsv = java.nio.file.Files.readAllBytes(Paths.get("scripts/api/data/metadatablocks/codemeta.tsv"));
} catch (IOException e) {
}
UtilIT.loadMetadataBlock("", codemetaTsv);
} else {
System.out.println("CodeMeta has already been added.");
}

Response createUser = UtilIT.createRandomUser();
createUser.then().assertThat().statusCode(OK.getStatusCode());
String username = UtilIT.getUsernameFromResponse(createUser);
Expand Down
13 changes: 3 additions & 10 deletions src/test/java/edu/harvard/iq/dataverse/api/MetadataBlocksIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import org.junit.jupiter.api.Disabled;

public class MetadataBlocksIT {

Expand All @@ -22,30 +21,24 @@ public static void setUpClass() {
RestAssured.baseURI = UtilIT.getRestAssuredBaseUri();
}

/**
* TODO: re-enable this test after deciding how to allow additional metadata
* blocks to be added by other tests. We load the "codeMeta20" block in
* DatasetTypesIT#testLinkSoftwareToCodemeta but it causes this test to
* break. It asserts there are only 6 blocks, for example.
*/
@Disabled
@Test
void testListMetadataBlocks() {
// No optional params enabled
Response listMetadataBlocksResponse = UtilIT.listMetadataBlocks(false, false);
int expectedDefaultNumberOfMetadataBlocks = 6;
int expectedDefaultNumberOfMetadataBlocks = 7;
listMetadataBlocksResponse.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data[0].fields", equalTo(null))
.body("data.size()", equalTo(expectedDefaultNumberOfMetadataBlocks));

// onlyDisplayedOnCreate=true
listMetadataBlocksResponse = UtilIT.listMetadataBlocks(true, false);
int expectedOnlyDisplayedOnCreateNumberOfMetadataBlocks = 1;
int expectedOnlyDisplayedOnCreateNumberOfMetadataBlocks = 2;
listMetadataBlocksResponse.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data[0].fields", equalTo(null))
.body("data[0].displayName", equalTo("Citation Metadata"))
.body("data[1].displayName", equalTo("Software Metadata (CodeMeta v2.0)"))
.body("data.size()", equalTo(expectedOnlyDisplayedOnCreateNumberOfMetadataBlocks));

// returnDatasetFieldTypes=true
Expand Down

0 comments on commit 5afad8e

Please sign in to comment.