Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplicate and invalid titles #6326

Merged
merged 10 commits into from
Jan 24, 2025
Prev Previous commit
Next Next commit
Refactor tests to include review comments
  • Loading branch information
BartChris committed Jan 24, 2025
commit e765de3d7711d30e34fcbb8d8ff0c63b75564f61
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.apache.commons.lang3.SystemUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.kitodo.ExecutionPermission;
Expand All @@ -50,6 +51,7 @@ public class CreateProcessFormIT {
private static final ProcessService processService = ServiceManager.getProcessService();

private static final String firstProcess = "First process";
private Process createdProcess;

/**
* Is running before the class runs.
Expand Down Expand Up @@ -77,6 +79,16 @@ public static void cleanDatabase() throws Exception {
MockDatabase.cleanDatabase();
}

@AfterEach
public void cleanUpAfterEach() throws Exception {
if (createdProcess != null && createdProcess.getId() != null) {
processService.remove(createdProcess.getId());
fileService.delete(URI.create(createdProcess.getId().toString()));
}
createdProcess = null;
setScriptPermissions(false);
}

// Helper to create and initialize a CreateProcessForm with common properties
private CreateProcessForm setupCreateProcessForm(String docType) throws Exception {
CreateProcessForm form = new CreateProcessForm();
Expand Down Expand Up @@ -106,13 +118,6 @@ private void setScriptPermissions(boolean enable) throws Exception {
}
}

// Helper to clean up database and file system
private void cleanUpProcess(Process process) throws Exception {
Integer processId = process.getId();
processService.remove(processId);
fileService.delete(URI.create(processId.toString()));
}

@Test
public void shouldCreateNewProcess() throws Exception {
CreateProcessForm underTest = setupCreateProcessForm("Monograph");
Expand All @@ -125,7 +130,7 @@ public void shouldCreateNewProcess() throws Exception {
long after = processService.count();
assertEquals(before + 1, after, "No process was created!");

cleanUpProcess(underTest.getMainProcess());
createdProcess = underTest.getMainProcess();
}

@Test
Expand All @@ -142,7 +147,7 @@ public void shouldCreateNewProcessWithoutWorkflow() throws Exception {
assertTrue(underTest.getMainProcess().getTasks().isEmpty(), "Process should not have tasks");
assertNull(underTest.getMainProcess().getSortHelperStatus(), "Process should not have sortHelperStatus");

cleanUpProcess(underTest.getMainProcess());
createdProcess = underTest.getMainProcess();
}

@Test
Expand Down Expand Up @@ -180,7 +185,7 @@ public void shouldNotAllowDuplicateTitles() throws Exception {
long afterDuplicate = processService.count();
assertEquals(beforeDuplicate, afterDuplicate, "A duplicate process with the same title was created!");

cleanUpProcess(underTest.getMainProcess());
createdProcess = underTest.getMainProcess();
}

}