From e57acdad6d458958cd445c2ea142752483de5321 Mon Sep 17 00:00:00 2001 From: BartChris Date: Tue, 2 Apr 2024 14:50:30 +0200 Subject: [PATCH] extend MassImportTest to cover multiple values for single key --- .../catalogimport/MassImportTest.java | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/MassImportTest.java b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/MassImportTest.java index 062a884099e..ee5d36503c5 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/MassImportTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/MassImportTest.java @@ -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 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 CSV_LINES = Arrays.asList(CSV_FIRST_LINE, CSV_SECOND_LINE, CSV_THIRD_LINE); + private static final List 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 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. @@ -93,11 +99,34 @@ public void shouldUpdateSeparator() { public void shouldPrepareMetadata() throws ImportException { MassImportService service = ServiceManager.getMassImportService(); List csvRecords = service.parseLines(CSV_LINES, StringConstants.COMMA_DELIMITER); - Map> metadata = service.prepareMetadata(METADATA_KEYS, csvRecords); + Map>> metadata = service.prepareMetadata(METADATA_KEYS, csvRecords); Assert.assertEquals("Wrong number of metadata sets prepared", 3, metadata.size()); - Map metadataSet = metadata.get("123"); + Map> 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 csvRecords_multiple_values = service.parseLines(CSV_LINES_MUTLIPLE_VALUES, + StringConstants.COMMA_DELIMITER); + Map>> metadata_multiple_values = service. + prepareMetadata(METADATA_KEYS_MUTLIPLE_VALUES, csvRecords_multiple_values); + Map> 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)); } }