diff --git a/src/test/java/edu/harvard/iq/dataverse/api/imports/ImportGenericServiceBeanTest.java b/src/test/java/edu/harvard/iq/dataverse/api/imports/ImportGenericServiceBeanTest.java index a4a4ffa5dca..ac17a5981dc 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/imports/ImportGenericServiceBeanTest.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/imports/ImportGenericServiceBeanTest.java @@ -6,6 +6,7 @@ import org.apache.commons.io.FileUtils; import com.google.gson.Gson; import java.io.File; +import java.io.IOException; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -23,51 +24,43 @@ public class ImportGenericServiceBeanTest { private ImportGenericServiceBean importGenericService; @Test - void testIdentifierHarvestableWithOtherID() { - - try { - // "otherIdValue" containing the value : doi:10.7910/DVN/TJCLKP - File file = new File("src/test/java/edu/harvard/iq/dataverse/util/json/JsonImportGenericWithOtherId.txt"); - String text = FileUtils.readFileToString(file, StandardCharsets.UTF_8); - DatasetVersionDTO dto = new Gson().fromJson(text, DatasetVersionDTO.class); + void testIdentifierHarvestableWithOtherID() throws IOException { + // "otherIdValue" containing the value : doi:10.7910/DVN/TJCLKP + File file = new File("src/test/resources/json/importGenericWithOtherId.json"); + String text = FileUtils.readFileToString(file, StandardCharsets.UTF_8); + DatasetVersionDTO dto = new Gson().fromJson(text, DatasetVersionDTO.class); - assertEquals("doi:10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "https://doi.org/10.7910/DVN/TJCLKP")); - // junk or null - assertEquals("doi:10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "junk")); - assertEquals("doi:10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, null)); - - } catch (Exception e) { - e.printStackTrace(); - } - + assertEquals("doi:10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "https://doi.org/10.7910/DVN/TJCLKP")); + // junk or null + assertEquals("doi:10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "junk")); + assertEquals("doi:10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, null)); + assertEquals("doi:10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "http://www.example.com")); + assertEquals("doi:10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "https://dataverse.org")); } @Test - void testIdentifierHarvestableWithoutOtherID() { - try { - // Does not contain data of type "otherIdValue" - File file = new File("src/test/java/edu/harvard/iq/dataverse/util/json/JsonImportGenericWithoutOtherId.txt"); - String text = FileUtils.readFileToString(file, StandardCharsets.UTF_8); - DatasetVersionDTO dto = new Gson().fromJson(text, DatasetVersionDTO.class); + void testIdentifierHarvestableWithoutOtherID() throws IOException { + // Does not contain data of type "otherIdValue" + File file = new File("src/test/resources/json/importGenericWithoutOtherId.json"); + String text = FileUtils.readFileToString(file, StandardCharsets.UTF_8); + DatasetVersionDTO dto = new Gson().fromJson(text, DatasetVersionDTO.class); - // non-URL - assertEquals("doi:10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "doi:10.7910/DVN/TJCLKP")); - assertEquals("hdl:10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "hdl:10.7910/DVN/TJCLKP")); - // HTTPS - assertEquals("https://doi.org/10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "https://doi.org/10.7910/DVN/TJCLKP")); - assertEquals("https://dx.doi.org/10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "https://dx.doi.org/10.7910/DVN/TJCLKP")); - assertEquals("https://hdl.handle.net/10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "https://hdl.handle.net/10.7910/DVN/TJCLKP")); - // HTTP (no S) - assertEquals("http://doi.org/10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "http://doi.org/10.7910/DVN/TJCLKP")); - assertEquals("http://dx.doi.org/10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "http://dx.doi.org/10.7910/DVN/TJCLKP")); - assertEquals("http://hdl.handle.net/10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "http://hdl.handle.net/10.7910/DVN/TJCLKP")); - // junk or null - assertNull(importGenericService.getIdentifierHarvestableByDataverse(dto, "junk")); - assertNull(importGenericService.getIdentifierHarvestableByDataverse(dto, null)); - - } catch (Exception e) { - e.printStackTrace(); - } + // non-URL + assertEquals("doi:10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "doi:10.7910/DVN/TJCLKP")); + assertEquals("hdl:10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "hdl:10.7910/DVN/TJCLKP")); + // HTTPS + assertEquals("https://doi.org/10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "https://doi.org/10.7910/DVN/TJCLKP")); + assertEquals("https://dx.doi.org/10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "https://dx.doi.org/10.7910/DVN/TJCLKP")); + assertEquals("https://hdl.handle.net/10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "https://hdl.handle.net/10.7910/DVN/TJCLKP")); + // HTTP (no S) + assertEquals("http://doi.org/10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "http://doi.org/10.7910/DVN/TJCLKP")); + assertEquals("http://dx.doi.org/10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "http://dx.doi.org/10.7910/DVN/TJCLKP")); + assertEquals("http://hdl.handle.net/10.7910/DVN/TJCLKP", importGenericService.getIdentifierHarvestableByDataverse(dto, "http://hdl.handle.net/10.7910/DVN/TJCLKP")); + // junk or null + assertNull(importGenericService.getIdentifierHarvestableByDataverse(dto, "junk")); + assertNull(importGenericService.getIdentifierHarvestableByDataverse(dto, null)); + assertNull(importGenericService.getIdentifierHarvestableByDataverse(dto, "http://www.example.com")); + assertNull(importGenericService.getIdentifierHarvestableByDataverse(dto, "https://dataverse.org")); } @Test @@ -85,6 +78,8 @@ void testReassignIdentifierAsGlobalId() { assertEquals("hdl:10.7910/DVN/TJCLKP", importGenericService.reassignIdentifierAsGlobalId("http://hdl.handle.net/10.7910/DVN/TJCLKP", new DatasetDTO())); // junk assertNull(importGenericService.reassignIdentifierAsGlobalId("junk", new DatasetDTO())); + assertNull(importGenericService.reassignIdentifierAsGlobalId("http://www.example.com", new DatasetDTO())); + assertNull(importGenericService.reassignIdentifierAsGlobalId("https://dataverse.org", new DatasetDTO())); } } diff --git a/src/test/java/edu/harvard/iq/dataverse/util/json/JsonImportGenericWithOtherId.txt b/src/test/resources/json/importGenericWithOtherId.json similarity index 100% rename from src/test/java/edu/harvard/iq/dataverse/util/json/JsonImportGenericWithOtherId.txt rename to src/test/resources/json/importGenericWithOtherId.json diff --git a/src/test/java/edu/harvard/iq/dataverse/util/json/JsonImportGenericWithoutOtherId.txt b/src/test/resources/json/importGenericWithoutOtherId.json similarity index 100% rename from src/test/java/edu/harvard/iq/dataverse/util/json/JsonImportGenericWithoutOtherId.txt rename to src/test/resources/json/importGenericWithoutOtherId.json