Skip to content

Commit

Permalink
Add tests for import with additional metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
BartChris committed Apr 2, 2024
1 parent 447d46d commit b4e777f
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

Expand Down Expand Up @@ -108,6 +110,8 @@ public class ImportServiceIT {
private static final int TEMPLATE_ID = 1;
private static final int PROJECT_ID = 1;
private static final int RULESET_ID = 1;
private static final String TITLE = "Title";
private static final String PLACE = "Place";
private static final int EXPECTED_NR_OF_CHILDREN = 23;
private static final String PICA_XML = "picaxml";
private static final String MODS = "mods";
Expand Down Expand Up @@ -169,6 +173,42 @@ public void testImportProcess() throws DAOException, DataException, ImportExcept
}
}

/**
* Tests whether basic catalog metadata import with additional preset metadata to a single process succeeds or not.
*
* @throws DAOException when loading ImportConfiguration or removing test process from test database fails.
* @throws ImportException when importing metadata fails
* @throws IOException when importing metadata fails
*/
@Test
public void testImportProcessWithAdditionalMetadata() throws DAOException, ImportException, IOException {
Map<String, List<String>> presetMetadata = new HashMap<>();
presetMetadata.put(TITLE, List.of("Band 1"));
presetMetadata.put(PLACE, List.of("Hamburg", "Berlin"));
Process processWithAdditionalMetadata = importProcessWithAdditionalMetadata(RECORD_ID,
MockDatabase.getK10PlusImportConfiguration(), presetMetadata);
Workpiece workpiece = ServiceManager.getMetsService()
.loadWorkpiece(processService.getMetadataFileUri(processWithAdditionalMetadata));
HashSet<Metadata> metadata = workpiece.getLogicalStructure().getMetadata();
try {
Assert.assertTrue("Process does not contain correct metadata",
assertMetadataSetContainsMetadata(metadata,TITLE,"Band 1"));
Assert.assertTrue("Process does not contain correct metadata",
assertMetadataSetContainsMetadata(metadata,PLACE,"Hamburg"));
Assert.assertTrue("Process does not contain correct metadata",
assertMetadataSetContainsMetadata(metadata,PLACE,"Berlin"));
} finally {
ProcessTestUtils.removeTestProcess(processWithAdditionalMetadata.getId());
}
}

private boolean assertMetadataSetContainsMetadata(HashSet<Metadata> metadataSet, String metadataKey, String metadataValue) {
return metadataSet.stream()
.filter(metadata -> metadata.getKey().equals(metadataKey))
.anyMatch(metadata -> metadata instanceof MetadataEntry &&
((MetadataEntry) metadata).getValue().equals(metadataValue));
}

@Test
public void shouldCreateUrlWithCustomParameters() throws DAOException, ImportException, IOException {
Process importedProcess = importProcess(CUSTOM_INTERFACE_RECORD_ID, MockDatabase.getCustomTypeImportConfiguration());
Expand Down Expand Up @@ -551,4 +591,19 @@ private Process importProcess(String recordId, ImportConfiguration importConfigu
}
return importedProcess;
}

private Process importProcessWithAdditionalMetadata(String recordId, ImportConfiguration importConfiguration,
Map<String, List<String>> presetMetadata)
throws IOException, ImportException {
File script = new File(ConfigCore.getParameter(ParameterCore.SCRIPT_CREATE_DIR_META));
if (!SystemUtils.IS_OS_WINDOWS) {
ExecutionPermission.setExecutePermission(script);
}
Process importedProcess = importService.importProcess(recordId, 1, 1,
importConfiguration, presetMetadata);
if (!SystemUtils.IS_OS_WINDOWS) {
ExecutionPermission.setNoExecutePermission(script);
}
return importedProcess;
}
}

0 comments on commit b4e777f

Please sign in to comment.