-
Notifications
You must be signed in to change notification settings - Fork 9
Add sample finder test for multi choice field #2903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package org.labkey.test.util.data; | ||
|
|
||
| import org.labkey.remoteapi.query.Filter; | ||
|
|
||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class TestArrayDataUtils | ||
| { | ||
| /** | ||
| * Filtering Map according to filter and then sorting values in alphabetical order. | ||
| * | ||
| * @return filtered Map | ||
| */ | ||
| public static Map<String, String> filterMap(Map<String, List<String>> sourceMap, List<String> searchValues, Filter.Operator filterType) | ||
| { | ||
| return sourceMap.entrySet().stream() | ||
| .filter(entry -> isMatch(entry.getValue(), searchValues, filterType)) | ||
| .collect(Collectors.toMap( | ||
| Map.Entry::getKey, | ||
| e -> e.getValue().stream().sorted().collect(Collectors.joining(", ")), | ||
| (e1, e2) -> e1, | ||
| LinkedHashMap::new | ||
| )); | ||
| } | ||
|
Comment on lines
+17
to
+27
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid losing information. Maybe create a separate method to sort and join the values in a standard format. Something like: |
||
|
|
||
| private static boolean isMatch(List<String> actualValues, List<String> searchValues, Filter.Operator type) | ||
| { | ||
| return switch (type) | ||
| { | ||
| case ARRAY_CONTAINS_ALL -> actualValues.containsAll(searchValues); | ||
| case ARRAY_CONTAINS_ANY -> searchValues.stream().anyMatch(actualValues::contains); | ||
| case ARRAY_CONTAINS_EXACT -> actualValues.size() == searchValues.size() && actualValues.containsAll(searchValues); | ||
| case ARRAY_CONTAINS_NONE -> searchValues.stream().noneMatch(actualValues::contains); | ||
| case ARRAY_CONTAINS_NOT_EXACT -> !(actualValues.size() == searchValues.size() && actualValues.containsAll(searchValues)); | ||
| case ARRAY_ISEMPTY -> actualValues.isEmpty(); | ||
| case ARRAY_ISNOTEMPTY -> !actualValues.isEmpty(); | ||
| default -> true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this default to |
||
| }; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving
TestDataUtils.parseMultiValueTextandResponsiveGrid.ARRAY_OPERATORSinto this class.