Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 27 additions & 38 deletions src/test/java/org/nrg/testing/xnat/tests/TestAdvancedSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.IOException;
import java.time.LocalDate;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -261,61 +262,49 @@ private void assertContainsAll(final String fieldName, final Collection<String>
}

private int getSubjectCountFromDataApi() {
return mainInterface()
.jsonQuery()
.get(formatRestUrl("/subjects"))
.then()
.assertThat()
.statusCode(200)
.extract()
.response()
.jsonPath()
.getList(RESULT_SET_DOT_RESULT)
.size();
return distinctRowCount(dataApiRows("/subjects"), r -> r.get("ID"));
}

private int getSessionCountFromDataApi() {
return mainInterface()
.jsonQuery()
.get(formatRestUrl("/experiments?xsiType=xnat:mrSessionData"))
.then()
.assertThat()
.statusCode(200)
.extract()
.response()
.jsonPath()
.getList(RESULT_SET_DOT_RESULT)
.size();
return distinctRowCount(dataApiRows("/experiments?xsiType=xnat:mrSessionData"), r -> r.get("ID"));
}

private int getScanCountFromDataApi() {
List<Map<String, Object>> results = mainInterface()
.jsonQuery()
.get(formatRestUrl("/experiments?columns=xnat:mrSessionData/scans/scan/ID"))
.then()
.assertThat()
.statusCode(200)
.extract()
.response()
.jsonPath()
.getList(RESULT_SET_DOT_RESULT);
return (int) results.stream()
.filter(r -> StringUtils.isNotBlank((String) r.get("xnat:mrsessiondata/scans/scan/id")))
.count();
// A scan is uniquely identified by its session plus its scan ID; count distinct pairs so that a
// session shared into multiple projects (which the listing repeats once per membership) is not
// over-counted relative to the DISTINCT stored search.
return distinctRowCount(
dataApiRows("/experiments?columns=xnat:mrSessionData/scans/scan/ID").stream()
.filter(r -> StringUtils.isNotBlank((String) r.get("xnat:mrsessiondata/scans/scan/id")))
.collect(Collectors.toList()),
r -> r.get("xnat:mrsessiondata/id") + "/" + r.get("xnat:mrsessiondata/scans/scan/id"));
}

private int getQcCountFromDataApi() {
return distinctRowCount(dataApiRows("/experiments?xsiType=xnat:qcManualAssessorData"), r -> r.get("ID"));
}

private List<Map<String, Object>> dataApiRows(final String path) {
return mainInterface()
.jsonQuery()
.get(formatRestUrl("/experiments?xsiType=xnat:qcManualAssessorData"))
.get(formatRestUrl(path))
.then()
.assertThat()
.statusCode(200)
.extract()
.response()
.jsonPath()
.getList(RESULT_SET_DOT_RESULT)
.size();
.getList(RESULT_SET_DOT_RESULT);
}

/**
* The data API listings ({@code /subjects}, {@code /experiments}) return one row per accessible
* project membership, so an entity shared into another project appears multiple times. The stored
* searches these counts are compared against return DISTINCT entities, so count distinct identities
* here to keep the two comparable regardless of sharing.
*/
private static int distinctRowCount(final List<Map<String, Object>> rows, final Function<Map<String, Object>, Object> identity) {
return (int) rows.stream().map(identity).distinct().count();
}

private List<Map<String, Object>> getRestCallResults(final String file) throws IOException {
Expand Down