Skip to content

Commit

Permalink
Removed redundant helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
janvanmansum committed Dec 9, 2024
1 parent 0efb264 commit 1ece89b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,32 +145,8 @@ protected void assertControlledMultiValueFieldContainsValues(List<MetadataField>
.containsExactly(List.of(values));
}

protected void assertCompoundMultiValueFieldContainsValues(List<MetadataField> fields, String typeName, List<Map<String, String>> expectedValues) {
var filteredFields = fields.stream()
.filter(f -> typeName.equals(f.getTypeName()))
.map(f -> (CompoundMultiValueField) f)
.toList();

assertThat(filteredFields).as("Field not found: " + typeName).isNotEmpty();
assertThat(filteredFields).as("Field appearing more than once: " + typeName).hasSize(1);

var actualValues = filteredFields.get(0).getValue();
assertThat(actualValues).as("Different number of actual and expected values: " + actualValues.size() + " vs " + expectedValues.size()).hasSize(expectedValues.size());

List<Map<String, String>> actualValuesList = new ArrayList<>();
for (var actualValue : actualValues) {
var actualValueMap = actualValue.entrySet().stream()
.map(e -> Map.entry(e.getKey(), e.getValue().getValue()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
actualValuesList.add(actualValueMap);
}

assertThat(actualValuesList).containsExactlyInAnyOrderElementsOf(expectedValues);

}

@SafeVarargs
protected final void assertCompoundMultiValueFieldContainsValues2(List<MetadataField> fields, String typeName, Map<String, String>... expectedValues) {
protected final void assertCompoundMultiValueFieldContainsValues(List<MetadataField> fields, String typeName, Map<String, String>... expectedValues) {
var filteredFields = fields.stream()
.filter(f -> typeName.equals(f.getTypeName()))
.map(f -> (CompoundMultiValueField) f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.util.List;
import java.util.Map;
import java.util.Optional;

Expand Down Expand Up @@ -54,16 +53,18 @@ public void run_converts_dans_sword_all_mappings_example_to_dataverse_ingest_dep
// Find the metadata field with property typeName = "title"
assertPrimitiveSinglevalueFieldContainsValue(citationBlockFields, "title", "A bag containing examples for each mapping rule");
assertPrimitiveMultiValueFieldContainsValues(citationBlockFields, "alternativeTitle", "DCTERMS title 1");
assertCompoundMultiValueFieldContainsValues2(citationBlockFields, "datasetContact", Map.of(
assertCompoundMultiValueFieldContainsValues(citationBlockFields, "datasetContact", Map.of(
"datasetContactName", "John Doe",
"datasetContactEmail", "[email protected]"
));
assertCompoundMultiValueFieldContainsValues2(citationBlockFields, "otherId",
assertCompoundMultiValueFieldContainsValues(citationBlockFields, "otherId",
Map.of("otherIdAgency", "", "otherIdValue", "DCTERMS_ID001"),
Map.of("otherIdAgency", "", "otherIdValue", "DC_ID002"),
Map.of("otherIdAgency", "", "otherIdValue", "DCTERMS_ID003"),
Map.of("otherIdAgency", "TESTPREFIX", "otherIdValue", "1234"));



// TODO: CHECK ALL THE OTHER FIELDS

}

Expand Down

0 comments on commit 1ece89b

Please sign in to comment.