Skip to content

Commit

Permalink
extend MassImportTest to cover multiple values for single key
Browse files Browse the repository at this point in the history
  • Loading branch information
BartChris committed Apr 2, 2024
1 parent cd73b9c commit e57acda
Showing 1 changed file with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ public class MassImportTest {
private static final String ID = "ID";
private static final String TITLE = "Title";
private static final String PLACE = "Place";
private static final String SECOND_PLACE = "Place";
private static final List<String> METADATA_KEYS = Arrays.asList(ID, TITLE, PLACE);
private static final String CSV_FIRST_LINE = "123, Band 1, Hamburg";
private static final String CSV_SECOND_LINE = "456, Band 2, Dresden";
private static final String CSV_THIRD_LINE = "789, Band 3, Berlin";
private static final List<String> CSV_LINES = Arrays.asList(CSV_FIRST_LINE, CSV_SECOND_LINE, CSV_THIRD_LINE);
private static final List<String> METADATA_KEYS_MUTLIPLE_VALUES = Arrays.asList(ID, TITLE, PLACE, SECOND_PLACE);
private static final String CSV_FIRST_LINE_MUTLIPLE_VALUES = "321, Band 1, Hamburg, Berlin";
private static final String CSV_SECOND_LINE_MUTLIPLE_VALUES = "654, Band 2, Dresden, Hannover";
private static final List<String> CSV_LINES_MUTLIPLE_VALUES = Arrays.asList(CSV_FIRST_LINE_MUTLIPLE_VALUES,
CSV_SECOND_LINE_MUTLIPLE_VALUES);

/**
* Tests parsing CSV lines into CSV records with multiple cells.
Expand Down Expand Up @@ -93,11 +99,34 @@ public void shouldUpdateSeparator() {
public void shouldPrepareMetadata() throws ImportException {
MassImportService service = ServiceManager.getMassImportService();
List<CsvRecord> csvRecords = service.parseLines(CSV_LINES, StringConstants.COMMA_DELIMITER);
Map<String, Map<String, String>> metadata = service.prepareMetadata(METADATA_KEYS, csvRecords);
Map<String, Map<String, List<String>>> metadata = service.prepareMetadata(METADATA_KEYS, csvRecords);
Assert.assertEquals("Wrong number of metadata sets prepared", 3, metadata.size());
Map<String, String> metadataSet = metadata.get("123");
Map<String, List<String>> metadataSet = metadata.get("123");
Assert.assertNotNull("Metadata for record with ID 123 is null", metadataSet);
Assert.assertTrue("Metadata for record with ID 123 does not contain title metadata", metadataSet.containsKey(TITLE));
Assert.assertEquals("Metadata for record with ID 123 contains wrong title", "Band 1", metadataSet.get(TITLE));
Assert.assertEquals("Metadata for record with ID 123 contains wrong title", 2,
metadataSet.size());
Assert.assertEquals("Metadata for record with ID 123 contains wrong title", "Band 1",
metadataSet.get(TITLE).get(0));
Assert.assertEquals("Metadata for record with ID 123 has wrong size of place list",
1, metadataSet.get(PLACE).size());
Assert.assertEquals("Metadata for record with ID 123 contains wrong place", "Hamburg",
metadataSet.get(PLACE).get(0));

List<CsvRecord> csvRecords_multiple_values = service.parseLines(CSV_LINES_MUTLIPLE_VALUES,
StringConstants.COMMA_DELIMITER);
Map<String, Map<String, List<String>>> metadata_multiple_values = service.
prepareMetadata(METADATA_KEYS_MUTLIPLE_VALUES, csvRecords_multiple_values);
Map<String, List<String>> metadataSet_multiple_values = metadata_multiple_values.get("321");
Assert.assertNotNull("Metadata for record with ID 321 is null", metadataSet_multiple_values);
Assert.assertEquals("Metadata for record with ID 321 contains wrong title", 2,
metadataSet_multiple_values.size());
Assert.assertTrue("Metadata for record with ID 321 does not contain place metadata",
metadataSet_multiple_values.containsKey(PLACE));
Assert.assertEquals("Metadata for record with ID 123 has wrong size of place list", 2,
metadataSet_multiple_values.get(PLACE).size());
Assert.assertEquals("Metadata for record with ID 321 has wrong size of place list", "Hamburg",
metadataSet_multiple_values.get(PLACE).get(0));
Assert.assertEquals("Metadata for record with ID 321 contains wrong place", "Berlin",
metadataSet_multiple_values.get(PLACE).get(1));
}
}

0 comments on commit e57acda

Please sign in to comment.