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 84955931a18..f7fc69fad95 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 @@ -151,7 +151,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"); @@ -174,10 +174,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/services/data/ImportService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java index d508e206198..bcf124e82d7 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 @@ -1173,7 +1173,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; @@ -1256,14 +1256,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/test/java/org/kitodo/production/services/data/ImportServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/ImportServiceIT.java index 85c2f7f241b..22adf086d5f 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 @@ -29,7 +29,11 @@ import java.nio.file.Paths; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.SystemUtils; import org.junit.AfterClass; @@ -39,6 +43,9 @@ import org.kitodo.ExecutionPermission; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; +import org.kitodo.api.Metadata; +import org.kitodo.api.MetadataEntry; +import org.kitodo.api.dataformat.Workpiece; import org.kitodo.config.ConfigCore; import org.kitodo.config.enums.ParameterCore; import org.kitodo.data.database.beans.ImportConfiguration; @@ -46,6 +53,7 @@ import org.kitodo.data.database.beans.UrlParameter; import org.kitodo.data.database.beans.User; import org.kitodo.data.database.exceptions.DAOException; +import org.kitodo.data.exceptions.DataException; import org.kitodo.exceptions.ImportException; import org.kitodo.production.services.ServiceManager; @@ -59,8 +67,12 @@ public class ImportServiceIT { private static final String TEST_FILE_ERROR_RESPONSE_PATH = "src/test/resources/customInterfaceErrorResponse.xml"; private static final String RECORD_ID = "11111"; private static final String CUSTOM_INTERFACE_RECORD_ID = "12345"; + private static final String TITLE = "Title"; + private static final String PLACE = "Place"; private static final int PORT = 8888; private static final String firstProcess = "First process"; + private static final File ORIGINAL_META_10 = new File("src/test/resources/metadata/10/meta.xml"); + private static final File BACKUP_META_10 = new File("src/test/resources/metadata/10/meta.xml.1"); @BeforeClass public static void prepareDatabase() throws Exception { @@ -79,13 +91,17 @@ public static void prepareDatabase() throws Exception { }); server = new StubServer(PORT).run(); setupServer(); + FileUtils.copyFile(ORIGINAL_META_10, BACKUP_META_10); } + @AfterClass public static void cleanDatabase() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); server.stop(); + FileUtils.deleteQuietly(ORIGINAL_META_10); + FileUtils.moveFile(BACKUP_META_10, ORIGINAL_META_10); } @Test @@ -98,6 +114,42 @@ public void testImportProcess() throws Exception { Assert.assertEquals("Not the correct amount of processes found", 8, (long) processService.count()); } + /** + * 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, DataException { + 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 { + ProcessService.deleteProcess(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()); @@ -160,4 +212,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/selenium/testframework/pages/CalendarPage.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/CalendarPage.java index 32475a38dfb..0a11eb59343 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/CalendarPage.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/CalendarPage.java @@ -22,15 +22,12 @@ import org.kitodo.selenium.testframework.Browser; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.FindBy; public class CalendarPage extends Page { private static final String BUTTON_CANCEL = "editForm:cancel"; private static final String BUTTON_ADD_BLOCK = "editForm:calendarTabView:addBlock"; private static final String DATEPICKER_FROM = "#editForm\\:calendarTabView\\:blockList td:first-child .p-datepicker input"; - private static final String DATEPICKER_FROM_LINK = "//div[@id='editForm:calendarTabView:blockList:0:blockFirstAppearance_panel']//" - + "a[text()='1']"; private static final String DATEPICKER_TO_LINK = "(//div[@id='editForm:calendarTabView:blockList:0:blockLastAppearance_panel']//" + "a[text()='7'])[last()]"; private static final String DATEPICKER_TO = "#editForm\\:calendarTabView\\:blockList td:last-child .p-datepicker input"; @@ -50,84 +47,10 @@ public class CalendarPage extends Page { private static final String METADATA_TYPE_PANEL = METADATA_TYPE + "_panel"; private static final String METADATA_VALUE = "calendarDayForm:issuesAccordion:0:metadataDataView:0:startValue"; private static final String CALENDAR_DIALOG_CLOSE_BUTTON = "calendarDayForm:close"; + private static final String CALENDAR = "editForm:calendarTabView:calendarTable"; + private static final String CALENDAR_ISSUES = ".issue.match"; - @SuppressWarnings("unused") - @FindBy(id = BUTTON_ADD_BLOCK) - private WebElement buttonAddBlock; - - @SuppressWarnings("unused") - @FindBy(id = BUTTON_CANCEL) - private WebElement buttonCancel; - - @SuppressWarnings("unused") - @FindBy(css = DATEPICKER_FROM) - private WebElement datepickerFrom; - - @SuppressWarnings("unused") - @FindBy(xpath = DATEPICKER_FROM_LINK) - private WebElement datepickerFromLink; - - @SuppressWarnings("unused") - @FindBy(css = DATEPICKER_TO) - private WebElement datepickerTo; - - @SuppressWarnings("unused") - @FindBy(xpath = DATEPICKER_TO_LINK) - private WebElement datepickerToLink; - - @SuppressWarnings("unused") - @FindBy(css = BUTTON_ADD_ISSUE) - private WebElement buttonAddIssue; - - @SuppressWarnings("unused") - @FindBy(css = INPUT_ISSUE) - private WebElement inputIssueName; - - @SuppressWarnings("unused") - @FindBy(id = HEADER_TEXT) - private WebElement headerText; - - @SuppressWarnings("unused") - @FindBy(css = CHECKBOX_MONDAY) - private WebElement checkboxMonday; - - @SuppressWarnings("unused") - @FindBy(css = CHECKBOX_TUESDAY) - private WebElement checkboxTuesday; - - @SuppressWarnings("unused") - @FindBy(xpath = CALENDAR_ENTRY) - private WebElement calendarEntry; - - @SuppressWarnings("unused") - @FindBy(xpath = CALENDAR_ENTRY_BUTTON) - private WebElement calendarEntryButton; - - @SuppressWarnings("unused") - @FindBy(id = BUTTON_ADD_METADATA_TO_THIS) - private WebElement buttonAddMetadataToThis; - - @SuppressWarnings("unused") - @FindBy(id = BUTTON_ADD_METADATA_TO_ALL) - private WebElement buttonAddMetadataToAll; - - @SuppressWarnings("unused") - @FindBy(id = METADATA_TYPE) - private WebElement metadataType; - - @SuppressWarnings("unused") - @FindBy(id = METADATA_TYPE_PANEL) - private WebElement metadataTypePanel; - - @SuppressWarnings("unused") - @FindBy(id = METADATA_VALUE) - private WebElement metadataValue; - - @SuppressWarnings("unused") - @FindBy(id = CALENDAR_DIALOG_CLOSE_BUTTON) - private WebElement calendarDialogCloseButton; - public CalendarPage() { super("pages/calendar.jsf"); } @@ -142,26 +65,35 @@ public CalendarPage goTo() { */ public void addBlock() { await("Wait for button to be displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(buttonAddBlock.isEnabled())); - buttonAddBlock.click(); + .untilAsserted(() -> assertTrue(getById(BUTTON_ADD_BLOCK).isEnabled())); + getById(BUTTON_ADD_BLOCK).click(); await("Wait for datepicker from being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(datepickerFrom.isEnabled())); - datepickerFrom.click(); - datepickerFromLink.click(); + .untilAsserted(() -> assertTrue(getByCSS(DATEPICKER_FROM).isEnabled())); + getByCSS(DATEPICKER_FROM).click(); + getByCSS(DATEPICKER_FROM).sendKeys("01.02.2023"); + getPageHeader().click(); await("Wait for datepicker to being displayed") - .pollDelay(3, TimeUnit.SECONDS) + .pollDelay(2, TimeUnit.SECONDS) + .pollInterval(400, TimeUnit.MILLISECONDS) + .atMost(10, TimeUnit.SECONDS) + .ignoreExceptions() + .untilAsserted(() -> assertTrue(getByXPath(DATEPICKER_TO_LINK).isEnabled())); + getByCSS(DATEPICKER_TO).click(); + await("Wait for datepicker to being displayed") + .pollDelay(2, TimeUnit.SECONDS) + .pollInterval(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(datepickerToLink.isEnabled())); - datepickerToLink.click(); + .untilAsserted(() -> assertTrue(getByXPath(DATEPICKER_TO_LINK).isEnabled())); + getByXPath(DATEPICKER_TO_LINK).click(); } /** @@ -170,47 +102,47 @@ public void addBlock() { */ public void addIssue(String title) { await("Wait for issue button being displayed") - .pollDelay(3, TimeUnit.SECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(buttonAddIssue.isEnabled())); - buttonAddIssue.click(); + .untilAsserted(() -> assertTrue(getByCSS(BUTTON_ADD_ISSUE).isEnabled())); + getByCSS(BUTTON_ADD_ISSUE).click(); await("Wait for issue input being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(inputIssueName.isEnabled())); - inputIssueName.click(); - inputIssueName.sendKeys(title); - headerText.click(); + .untilAsserted(() -> assertTrue(getByCSS(INPUT_ISSUE).isEnabled())); + getByCSS(INPUT_ISSUE).click(); + getByCSS(INPUT_ISSUE).sendKeys(title); + getById(HEADER_TEXT).click(); await("Wait for checkbox being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(checkboxMonday.isDisplayed())); - checkboxMonday.click(); + .untilAsserted(() -> assertTrue(getByCSS(CHECKBOX_MONDAY).isDisplayed())); + getByCSS(CHECKBOX_MONDAY).click(); await("Wait for checkbox being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(checkboxMonday.isDisplayed())); - checkboxTuesday.click(); + .untilAsserted(() -> assertTrue(getByCSS(CHECKBOX_MONDAY).isDisplayed())); + getByCSS(CHECKBOX_TUESDAY).click(); } /** * Add metadata to this issue. Type "Process title" and value "Test" will be inserted. */ public void addMetadataToThis() { - addMetadata("Process title", "Test", buttonAddMetadataToThis); + addMetadata("Process title", "Test", BUTTON_ADD_METADATA_TO_THIS); } /** * Add metadata to this and all following issues. Type "Signatur" and value "1234" will be used. */ public void addMetadataToAll() { - addMetadata("Signatur", "1234", buttonAddMetadataToAll); + addMetadata("Signatur", "1234", BUTTON_ADD_METADATA_TO_ALL); } /** @@ -220,21 +152,22 @@ public void addMetadataToAll() { */ public List getMetadata(String issueName) { await("Wait for calendar entry being displayed") - .pollDelay(3, TimeUnit.SECONDS) + .pollDelay(2, TimeUnit.SECONDS) + .pollInterval(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue( calendarEntry.isDisplayed())); - calendarEntryButton.click(); + .untilAsserted(() -> assertTrue(getByXPath(CALENDAR_ENTRY).isDisplayed())); + getByXPath(CALENDAR_ENTRY_BUTTON).click(); await("Wait for issue '" + issueName + "' being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() .untilAsserted(() -> assertTrue(getIssue(issueName).isDisplayed())); if (Objects.equals(getIssue(issueName).getAttribute("aria-expanded"), "false")) { - Browser.getDriver().findElementByXPath("//div[@aria-expanded='true']").click(); + getByXPath("//div[@aria-expanded='true']").click(); await("Wait for issue '" + issueName + "' being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() .untilAsserted(() -> assertTrue(getIssue(issueName).isDisplayed())); @@ -242,13 +175,13 @@ public List getMetadata(String issueName) { } await("Wait for issue content for '" + issueName + "' being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() .untilAsserted(() -> assertTrue(getIssueContent(issueName).isDisplayed())); List metadataList = readMetadataTypes(issueName); - calendarDialogCloseButton.click(); + getById(CALENDAR_DIALOG_CLOSE_BUTTON).click(); return metadataList; } @@ -257,46 +190,46 @@ public List getMetadata(String issueName) { * Click cancel button and leave calendar. */ public void closePage() { - buttonCancel.click(); + getById(BUTTON_CANCEL).click(); } - private void addMetadata(String type, String value, WebElement addButton) { + private void addMetadata(String type, String value, String addButton) { await("Wait for calendar entry being displayed") - .pollDelay(3, TimeUnit.SECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue( calendarEntry.isDisplayed())); - calendarEntryButton.click(); + .untilAsserted(() -> assertTrue(getByXPath(CALENDAR_ENTRY).isDisplayed())); + getByXPath(CALENDAR_ENTRY_BUTTON).click(); await("Wait for button to add metadata to this issue being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(addButton.isEnabled())); - addButton.click(); + .untilAsserted(() -> assertTrue(getById(addButton).isEnabled())); + getById(addButton).click(); await("Wait for button to add metadata to this issue being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(metadataType.isEnabled())); - metadataType.click(); - metadataTypePanel.findElement(By.xpath("//li[text()='" + type + "']")).click(); + .untilAsserted(() -> assertTrue(getById(METADATA_TYPE).isEnabled())); + getById(METADATA_TYPE).click(); + getById(METADATA_TYPE_PANEL).findElement(By.xpath("//li[text()='" + type + "']")).click(); await("Wait for metadata input being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(metadataValue.isEnabled())); - metadataValue.sendKeys(value); - calendarDialogCloseButton.click(); + .untilAsserted(() -> assertTrue(getById(METADATA_VALUE).isEnabled())); + getById(METADATA_VALUE).sendKeys(value); + getById(CALENDAR_DIALOG_CLOSE_BUTTON).click(); } - + private WebElement getIssue(String name) { - return Browser.getDriver().findElementByXPath( "//div[text()='" + name + " erschien']"); + return getByXPath( "//div[text()='" + name + " erschien']"); } private WebElement getIssueContent(String name) { - return Browser.getDriver().findElementByXPath("//div[text()='" + name + " erschien']/following-sibling::div"); + return getByXPath("//div[text()='" + name + " erschien']/following-sibling::div"); } private List readMetadataTypes(String issueName) { @@ -304,4 +237,16 @@ private List readMetadataTypes(String issueName) { + " erschien']/following-sibling::div[@aria-hidden='false']//div[@title='Art']/label"); return metadataTypeLabels.stream().map(WebElement::getText).collect(Collectors.toList()); } -} + + private WebElement getById(String id) { + return Browser.getDriver().findElementById(id); + } + + private WebElement getByCSS(String cssSelector) { + return Browser.getDriver().findElementByCssSelector(cssSelector); + } + + private WebElement getByXPath(String xpath) { + return Browser.getDriver().findElementByXPath(xpath); + } +} \ No newline at end of file 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 b3fc4580c90..7b402f1bd33 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 @@ -70,6 +70,10 @@ public abstract class Page { @FindBy(id = "search-form:search") private WebElement searchButton; + @SuppressWarnings("unused") + @FindBy(id = "portal-header") + private WebElement pageHeader; + private String URL; Page(String URL) { @@ -212,6 +216,10 @@ protected void clickElement(WebElement element) { .ignoreExceptions().until(() -> isButtonClicked.test(element)); } + public WebElement getPageHeader() { + return pageHeader; + } + /** * Get header text. * 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 e0e1dda4ab7..107dae74c4e 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 @@ -50,8 +50,8 @@ public class ProcessesPage extends Page { private static final String WAIT_FOR_ACTIONS_MENU = "Wait for actions menu to open"; private static final String WAIT_FOR_COLUMN_SORT = "Wait for column sorting"; private static final String MULTI_VOLUME_WORK_PROCESS_TITLE = "Multi volume work test process"; - private static final String WAIT_FOR_SELECTION_MENU = "Wait for process selection menu to open"; + private static final String CALENDER_ACTION_XPATH = "//a[@href='/kitodo/pages/calendarEdit.jsf?id=10']"; @SuppressWarnings("unused") @FindBy(id = PROCESSES_TAB_VIEW) @@ -495,6 +495,7 @@ public void clickProcessesTableHeaderForSorting(int column) { } public void goToCalendar() throws Exception { + WebElement openCalendarLink = Browser.getDriver().findElementByXPath(CALENDER_ACTION_XPATH); if (isNotAt()) { goTo(); }