diff --git a/Kitodo/src/test/java/org/kitodo/MockDatabase.java b/Kitodo/src/test/java/org/kitodo/MockDatabase.java index 5766949a28b..7236ce6b8ff 100644 --- a/Kitodo/src/test/java/org/kitodo/MockDatabase.java +++ b/Kitodo/src/test/java/org/kitodo/MockDatabase.java @@ -744,16 +744,6 @@ public static int insertRuleset(String rulesetTitle, String rulesetFilename, int return ruleset.getId(); } - public static void insertProcessForCalendarHierarchyTests() throws DAOException, DataException { - int rulesetId = MockDatabase.insertRuleset("Newspaper", "newspaper.xml", 1); - Process tenthProcess = new Process(); - tenthProcess.setProject(ServiceManager.getProjectService().getById(1)); - tenthProcess.setTemplate(ServiceManager.getTemplateService().getById(1)); - tenthProcess.setRuleset(ServiceManager.getRulesetService().getById(rulesetId)); - tenthProcess.setTitle("NewspaperOverallProcess"); - ServiceManager.getProcessService().save(tenthProcess); - } - private static void insertTemplates() throws DAOException, DataException { Project project = ServiceManager.getProjectService().getById(1); @@ -1076,8 +1066,8 @@ private static void insertFolders() throws DAOException, DataException { * @throws DAOException when loading test project fails * @throws DataException when saving dummy process fails */ - public static int insertDummyProcess(int dummyProcessId) throws DAOException, DataException { - Project firstProject = ServiceManager.getProjectService().getById(2); + public static int insertDummyProcess(int dummyProcessId, int projectId) throws DAOException, DataException { + Project firstProject = ServiceManager.getProjectService().getById(projectId); Template template = firstProject.getTemplates().get(0); Process dummyProcess = new Process(); dummyProcess.setTitle("Dummy_process_" + dummyProcessId); diff --git a/Kitodo/src/test/java/org/kitodo/production/process/NewspaperProcessesGeneratorIT.java b/Kitodo/src/test/java/org/kitodo/production/process/NewspaperProcessesGeneratorIT.java index 931f6b3d592..38db8f72eab 100644 --- a/Kitodo/src/test/java/org/kitodo/production/process/NewspaperProcessesGeneratorIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/process/NewspaperProcessesGeneratorIT.java @@ -118,7 +118,7 @@ public static void tearDown() throws Exception { */ @Before public void prepareNewspaperProcess() throws DAOException, DataException, IOException { - dummyProcessIds = ProcessTestUtils.insertDummyProcesses(); + dummyProcessIds = ProcessTestUtils.insertDummyProcesses(2); newspaperTestProcessId = MockDatabase.insertTestProcess(NEWSPAPER_TEST_PROCESS_TITLE, 1, 1, rulesetId); ProcessTestUtils.copyTestFiles(newspaperTestProcessId, NEWSPAPER_TEST_METADATA_FILE); } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/file/FileServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/file/FileServiceIT.java index eb6a935ceb2..352671db7b5 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/file/FileServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/file/FileServiceIT.java @@ -139,9 +139,9 @@ public void testMetadataImageComparator() { @Test public void testRenamingOfMultipleProcesses() throws DAOException, DataException, IOException, InterruptedException { - dummyProcessIds = ProcessTestUtils.insertDummyProcesses(); + dummyProcessIds = ProcessTestUtils.insertDummyProcesses(2); mediaRenamingFirstProcessId = MockDatabase.insertTestProcessIntoSecondProject(RENAME_MEDIA_PROCESS_1); - ProcessTestUtils.insertDummyProcesses(); + ProcessTestUtils.insertDummyProcesses(2); mediaRenamingSecondProcessId = MockDatabase.insertTestProcessIntoSecondProject(RENAME_MEDIA_PROCESS_2); ProcessTestUtils.copyTestFiles(mediaRenamingFirstProcessId, TEST_RENAME_MEDIA_FILE); ProcessTestUtils.copyTestFiles(mediaRenamingSecondProcessId, TEST_RENAME_MEDIA_FILE); @@ -163,7 +163,7 @@ public void testRenamingOfMultipleProcesses() throws DAOException, DataException @Test public void testRevertingOriginalFilenamesAfterRenamingError() throws DAOException, DataException, IOException, InterruptedException { - dummyProcessIds = ProcessTestUtils.insertDummyProcesses(); + dummyProcessIds = ProcessTestUtils.insertDummyProcesses(2); revertMediaRenamingProcessId = MockDatabase.insertTestProcessIntoSecondProject(RENAME_MEDIA_REVERT_PROCESS); ProcessTestUtils.copyTestFiles(revertMediaRenamingProcessId, TEST_RENAME_MEDIA_FILE); Path processScansDir = Paths.get(ConfigCore.getKitodoDataDirectory(), revertMediaRenamingProcessId diff --git a/Kitodo/src/test/java/org/kitodo/selenium/CalendarST.java b/Kitodo/src/test/java/org/kitodo/selenium/CalendarST.java index f3372173b75..7dc20e2dc4f 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/CalendarST.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/CalendarST.java @@ -13,29 +13,57 @@ import static org.junit.Assert.assertEquals; +import java.io.IOException; import java.util.Arrays; +import java.util.LinkedList; import java.util.List; 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.beans.User; +import org.kitodo.data.database.exceptions.DAOException; +import org.kitodo.data.elasticsearch.exceptions.CustomResponseException; +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.Pages; import org.kitodo.selenium.testframework.pages.CalendarPage; import org.kitodo.selenium.testframework.pages.ProcessesPage; +import org.kitodo.utils.ProcessTestUtils; public class CalendarST extends BaseTestSelenium { private static ProcessesPage processesPage; private static CalendarPage calendarPage; + private static List dummyProcessIds = new LinkedList<>(); + private static int newspaperTestProcessId = -1; + private static final String NEWSPAPER_TEST_METADATA_FILE = "testmetaNewspaper.xml"; + private static final String NEWSPAPER_TEST_PROCESS_TITLE = "NewspaperOverallProcess"; + private static final int PROJECT_ID = 1; @BeforeClass public static void setup() throws Exception { processesPage = Pages.getProcessesPage(); calendarPage = Pages.getCalendarPage(); + int rulesetId = MockDatabase.insertRuleset("Newspaper", "newspaper.xml", 1); + dummyProcessIds = ProcessTestUtils.insertDummyProcesses(PROJECT_ID); + newspaperTestProcessId = MockDatabase.insertTestProcess(NEWSPAPER_TEST_PROCESS_TITLE, 1, 1, rulesetId); + ProcessTestUtils.copyTestMetadataFile(newspaperTestProcessId, NEWSPAPER_TEST_METADATA_FILE); + Process newsPaperProcess = ServiceManager.getProcessService().getById(newspaperTestProcessId); + // re-save process to index meta.xml including process base type! + ServiceManager.getProcessService().save(newsPaperProcess); + } + + @Before + public void login() throws Exception { + User calendarUser = ServiceManager.getUserService().getByLogin("kowal"); + Pages.getLoginPage().goTo().performLogin(calendarUser); } @After @@ -44,14 +72,15 @@ public void logout() throws Exception { Pages.getTopNavigation().logout(); } + @AfterClass + public static void cleanup() throws CustomResponseException, DAOException, DataException, IOException { + cleanupNewspaperProcess(); + } + @Test public void createProcessFromCalendar() throws Exception { - // add process to access calendar - MockDatabase.insertProcessForCalendarHierarchyTests(); - - login(); processesPage.goTo(); - processesPage.goToCalendar(); + processesPage.goToCalendar(newspaperTestProcessId); calendarPage.addBlock(); calendarPage.addIssue("Morning issue"); calendarPage.addIssue("Evening issue"); @@ -63,8 +92,20 @@ public void createProcessFromCalendar() throws Exception { assertEquals("Metadata for evening issue is incorrect", List.of("Signatur"), eveningIssueMetadata); } - private void login() throws Exception { - User calendarUser = ServiceManager.getUserService().getByLogin("kowal"); - Pages.getLoginPage().goTo().performLogin(calendarUser); + private static void deleteProcessHierarchy(Process process) throws DAOException, DataException, IOException { + for (Process childProcess : process.getChildren()) { + deleteProcessHierarchy(childProcess); + } + ProcessService.deleteProcess(process.getId()); + } + + private static void cleanupNewspaperProcess() throws CustomResponseException, DataException, DAOException, IOException { + for (int processId : dummyProcessIds) { + ServiceManager.getProcessService().removeFromDatabase(processId); + ServiceManager.getProcessService().removeFromIndex(processId, false); + } + if (newspaperTestProcessId > 0) { + deleteProcessHierarchy(ServiceManager.getProcessService().getById(newspaperTestProcessId)); + } } } diff --git a/Kitodo/src/test/java/org/kitodo/selenium/MetadataST.java b/Kitodo/src/test/java/org/kitodo/selenium/MetadataST.java index 468b70540dd..c924c9bb850 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/MetadataST.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/MetadataST.java @@ -64,28 +64,29 @@ public class MetadataST extends BaseTestSelenium { private static List processHierarchyTestProcessIds = new LinkedList<>(); private static final String FIRST_STRUCTURE_TREE_NODE_LABEL = "1 : -"; private static final String SECOND_STRUCTURE_TREE_NODE_LABEL = "2 : -"; + private static final int PROJECT_ID = 2; private static void prepareMediaReferenceProcess() throws DAOException, DataException, IOException { - dummyProcessIds = ProcessTestUtils.insertDummyProcesses(); + dummyProcessIds = ProcessTestUtils.insertDummyProcesses(PROJECT_ID); insertTestProcessForMediaReferencesTest(); copyTestFilesForMediaReferences(); } private static void prepareMetadataLockProcess() throws DAOException, DataException, IOException { - dummyProcessIds = ProcessTestUtils.insertDummyProcesses(); + dummyProcessIds = ProcessTestUtils.insertDummyProcesses(PROJECT_ID); insertTestProcessForMetadataLockTest(); ProcessTestUtils.copyTestMetadataFile(metadataLockProcessId, TEST_METADATA_LOCK_FILE); } private static void prepareProcessHierarchyProcesses() throws DAOException, IOException, DataException { - dummyProcessIds = ProcessTestUtils.insertDummyProcesses(); + dummyProcessIds = ProcessTestUtils.insertDummyProcesses(PROJECT_ID); processHierarchyTestProcessIds = linkProcesses(); copyTestParentProcessMetadataFile(); updateChildProcessIdsInParentProcessMetadataFile(); } private static void prepareMediaRenamingProcess() throws DAOException, DataException, IOException { - dummyProcessIds = ProcessTestUtils.insertDummyProcesses(); + dummyProcessIds = ProcessTestUtils.insertDummyProcesses(PROJECT_ID); insertTestProcessForRenamingMediaFiles(); copyTestFilesForRenamingMediaFiles(); } @@ -291,9 +292,9 @@ private static void insertTestProcessForRenamingMediaFiles() throws DAOException private static List linkProcesses() throws DAOException, DataException { List processIds = new LinkedList<>(); List childProcesses = new LinkedList<>(); - childProcesses.add(ProcessTestUtils.addProcess(FIRST_CHILD_PROCESS_TITLE)); - childProcesses.add(ProcessTestUtils.addProcess(SECOND_CHILD_PROCESS_TITLE)); - Process parentProcess = ProcessTestUtils.addProcess(PARENT_PROCESS_TITLE); + childProcesses.add(ProcessTestUtils.addProcess(FIRST_CHILD_PROCESS_TITLE, PROJECT_ID)); + childProcesses.add(ProcessTestUtils.addProcess(SECOND_CHILD_PROCESS_TITLE, PROJECT_ID)); + Process parentProcess = ProcessTestUtils.addProcess(PARENT_PROCESS_TITLE, PROJECT_ID); parentProcess.getChildren().addAll(childProcesses); ServiceManager.getProcessService().save(parentProcess); parentProcessId = parentProcess.getId(); 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..bbbb1f1aff7 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 @@ -83,9 +83,6 @@ public class ProcessesPage extends Page { private WebElement editMetadataLink; - @FindBy(xpath = "//a[@href='/kitodo/pages/calendarEdit.jsf?id=10']") - private WebElement openCalendarLink; - @SuppressWarnings("unused") @FindBy(id = "search") private WebElement searchForProcessesButton; @@ -494,7 +491,8 @@ public void clickProcessesTableHeaderForSorting(int column) { .until(() -> !columnHeader.getAttribute("aria-sort").equals(previousAriaSort)); } - public void goToCalendar() throws Exception { + public void goToCalendar(int processId) throws Exception { + WebElement openCalendarLink = Browser.getDriver().findElementByXPath("//a[@href='/kitodo/pages/calendarEdit.jsf?id=" + processId + "']"); if (isNotAt()) { goTo(); } diff --git a/Kitodo/src/test/java/org/kitodo/utils/ProcessTestUtils.java b/Kitodo/src/test/java/org/kitodo/utils/ProcessTestUtils.java index 113c65e12a8..8e95929c1d5 100644 --- a/Kitodo/src/test/java/org/kitodo/utils/ProcessTestUtils.java +++ b/Kitodo/src/test/java/org/kitodo/utils/ProcessTestUtils.java @@ -124,8 +124,8 @@ public static void copyTestMetadataFile(int processId, String filename) throws I * @throws DAOException when adding process fails * @throws DataException when adding process fails */ - public static Process addProcess(String processTitle) throws DAOException, DataException { - insertDummyProcesses(); + public static Process addProcess(String processTitle, int projectId) throws DAOException, DataException { + insertDummyProcesses(projectId); return MockDatabase.addProcess(processTitle, TEST_PROJECT_ID, TEST_TEMPLATE_ID); } @@ -136,13 +136,13 @@ public static Process addProcess(String processTitle) throws DAOException, DataE * @throws DAOException when retrieving existing processes from or inserting dummy processes into database fails * @throws DataException when inserting dummy processes into database fails */ - public static List insertDummyProcesses() throws DAOException, DataException { + public static List insertDummyProcesses(Integer projectId) throws DAOException, DataException { List dummyProcessIds = new LinkedList<>(); List processIds = ServiceManager.getProcessService().getAll().stream().map(Process::getId) .collect(Collectors.toList()); int id = Collections.max(processIds) + 1; while (processDirExists(id)) { - dummyProcessIds.add(MockDatabase.insertDummyProcess(id)); + dummyProcessIds.add(MockDatabase.insertDummyProcess(id, projectId)); id++; } return dummyProcessIds;