Skip to content

Commit

Permalink
Refactor ProcessHelperIT to load test files dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Dec 14, 2023
1 parent 0baae0d commit c1ec3aa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import java.util.List;
import java.util.Locale;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.kitodo.MockDatabase;
Expand All @@ -29,6 +31,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.exceptions.DataException;
import org.kitodo.exceptions.ProcessGenerationException;
import org.kitodo.production.forms.createprocess.ProcessFieldedMetadata;
import org.kitodo.production.process.TitleGenerator;
Expand All @@ -39,8 +42,10 @@ public class ProcessHelperIT {

public static final String DOCTYPE = "Monograph";
private static final String ACQUISITION_STAGE_CREATE = "create";

private static final String TEST_PROCESS_TITLE = "Second process";
private static List<Locale.LanguageRange> priorityList;
private static int processHelperTestProcessId = -1;
private static final String metadataTestfile = "testMetadataForKitodoScript.xml";

/**
* Function to run before test is executed.
Expand All @@ -64,6 +69,19 @@ public static void tearDown() throws Exception {
MockDatabase.cleanDatabase();
}

@Before
public void prepareTestProcess() throws DAOException, DataException, IOException {
processHelperTestProcessId = MockDatabase.insertTestProcess(TEST_PROCESS_TITLE, 1, 1, 1);
ProcessTestUtils.copyTestMetadataFile(processHelperTestProcessId, metadataTestfile);
System.out.println("Test process ID: " + processHelperTestProcessId);
}

@After
public void removeTestProcess() throws DAOException, DataException, IOException {
ProcessTestUtils.removeTestProcess(processHelperTestProcessId);
processHelperTestProcessId = -1;
}

/**
* Tests the ProcessHelper functions of generating the atstsl fields.
*
Expand Down Expand Up @@ -96,13 +114,13 @@ private void testForceRegenerationByParentProcess(TempProcess tempProcess,
RulesetManagementInterface rulesetManagement) throws ProcessGenerationException, DAOException {
ProcessHelper.generateAtstslFields(tempProcess, tempProcess.getProcessMetadata().getProcessDetailsElements(),
null, DOCTYPE, rulesetManagement, ACQUISITION_STAGE_CREATE, priorityList,
ServiceManager.getProcessService().getById(2), true);
ServiceManager.getProcessService().getById(processHelperTestProcessId), true);
assertEquals("Secopr", tempProcess.getAtstsl());
}

private void testForceRegenerationByTempProcessParents(TempProcess tempProcess,
RulesetManagementInterface rulesetManagement) throws DAOException, ProcessGenerationException {
TempProcess tempProcessParent = new TempProcess(ServiceManager.getProcessService().getById(2), new Workpiece());
TempProcess tempProcessParent = new TempProcess(ServiceManager.getProcessService().getById(processHelperTestProcessId), new Workpiece());
tempProcess.getProcessMetadata().setProcessDetails(new ProcessFieldedMetadata() {
{
treeNode.getChildren()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public static void cleanDatabase() throws Exception {
@Before
public void prepareFileCopy() throws IOException, DAOException, DataException {
kitodoScriptTestProcessId = MockDatabase.insertTestProcess(testProcessTitle, projectId, templateId, rulesetId);
System.out.println("Test process inserted: " + kitodoScriptTestProcessId);
ProcessTestUtils.copyTestResources(kitodoScriptTestProcessId, directoryForDerivateGeneration);
ProcessTestUtils.copyTestMetadataFile(kitodoScriptTestProcessId, metadataWithDuplicatesTestFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,8 @@ public void testFindAllIDs() throws DataException {
allIDs = ServiceManager.getProcessService().findAllIDs(0L, 5);
Assert.assertEquals("Wrong amount of id's in index", 5, allIDs.size());
Assert.assertEquals("Duplicate ids in index", allIDs.size(), new HashSet<Integer>(allIDs).size());
Integer maxId = allIDs.stream().mapToInt(Integer::intValue).max().getAsInt();
Integer minId = allIDs.stream().mapToInt(Integer::intValue).min().getAsInt();
int maxId = allIDs.stream().mapToInt(Integer::intValue).max().getAsInt();
int minId = allIDs.stream().mapToInt(Integer::intValue).min().getAsInt();
Assert.assertTrue("Ids should all be smaller than 8", maxId < 8);
Assert.assertTrue("Ids should all be larger than 0", minId > 0);

Expand Down

0 comments on commit c1ec3aa

Please sign in to comment.