diff --git a/Kitodo/src/test/java/org/kitodo/MockDatabase.java b/Kitodo/src/test/java/org/kitodo/MockDatabase.java index f3f956a78b5..04ee51dc1eb 100644 --- a/Kitodo/src/test/java/org/kitodo/MockDatabase.java +++ b/Kitodo/src/test/java/org/kitodo/MockDatabase.java @@ -724,23 +724,24 @@ public static void removeProcessesForHierarchyTests() throws DataException { ServiceManager.getProcessService().remove(4); } - - public static void insertProcessForCalendarHierarchyTests() throws DAOException, DataException { - Ruleset fivthRuleset = new Ruleset(); - fivthRuleset.setTitle("Newspaper"); - fivthRuleset.setFile("newspaper.xml"); - fivthRuleset.setOrderMetadataByRuleset(false); - fivthRuleset.setClient(ServiceManager.getClientService().getById(1)); - ServiceManager.getRulesetService().save(fivthRuleset); - - insertPlaceholderProcesses(4, 9); - - Process tenthProcess = new Process(); - tenthProcess.setProject(ServiceManager.getProjectService().getById(1)); - tenthProcess.setTemplate(ServiceManager.getTemplateService().getById(1)); - tenthProcess.setRuleset(ServiceManager.getRulesetService().getById(5)); - tenthProcess.setTitle("NewspaperOverallProcess"); - ServiceManager.getProcessService().save(tenthProcess); + /** + * Insert ruleset. + * @param rulesetTitle ruleset title + * @param rulesetFilename ruleset filename + * @param clientId client id + * @return id of ruleset + * @throws DAOException when retrieving client by ID fails + * @throws DataException when saving ruleset failed + */ + public static int insertRuleset(String rulesetTitle, String rulesetFilename, int clientId) throws DAOException, + DataException { + Ruleset ruleset = new Ruleset(); + ruleset.setTitle(rulesetTitle); + ruleset.setFile(rulesetFilename); + ruleset.setOrderMetadataByRuleset(false); + ruleset.setClient(ServiceManager.getClientService().getById(clientId)); + ServiceManager.getRulesetService().save(ruleset); + return ruleset.getId(); } private static void insertTemplates() throws DAOException, DataException { @@ -1061,12 +1062,13 @@ private static void insertFolders() throws DAOException, DataException { /** * Insert dummy process into database. * @param dummyProcessId id used in dummy process title + * @param projectId id of project to which the dummy process is added * @return database ID of created dummy process * @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); @@ -1127,6 +1129,31 @@ public static int insertTestProcessIntoSecondProject(String processTitle) throws return mediaReferencesProcess.getId(); } + /** + * Insert test process. + * @param processTitle process title of test process + * @param projectId project id of test process + * @param templateId template id of test process + * @param rulesetId ruleset id of test process + * @return id of test process + * @throws DAOException when retrieving project, template or ruleset fails + * @throws DataException when saving test process fails + */ + public static int insertTestProcess(String processTitle, int projectId, int templateId, int rulesetId) + throws DAOException, DataException { + Project project = ServiceManager.getProjectService().getById(projectId); + Template template = ServiceManager.getTemplateService().getById(templateId); + Ruleset ruleset = ServiceManager.getRulesetService().getById(rulesetId); + Process process = new Process(); + process.setTitle(processTitle); + process.setProject(project); + process.setTemplate(template); + process.setRuleset(ruleset); + process.setDocket(template.getDocket()); + ServiceManager.getProcessService().save(process); + return process.getId(); + } + /** * Insert folders into database and add them to second test project. * @throws DAOException when loading project or template fails 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 e539bb91b53..1288b9d567e 100644 --- a/Kitodo/src/test/java/org/kitodo/production/metadata/MetadataEditorIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/metadata/MetadataEditorIT.java @@ -87,7 +87,7 @@ public void shouldAddLink() throws Exception { MetadataEditor.addLink(ServiceManager.getProcessService().getById(4), "0", 7); assertTrue("The link was not added correctly!", - isInternalMetsLink(FileUtils.readLines(metaXmlFile, StandardCharsets.UTF_8).get(37), 7)); + isInternalMetsLink(FileUtils.readLines(metaXmlFile, StandardCharsets.UTF_8).get(36), 7)); FileUtils.writeLines(metaXmlFile, StandardCharsets.UTF_8.toString(), metaXmlContentBefore); FileUtils.deleteQuietly(new File("src/test/resources/metadata/4/meta.xml.1")); 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 0f128dba220..10aee55886d 100644 --- a/Kitodo/src/test/java/org/kitodo/production/process/NewspaperProcessesGeneratorIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/process/NewspaperProcessesGeneratorIT.java @@ -14,22 +14,20 @@ import java.io.File; import java.io.IOException; import java.net.URI; -import java.nio.file.DirectoryStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.time.MonthDay; import java.util.Arrays; +import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.SystemUtils; import org.awaitility.Awaitility; import org.junit.After; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -38,7 +36,6 @@ import org.kitodo.MockDatabase; import org.kitodo.NewspaperCourse; import org.kitodo.SecurityTestUtils; -import org.kitodo.TreeDeleter; import org.kitodo.api.MetadataEntry; import org.kitodo.api.dataformat.LogicalDivision; import org.kitodo.api.dataformat.Workpiece; @@ -48,6 +45,7 @@ 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.dto.ProcessDTO; import org.kitodo.production.helper.tasks.GeneratesNewspaperProcessesThread; @@ -56,6 +54,7 @@ import org.kitodo.production.services.ServiceManager; import org.kitodo.production.services.data.ProcessService; import org.kitodo.production.services.dataformat.MetsService; +import org.kitodo.utils.ProcessTestUtils; public class NewspaperProcessesGeneratorIT { private static final ProcessService processService = ServiceManager.getProcessService(); @@ -63,6 +62,11 @@ public class NewspaperProcessesGeneratorIT { private static final String firstProcess = "First process"; private static final File script = new File(ConfigCore.getParameter(ParameterCore.SCRIPT_CREATE_DIR_META)); + private static List dummyProcessIds = new LinkedList<>(); + private static int newspaperTestProcessId = -1; + private static int rulesetId = -1; + private static final String NEWSPAPER_TEST_METADATA_FILE = "testmetaNewspaper.xml"; + private static final String NEWSPAPER_TEST_PROCESS_TITLE = "NewspaperOverallProcess"; @Rule public ExpectedException expectedEx = ExpectedException.none(); @@ -73,16 +77,17 @@ public class NewspaperProcessesGeneratorIT { * @throws Exception * if that does not work */ - @Before - public void setUp() throws Exception { + @BeforeClass + public static void setUp() throws Exception { if (!SystemUtils.IS_OS_WINDOWS) { ExecutionPermission.setExecutePermission(script); } FileLoader.createConfigProjectsFileForCalendarHierarchyTests(); MockDatabase.startNode(); MockDatabase.insertProcessesFull(); - MockDatabase.insertProcessForCalendarHierarchyTests(); + MockDatabase.insertFoldersForSecondProject(); MockDatabase.setUpAwaitility(); + rulesetId = MockDatabase.insertRuleset("Newspaper", "newspaper.xml", 1); User userOne = ServiceManager.getUserService().getById(1); SecurityTestUtils.addUserDataToSecurityContext(userOne, 1); Awaitility.await().until(() -> { @@ -94,8 +99,8 @@ public void setUp() throws Exception { /** * The test environment is cleaned up and the database is closed. */ - @After - public void tearDown() throws Exception { + @AfterClass + public static void tearDown() throws Exception { MockDatabase.stopNode(); MockDatabase.cleanDatabase(); KitodoConfigFile.PROJECT_CONFIGURATION.getFile().delete(); @@ -105,37 +110,74 @@ public void tearDown() throws Exception { } } + /** + * Create dummy processes and newspaper test process and copy corresponding meta.xml file. + * @throws DAOException when inserting test or dummy processes fails + * @throws DataException when inserting test or dummy processes fails + * @throws IOException when copying test metadata file fails + */ + @Before + public void prepareNewspaperProcess() throws DAOException, DataException, IOException { + dummyProcessIds = ProcessTestUtils.insertDummyProcesses(2); + newspaperTestProcessId = MockDatabase.insertTestProcess(NEWSPAPER_TEST_PROCESS_TITLE, 1, 1, rulesetId); + ProcessTestUtils.copyTestFiles(newspaperTestProcessId, NEWSPAPER_TEST_METADATA_FILE); + } + + /** + * Remove dummy and newspaper test processes. + * @throws DAOException when removing dummy processes from database fails + * @throws CustomResponseException when removing dummy processes from index fails + * @throws DataException when deleting newspaper test processes fails + * @throws IOException when deleting metadata test files fails + */ + @After + public void cleanupNewspaperProcess() throws DAOException, CustomResponseException, DataException, IOException { + for (int processId : dummyProcessIds) { + ServiceManager.getProcessService().removeFromDatabase(processId); + ServiceManager.getProcessService().removeFromIndex(processId, false); + } + if (newspaperTestProcessId > 0) { + deleteProcessHierarchy(ServiceManager.getProcessService().getById(newspaperTestProcessId)); + } + } + + private static void deleteProcessHierarchy(Process process) throws DAOException, DataException, IOException { + for (Process childProcess : process.getChildren()) { + deleteProcessHierarchy(childProcess); + } + ProcessService.deleteProcess(process.getId()); + } + /** * Perform the test. A long-running task is simulated: Progress and number * of steps are queried and the next step is performed. */ @Test public void shouldGenerateNewspaperProcesses() throws Exception { - // create backup of meta data file as this file is modified inside test - File metaFile = new File("src/test/resources/metadata/10/meta.xml"); - File backupFile = new File("src/test/resources/metadata/10/meta.xml.1"); - FileUtils.copyFile(metaFile, backupFile); - - Process completeEdition = ServiceManager.getProcessService().getById(10); + Process completeEdition = ServiceManager.getProcessService().getById(newspaperTestProcessId); Course course = NewspaperCourse.getCourse(); course.splitInto(Granularity.DAYS); NewspaperProcessesGenerator underTest = new NewspaperProcessesGenerator(completeEdition, course); while (underTest.getProgress() < underTest.getNumberOfSteps()) { underTest.nextStep(); } + int maxId = getChildProcessWithLargestId(completeEdition, 0); Assert.assertEquals("The newspaper processes generator has not been completed!", underTest.getNumberOfSteps(), underTest.getProgress()); Assert.assertEquals("Process title missing in newspaper's meta.xml", "NewspaperOverallProcess", - readProcessTitleFromMetadata(10, false)); + readProcessTitleFromMetadata(newspaperTestProcessId, false)); Assert.assertEquals("Process title missing in year's meta.xml", "NewspaperOverallProcess_1703", - readProcessTitleFromMetadata(11, false)); + readProcessTitleFromMetadata(newspaperTestProcessId + 1, false)); Assert.assertEquals("Process title missing in issue's meta.xml", "NewspaperOverallProcess_17050127", - readProcessTitleFromMetadata(28, true)); + readProcessTitleFromMetadata(maxId, true)); + } - // restore backuped meta data file - FileUtils.deleteQuietly(metaFile); - FileUtils.moveFile(backupFile, metaFile); - cleanUp(); + private int getChildProcessWithLargestId(Process process, int maxId) { + maxId = Math.max(maxId, process.getId()); + for (Process childProcess : process.getChildren()) { + maxId = getChildProcessWithLargestId(childProcess, maxId); + } + return maxId; } /* @@ -162,13 +204,7 @@ private String readProcessTitleFromMetadata(int processId, boolean issue) throws */ @Test public void shouldGenerateSeasonProcesses() throws Exception { - // create backup of meta data file as this file is modified inside test - File metaFile = new File("src/test/resources/metadata/10/meta.xml"); - File backupFile = new File("src/test/resources/metadata/10/meta.xml.1"); - FileUtils.copyFile(metaFile, backupFile); - - // Set base type in metadata/10/meta.xml to "Season" - Process seasonProcess = ServiceManager.getProcessService().getById(10); + Process seasonProcess = ServiceManager.getProcessService().getById(newspaperTestProcessId); URI seasonUri = processService.getMetadataFileUri(seasonProcess); Workpiece seasonMets = metsService.loadWorkpiece(seasonUri); seasonMets.getLogicalStructure().setType("Season"); @@ -197,32 +233,26 @@ public void shouldGenerateSeasonProcesses() throws Exception { */ String twoYears = workpiece.getLogicalStructure().getOrderlabel(); List years = Arrays.asList(twoYears.split("/", 2)); - Assert.assertTrue("Bad season-year in " + seasonProcess + ": " + twoYears, - Integer.parseInt(years.get(0)) + 1 == Integer.parseInt(years.get(1))); + Assert.assertEquals("Bad season-year in " + seasonProcess + ": " + twoYears, + Integer.parseInt(years.get(0)) + 1, Integer.parseInt(years.get(1))); // more tests monthChecksOfShouldGenerateSeasonProcesses(seasonProcess, workpiece, twoYears, years); dayChecksOfShouldGenerateSeasonProcesses(seasonProcess, workpiece); } } - - // restore backed-up meta data file - FileUtils.deleteQuietly(metaFile); - FileUtils.moveFile(backupFile, metaFile); - cleanUp(); } @Test public void shouldNotGenerateDuplicateProcessTitle() throws DAOException, DataException { - Process completeEdition = ServiceManager.getProcessService().getById(10); + Process completeEdition = ServiceManager.getProcessService().getById(newspaperTestProcessId); Course course = NewspaperCourse.getDuplicatedCourse(); course.splitInto(Granularity.DAYS); GeneratesNewspaperProcessesThread generatesNewspaperProcessesThread = new GeneratesNewspaperProcessesThread(completeEdition, course); - generatesNewspaperProcessesThread.run(); + generatesNewspaperProcessesThread.start(); ProcessDTO byId = ServiceManager.getProcessService().findById(11); Assert.assertNull("Process should not have been created", byId.getTitle()); - } private void dayChecksOfShouldGenerateSeasonProcesses(Process seasonProcess, Workpiece seasonYearWorkpiece) { @@ -291,19 +321,4 @@ private void monthChecksOfShouldGenerateSeasonProcesses(Process seasonProcess, W previousMonthValue = monthValue; } } - - /** - * To clean up after the end of the test. All metadata directories >10 will - * be deleted. - */ - private static void cleanUp() throws IOException { - Path dirProcesses = Paths.get(ConfigCore.getParameter(ParameterCore.DIR_PROCESSES)); - DirectoryStream directoryStream = Files.newDirectoryStream(dirProcesses); - for (Path path : directoryStream) { - String fileName = path.getFileName().toString(); - if (fileName.matches("\\d+") && Integer.valueOf(fileName) > 10) { - TreeDeleter.deltree(path); - } - } - } } diff --git a/Kitodo/src/test/java/org/kitodo/production/services/command/KitodoScriptServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/command/KitodoScriptServiceIT.java index 049f5bc1930..fd3d0d0902b 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/command/KitodoScriptServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/command/KitodoScriptServiceIT.java @@ -366,8 +366,7 @@ public void shouldCopyMultipleDataToChildren() throws Exception { backupHierarchieFiles(); String metadataKey = "DigitalCollection"; HashMap metadataSearchMap = new HashMap<>(); - metadataSearchMap.put(metadataKey,"Kollektion1"); - metadataSearchMap.put(metadataKey,"Kollektion2"); + metadataSearchMap.put(metadataKey, "Kollektion2"); final List processByMetadata = ServiceManager.getProcessService().findByMetadata(metadataSearchMap); Assert.assertEquals("should not contain metadata beforehand", 1, processByMetadata.size() ); 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..0fb46689c37 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 @@ -57,6 +57,7 @@ public class FileServiceIT { private static final String RENAME_MEDIA_PROCESS_1 = "renameMediaProcess1"; private static final String RENAME_MEDIA_PROCESS_2 = "renameMediaProcess2"; private static final String RENAME_MEDIA_REVERT_PROCESS = "revertMediaRenamingProcess"; + private static final int PROJECT_ID = 2; private static List dummyProcessIds = new LinkedList<>(); private static int mediaRenamingFirstProcessId = -1; private static int mediaRenamingSecondProcessId = -1; @@ -139,9 +140,9 @@ public void testMetadataImageComparator() { @Test public void testRenamingOfMultipleProcesses() throws DAOException, DataException, IOException, InterruptedException { - dummyProcessIds = ProcessTestUtils.insertDummyProcesses(); + dummyProcessIds = ProcessTestUtils.insertDummyProcesses(PROJECT_ID); mediaRenamingFirstProcessId = MockDatabase.insertTestProcessIntoSecondProject(RENAME_MEDIA_PROCESS_1); - ProcessTestUtils.insertDummyProcesses(); + ProcessTestUtils.insertDummyProcesses(PROJECT_ID); mediaRenamingSecondProcessId = MockDatabase.insertTestProcessIntoSecondProject(RENAME_MEDIA_PROCESS_2); ProcessTestUtils.copyTestFiles(mediaRenamingFirstProcessId, TEST_RENAME_MEDIA_FILE); ProcessTestUtils.copyTestFiles(mediaRenamingSecondProcessId, TEST_RENAME_MEDIA_FILE); @@ -163,7 +164,7 @@ public void testRenamingOfMultipleProcesses() throws DAOException, DataException @Test public void testRevertingOriginalFilenamesAfterRenamingError() throws DAOException, DataException, IOException, InterruptedException { - dummyProcessIds = ProcessTestUtils.insertDummyProcesses(); + dummyProcessIds = ProcessTestUtils.insertDummyProcesses(PROJECT_ID); 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/production/services/workflow/WorkflowControllerServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/workflow/WorkflowControllerServiceIT.java index 18839d9a4d0..2cf149e687b 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 @@ -43,8 +43,10 @@ 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.production.services.data.TaskService; import org.kitodo.production.services.file.FileService; +import org.kitodo.utils.ProcessTestUtils; public class WorkflowControllerServiceIT { @@ -58,11 +60,14 @@ public class WorkflowControllerServiceIT { private static final FileService fileService = ServiceManager.getFileService(); private static final TaskService taskService = ServiceManager.getTaskService(); private static final WorkflowControllerService workflowService = new WorkflowControllerService(); + private static int workflowTestProcessId = -1; @Before public void prepareDatabase() throws Exception { MockDatabase.startNode(); MockDatabase.insertProcessesForWorkflowFull(); + workflowTestProcessId = Math.toIntExact(ServiceManager.getProcessService().count()); + ProcessTestUtils.copyTestFiles(workflowTestProcessId, "testmetaNewspaper.xml"); SecurityTestUtils.addUserDataToSecurityContext(ServiceManager.getUserService().getById(1), 1); usersDirectory.mkdir(); @@ -77,6 +82,7 @@ public void prepareDatabase() throws Exception { @After public void cleanDatabase() throws Exception { + ProcessService.deleteProcess(workflowTestProcessId); MockDatabase.stopNode(); MockDatabase.cleanDatabase(); SecurityTestUtils.cleanSecurityContext(); @@ -300,7 +306,7 @@ public void shouldCloseAndAssignNextForProcessWithParallelTasks() throws Excepti @Test public void shouldCloseForProcessWithScriptParallelTasks() throws Exception { - assumeTrue(!SystemUtils.IS_OS_WINDOWS && !SystemUtils.IS_OS_MAC); + assumeTrue(!SystemUtils.IS_OS_WINDOWS); // if you want to execute test on windows change sh to bat in // gateway-test5.bpmn20.xml diff --git a/Kitodo/src/test/java/org/kitodo/selenium/CalendarST.java b/Kitodo/src/test/java/org/kitodo/selenium/CalendarST.java index f3372173b75..3463aad6da1 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 content 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..f281ee37e78 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=%s']"; @SuppressWarnings("unused") @FindBy(id = PROCESSES_TAB_VIEW) @@ -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,9 @@ public void clickProcessesTableHeaderForSorting(int column) { .until(() -> !columnHeader.getAttribute("aria-sort").equals(previousAriaSort)); } - public void goToCalendar() throws Exception { + public void goToCalendar(int processId) throws Exception { + String xpath = String.format(CALENDER_ACTION_XPATH, processId); + WebElement openCalendarLink = Browser.getDriver().findElementByXPath(xpath); 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..26c6d39615e 100644 --- a/Kitodo/src/test/java/org/kitodo/utils/ProcessTestUtils.java +++ b/Kitodo/src/test/java/org/kitodo/utils/ProcessTestUtils.java @@ -120,29 +120,31 @@ public static void copyTestMetadataFile(int processId, String filename) throws I * Add process with given title "processTitle" and to project with configured ID 'TEST_PROJECT_ID' and template * 'TEST_TEMPLATE_ID' to mock database. * @param processTitle title of process to add + * @param projectId id of project to which dummy processes are inserted before new process is added * @return created process * @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); } /** * Insert dummy processes into database to avoid conflicts with existing test processes and process directories with * static identifiers. + * @param projectId id of project into which dummy processes are inserted * @return list of dummy process IDs * @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; diff --git a/Kitodo/src/test/resources/metadata/4/meta.xml b/Kitodo/src/test/resources/metadata/4/meta.xml index 0240d7a40f5..adeb07d1a41 100644 --- a/Kitodo/src/test/resources/metadata/4/meta.xml +++ b/Kitodo/src/test/resources/metadata/4/meta.xml @@ -21,7 +21,6 @@ Second process Proc - Kollektion1 Kollektion2 Second diff --git a/Kitodo/src/test/resources/metadata/10/meta.xml b/Kitodo/src/test/resources/metadata/testmetaNewspaper.xml similarity index 100% rename from Kitodo/src/test/resources/metadata/10/meta.xml rename to Kitodo/src/test/resources/metadata/testmetaNewspaper.xml