-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started implementing tests for the sword examples.
- Loading branch information
1 parent
28d6484
commit 0efb264
Showing
3 changed files
with
154 additions
and
6 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
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 |
---|---|---|
|
@@ -17,12 +17,13 @@ | |
|
||
import nl.knaw.dans.dvingest.core.service.YamlService; | ||
import nl.knaw.dans.dvingest.core.service.YamlServiceImpl; | ||
import nl.knaw.dans.lib.dataverse.model.dataset.Dataset; | ||
import nl.knaw.dans.lib.dataverse.model.user.AuthenticatedUser; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
@@ -34,20 +35,36 @@ public class DansDepositConverterTest extends DansConversionFixture { | |
@Test | ||
public void run_converts_dans_sword_all_mappings_example_to_dataverse_ingest_deposit() throws Exception { | ||
// Given | ||
FileUtils.copyDirectoryToDirectory(Paths.get("src/test/resources/unit-test/d0919038-9866-49e8-986a-bcef54ae7566").toFile(), testDir.toFile()); | ||
var depositDir = testDir.resolve("d0919038-9866-49e8-986a-bcef54ae7566"); | ||
var deposit = dansBagDepositReader.readDeposit(depositDir); | ||
var depositDir = createValidDeposit("all-mappings", "00000000-0000-0000-0000-000000000001"); | ||
var authenticatedUser = new AuthenticatedUser(); | ||
authenticatedUser.setFirstName("John"); | ||
authenticatedUser.setLastName("Doe"); | ||
authenticatedUser.setEmail("[email protected]"); | ||
authenticatedUser.setDisplayName("John Doe"); | ||
Mockito.when(dataverseServiceMock.getUserById(Mockito.anyString())).thenReturn(Optional.of(authenticatedUser)); | ||
var deposit = dansBagDepositReader.readDeposit(depositDir); | ||
|
||
// When | ||
new DansDepositConverter(deposit, null, mappingService, yamlService).run(); | ||
|
||
// Then | ||
assertThat(deposit.getBagDir().resolve("dataset.yml")).exists(); | ||
var datasetYml = yamlService.readYaml(deposit.getBagDir().resolve("dataset.yml"), Dataset.class); | ||
var citationBlockFields = datasetYml.getDatasetVersion().getMetadataBlocks().get("citation").getFields(); | ||
// Find the metadata field with property typeName = "title" | ||
assertPrimitiveSinglevalueFieldContainsValue(citationBlockFields, "title", "A bag containing examples for each mapping rule"); | ||
assertPrimitiveMultiValueFieldContainsValues(citationBlockFields, "alternativeTitle", "DCTERMS title 1"); | ||
assertCompoundMultiValueFieldContainsValues2(citationBlockFields, "datasetContact", Map.of( | ||
"datasetContactName", "John Doe", | ||
"datasetContactEmail", "[email protected]" | ||
)); | ||
assertCompoundMultiValueFieldContainsValues2(citationBlockFields, "otherId", | ||
Map.of("otherIdAgency", "", "otherIdValue", "DCTERMS_ID001"), | ||
Map.of("otherIdAgency", "", "otherIdValue", "DC_ID002"), | ||
Map.of("otherIdAgency", "", "otherIdValue", "DCTERMS_ID003"), | ||
Map.of("otherIdAgency", "TESTPREFIX", "otherIdValue", "1234")); | ||
|
||
|
||
} | ||
|
||
} |