Skip to content

Commit

Permalink
Refactor tests to include review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
BartChris committed Dec 10, 2024
1 parent 667867d commit 5d6a7d4
Showing 1 changed file with 15 additions and 10 deletions.
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();
}

}

0 comments on commit 5d6a7d4

Please sign in to comment.