Skip to content

Commit

Permalink
refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BartChris committed Dec 6, 2024
1 parent 75d4aa0 commit 849dadc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ static boolean setChildCount(Process parent, RulesetManagementInterface ruleset,
/**
* Create process hierarchy.
*/
private void createProcessHierarchy()
public void createProcessHierarchy()
throws DataException, ProcessGenerationException, IOException {
// discard all processes in hierarchy except the first if parent process in
// title record link tab is selected!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
package org.kitodo.production.forms.copyprocess;

import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

import java.io.File;
import java.net.URI;
Expand All @@ -33,6 +31,7 @@
import org.kitodo.config.enums.ParameterCore;
import org.kitodo.data.database.beans.Process;
import org.kitodo.data.database.beans.User;
import org.kitodo.exceptions.ProcessGenerationException;
import org.kitodo.production.forms.createprocess.CreateProcessForm;
import org.kitodo.production.helper.TempProcess;
import org.kitodo.production.services.ServiceManager;
Expand Down Expand Up @@ -76,7 +75,7 @@ public static void cleanDatabase() throws Exception {
}

// Helper to create and initialize a CreateProcessForm with common properties
private CreateProcessForm setupCreateProcessForm(String docType, String title) throws Exception {
private CreateProcessForm setupCreateProcessForm(String docType) throws Exception {
CreateProcessForm form = new CreateProcessForm();
form.getProcessDataTab().setDocType(docType);

Expand All @@ -87,7 +86,6 @@ private CreateProcessForm setupCreateProcessForm(String docType, String title) t

form.getMainProcess().setProject(ServiceManager.getProjectService().getById(1));
form.getMainProcess().setRuleset(ServiceManager.getRulesetService().getById(1));
form.getMainProcess().setTitle(title);

form.updateRulesetAndDocType(tempProcess.getProcess().getRuleset());
return form;
Expand All @@ -114,8 +112,8 @@ private void cleanUpProcess(Process process) throws Exception {

@Test
public void shouldCreateNewProcess() throws Exception {
CreateProcessForm underTest = setupCreateProcessForm("Monograph", "title");

CreateProcessForm underTest = setupCreateProcessForm("Monograph");
underTest.getMainProcess().setTitle("title");
setScriptPermissions(true);
long before = processService.count();
underTest.createNewProcess();
Expand All @@ -129,8 +127,8 @@ public void shouldCreateNewProcess() throws Exception {

@Test
public void shouldCreateNewProcessWithoutWorkflow() throws Exception {
CreateProcessForm underTest = setupCreateProcessForm("MultiVolumeWork", "title");

CreateProcessForm underTest = setupCreateProcessForm("MultiVolumeWork");
underTest.getMainProcess().setTitle("title");
setScriptPermissions(true);
long before = processService.count();
underTest.createNewProcess();
Expand All @@ -145,36 +143,38 @@ public void shouldCreateNewProcessWithoutWorkflow() throws Exception {
}

@Test
public void shouldNotCreateNewProcessWithInvalidTitle() throws Exception {
CreateProcessForm underTest = setupCreateProcessForm("Monograph", "title with whitespaces");

public void shouldThrowExceptionForInvalidTitle() throws Exception {
// Attempt to create a process with an invalid title
CreateProcessForm underTest = setupCreateProcessForm("Monograph");
underTest.getMainProcess().setTitle("title with whitespaces");
long before = processService.count();
underTest.createNewProcess();
assertThrows(ProcessGenerationException.class, underTest::createProcessHierarchy,
"Expected a ProcessGenerationException to be thrown for an invalid title, but it was not.");
long after = processService.count();

// Ensure no process was created
assertEquals(before, after, "A process with an invalid title was created!");
}

@Test
public void shouldNotAllowDuplicateTitles() throws Exception {
// First process creation
CreateProcessForm underTest = setupCreateProcessForm("Monograph", "title");
CreateProcessForm underTest = setupCreateProcessForm("Monograph");
underTest.getMainProcess().setTitle("title");

setScriptPermissions(true);
long before = processService.count();
underTest.createNewProcess();
underTest.createProcessHierarchy();
setScriptPermissions(false);

long after = processService.count();
assertEquals(before + 1, after, "First process creation failed. No process was created!");

// Second process creation with duplicate title
CreateProcessForm underTestTwo = setupCreateProcessForm("Monograph", "title");

CreateProcessForm underTestTwo = setupCreateProcessForm("Monograph");
underTestTwo.getMainProcess().setTitle("title");
long beforeDuplicate = processService.count();
underTestTwo.createNewProcess();
assertThrows(ProcessGenerationException.class, underTestTwo::createProcessHierarchy,
"Expected a ProcessGenerationException to be thrown for duplicate title, but it was not.");
long afterDuplicate = processService.count();

assertEquals(beforeDuplicate, afterDuplicate, "A duplicate process with the same title was created!");

cleanUpProcess(underTest.getMainProcess());
Expand Down

0 comments on commit 849dadc

Please sign in to comment.