diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 05d6aefe092..e4b88c595b8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -68,6 +68,6 @@ jobs: mvn --version - name: run build run: - mvn clean install -B '-Pall-tests,flyway,checkstyle,spotbugs,!development' && xvfb-run --server-args="-screen 0 1600x1280x24" mvn clean install -B '-Pselenium,!development' + mvn clean install -B '-Pall-tests,flyway,checkstyle,!development' && xvfb-run --server-args="-screen 0 1600x1280x24" mvn clean install -B '-Pselenium,!development' diff --git a/Kitodo-API/pom.xml b/Kitodo-API/pom.xml index 5931ee81f59..15801a17745 100644 --- a/Kitodo-API/pom.xml +++ b/Kitodo-API/pom.xml @@ -82,10 +82,6 @@ org.junit.jupiter junit-jupiter-engine - - org.junit.vintage - junit-vintage-engine - org.mockito mockito-core diff --git a/Kitodo-API/src/test/java/org/kitodo/api/dataformat/DivisionTest.java b/Kitodo-API/src/test/java/org/kitodo/api/dataformat/DivisionTest.java index eb828c45b69..3be853eed44 100644 --- a/Kitodo-API/src/test/java/org/kitodo/api/dataformat/DivisionTest.java +++ b/Kitodo-API/src/test/java/org/kitodo/api/dataformat/DivisionTest.java @@ -11,13 +11,13 @@ package org.kitodo.api.dataformat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; import java.util.stream.Collectors; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class DivisionTest { diff --git a/Kitodo-API/src/test/java/org/kitodo/config/ConfigTest.java b/Kitodo-API/src/test/java/org/kitodo/config/ConfigTest.java index 9fab06b676a..89618d8861a 100644 --- a/Kitodo-API/src/test/java/org/kitodo/config/ConfigTest.java +++ b/Kitodo-API/src/test/java/org/kitodo/config/ConfigTest.java @@ -16,7 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import org.apache.commons.configuration.PropertiesConfiguration; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ConfigTest { diff --git a/Kitodo-API/src/test/java/org/kitodo/config/KitodoConfigTest.java b/Kitodo-API/src/test/java/org/kitodo/config/KitodoConfigTest.java index 9f82b224f86..45da50584cd 100644 --- a/Kitodo-API/src/test/java/org/kitodo/config/KitodoConfigTest.java +++ b/Kitodo-API/src/test/java/org/kitodo/config/KitodoConfigTest.java @@ -11,10 +11,10 @@ package org.kitodo.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockStatic; @@ -22,8 +22,8 @@ import java.util.NoSuchElementException; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kitodo.config.enums.ParameterAPI; public class KitodoConfigTest { @@ -35,7 +35,7 @@ public class KitodoConfigTest { * * @throws Exception the exceptions thrown by method */ - @BeforeClass + @BeforeAll public static void init() { NONE = mock(ParameterAPI.class); doReturn(3).when(NONE).ordinal(); @@ -49,13 +49,13 @@ public static void init() { @Test public void shouldGetStringParameterWithoutDefault() { String param = KitodoConfig.getParameter(ParameterAPI.DIR_XML_CONFIG); - assertEquals("Incorrect param!", "String", param); + assertEquals("String", param, "Incorrect param!"); } @Test public void shouldGetStringParameterWithDefault() { String param = KitodoConfig.getParameter(ParameterAPI.DIR_XML_CONFIG, "test"); - assertEquals("Incorrect param!", "String", param); + assertEquals("String", param, "Incorrect param!"); } @Test @@ -64,52 +64,51 @@ public void shouldGetStringParameterForNonexistentWithoutDefault() { () -> KitodoConfig.getParameter(ParameterAPI.DIR_PROCESSES), "Expected NoSuchElementException to be thrown, but it didn't"); - assertEquals("No configuration found in kitodo_config.properties for key directory.metadata!", - thrown.getMessage()); + assertEquals("No configuration found in kitodo_config.properties for key directory.metadata!", thrown.getMessage()); } @Test public void shouldGetStringParameterForNonexistentWithDefault() { String param = KitodoConfig.getParameter(ParameterAPI.DIR_PROCESSES, "Default"); - assertEquals("Incorrect param!", "Default", param); + assertEquals("Default", param, "Incorrect param!"); } @Test public void shouldGetBooleanParameter() { - assertTrue("Incorrect param!", KitodoConfig.getBooleanParameter(ParameterAPI.DIR_MODULES)); + assertTrue(KitodoConfig.getBooleanParameter(ParameterAPI.DIR_MODULES), "Incorrect param!"); } @Test public void shouldGetBooleanParameterForNonexistentWithoutDefault() { - assertFalse("Incorrect param!", KitodoConfig.getBooleanParameter(ParameterAPI.DIR_PROCESSES)); + assertFalse(KitodoConfig.getBooleanParameter(ParameterAPI.DIR_PROCESSES), "Incorrect param!"); } @Test public void shouldGetBooleanParameterForNonexistentWithDefault() { - assertTrue("Incorrect param!", KitodoConfig.getBooleanParameter(ParameterAPI.DIR_PROCESSES, true)); + assertTrue(KitodoConfig.getBooleanParameter(ParameterAPI.DIR_PROCESSES, true), "Incorrect param!"); } @Test public void shouldGetIntParameterWithoutDefault() { int param = KitodoConfig.getIntParameter(NONE); - assertEquals("Incorrect param for non existing enum without default value!", 0, param); + assertEquals(0, param, "Incorrect param for non existing enum without default value!"); } @Test public void shouldGetIntParameterWithDefault() { int param = KitodoConfig.getIntParameter(NONE, 3); - assertEquals("Incorrect param for non existing enum with default value!", 3, param); + assertEquals(3, param, "Incorrect param for non existing enum with default value!"); } @Test public void shouldGetIntParameterForNonexistentWithoutDefault() { int param = KitodoConfig.getIntParameter(ParameterAPI.DIR_PROCESSES); - assertEquals("Incorrect param!", 0, param); + assertEquals(0, param, "Incorrect param!"); } @Test public void shouldGetIntParameterForNonexistentWithDefault() { int param = KitodoConfig.getIntParameter(ParameterAPI.DIR_PROCESSES, 3); - assertEquals("Incorrect param!", 3, param); + assertEquals(3, param, "Incorrect param!"); } } diff --git a/Kitodo-API/src/test/java/org/kitodo/utils/MediaUtilTest.java b/Kitodo-API/src/test/java/org/kitodo/utils/MediaUtilTest.java index d106a76074c..f39cd300e7f 100644 --- a/Kitodo-API/src/test/java/org/kitodo/utils/MediaUtilTest.java +++ b/Kitodo-API/src/test/java/org/kitodo/utils/MediaUtilTest.java @@ -11,11 +11,11 @@ package org.kitodo.utils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kitodo.api.dataformat.PhysicalDivision; public class MediaUtilTest { diff --git a/Kitodo-DataFormat/src/main/java/org/kitodo/dataformat/access/DivXmlElementAccess.java b/Kitodo-DataFormat/src/main/java/org/kitodo/dataformat/access/DivXmlElementAccess.java index 7ebd2327d83..df63a7350e7 100644 --- a/Kitodo-DataFormat/src/main/java/org/kitodo/dataformat/access/DivXmlElementAccess.java +++ b/Kitodo-DataFormat/src/main/java/org/kitodo/dataformat/access/DivXmlElementAccess.java @@ -15,6 +15,7 @@ import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.Collection; +import java.util.Comparator; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -254,8 +255,9 @@ DivType toDiv(Map physicalDivisionIDs, LinkedList Pair.of(metsReferrerId, physicalDivisionId)).collect(Collectors.toList())); + smLinkData.addAll(super.getViews().stream().map(View::getPhysicalDivision) + .sorted(Comparator.comparing(PhysicalDivision::getOrder)).map(physicalDivisionIDs::get) + .map(physicalDivisionId -> Pair.of(metsReferrerId, physicalDivisionId)).collect(Collectors.toList())); Optional optionalDmdSec = createMdSec(super.getMetadata(), MdSec.DMD_SEC); if (optionalDmdSec.isPresent()) { diff --git a/Kitodo-DataFormat/src/main/java/org/kitodo/dataformat/access/MetsXmlElementAccess.java b/Kitodo-DataFormat/src/main/java/org/kitodo/dataformat/access/MetsXmlElementAccess.java index f27a6fb5642..52a8f45ec59 100644 --- a/Kitodo-DataFormat/src/main/java/org/kitodo/dataformat/access/MetsXmlElementAccess.java +++ b/Kitodo-DataFormat/src/main/java/org/kitodo/dataformat/access/MetsXmlElementAccess.java @@ -427,18 +427,19 @@ private DivType generatePhysicalStructMapRecursive(PhysicalDivision physicalDivi */ private StructLink createStructLink(LinkedList> smLinkData) { StructLink structLink = new StructLink(); - structLink.getSmLinkOrSmLinkGrp().addAll(smLinkData.parallelStream().map(entry -> { - if (Objects.isNull(entry.getLeft())) { - throw new IllegalArgumentException("smLinkData.entry[?].left must not be null"); + List content = structLink.getSmLinkOrSmLinkGrp(); + for (Pair link : smLinkData) { + if (Objects.isNull(link.getLeft())) { + throw new IllegalArgumentException("link.left must not be null"); } - if (Objects.isNull(entry.getRight())) { - throw new IllegalArgumentException("smLinkData.entry[?].right must not be null"); + if (Objects.isNull(link.getRight())) { + throw new IllegalArgumentException("link.right must not be null"); } SmLink smLink = new SmLink(); - smLink.setFrom(entry.getLeft()); - smLink.setTo(entry.getRight()); - return smLink; - }).collect(Collectors.toList())); + smLink.setFrom(link.getLeft()); + smLink.setTo(link.getRight()); + content.add(smLink); + } return structLink; } diff --git a/Kitodo-Validation/src/main/java/org/kitodo/validation/metadata/MetadataValidation.java b/Kitodo-Validation/src/main/java/org/kitodo/validation/metadata/MetadataValidation.java index 179dd4edb6d..9049049cac0 100644 --- a/Kitodo-Validation/src/main/java/org/kitodo/validation/metadata/MetadataValidation.java +++ b/Kitodo-Validation/src/main/java/org/kitodo/validation/metadata/MetadataValidation.java @@ -341,7 +341,7 @@ private static ValidationResult checkForDetailsInTheMetadata( .getSortedVisibleMetadata(containedMetadata, Collections.emptyList()); for (MetadataViewWithValuesInterface metadataViewWithValues : metadataViewsWithValues) { Optional optionalMetadataView = metadataViewWithValues.getMetadata(); - if (!optionalMetadataView.isPresent()) { + if (optionalMetadataView.isEmpty()) { continue; } MetadataViewInterface metadataView = optionalMetadataView.orElseThrow(IllegalStateException::new); @@ -419,7 +419,7 @@ private static Map> squash( Map> squashed = new HashMap<>(); for (MetadataViewWithValuesInterface metadataViewWithValues : metadataViewsWithValues) { Optional optionalMetadataView = metadataViewWithValues.getMetadata(); - if (!optionalMetadataView.isPresent()) { + if (optionalMetadataView.isEmpty()) { continue; } squashed.computeIfAbsent(optionalMetadataView.get(), each -> new ArrayList<>()); diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java index f933e656756..1c2c22b4c53 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java @@ -757,7 +757,7 @@ public List> getSelectedMedia() { *

Note: This method is called potentially thousands of times when rendering large galleries.

*/ public boolean consecutivePagesSelected() { - if (selectedMedia.isEmpty()) { + if (Objects.isNull(selectedMedia) || selectedMedia.isEmpty()) { return false; } int maxOrder = selectedMedia.stream().mapToInt(m -> m.getLeft().getOrder()).max().orElseThrow(NoSuchElementException::new); diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/massimport/MassImportForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/massimport/MassImportForm.java index d7dbed06d75..87087b4d011 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/massimport/MassImportForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/massimport/MassImportForm.java @@ -153,7 +153,7 @@ public void startMassImport() { importSuccessMap = new HashMap<>(); PrimeFaces.current().ajax().update("massImportResultDialog"); try { - Map> presetMetadata = massImportService.prepareMetadata(metadataKeys, records); + Map>> presetMetadata = massImportService.prepareMetadata(metadataKeys, records); importRecords(presetMetadata); PrimeFaces.current().executeScript("PF('massImportResultDialog').show();"); PrimeFaces.current().ajax().update("massImportResultDialog"); @@ -181,10 +181,10 @@ public void prepare() { * * @param processMetadata Map containing record IDs as keys and preset metadata lists as values */ - private void importRecords(Map> processMetadata) { + private void importRecords(Map>> processMetadata) { ImportService importService = ServiceManager.getImportService(); PrimeFaces.current().ajax().update("massImportProgressDialog"); - for (Map.Entry> entry : processMetadata.entrySet()) { + for (Map.Entry>> entry : processMetadata.entrySet()) { try { importService.importProcess(entry.getKey(), projectId, templateId, importConfiguration, entry.getValue()); diff --git a/Kitodo/src/main/java/org/kitodo/production/helper/FacesUtils.java b/Kitodo/src/main/java/org/kitodo/production/helper/FacesUtils.java deleted file mode 100644 index 35a6650474f..00000000000 --- a/Kitodo/src/main/java/org/kitodo/production/helper/FacesUtils.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * (c) Kitodo. Key to digital objects e. V. - * - * This file is part of the Kitodo project. - * - * It is licensed under GNU General Public License version 3 or later. - * - * For the full copyright and license information, please read the - * GPL3-License.txt file that was distributed with this source code. - */ - -package org.kitodo.production.helper; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; - -import javax.faces.context.FacesContext; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -/** - * The class FacesUtils contains an omnium-gatherum of functions that perform - * recurring tasks related to JavaServer Faces. - */ -public class FacesUtils { - - /** - * Private constructor to hide the implicit public one. - */ - private FacesUtils() { - - } - - /** - * Sends a byte[] of data in the HTTP response - * of a user interaction as a file download. Calling this procedure is only - * sensible during the invoke application phase of the JSF life cycle, i.e. - * in procedures that are designed to provide the action for a JSF command - * link or command button. - * - * @param data - * the content of the file - * @param saveAsName - * a file name proposed to the user - * @throws IOException - * if an I/O error occurs - */ - public static void sendDownload(byte[] data, String saveAsName) throws IOException { - String disposition; - - FacesContext context = FacesContext.getCurrentInstance(); - HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); - response.reset(); - try { - disposition = "attachment; filename*=UTF-8''".concat(new URI(null, saveAsName, null).toASCIIString()); - response.setHeader("Content-Disposition", disposition); - } catch (URISyntaxException e) { - response.setHeader("Content-Disposition", "attachment; filename=Course.xml"); - } - response.setContentType(MediaType.APPLICATION_OCTET_STREAM); - response.setContentLength(data.length); - response.getOutputStream().write(data); - context.responseComplete(); - } -} diff --git a/Kitodo/src/main/java/org/kitodo/production/metadata/MetadataEditor.java b/Kitodo/src/main/java/org/kitodo/production/metadata/MetadataEditor.java index 5856af657e9..4a5a33c5fbc 100644 --- a/Kitodo/src/main/java/org/kitodo/production/metadata/MetadataEditor.java +++ b/Kitodo/src/main/java/org/kitodo/production/metadata/MetadataEditor.java @@ -198,7 +198,7 @@ private static void addMultipleStructuresWithMetadataGroup(int number, String ty for (int i = 0; i < number; i++) { LogicalDivision newStructure = addLogicalDivision(type, workpiece, structure, position, Collections.emptyList()); - if (Objects.isNull(newStructure) || metadataKey.isEmpty() || metadataKey == null) { + if (Objects.isNull(newStructure) || metadataKey == null || metadataKey.isEmpty()) { continue; } MetadataGroup metadataGroup = new MetadataGroup(); diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/FilterService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/FilterService.java index 7b3385a0d47..64a65d1c317 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/FilterService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/FilterService.java @@ -261,9 +261,9 @@ private QueryBuilder buildQueryFromCondition(String condition, ObjectType object } private String replaceLegacyFilters(String filter) { - filter.replace("processproperty","property"); - filter.replace("workpiece","property"); - filter.replace("template","property"); + filter = filter.replace("processproperty","property"); + filter = filter.replace("workpiece","property"); + filter = filter.replace("template","property"); return filter; } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java index 48fe88c3470..0bb9a2b95c1 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java @@ -1174,7 +1174,7 @@ public static void processTempProcess(TempProcess tempProcess, RulesetManagement * @return the importedProcess */ public Process importProcess(String ppn, int projectId, int templateId, ImportConfiguration importConfiguration, - Map presetMetadata) throws ImportException { + Map> presetMetadata) throws ImportException { LinkedList processList = new LinkedList<>(); TempProcess tempProcess; Template template; @@ -1257,14 +1257,16 @@ private static Collection getFunctionalMetadata(Ruleset ruleset, Functio return rulesetManagement.getFunctionalKeys(metadata); } - private List createMetadata(Map presetMetadata) { + private List createMetadata(Map> presetMetadata) { List metadata = new LinkedList<>(); - for (Map.Entry presetMetadataEntry : presetMetadata.entrySet()) { - MetadataEntry metadataEntry = new MetadataEntry(); - metadataEntry.setKey(presetMetadataEntry.getKey()); - metadataEntry.setValue(presetMetadataEntry.getValue()); - metadataEntry.setDomain(MdSec.DMD_SEC); - metadata.add(metadataEntry); + for (Map.Entry> presetMetadataEntry : presetMetadata.entrySet()) { + for (String presetMetadataEntryValue : presetMetadataEntry.getValue()) { + MetadataEntry metadataEntry = new MetadataEntry(); + metadataEntry.setKey(presetMetadataEntry.getKey()); + metadataEntry.setValue(presetMetadataEntryValue); + metadataEntry.setDomain(MdSec.DMD_SEC); + metadata.add(metadataEntry); + } } return metadata; } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/MassImportService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/MassImportService.java index 522fed00b9c..fc0c3fd6d0f 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/MassImportService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/MassImportService.java @@ -114,16 +114,17 @@ public List parseLines(List lines, String separator) { * @param metadataKeys metadata keys for additional metadata added to individual records during import * @param records list of CSV records */ - public Map> prepareMetadata(List metadataKeys, List records) + public Map>> prepareMetadata(List metadataKeys, List records) throws ImportException { - Map> presetMetadata = new LinkedHashMap<>(); + Map>> presetMetadata = new LinkedHashMap<>(); for (CsvRecord record : records) { - Map processMetadata = new HashMap<>(); + Map> processMetadata = new HashMap<>(); // skip first metadata key as it always contains the record ID to be used for search for (int index = 1; index < metadataKeys.size(); index++) { String metadataKey = metadataKeys.get(index); if (StringUtils.isNotBlank(metadataKey)) { - processMetadata.put(metadataKey, record.getCsvCells().get(index).getValue()); + List values = processMetadata.computeIfAbsent(metadataKey, k -> new ArrayList<>()); + values.add(record.getCsvCells().get(index).getValue()); } } presetMetadata.put(record.getCsvCells().get(0).getValue(), processMetadata); diff --git a/Kitodo/src/main/java/org/kitodo/production/services/validation/MetadataValidationService.java b/Kitodo/src/main/java/org/kitodo/production/services/validation/MetadataValidationService.java index a8014978b60..a2952083cbc 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/validation/MetadataValidationService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/validation/MetadataValidationService.java @@ -36,7 +36,6 @@ import org.kitodo.data.database.beans.Process; import org.kitodo.data.database.beans.User; import org.kitodo.data.database.exceptions.DAOException; -import org.kitodo.data.exceptions.DataException; import org.kitodo.production.helper.Helper; import org.kitodo.production.helper.metadata.legacytypeimplementations.LegacyMetsModsDigitalDocumentHelper; import org.kitodo.production.helper.metadata.legacytypeimplementations.LegacyPrefsHelper; diff --git a/Kitodo/src/test/java/org/kitodo/MockDatabase.java b/Kitodo/src/test/java/org/kitodo/MockDatabase.java index 0de1dce0efa..bffb046d806 100644 --- a/Kitodo/src/test/java/org/kitodo/MockDatabase.java +++ b/Kitodo/src/test/java/org/kitodo/MockDatabase.java @@ -105,6 +105,7 @@ import org.kitodo.production.services.ServiceManager; import org.kitodo.production.workflow.model.Converter; import org.kitodo.test.utils.ProcessTestUtils; +import org.kitodo.test.utils.TestConstants; import static com.xebialabs.restito.builder.stub.StubHttp.whenHttp; import static com.xebialabs.restito.semantics.Condition.get; @@ -136,6 +137,7 @@ public class MockDatabase { public static final String HIERARCHY_CHILD_TO_KEEP = "HierarchyChildToKeep"; public static final String HIERARCHY_CHILD_TO_REMOVE = "HierarchyChildToRemove"; public static final String HIERARCHY_CHILD_TO_ADD = "HierarchyChildToAdd"; + public static final int PORT = 8888; public static void startDatabaseServer() throws SQLException { tcpServer = Server.createTcpServer().start(); @@ -1685,7 +1687,7 @@ public static void insertImportConfigurations() throws DAOException, DataExcepti // add GBV import configuration, including id and default search fields ImportConfiguration gbvConfiguration = new ImportConfiguration(); - gbvConfiguration.setTitle("GBV"); + gbvConfiguration.setTitle(TestConstants.GBV); gbvConfiguration.setConfigurationType(ImportConfigurationType.OPAC_SEARCH.name()); gbvConfiguration.setInterfaceType(SearchInterfaceType.SRU.name()); gbvConfiguration.setSruVersion("1.2"); @@ -1709,7 +1711,7 @@ public static void insertImportConfigurations() throws DAOException, DataExcepti // add Kalliope import configuration, including id search field ImportConfiguration kalliopeConfiguration = new ImportConfiguration(); - kalliopeConfiguration.setTitle("Kalliope"); + kalliopeConfiguration.setTitle(TestConstants.KALLIOPE); kalliopeConfiguration.setConfigurationType(ImportConfigurationType.OPAC_SEARCH.name()); kalliopeConfiguration.setInterfaceType(SearchInterfaceType.SRU.name()); kalliopeConfiguration.setSruVersion("1.2"); @@ -1717,7 +1719,7 @@ public static void insertImportConfigurations() throws DAOException, DataExcepti kalliopeConfiguration.setHost("localhost"); kalliopeConfiguration.setScheme("http"); kalliopeConfiguration.setPath("/sru"); - kalliopeConfiguration.setPort(8888); + kalliopeConfiguration.setPort(PORT); kalliopeConfiguration.setPrestructuredImport(false); kalliopeConfiguration.setReturnFormat(FileFormat.XML.name()); kalliopeConfiguration.setMetadataFormat(MetadataFormat.MODS.name()); @@ -1725,12 +1727,12 @@ public static void insertImportConfigurations() throws DAOException, DataExcepti .getById(1))); SearchField idSearchFieldKalliope = new SearchField(); - idSearchFieldKalliope.setValue("ead.id"); + idSearchFieldKalliope.setValue(TestConstants.EAD_ID); idSearchFieldKalliope.setLabel("Identifier"); idSearchFieldKalliope.setImportConfiguration(kalliopeConfiguration); SearchField parentIdSearchFieldKalliope = new SearchField(); - parentIdSearchFieldKalliope.setValue("context.ead.id"); + parentIdSearchFieldKalliope.setValue(TestConstants.EAD_PARENT_ID); parentIdSearchFieldKalliope.setLabel("Parent ID"); parentIdSearchFieldKalliope.setImportConfiguration(kalliopeConfiguration); @@ -1747,7 +1749,7 @@ public static void insertImportConfigurations() throws DAOException, DataExcepti // add K10Plus import configuration, including id search field ImportConfiguration k10plusConfiguration = new ImportConfiguration(); - k10plusConfiguration.setTitle("K10Plus"); + k10plusConfiguration.setTitle(TestConstants.K10PLUS); k10plusConfiguration.setConfigurationType(ImportConfigurationType.OPAC_SEARCH.name()); k10plusConfiguration.setInterfaceType(SearchInterfaceType.SRU.name()); k10plusConfiguration.setSruVersion("1.1"); @@ -1755,7 +1757,8 @@ public static void insertImportConfigurations() throws DAOException, DataExcepti k10plusConfiguration.setHost("localhost"); k10plusConfiguration.setScheme("http"); k10plusConfiguration.setPath("/sru"); - k10plusConfiguration.setPort(8888); + k10plusConfiguration.setPort(PORT); + k10plusConfiguration.setDefaultImportDepth(1); k10plusConfiguration.setPrestructuredImport(false); k10plusConfiguration.setReturnFormat(FileFormat.XML.name()); k10plusConfiguration.setMetadataFormat(MetadataFormat.PICA.name()); @@ -1807,7 +1810,7 @@ public static void insertImportconfigurationWithCustomUrlParameters() throws DAO customConfiguration.setHost("localhost"); customConfiguration.setScheme("http"); customConfiguration.setPath("/custom"); - customConfiguration.setPort(8888); + customConfiguration.setPort(PORT); customConfiguration.setPrestructuredImport(false); customConfiguration.setReturnFormat(FileFormat.XML.name()); customConfiguration.setMetadataFormat(MetadataFormat.PICA.name()); @@ -2165,6 +2168,23 @@ public static Process addProcess(String processTitle, int projectId, int templat * @param numberOfRecords URL parameter containing maximum number of records associated with this endpoint * @throws IOException when reading the response file fails */ + public static void addRestEndPointForSru(StubServer server, String query, String filePath, String format, + int startRecord, int numberOfRecords) + throws IOException { + try (InputStream inputStream = Files.newInputStream(Paths.get(filePath))) { + String serverResponse = IOUtils.toString(inputStream, StandardCharsets.UTF_8); + whenHttp(server) + .match(get("/sru"), + parameter("operation", "searchRetrieve"), + parameter("recordSchema", format), + parameter("startRecord", String.valueOf(startRecord)), + parameter("maximumRecords", String.valueOf(numberOfRecords)), + parameter("query", query)) + .then(Action.ok(), Action.contentType("text/xml"), Action.stringContent(serverResponse)); + } + + } + public static void addRestEndPointForSru(StubServer server, String query, String filePath, String format, int numberOfRecords) throws IOException { diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/FolderGeneratorTest.java b/Kitodo/src/test/java/org/kitodo/production/forms/FolderGeneratorTest.java new file mode 100644 index 00000000000..ad4271ea2ac --- /dev/null +++ b/Kitodo/src/test/java/org/kitodo/production/forms/FolderGeneratorTest.java @@ -0,0 +1,60 @@ +/* + * (c) Kitodo. Key to digital objects e. V. + * + * This file is part of the Kitodo project. + * + * It is licensed under GNU General Public License version 3 or later. + * + * For the full copyright and license information, please read the + * GPL3-License.txt file that was distributed with this source code. + */ + +package org.kitodo.production.forms; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.kitodo.data.database.beans.Folder; +import org.kitodo.forms.FolderGenerator; + +public class FolderGeneratorTest { + + private static final String DERIVATIVE = "createDerivative"; + private static final String DPI = "changeDpi"; + private static final String IMAGE_SIZE = "getSizedWebImage"; + + @Test + public void shouldGetMethod() { + Folder derivativeFolder = new Folder(); + derivativeFolder.setDerivative(0.75d); + Folder dpiFolder = new Folder(); + dpiFolder.setDpi(300); + Folder imageSizeFolder = new Folder(); + imageSizeFolder.setImageSize(150); + FolderGenerator derivativeFolderGenerator = new FolderGenerator(derivativeFolder); + Assertions.assertEquals(DERIVATIVE, derivativeFolderGenerator.getMethod()); + FolderGenerator dpiFolderGenerator = new FolderGenerator(dpiFolder); + Assertions.assertEquals(DPI, dpiFolderGenerator.getMethod()); + FolderGenerator imageSizeFolderGenerator = new FolderGenerator(imageSizeFolder); + Assertions.assertEquals(IMAGE_SIZE, imageSizeFolderGenerator.getMethod()); + } + + @Test + public void shouldSetMethod() { + Folder folder = new Folder(); + FolderGenerator folderGenerator = new FolderGenerator(folder); + folderGenerator.setMethod(DERIVATIVE); + Assertions.assertTrue(folder.getDerivative().isPresent(), "Derivative should be set"); + Assertions.assertEquals(1.00d, folder.getDerivative().get()); + Assertions.assertFalse(folder.getDpi().isPresent(), "DPI should be null"); + Assertions.assertFalse(folder.getImageSize().isPresent(), "Image size should be null"); + folderGenerator.setMethod(DPI); + Assertions.assertFalse(folder.getDerivative().isPresent(), "Derivative should be null"); + Assertions.assertTrue(folder.getDpi().isPresent(), "DPI should be set"); + Assertions.assertFalse(folder.getImageSize().isPresent(), "Image size should be null"); + folderGenerator.setMethod(IMAGE_SIZE); + Assertions.assertFalse(folder.getDerivative().isPresent(), "Derivative should be null"); + Assertions.assertFalse(folder.getDpi().isPresent(), "DPI should be null"); + Assertions.assertTrue(folder.getImageSize().isPresent(), "Image size should be set"); + } + +} diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/ProcessDetailIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/ProcessDetailIT.java index 179e528d633..e71194664ae 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/ProcessDetailIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/createprocess/ProcessDetailIT.java @@ -22,6 +22,7 @@ import org.kitodo.api.dataeditor.rulesetmanagement.StructuralElementViewInterface; import org.kitodo.api.dataformat.LogicalDivision; import org.kitodo.production.services.ServiceManager; +import org.kitodo.test.utils.TestConstants; import org.primefaces.model.TreeNode; public class ProcessDetailIT { @@ -29,7 +30,7 @@ public class ProcessDetailIT { @Test public void shouldCopyProcessDetail() throws Exception { RulesetManagementInterface ruleset = ServiceManager.getRulesetManagementService().getRulesetManagement(); - ruleset.load(new File("src/test/resources/rulesets/ruleset_test.xml")); + ruleset.load(new File(TestConstants.TEST_RULESET)); StructuralElementViewInterface divisionView = ruleset.getStructuralElementView("Monograph", "edit", Locale.LanguageRange.parse("en")); LogicalDivision division = new LogicalDivision(); diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/XMLUtilsTest.java b/Kitodo/src/test/java/org/kitodo/production/helper/XMLUtilsTest.java new file mode 100644 index 00000000000..1adb8cc1353 --- /dev/null +++ b/Kitodo/src/test/java/org/kitodo/production/helper/XMLUtilsTest.java @@ -0,0 +1,97 @@ +/* + * (c) Kitodo. Key to digital objects e. V. + * + * This file is part of the Kitodo project. + * + * It is licensed under GNU General Public License version 3 or later. + * + * For the full copyright and license information, please read the + * GPL3-License.txt file that was distributed with this source code. + */ + +package org.kitodo.production.helper; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.kitodo.production.model.bibliography.course.Course; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import javax.xml.transform.TransformerException; +import javax.xml.xpath.XPathExpressionException; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Locale; + +public class XMLUtilsTest { + + private static final String VALID_XPATH = ".//this/is/a/valid/xpath"; + private static final String INVALID_XPATH = ".//["; + private static final String TEST_ELEMENT = "testElement"; + private static final String TEST_CHILD_ELEMENT = "testChildElement"; + private static final String XML_STRING = "Text"; + private static final String EXPECTED_EXCEPTION_MESSAGE = "javax.xml.transform.TransformerException: " + + "A location step was expected following the '/' or '//' token."; + private static Locale originalDefaultLocale; + + @BeforeAll + public static void setLocaleToEnglish() { + originalDefaultLocale = Locale.getDefault(); + Locale.setDefault(Locale.ENGLISH); + } + + @AfterAll + public static void resetLocaleToOriginalDefault() { + Locale.setDefault(originalDefaultLocale); + } + + @Test + public void shouldConvertDocumentToByteArray() throws IOException, TransformerException { + Course course = new Course(); + Document document = course.toXML(); + byte[] byteArray = XMLUtils.documentToByteArray(document, 2); + Assertions.assertNotNull(byteArray); + } + + @Test + public void shouldGetFirstChildWithTagName() throws IOException { + Document document = XMLUtils.newDocument(); + Node parentNode = document.createElement(TEST_ELEMENT); + parentNode.appendChild(document.createElement(TEST_CHILD_ELEMENT)); + Element childNode = XMLUtils.getFirstChildWithTagName(parentNode, TEST_CHILD_ELEMENT); + Assertions.assertNotNull(childNode); + } + + @Test + public void shouldLoadInputStream() { + InputStream inputStream = new ByteArrayInputStream(XML_STRING.getBytes()); + Assertions.assertDoesNotThrow(() -> XMLUtils.load(inputStream)); + } + + @Test + public void shouldCreateNewDocument() { + Assertions.assertDoesNotThrow(XMLUtils::newDocument); + } + + @Test + public void shouldParseXMLString() { + Assertions.assertDoesNotThrow(() -> XMLUtils.parseXMLString(XML_STRING)); + } + + @Test + public void shouldValidateXpathSyntax() { + Assertions.assertDoesNotThrow(() -> XMLUtils.validateXPathSyntax(VALID_XPATH)); + } + + @Test + public void shouldThrowExceptionWhenValidatingInvalidXPathSyntax() { + XPathExpressionException exception = Assertions.assertThrows(XPathExpressionException.class, + () -> XMLUtils.validateXPathSyntax(INVALID_XPATH)); + Assertions.assertEquals(EXPECTED_EXCEPTION_MESSAGE, exception.getMessage()); + } +} diff --git a/Kitodo/src/test/java/org/kitodo/production/interfaces/activemq/TaskActionProcessorIT.java b/Kitodo/src/test/java/org/kitodo/production/interfaces/activemq/TaskActionProcessorIT.java index c31762420bb..a520ce193eb 100644 --- a/Kitodo/src/test/java/org/kitodo/production/interfaces/activemq/TaskActionProcessorIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/interfaces/activemq/TaskActionProcessorIT.java @@ -16,6 +16,7 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; +import java.io.File; import java.util.List; import java.util.Objects; @@ -25,8 +26,11 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.kitodo.ExecutionPermission; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; +import org.kitodo.config.ConfigCore; +import org.kitodo.config.enums.ParameterCore; import org.kitodo.data.database.beans.Comment; import org.kitodo.data.database.beans.Task; import org.kitodo.data.database.enums.TaskStatus; @@ -38,6 +42,11 @@ public class TaskActionProcessorIT { private static final TaskService taskService = ServiceManager.getTaskService(); + private static final File scriptDeleteSymLink = new File( + ConfigCore.getParameter(ParameterCore.SCRIPT_DELETE_SYMLINK)); + private static final File scriptCreateDirMeta = new File( + ConfigCore.getParameter(ParameterCore.SCRIPT_CREATE_DIR_USER_HOME)); + /** * Prepare the data for every test. * @@ -49,6 +58,8 @@ public void prepare() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesForWorkflowFull(); SecurityTestUtils.addUserDataToSecurityContext(ServiceManager.getUserService().getById(1), 1); + ExecutionPermission.setExecutePermission(scriptCreateDirMeta); + ExecutionPermission.setExecutePermission(scriptDeleteSymLink); } /** @@ -62,6 +73,8 @@ public void clean() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); SecurityTestUtils.cleanSecurityContext(); + ExecutionPermission.setNoExecutePermission(scriptCreateDirMeta); + ExecutionPermission.setNoExecutePermission(scriptDeleteSymLink); } @Test(expected = ProcessorException.class) diff --git a/Kitodo/src/test/java/org/kitodo/production/metadata/MetadataEditorIT.java b/Kitodo/src/test/java/org/kitodo/production/metadata/MetadataEditorIT.java index 68b5b7d4f6e..11f3a6961be 100644 --- a/Kitodo/src/test/java/org/kitodo/production/metadata/MetadataEditorIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/metadata/MetadataEditorIT.java @@ -43,6 +43,7 @@ import org.kitodo.production.services.ServiceManager; import org.kitodo.production.services.data.ProcessService; import org.kitodo.test.utils.ProcessTestUtils; +import org.kitodo.test.utils.TestConstants; public class MetadataEditorIT { @@ -125,7 +126,7 @@ public void shouldAddMultipleStructuresWithoutMetadata() throws Exception { public void shouldAddMultipleStructuresWithMetadataGroup() throws Exception { RulesetManagementInterface ruleset = ServiceManager.getRulesetManagementService().getRulesetManagement(); - ruleset.load(new File("src/test/resources/rulesets/ruleset_test.xml")); + ruleset.load(new File(TestConstants.TEST_RULESET)); StructuralElementViewInterface divisionView = ruleset.getStructuralElementView("Monograph", "edit", Locale.LanguageRange.parse("en")); String metadataKey = "TitleDocMain"; @@ -160,7 +161,7 @@ public void shouldAddMultipleStructuresWithMetadataGroup() throws Exception { @Test public void shouldAddMultipleStructuresWithMetadataEntry() throws Exception { RulesetManagementInterface ruleset = ServiceManager.getRulesetManagementService().getRulesetManagement(); - ruleset.load(new File("src/test/resources/rulesets/ruleset_test.xml")); + ruleset.load(new File(TestConstants.TEST_RULESET)); StructuralElementViewInterface divisionView = ruleset.getStructuralElementView("Monograph", "edit", Locale.LanguageRange.parse("en")); String metadataKey = "Person"; diff --git a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java index 425f66c7319..8f34cc09e24 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java @@ -25,14 +25,12 @@ import org.kitodo.SecurityTestUtils; import org.kitodo.production.helper.TempProcess; import org.kitodo.production.services.ServiceManager; +import org.kitodo.test.utils.TestConstants; public class CatalogImportIT { private static StubServer server; private static final int PORT = 8888; - private static final String HITLIST_RECORD_PATH = "src/test/resources/importRecords/importHitlist.xml"; - private static final String CHILD_RECORD_PATH = "src/test/resources/importRecords/importChildRecord.xml"; - private static final String PARENT_RECORD_PATH = "src/test/resources/importRecords/importParentRecord.xml"; private static final String CHILD_RECORD_ID = "1"; private static final String PARENT_RECORD_ID = "2"; private static final int PROJECT_ID = 1; @@ -67,8 +65,8 @@ public void shouldImportProcessHierarchy() throws Exception { private static void setupServer() throws IOException { server = new StubServer(PORT).run(); - MockDatabase.addRestEndPointForSru(server, "ead.id=" + CHILD_RECORD_ID, CHILD_RECORD_PATH, "mods", 1); - MockDatabase.addRestEndPointForSru(server, "ead.id=" + PARENT_RECORD_ID, PARENT_RECORD_PATH, "mods", 1); - MockDatabase.addRestEndPointForSru(server, "ead.title=test", HITLIST_RECORD_PATH, "mods",10); + MockDatabase.addRestEndPointForSru(server, "ead.id=" + CHILD_RECORD_ID, TestConstants.CHILD_RECORD_PATH, "mods", 1); + MockDatabase.addRestEndPointForSru(server, "ead.id=" + PARENT_RECORD_ID, TestConstants.PARENT_RECORD_PATH, "mods", 1); + MockDatabase.addRestEndPointForSru(server, "ead.title=test", TestConstants.HITLIST_RECORD_PATH, "mods",10); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/ImportServiceTest.java b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/ImportServiceTest.java index 5668bd6b642..f78bfc8c83b 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/ImportServiceTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/ImportServiceTest.java @@ -28,6 +28,7 @@ import org.kitodo.production.helper.Helper; import org.kitodo.production.services.ServiceManager; import org.kitodo.production.services.data.ImportService; +import org.kitodo.test.utils.TestConstants; public class ImportServiceTest { @@ -181,8 +182,8 @@ private ImportConfiguration createImportConfiguration(SearchInterfaceType interf private List createSearchFields(ImportConfiguration importConfiguration) { List SearchFields = new ArrayList<>(); SearchFields.add(addSearchField(TITLE, "ead.tit", importConfiguration, true)); - SearchFields.add(addSearchField(RECORD_ID, "ead.id", importConfiguration, true)); - SearchFields.add(addSearchField(PARENT_ID, "context.ead.id", importConfiguration, false)); + SearchFields.add(addSearchField(RECORD_ID, TestConstants.EAD_ID, importConfiguration, true)); + SearchFields.add(addSearchField(PARENT_ID, TestConstants.EAD_PARENT_ID, importConfiguration, false)); importConfiguration.setSearchFields(SearchFields); return SearchFields; } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/MassImportTest.java b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/MassImportTest.java index 062a884099e..910427e6a7e 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/MassImportTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/MassImportTest.java @@ -35,6 +35,11 @@ public class MassImportTest { private static final String CSV_SECOND_LINE = "456, Band 2, Dresden"; private static final String CSV_THIRD_LINE = "789, Band 3, Berlin"; private static final List CSV_LINES = Arrays.asList(CSV_FIRST_LINE, CSV_SECOND_LINE, CSV_THIRD_LINE); + private static final List METADATA_KEYS_MUTLIPLE_VALUES = Arrays.asList(ID, TITLE, PLACE, PLACE); + private static final String CSV_FIRST_LINE_MUTLIPLE_VALUES = "321, Band 1, Hamburg, Berlin"; + private static final String CSV_SECOND_LINE_MUTLIPLE_VALUES = "654, Band 2, Dresden, Hannover"; + private static final List CSV_LINES_MUTLIPLE_VALUES = Arrays.asList(CSV_FIRST_LINE_MUTLIPLE_VALUES, + CSV_SECOND_LINE_MUTLIPLE_VALUES); /** * Tests parsing CSV lines into CSV records with multiple cells. @@ -93,11 +98,34 @@ public void shouldUpdateSeparator() { public void shouldPrepareMetadata() throws ImportException { MassImportService service = ServiceManager.getMassImportService(); List csvRecords = service.parseLines(CSV_LINES, StringConstants.COMMA_DELIMITER); - Map> metadata = service.prepareMetadata(METADATA_KEYS, csvRecords); + Map>> metadata = service.prepareMetadata(METADATA_KEYS, csvRecords); Assert.assertEquals("Wrong number of metadata sets prepared", 3, metadata.size()); - Map metadataSet = metadata.get("123"); + Map> metadataSet = metadata.get("123"); Assert.assertNotNull("Metadata for record with ID 123 is null", metadataSet); - Assert.assertTrue("Metadata for record with ID 123 does not contain title metadata", metadataSet.containsKey(TITLE)); - Assert.assertEquals("Metadata for record with ID 123 contains wrong title", "Band 1", metadataSet.get(TITLE)); + Assert.assertEquals("Wrong number of metadata sets prepared", 2, + metadataSet.size()); + Assert.assertEquals("Metadata for record with ID 123 contains wrong title", "Band 1", + metadataSet.get(TITLE).get(0)); + Assert.assertEquals("Metadata for record with ID 123 has wrong size of place list", + 1, metadataSet.get(PLACE).size()); + Assert.assertEquals("Metadata for record with ID 123 contains wrong place", "Hamburg", + metadataSet.get(PLACE).get(0)); + + List csvRecordsMultipleValues = service.parseLines(CSV_LINES_MUTLIPLE_VALUES, + StringConstants.COMMA_DELIMITER); + Map>> metadataMultipleValues = service. + prepareMetadata(METADATA_KEYS_MUTLIPLE_VALUES, csvRecordsMultipleValues); + Map> metadataSetMultipleValues = metadataMultipleValues.get("321"); + Assert.assertNotNull("Metadata for record with ID 321 is null", metadataSetMultipleValues); + Assert.assertEquals("Metadata for record with ID 321 contains wrong title", 2, + metadataSetMultipleValues.size()); + Assert.assertTrue("Metadata for record with ID 321 does not contain place metadata", + metadataSetMultipleValues.containsKey(PLACE)); + Assert.assertEquals("Metadata for record with ID 123 has wrong size of place list", 2, + metadataSetMultipleValues.get(PLACE).size()); + Assert.assertEquals("Metadata for record with ID 321 contains wrong place", "Hamburg", + metadataSetMultipleValues.get(PLACE).get(0)); + Assert.assertEquals("Metadata for record with ID 321 contains wrong place", "Berlin", + metadataSetMultipleValues.get(PLACE).get(1)); } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/ImportServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/ImportServiceIT.java index 703d7691c3a..35c4213deec 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/ImportServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/ImportServiceIT.java @@ -27,8 +27,10 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -73,6 +75,7 @@ import org.kitodo.production.helper.XMLUtils; import org.kitodo.production.services.ServiceManager; import org.kitodo.test.utils.ProcessTestUtils; +import org.kitodo.test.utils.TestConstants; import org.w3c.dom.Document; import org.xml.sax.SAXException; @@ -92,7 +95,6 @@ public class ImportServiceIT { private static final String PARENT_PROCESS_TEST_FILE = "testMetadataForKalliopeParentProcess.xml"; private static final String CHILD_RECORDS_PATH = "src/test/resources/importRecords/importMultipleChildRecords.xml"; private static final String MODS_TEST_RECORD_PATH = "src/test/resources/importRecords/modsTestRecord.xml"; - private static final String TEST_RULESET = "src/test/resources/rulesets/ruleset_test.xml"; private static final String TEST_KITODO_METADATA_FILE = "testMetadataFileTempProcess.xml"; private static final String TEST_METADATA_WITH_AUTHOR_FILE = "testMetadataWithAuthor.xml"; private static final String TEST_KITODO_METADATA_FILE_PATH = "src/test/resources/metadata/metadataFiles/" @@ -104,16 +106,15 @@ public class ImportServiceIT { private static final List CHILD_RECORD_IDS = Arrays.asList("9991", "9992", "9993"); private static final String KALLIOPE_RECORD_ID = "999"; private static final String CUSTOM_INTERFACE_RECORD_ID = "12345"; - private static final int PORT = 8888; private static final int TEMPLATE_ID = 1; private static final int PROJECT_ID = 1; private static final int RULESET_ID = 1; + private static final String TITLE = "Title"; + private static final String PLACE = "Place"; private static final int EXPECTED_NR_OF_CHILDREN = 23; private static final String PICA_XML = "picaxml"; - private static final String MODS = "mods"; private static final String PICA_PPN = "pica.ppn"; private static final String PICA_PARENT_ID = "pica.parentId"; - private static final String EAD_PARENT_ID = "context.ead.id"; private static final String firstProcess = "First process"; private static final String TEST_PROCESS_TITLE = "Testtitel"; private static final String KITODO = "kitodo"; @@ -136,7 +137,7 @@ public static void prepareDatabase() throws Exception { SecurityTestUtils.addUserDataToSecurityContext(userOne, 1); return !processService.findByTitle(firstProcess).isEmpty(); }); - server = new StubServer(PORT).run(); + server = new StubServer(MockDatabase.PORT).run(); setupServer(); } @@ -169,6 +170,42 @@ public void testImportProcess() throws DAOException, DataException, ImportExcept } } + /** + * Tests whether basic catalog metadata import with additional preset metadata to a single process succeeds or not. + * + * @throws DAOException when loading ImportConfiguration or removing test process from test database fails. + * @throws ImportException when importing metadata fails + * @throws IOException when importing metadata fails + */ + @Test + public void testImportProcessWithAdditionalMetadata() throws DAOException, ImportException, IOException { + Map> presetMetadata = new HashMap<>(); + presetMetadata.put(TITLE, List.of("Band 1")); + presetMetadata.put(PLACE, List.of("Hamburg", "Berlin")); + Process processWithAdditionalMetadata = importProcessWithAdditionalMetadata(RECORD_ID, + MockDatabase.getK10PlusImportConfiguration(), presetMetadata); + Workpiece workpiece = ServiceManager.getMetsService() + .loadWorkpiece(processService.getMetadataFileUri(processWithAdditionalMetadata)); + HashSet metadata = workpiece.getLogicalStructure().getMetadata(); + try { + Assert.assertTrue("Process does not contain correct metadata", + assertMetadataSetContainsMetadata(metadata, TITLE, "Band 1")); + Assert.assertTrue("Process does not contain correct metadata", + assertMetadataSetContainsMetadata(metadata, PLACE, "Hamburg")); + Assert.assertTrue("Process does not contain correct metadata", + assertMetadataSetContainsMetadata(metadata, PLACE, "Berlin")); + } finally { + ProcessTestUtils.removeTestProcess(processWithAdditionalMetadata.getId()); + } + } + + private boolean assertMetadataSetContainsMetadata(HashSet metadataSet, String metadataKey, String metadataValue) { + return metadataSet.stream() + .filter(metadata -> metadata.getKey().equals(metadataKey)) + .anyMatch(metadata -> metadata instanceof MetadataEntry && + ((MetadataEntry) metadata).getValue().equals(metadataValue)); + } + @Test public void shouldCreateUrlWithCustomParameters() throws DAOException, ImportException, IOException { Process importedProcess = importProcess(CUSTOM_INTERFACE_RECORD_ID, MockDatabase.getCustomTypeImportConfiguration()); @@ -198,7 +235,7 @@ public void shouldFailToImportFromCustomInterfaceWithoutConfiguredUrlParameters( public void shouldTestWhetherRecordIdentifierMetadataIsConfigured() throws IOException { RulesetManagementInterface rulesetManagement = ServiceManager.getRulesetManagementService() .getRulesetManagement(); - rulesetManagement.load(new File(TEST_RULESET)); + rulesetManagement.load(new File(TestConstants.TEST_RULESET)); Assert.assertTrue("Should determine that recordIdentifier is configured for all document types", ServiceManager.getImportService().isRecordIdentifierMetadataConfigured(rulesetManagement)); } @@ -527,9 +564,9 @@ private static void setupServer() throws IOException { // REST endpoint for testing failed import of child records MockDatabase.addRestEndPointForSru(server, PICA_PARENT_ID + "=" + RECORD_ID, TEST_FILE_PATH_NUMBER_OF_HITS, PICA_XML, 1); // REST endpoint for testing successful import of child records - MockDatabase.addRestEndPointForSru(server, EAD_PARENT_ID + "=" + KALLIOPE_RECORD_ID, CHILD_RECORDS_PATH, MODS, 3); + MockDatabase.addRestEndPointForSru(server, TestConstants.EAD_PARENT_ID + "=" + KALLIOPE_RECORD_ID, CHILD_RECORDS_PATH, TestConstants.MODS, 3); // REST endpoint for testing retrieval of child records given existing parent process - MockDatabase.addRestEndPointForSru(server, EAD_PARENT_ID + "=" + PARENT_RECORD_CATALOG_ID, CHILD_RECORDS_PATH, MODS,3); + MockDatabase.addRestEndPointForSru(server, TestConstants.EAD_PARENT_ID + "=" + PARENT_RECORD_CATALOG_ID, CHILD_RECORDS_PATH, TestConstants.MODS,3); // REST endpoint for successful import from custom search interface MockDatabase.addRestEndPointForCustom(server, TEST_FILE_SUCCESS_RESPONSE_PATH, CUSTOM_INTERFACE_RECORD_ID, "firstValue"); @@ -551,4 +588,19 @@ private Process importProcess(String recordId, ImportConfiguration importConfigu } return importedProcess; } + + private Process importProcessWithAdditionalMetadata(String recordId, ImportConfiguration importConfiguration, + Map> presetMetadata) + throws IOException, ImportException { + File script = new File(ConfigCore.getParameter(ParameterCore.SCRIPT_CREATE_DIR_META)); + if (!SystemUtils.IS_OS_WINDOWS) { + ExecutionPermission.setExecutePermission(script); + } + Process importedProcess = importService.importProcess(recordId, 1, 1, + importConfiguration, presetMetadata); + if (!SystemUtils.IS_OS_WINDOWS) { + ExecutionPermission.setNoExecutePermission(script); + } + return importedProcess; + } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/validation/MetadataValidationServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/validation/MetadataValidationServiceIT.java new file mode 100644 index 00000000000..64be0855bab --- /dev/null +++ b/Kitodo/src/test/java/org/kitodo/production/services/validation/MetadataValidationServiceIT.java @@ -0,0 +1,104 @@ +/* + * (c) Kitodo. Key to digital objects e. V. + * + * This file is part of the Kitodo project. + * + * It is licensed under GNU General Public License version 3 or later. + * + * For the full copyright and license information, please read the + * GPL3-License.txt file that was distributed with this source code. + */ + +package org.kitodo.production.services.validation; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.kitodo.api.dataeditor.rulesetmanagement.RulesetManagementInterface; +import org.kitodo.api.dataformat.Workpiece; +import org.kitodo.api.validation.State; +import org.kitodo.api.validation.ValidationResult; +import org.kitodo.data.database.exceptions.DAOException; +import org.kitodo.production.services.ServiceManager; +import org.kitodo.test.utils.TestConstants; + +public class MetadataValidationServiceIT { + + private static final String WRONG_NUMBER_MESSAGE = "Wrong number of result messages"; + private static final String WRONG_STATE_MESSAGE = "Wrong validation state"; + private static final String WRONG_VALIDATION_MESSAGE = "Wrong validation message"; + private static final String SHOULD_NOT_PRODUCE_WARNINGS_MESSAGE = "Lax validation should not produce warnings"; + private static final String SHOULD_SUCCEED_MESSAGE = "Lax validation should succeed without errors"; + private static final String SHOULD_FAIL_MESSAGE = "Lax validation should fail with actual errors"; + private static final String SHOULD_PRODUCE_ERRORS_MESSAGE = "Lax validation should raise error messages for errors"; + private static final String NO_MEDIA_ASSIGNED_MESSAGE = "The structure has no media assigned: Text \"null\""; + private static final String MISSING_ID_MESSAGE = "Missing value for the identifier."; + private static final String TEST_FILES_DIR = "./src/test/resources/metadata/metadataFiles/"; + private static final String TEST_META = TEST_FILES_DIR + "testmeta.xml"; + private static final String TEST_KALLIOPE_PARENT = TEST_FILES_DIR + "testMetadataForKalliopeParentProcess.xml"; + + @Test + public void shouldValidateMetadataByURIAndWarnAboutMissingMedia() { + ValidationResult result = getValidationResultByURI(TEST_META); + List validationMessages = new ArrayList<>(result.getResultMessages()); + Assertions.assertEquals(1, validationMessages.size(), WRONG_NUMBER_MESSAGE); + Assertions.assertTrue(validationMessages.contains(NO_MEDIA_ASSIGNED_MESSAGE), WRONG_VALIDATION_MESSAGE); + Assertions.assertEquals(State.WARNING, result.getState(), WRONG_STATE_MESSAGE); + } + + @Test + public void shouldValidateMetadataByURIAndRaiseError() { + ValidationResult result = getValidationResultByURI(TEST_KALLIOPE_PARENT); + Assertions.assertEquals(State.ERROR, result.getState(), WRONG_STATE_MESSAGE); + } + + @Test + public void shouldValidateMetadataByWorkpieceAndWarnAboutMissingMediaAndID() throws IOException, DAOException { + URI metsUri = Paths.get(TEST_META).toUri(); + RulesetManagementInterface ruleset = ServiceManager.getRulesetManagementService().getRulesetManagement(); + ruleset.load(new File(TestConstants.TEST_RULESET)); + Workpiece workpiece = ServiceManager.getMetsService().loadWorkpiece(metsUri); + ValidationResult result = ServiceManager.getMetadataValidationService().validate(workpiece, ruleset); + List validationMessages = new ArrayList<>(result.getResultMessages()); + // the number of expected warnings is 2 instead of 1 here because validating by workpiece additionally adds a + // warning for missing process IDs in the workpiece + Assertions.assertEquals(2, validationMessages.size(), WRONG_NUMBER_MESSAGE); + Assertions.assertTrue(validationMessages.contains(NO_MEDIA_ASSIGNED_MESSAGE), WRONG_VALIDATION_MESSAGE); + Assertions.assertTrue(validationMessages.contains(MISSING_ID_MESSAGE), WRONG_VALIDATION_MESSAGE); + Assertions.assertEquals(State.WARNING, result.getState(), WRONG_STATE_MESSAGE); + } + + @Test + public void shouldValidateMetadataByWorkpieceWithoutWarning() throws IOException, DAOException { + URI metsUri = Paths.get(TEST_META).toUri(); + RulesetManagementInterface ruleset = ServiceManager.getRulesetManagementService().getRulesetManagement(); + ruleset.load(new File(TestConstants.TEST_RULESET)); + Workpiece workpiece = ServiceManager.getMetsService().loadWorkpiece(metsUri); + ValidationResult result = ServiceManager.getMetadataValidationService().validate(workpiece, ruleset, false); + Assertions.assertTrue(result.getResultMessages().isEmpty(), SHOULD_NOT_PRODUCE_WARNINGS_MESSAGE); + Assertions.assertEquals(State.SUCCESS, result.getState(), SHOULD_SUCCEED_MESSAGE); + } + + @Test + public void shouldValidateAndRaiseErrorAndLaxValidation() throws IOException, DAOException { + URI metsUri = Paths.get(TEST_KALLIOPE_PARENT).toUri(); + RulesetManagementInterface ruleset = ServiceManager.getRulesetManagementService().getRulesetManagement(); + ruleset.load(new File(TestConstants.TEST_RULESET)); + Workpiece workpiece = ServiceManager.getMetsService().loadWorkpiece(metsUri); + ValidationResult result = ServiceManager.getMetadataValidationService().validate(workpiece, ruleset, false); + Assertions.assertFalse(result.getResultMessages().isEmpty(), SHOULD_PRODUCE_ERRORS_MESSAGE); + Assertions.assertEquals(State.ERROR, result.getState(), SHOULD_FAIL_MESSAGE); + } + + private ValidationResult getValidationResultByURI(String metadataFile) { + URI metsUri = Paths.get(metadataFile).toUri(); + URI rulesetUri = Paths.get(TestConstants.TEST_RULESET).toUri(); + return ServiceManager.getMetadataValidationService().validate(metsUri, rulesetUri); + } +} diff --git a/Kitodo/src/test/java/org/kitodo/production/services/workflow/WorkflowControllerServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/workflow/WorkflowControllerServiceIT.java index 55c38a9130d..8747b824acf 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/workflow/WorkflowControllerServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/workflow/WorkflowControllerServiceIT.java @@ -53,6 +53,8 @@ public class WorkflowControllerServiceIT { ConfigCore.getParameter(ParameterCore.SCRIPT_CREATE_DIR_USER_HOME)); private static final File scriptCreateSymLink = new File( ConfigCore.getParameter(ParameterCore.SCRIPT_CREATE_SYMLINK)); + private static final File scriptDeleteSymLink = new File( + ConfigCore.getParameter(ParameterCore.SCRIPT_DELETE_SYMLINK)); private static final File scriptNotWorking = new File("src/test/resources/scripts/not_working_script.sh"); private static final File scriptWorking = new File("src/test/resources/scripts/working_script.sh"); private static final File usersDirectory = new File("src/test/resources/users"); @@ -79,6 +81,7 @@ public void prepareDatabase() throws Exception { if (!SystemUtils.IS_OS_WINDOWS) { ExecutionPermission.setExecutePermission(scriptCreateDirUserHome); ExecutionPermission.setExecutePermission(scriptCreateSymLink); + ExecutionPermission.setExecutePermission(scriptDeleteSymLink); ExecutionPermission.setExecutePermission(scriptNotWorking); ExecutionPermission.setExecutePermission(scriptWorking); } @@ -95,6 +98,7 @@ public void cleanDatabase() throws Exception { if (!SystemUtils.IS_OS_WINDOWS) { ExecutionPermission.setNoExecutePermission(scriptCreateDirUserHome); ExecutionPermission.setNoExecutePermission(scriptCreateSymLink); + ExecutionPermission.setNoExecutePermission(scriptDeleteSymLink); ExecutionPermission.setNoExecutePermission(scriptNotWorking); ExecutionPermission.setNoExecutePermission(scriptWorking); } diff --git a/Kitodo/src/test/java/org/kitodo/selenium/AddingST.java b/Kitodo/src/test/java/org/kitodo/selenium/AddingST.java index 13eebcd9927..34e04dc89af 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/AddingST.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/AddingST.java @@ -18,9 +18,12 @@ import static org.junit.Assume.assumeTrue; import java.io.File; +import java.io.IOException; import java.util.List; +import java.util.Optional; import java.util.concurrent.TimeUnit; +import com.xebialabs.restito.server.StubServer; import org.apache.commons.lang3.SystemUtils; import org.junit.After; import org.junit.AfterClass; @@ -60,6 +63,7 @@ public class AddingST extends BaseTestSelenium { + private static StubServer server; private static ProcessesPage processesPage; private static ProjectsPage projectsPage; private static UsersPage usersPage; @@ -68,6 +72,9 @@ public class AddingST extends BaseTestSelenium { private static ImportConfigurationEditPage importConfigurationEditPage; private static final String TEST_METADATA_FILE = "testMetadataFileServiceTest.xml"; private static int secondProcessId = -1; + private static final String PICA_PPN = "pica.ppn"; + private static final String PICA_XML = "picaxml"; + private static final String TEST_FILE_PATH = "src/test/resources/sruTestRecord.xml"; @BeforeClass public static void setup() throws Exception { @@ -88,6 +95,13 @@ public static void setup() throws Exception { } assertTrue("Should find exactly one second process!", secondProcessId > 0); ProcessTestUtils.copyTestMetadataFile(secondProcessId, TEST_METADATA_FILE); + server = new StubServer(MockDatabase.PORT).run(); + setupServer(); + } + + private static void setupServer() throws IOException { + // REST endpoint for testing metadata import + MockDatabase.addRestEndPointForSru(server, PICA_PPN + "=test", TEST_FILE_PATH, PICA_XML, 1); } /** @@ -97,6 +111,7 @@ public static void setup() throws Exception { @AfterClass public static void removeUnsuitableParentTestProcess() throws DAOException { ProcessTestUtils.removeTestProcess(secondProcessId); + server.stop(); } @Before @@ -158,12 +173,10 @@ public void addProcessesTest() throws Exception { assertTrue("Created Process was not listed at processes table!", processAvailable); ProcessService processService = ServiceManager.getProcessService(); - // TODO: make processService.findByTitle(generatedTitle) work - int recordNumber = 1; - Process generatedProcess; - do { - generatedProcess = processService.getById(recordNumber++); - } while (!generatedTitle.equals(generatedProcess.getTitle())); + Optional optionalProcess = processService.getAll().stream().filter(process -> generatedTitle + .equals(process.getTitle())).findAny(); + assertTrue("Generated process not found in database", optionalProcess.isPresent()); + Process generatedProcess = optionalProcess.get(); assertNull("Created Process unexpectedly got a parent!", generatedProcess.getParent()); projectsPage.createNewProcess(); @@ -173,12 +186,12 @@ public void addProcessesTest() throws Exception { boolean childProcessAvailable = processesPage.getProcessTitles().contains(generatedChildTitle); assertTrue("Created Process was not listed at processes table!", childProcessAvailable); - // TODO: make processService.findByTitle(generatedChildTitle) work - Process generatedChildProcess; - do { - generatedChildProcess = processService.getById(recordNumber++); - } while (!generatedChildTitle.equals(generatedChildProcess.getTitle())); + Optional optionalChildProcess = processService.getAll().stream().filter(process -> generatedChildTitle + .equals(process.getTitle())).findAny(); + assertTrue("Generated child process not found in database", optionalChildProcess.isPresent()); + Process generatedChildProcess = optionalChildProcess.get(); assertEquals("Created Process has a wrong parent!", generatedProcess, generatedChildProcess.getParent()); + ProcessTestUtils.removeTestProcess(generatedProcess.getId()); } @Test @@ -189,10 +202,9 @@ public void addProcessAsChildNotPossible() throws Exception { Pages.getProcessFromTemplatePage().cancel(); } - @Ignore @Test public void addProcessFromCatalogTest() throws Exception { - assumeTrue(!SystemUtils.IS_OS_WINDOWS && !SystemUtils.IS_OS_MAC); + assumeTrue(!SystemUtils.IS_OS_WINDOWS); projectsPage.createNewProcess(); assertEquals("Header for create new process is incorrect", "Einen neuen Vorgang anlegen (Produktionsvorlage: 'First template')", @@ -201,6 +213,10 @@ public void addProcessFromCatalogTest() throws Exception { String generatedTitle = Pages.getProcessFromTemplatePage().createProcessFromCatalog(); boolean processAvailable = processesPage.getProcessTitles().contains(generatedTitle); assertTrue("Created Process was not listed at processes table!", processAvailable); + int index = processesPage.getProcessTitles().indexOf(generatedTitle); + assertTrue("Process table does not contain ID or new process", index >= 0); + int processId = Integer.parseInt(processesPage.getProcessIds().get(index)); + ProcessTestUtils.removeTestProcess(processId); } @Test diff --git a/Kitodo/src/test/java/org/kitodo/selenium/ConfigConversionST.java b/Kitodo/src/test/java/org/kitodo/selenium/ConfigConversionST.java index ead8a416d16..3a1e16142a1 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/ConfigConversionST.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/ConfigConversionST.java @@ -29,6 +29,7 @@ import org.kitodo.selenium.testframework.Browser; import org.kitodo.selenium.testframework.Pages; import org.kitodo.selenium.testframework.pages.ProjectsPage; +import org.openqa.selenium.By; public class ConfigConversionST extends BaseTestSelenium { @@ -61,7 +62,12 @@ public void shouldImportCatalogConfigurations() throws Exception { assertEquals(MODS_2_KITODO, importConfigurationsTab.getMappingFileTitle()); importConfigurationsTab.selectInputFormatMods(); importConfigurationsTab.selectOutputFormatKitodo(); - importConfigurationsTab.clickMappingFileOkButton(); + await("Wait for 'confirm mapping' button to be enabled") + .pollDelay(1, TimeUnit.SECONDS) + .pollInterval(1, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS).ignoreExceptions() + .until(() -> Browser.getDriver().findElement(By.id("mappingFileFormatsForm:ok")).isEnabled()); + Browser.getDriver().findElement(By.id("mappingFileFormatsForm:ok")).click(); await("Wait for 'Results' dialog to be displayed") .atMost(5, TimeUnit.SECONDS) diff --git a/Kitodo/src/test/java/org/kitodo/selenium/ImportingST.java b/Kitodo/src/test/java/org/kitodo/selenium/ImportingST.java index 7b2f6f3aa67..8cdc38f789b 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/ImportingST.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/ImportingST.java @@ -20,16 +20,15 @@ import java.util.List; import java.util.concurrent.TimeUnit; +import com.xebialabs.restito.server.StubServer; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.kitodo.MockDatabase; -import org.kitodo.data.database.beans.Process; import org.kitodo.data.database.exceptions.DAOException; import org.kitodo.data.exceptions.DataException; -import org.kitodo.production.services.ServiceManager; import org.kitodo.production.services.data.ProcessService; import org.kitodo.selenium.testframework.BaseTestSelenium; import org.kitodo.selenium.testframework.Browser; @@ -38,14 +37,12 @@ import org.kitodo.selenium.testframework.pages.ProcessesPage; import org.kitodo.selenium.testframework.pages.ProjectsPage; import org.kitodo.test.utils.ProcessTestUtils; +import org.kitodo.test.utils.TestConstants; import org.openqa.selenium.support.ui.Select; public class ImportingST extends BaseTestSelenium { - private static final String PPN = "PPN"; - private static final String GBV = "GBV"; - private static final String K10PLUS = "K10Plus"; - private static final String KALLIOPE = "Kalliope"; + private static StubServer server; private static final String TEST_VOLUME = "Test volume"; private static final String TEST_MULTI_VOLUME_WORK_FILE = "testMultiVolumeWorkMeta.xml"; private static ProcessFromTemplatePage importPage; @@ -63,6 +60,8 @@ public static void setup() throws Exception { MockDatabase.insertMappingFiles(); MockDatabase.insertImportConfigurations(); MockDatabase.addDefaultChildProcessImportConfigurationToFirstProject(); + server = new StubServer(MockDatabase.PORT).run(); + setupServer(); } @Before @@ -81,18 +80,31 @@ public void logout() throws Exception { @AfterClass public static void cleanup() throws DAOException, DataException, IOException { ProcessService.deleteProcess(multiVolumeWorkId); + server.stop(); + } + + private static void setupServer() throws IOException { + // endpoint for retrieving number of child records of process with given ID + MockDatabase.addRestEndPointForSru(server, TestConstants.EAD_PARENT_ID + "=" + TestConstants.KALLIOPE_PARENT_ID, + TestConstants.NUMBER_OF_CHILD_RECORDS_PATH, TestConstants.MODS, 0); + // endpoint for retrieving parent process with given ID + MockDatabase.addRestEndPointForSru(server, TestConstants.EAD_ID + "=" + TestConstants.KALLIOPE_PARENT_ID, + TestConstants.PARENT_RECORD_PATH, TestConstants.MODS, 1); + // endpoint for retrieving child records of process with given ID + MockDatabase.addRestEndPointForSru(server, TestConstants.EAD_PARENT_ID + "=" + TestConstants.KALLIOPE_PARENT_ID, + TestConstants.MULTIPLE_CHILD_RECORDS_PATH, TestConstants.MODS, 1, 3); } @Test public void checkDefaultValuesTest() throws Exception { projectsPage.createNewProcess(); Select catalogSelectMenu = new Select(importPage.getCatalogMenu()); - assertEquals("Wrong default catalog selected", K10PLUS, + assertEquals("Wrong default catalog selected", TestConstants.K10PLUS, catalogSelectMenu.getFirstSelectedOption().getAttribute("label")); importPage.selectGBV(); Select searchFieldSelectMenu = new Select(importPage.getSearchFieldMenu()); - assertEquals("Wrong default search field selected", PPN, + assertEquals("Wrong default search field selected", TestConstants.PPN, searchFieldSelectMenu.getFirstSelectedOption().getAttribute("label")); } @@ -106,7 +118,7 @@ public void checkSearchButtonActivatedText() throws Exception { projectsPage.createNewProcess(); assertFalse("'Search' button should be deactivated until import configuration, search field and " + "search term have been selected", importPage.getSearchButton().isEnabled()); - importPage.enterTestSearchValue(); + importPage.enterTestSearchValue("12345"); await("Wait for 'Search' button to be enabled").pollDelay(700, TimeUnit.MILLISECONDS) .atMost(30, TimeUnit.SECONDS).ignoreExceptions() .until(() -> importPage.getSearchButton().isEnabled()); @@ -120,7 +132,6 @@ public void checkSearchButtonActivatedText() throws Exception { */ @Test public void checkDefaultChildProcessImportConfiguration() throws Exception { - Process process = ServiceManager.getProcessService().getById(multiVolumeWorkId); ProcessTestUtils.copyTestMetadataFile(multiVolumeWorkId, TEST_MULTI_VOLUME_WORK_FILE); processesPage.goTo(); processesPage.applyFilter("id:" + multiVolumeWorkId); @@ -139,8 +150,40 @@ public void checkDefaultChildProcessImportConfiguration() throws Exception { public void checkOrderOfImportConfigurations() throws Exception { projectsPage.createNewProcess(); List importConfigurationNames = importPage.getImportConfigurationsTitles(); - assertEquals("Wrong first import configuration title", GBV, importConfigurationNames.get(1)); - assertEquals("Wrong first import configuration title", K10PLUS, importConfigurationNames.get(2)); - assertEquals("Wrong first import configuration title", KALLIOPE, importConfigurationNames.get(3)); + assertEquals("Wrong title of first import configuration", TestConstants.GBV, importConfigurationNames.get(1)); + assertEquals("Wrong title of second import configuration", TestConstants.K10PLUS, importConfigurationNames.get(2)); + assertEquals("Wrong title of third import configuration", TestConstants.KALLIOPE, importConfigurationNames.get(3)); + } + + /** + * Tests whether import process hierarchies works correctly or not. + */ + @Test + public void checkHierarchyImport() throws Exception { + projectsPage.createNewProcess(); + Select catalogSelectMenu = new Select(importPage.getCatalogMenu()); + assertEquals("Wrong default catalog selected", TestConstants.K10PLUS, + catalogSelectMenu.getFirstSelectedOption().getAttribute("label")); + importPage.selectKalliope(); + Select searchFieldSelectMenu = new Select(importPage.getSearchFieldMenu()); + assertEquals("Wrong default search field selected", TestConstants.IDENTIFIER, + searchFieldSelectMenu.getFirstSelectedOption().getAttribute("label")); + importPage.enterTestSearchValue(TestConstants.KALLIOPE_PARENT_ID); + importPage.activateChildProcessImport(); + importPage.decreaseImportDepth(); + importPage.getSearchButton().click(); + assertTrue("Hierarchy panel should be visible", importPage.isHierarchyPanelVisible()); + String parentTitle = importPage.getProcessTitle(); + Pages.getProcessFromTemplatePage().save(); + processesPage.applyFilter(parentTitle); + assertEquals("Exactly one imported parent process should be displayed", 1, + processesPage.countListedProcesses()); + List processIds = processesPage.getProcessIds(); + assertEquals("Exactly one process ID should be visible", 1, processIds.size()); + int processId = Integer.parseInt(processIds.get(0)); + processesPage.filterByChildren(); + List childProcessIds = processesPage.getProcessIds(); + assertEquals("Wrong number of child processes", 3, childProcessIds.size()); + ProcessTestUtils.removeTestProcess(processId); } } diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/helper/WebDriverProvider.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/helper/WebDriverProvider.java index a4a659614c8..e1c791b6789 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/helper/WebDriverProvider.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/testframework/helper/WebDriverProvider.java @@ -122,13 +122,13 @@ public static void provideGeckoDriver(String geckoDriverVersion, String download public static void provideChromeDriver(String downloadFolder, String extractFolder) throws IOException { String chromeDriverVersion = fetchLatestStableChromeDriverVersion(); - String chromeDriverUrl = CHROME_FOR_TESTING_URL + chromeDriverVersion + File.separator; + String chromeDriverUrl = CHROME_FOR_TESTING_URL + chromeDriverVersion + '/'; String driverFilename = CHROME_DRIVER; File chromeDriverFile; if (SystemUtils.IS_OS_WINDOWS) { driverFilename = driverFilename + EXE; File chromeDriverZipFile = new File(downloadFolder + CHROME_DRIVER_WIN_SUBDIR + File.separator + ZIP_FILE); - FileUtils.copyURLToFile(new URL(chromeDriverUrl + CHROME_DRIVER_WIN_PREFIX + File.separator + FileUtils.copyURLToFile(new URL(chromeDriverUrl + CHROME_DRIVER_WIN_PREFIX + '/' + CHROME_DRIVER_WIN_SUBDIR + ZIP), chromeDriverZipFile); chromeDriverFile = extractZipFileToFolder(chromeDriverZipFile, new File(extractFolder), driverFilename, CHROME_DRIVER_WIN_SUBDIR); diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/Page.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/Page.java index bcc419bb380..e018516f0e4 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/Page.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/Page.java @@ -196,7 +196,7 @@ protected void clickButtonAndWaitForRedirect(WebElement button, String url) { WebDriverWait webDriverWait = new WebDriverWait(Browser.getDriver(), 60); for (int attempt = 1; attempt < 4; attempt++) { try { - await("Wait for button clicked").pollDelay(700, TimeUnit.MILLISECONDS).atMost(30, TimeUnit.SECONDS) + await("Wait for button clicked").pollDelay(700, TimeUnit.MILLISECONDS).atMost(10, TimeUnit.SECONDS) .ignoreExceptions().until(() -> isButtonClicked.test(button)); if (Browser.isAlertPresent() && url.contains("login")) { Browser.getDriver().switchTo().alert().accept(); @@ -212,7 +212,7 @@ protected void clickButtonAndWaitForRedirect(WebElement button, String url) { } protected void clickElement(WebElement element) { - await("Wait for element clicked").pollDelay(500, TimeUnit.MILLISECONDS).atMost(20, TimeUnit.SECONDS) + await("Wait for element " + element.getText() + ", " + element.getTagName() + " to be clicked").pollDelay(500, TimeUnit.MILLISECONDS).atMost(20, TimeUnit.SECONDS) .ignoreExceptions().until(() -> isButtonClicked.test(element)); } diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/ProcessFromTemplatePage.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/ProcessFromTemplatePage.java index 0874a92241e..7a309d4a65e 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/ProcessFromTemplatePage.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/ProcessFromTemplatePage.java @@ -20,6 +20,7 @@ import org.awaitility.core.ConditionTimeoutException; import org.kitodo.selenium.testframework.Browser; import org.kitodo.selenium.testframework.Pages; +import org.kitodo.test.utils.TestConstants; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; @@ -28,6 +29,8 @@ public class ProcessFromTemplatePage extends EditPage { private static final String TAB_VIEW = EDIT_FORM + ":processFromTemplateTabView"; private static final String OPAC_SEARCH_FORM = "catalogSearchForm"; + private static final String HIERARCHY_PANEL = "editForm:processFromTemplateTabView:processHierarchyContent"; + private static final String IMPORT_CHILD_PROCESSES_SWITCH = "#catalogSearchForm\\:importChildren .ui-chkbox-box"; @SuppressWarnings("unused") @FindBy(id = TAB_VIEW) @@ -90,7 +93,7 @@ public class ProcessFromTemplatePage extends EditPage { private WebElement searchTermInput; @SuppressWarnings("unused") - @FindBy(id = TAB_VIEW + ":performCatalogSearch") + @FindBy(id = OPAC_SEARCH_FORM + ":performCatalogSearch") private WebElement performCatalogSearchButton; @SuppressWarnings("unused") @@ -137,14 +140,26 @@ public WebElement getTemplateProcessMenu() { return Browser.getDriver().findElementById("searchEditForm:processSelect_input"); } + private void selectCatalog(String catalogName) throws InterruptedException { + clickElement(catalogSelect.findElement(By.cssSelector(CSS_SELECTOR_DROPDOWN_TRIGGER))); + clickElement(Browser.getDriver().findElement(By.cssSelector("li[data-label='" + catalogName + "']"))); + Thread.sleep(Browser.getDelayAfterCatalogSelection()); + } + /** * Select GBV catalog. * @throws InterruptedException when thread is interrupted */ public void selectGBV() throws InterruptedException { - clickElement(catalogSelect.findElement(By.cssSelector(CSS_SELECTOR_DROPDOWN_TRIGGER))); - clickElement(Browser.getDriver().findElement(By.id(catalogSelect.getAttribute("id") + "_1"))); - Thread.sleep(Browser.getDelayAfterCatalogSelection()); + selectCatalog(TestConstants.GBV); + } + + /** + * Select Kalliope catalog. + * @throws InterruptedException when thread is interrupted + */ + public void selectKalliope() throws InterruptedException { + selectCatalog(TestConstants.KALLIOPE); } /** @@ -177,7 +192,7 @@ public String createProcess() throws Exception { generateTitleButton.click(); await("Wait for title generation").pollDelay(3, TimeUnit.SECONDS).atMost(10, TimeUnit.SECONDS) .ignoreExceptions().until(() -> isInputValueNotEmpty.test(processTitleInput)); - String generatedTitle = processTitleInput.getAttribute("value"); + String generatedTitle = processTitleInput.getAttribute(TestConstants.VALUE); save(); return generatedTitle; } @@ -207,7 +222,7 @@ public String createProcessAsChild(String parentProcessTitle) throws Exception { generateTitleButton.click(); await("Wait for title generation").pollDelay(3, TimeUnit.SECONDS).atMost(10, TimeUnit.SECONDS) .ignoreExceptions().until(() -> isInputValueNotEmpty.test(processTitleInput)); - final String generatedTitle = processTitleInput.getAttribute("value"); + final String generatedTitle = processTitleInput.getAttribute(TestConstants.VALUE); switchToTabByIndex(1); searchForParentInput.sendKeys(parentProcessTitle); @@ -262,35 +277,80 @@ public boolean createProcessAsChildNotPossible() throws Exception { } } + /** + * Tests importing metadata from a simulated OPAC and saving it as a process in Kitodo.Production. + * @return title of the created process as String. + * @throws Exception when saving the imported process fails. + */ public String createProcessFromCatalog() throws Exception { clickElement(catalogSelect.findElement(By.cssSelector(CSS_SELECTOR_DROPDOWN_TRIGGER))); - clickElement(Browser.getDriver().findElement(By.id(catalogSelect.getAttribute("id") + "_2"))); - + clickElement(Browser.getDriver().findElement(By.cssSelector("li[data-label='K10Plus']"))); clickElement(fieldSelect.findElement(By.cssSelector(CSS_SELECTOR_DROPDOWN_TRIGGER))); - clickElement(Browser.getDriver().findElement(By.id(fieldSelect.getAttribute("id") + "_1"))); - + clickElement(Browser.getDriver().findElement(By.cssSelector("li[data-label='PPN']"))); + await("Wait for 'searchInput' field to become active").pollDelay(100, TimeUnit.MILLISECONDS) + .atMost(3, TimeUnit.SECONDS).ignoreExceptions().until(() -> searchTermInput.isEnabled()); searchTermInput.sendKeys("test"); + await("Wait for 'performSearch' button to become active").pollDelay(100, TimeUnit.MILLISECONDS) + .atMost(3, TimeUnit.SECONDS).ignoreExceptions().until(() -> performCatalogSearchButton.isEnabled()); performCatalogSearchButton.click(); - selectRecord.click(); - - Thread.sleep(Browser.getDelayAfterPickListClick()); + await("Wait for popup dialog and loading screen to disappear").pollDelay(1, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS).ignoreExceptions().until(() -> !Browser.getDriver() + .findElement(By.id("loadingScreen")).isDisplayed()); titleSortInput.sendKeys("Test"); ppnAnalogInput.sendKeys("12345"); - + ppnDigitalInput.sendKeys("67890"); guessImagesInput.sendKeys("299"); generateTitleButton.click(); await("Wait for title generation").pollDelay(3, TimeUnit.SECONDS).atMost(10, TimeUnit.SECONDS) .ignoreExceptions().until(() -> isInputValueNotEmpty.test(processTitleInput)); - String generatedTitle = processTitleInput.getAttribute("value"); + String generatedTitle = processTitleInput.getAttribute(TestConstants.VALUE); save(); return generatedTitle; } + /** + * Get process title from corresponding "CreateProcessForm" input field. + * @return process title input field value + */ + public String getProcessTitle() { + return processTitleInput.getAttribute(TestConstants.VALUE); + } + + /** + * Check and return whether hierarchy panel is visible or not after triggering catalog import. + * @return whether hierarchy panel is visible + */ + public boolean isHierarchyPanelVisible() { + WebElement hierarchyPanel = Browser.getDriver().findElement(By.id(HIERARCHY_PANEL)); + return hierarchyPanel.isDisplayed(); + } + + /** + * Activate automatic import of child records by clicking on the switch labeled "Import child processes" + */ + public void activateChildProcessImport() { + // activate child process search + WebElement childProcessSwitch = Browser.getDriver().findElement(By.cssSelector(IMPORT_CHILD_PROCESSES_SWITCH)); + await("Wait for 'childProcessImport' switch to become active").pollDelay(100, TimeUnit.MILLISECONDS) + .atMost(3, TimeUnit.SECONDS).ignoreExceptions().until(childProcessSwitch::isEnabled); + clickElement(childProcessSwitch); + } + + /** + * Decrease the import depth for the catalog by clicking on the chevron-down arrow in the corresponding input field. + * @throws InterruptedException when putting the thread to sleep fails + */ + public void decreaseImportDepth() throws InterruptedException { + WebElement spinnerDown = Browser.getDriver().findElement(By.cssSelector("#catalogSearchForm .ui-spinner-down")); + spinnerDown.click(); + Thread.sleep(Browser.getDelayAfterCatalogSelection()); + } + /** * Enter test value into search term field. */ - public void enterTestSearchValue() { - searchTermInput.sendKeys("12345"); + public void enterTestSearchValue(String searchTerm) { + searchTermInput.sendKeys(searchTerm); } public ProcessesPage save() throws IllegalAccessException, InstantiationException { diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/ProcessesPage.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/ProcessesPage.java index 666c2709934..7d3476513d7 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/ProcessesPage.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/ProcessesPage.java @@ -234,6 +234,19 @@ public List getProcessTitles() throws Exception { return getTableDataByColumn(processesTable, 3); } + /** + * Returns a list of all process IDs which were displayed on process page. + * + * @return list of process IDs + * @throws Exception when navigating to processes page fails + */ + public List getProcessIds() throws Exception { + if (isNotAt()) { + goTo(); + } + return getTableDataByColumn(processesTable, 2); + } + public void createNewBatch() throws Exception { switchToTabByIndex(TabIndex.BATCHES.getIndex()); @@ -559,4 +572,21 @@ public void createChildProcess() throws InstantiationException, IllegalAccessExc + MULTI_VOLUME_WORK_PROCESS_TITLE + "'"); } } + + /** + * Toggles first row expansion in process list. + */ + public void filterByChildren() { + WebElement rowToggler = processesTable.findElement(By.className("ui-row-toggler")); + rowToggler.click(); + await("Wait for row expansion to become visible").pollDelay(1, TimeUnit.SECONDS) + .pollInterval(500, TimeUnit.MILLISECONDS).atMost(3, TimeUnit.SECONDS) + .until(() -> Browser.getDriver().findElement(By.className("row-expansion-wrapper")).isDisplayed()); + WebElement rowExpansion = Browser.getDriver().findElement(By.className("row-expansion-wrapper")); + WebElement childFilterLink = rowExpansion.findElement(By.cssSelector(".value a")); + childFilterLink.click(); + await("Wait for execution of link click").pollDelay(1, TimeUnit.SECONDS) + .atMost(Browser.getDelayMaxAfterLinkClick(), TimeUnit.MILLISECONDS).ignoreExceptions() + .until(this::isAt); + } } diff --git a/Kitodo/src/test/java/org/kitodo/test/utils/ProcessTestUtils.java b/Kitodo/src/test/java/org/kitodo/test/utils/ProcessTestUtils.java index fd472582570..c83295681b6 100644 --- a/Kitodo/src/test/java/org/kitodo/test/utils/ProcessTestUtils.java +++ b/Kitodo/src/test/java/org/kitodo/test/utils/ProcessTestUtils.java @@ -14,18 +14,14 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.OutputStream; import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.logging.log4j.LogManager; @@ -232,10 +228,7 @@ public static void updateIdentifier(int processId) throws DAOException, IOExcept Process process = ServiceManager.getProcessService().getById(processId); URI metadataFileUri = ServiceManager.getFileService().getMetadataFilePath(process); try (InputStream fileContent = ServiceManager.getFileService().readMetadataFile(process)) { - InputStreamReader inputStreamReader = new InputStreamReader(fileContent); - BufferedReader bufferedReader = new BufferedReader(inputStreamReader); - List textLines = bufferedReader.lines().collect(Collectors.toList()); - String textContent = String.join("", textLines); + String textContent = new String(fileContent.readAllBytes()); textContent = textContent.replace(ID_PLACEHOLDER, String.valueOf(processId)); try (OutputStream updatedFileContent = ServiceManager.getFileService().write(metadataFileUri)) { updatedFileContent.write(textContent.getBytes()); diff --git a/Kitodo/src/test/java/org/kitodo/test/utils/TestConstants.java b/Kitodo/src/test/java/org/kitodo/test/utils/TestConstants.java new file mode 100644 index 00000000000..6f4875824b0 --- /dev/null +++ b/Kitodo/src/test/java/org/kitodo/test/utils/TestConstants.java @@ -0,0 +1,35 @@ +/* + * (c) Kitodo. Key to digital objects e. V. + * + * This file is part of the Kitodo project. + * + * It is licensed under GNU General Public License version 3 or later. + * + * For the full copyright and license information, please read the + * GPL3-License.txt file that was distributed with this source code. + */ + +package org.kitodo.test.utils; + +/** + * This class is used to group constants used in various tests in one place from which they can be retrieved. + */ +public final class TestConstants { + + public static final String MODS = "mods"; + public static final String GBV = "GBV"; + public static final String K10PLUS = "K10Plus"; + public static final String KALLIOPE = "Kalliope"; + public static final String PPN = "PPN"; + public static final String PARENT_RECORD_PATH = "src/test/resources/importRecords/importParentRecord.xml"; + public static final String NUMBER_OF_CHILD_RECORDS_PATH = "src/test/resources/importRecords/sruNumberOfChildRecords.xml"; + public static final String MULTIPLE_CHILD_RECORDS_PATH = "src/test/resources/importRecords/importMultipleChildRecords.xml"; + public static final String CHILD_RECORD_PATH = "src/test/resources/importRecords/importChildRecord.xml"; + public static final String HITLIST_RECORD_PATH = "src/test/resources/importRecords/importHitlist.xml"; + public static final String EAD_ID = "ead.id"; + public static final String EAD_PARENT_ID = "context.ead.id"; + public static final String KALLIOPE_PARENT_ID = "DE-1234-BE-56-7890"; + public static final String IDENTIFIER = "Identifier"; + public static final String VALUE = "value"; + public static final String TEST_RULESET = "src/test/resources/rulesets/ruleset_test.xml"; +} diff --git a/Kitodo/src/test/resources/importRecords/importMultipleChildRecords.xml b/Kitodo/src/test/resources/importRecords/importMultipleChildRecords.xml index c61c35a2d3d..d7cf64a7486 100644 --- a/Kitodo/src/test/resources/importRecords/importMultipleChildRecords.xml +++ b/Kitodo/src/test/resources/importRecords/importMultipleChildRecords.xml @@ -25,11 +25,15 @@ 9991 - 123123 + DE-1234-BE-56-7890 Child process 1 + Volume + + single unit + @@ -45,11 +49,15 @@ 9992 - 123123 + DE-1234-BE-56-7890 Child process 2 + Volume + + single unit + @@ -65,11 +73,15 @@ 9993 - 123123 + DE-1234-BE-56-7890 Child process 3 + Volume + + single unit + diff --git a/Kitodo/src/test/resources/importRecords/importParentRecord.xml b/Kitodo/src/test/resources/importRecords/importParentRecord.xml index 479023e92ec..0a4c3027003 100644 --- a/Kitodo/src/test/resources/importRecords/importParentRecord.xml +++ b/Kitodo/src/test/resources/importRecords/importParentRecord.xml @@ -23,13 +23,16 @@ xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-4.xsd"> http://www.test.id - 2 + DE-1234-BE-56-7890 2019-11-09 2019-11-09 Elternvorgang + + multipart monograph + diff --git a/Kitodo/src/test/resources/importRecords/sruNumberOfChildRecords.xml b/Kitodo/src/test/resources/importRecords/sruNumberOfChildRecords.xml new file mode 100644 index 00000000000..b09398419fb --- /dev/null +++ b/Kitodo/src/test/resources/importRecords/sruNumberOfChildRecords.xml @@ -0,0 +1,22 @@ + + + + 1.2 + 3 + + 1.2 + pica.ppn=11111 + 0 + xml + mods + + diff --git a/Kitodo/src/test/resources/rulesets/ruleset_test.xml b/Kitodo/src/test/resources/rulesets/ruleset_test.xml index 19ec16d3e95..ab70eded5ec 100644 --- a/Kitodo/src/test/resources/rulesets/ruleset_test.xml +++ b/Kitodo/src/test/resources/rulesets/ruleset_test.xml @@ -46,6 +46,9 @@ + + + diff --git a/Kitodo/src/test/resources/xslt/mods2kitodo.xsl b/Kitodo/src/test/resources/xslt/mods2kitodo.xsl index 45a18373d77..b3ef2deac8b 100644 --- a/Kitodo/src/test/resources/xslt/mods2kitodo.xsl +++ b/Kitodo/src/test/resources/xslt/mods2kitodo.xsl @@ -27,7 +27,7 @@ - +