forked from Luke-Sikina/picsure-search-refinement
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ticket not made yet] - Fix concept query when search eliminates results
- Loading branch information
Luke Sikina
committed
Aug 20, 2024
1 parent
9d10bfa
commit 6c0a726
Showing
4 changed files
with
135 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...est/java/edu/harvard/dbmi/avillach/dictionary/filter/ConceptFilterQueryGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.filter; | ||
|
||
import edu.harvard.dbmi.avillach.dictionary.concept.ConceptFilterQueryGenerator; | ||
import edu.harvard.dbmi.avillach.dictionary.facet.Facet; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.testcontainers.utility.MountableFile; | ||
|
||
import java.util.List; | ||
|
||
@Testcontainers | ||
@SpringBootTest | ||
class ConceptFilterQueryGeneratorTest { | ||
|
||
@Container | ||
static final PostgreSQLContainer<?> databaseContainer = | ||
new PostgreSQLContainer<>("postgres:16") | ||
.withReuse(true) | ||
.withCopyFileToContainer( | ||
MountableFile.forClasspathResource("seed.sql"), "/docker-entrypoint-initdb.d/seed.sql" | ||
); | ||
|
||
@DynamicPropertySource | ||
static void mySQLProperties(DynamicPropertyRegistry registry) { | ||
registry.add("spring.datasource.url", databaseContainer::getJdbcUrl); | ||
registry.add("spring.datasource.username", databaseContainer::getUsername); | ||
registry.add("spring.datasource.password", databaseContainer::getPassword); | ||
registry.add("spring.datasource.db", databaseContainer::getDatabaseName); | ||
} | ||
|
||
@Autowired | ||
ConceptFilterQueryGenerator subject; | ||
|
||
@Autowired | ||
NamedParameterJdbcTemplate template; | ||
|
||
@Test | ||
void shouldGenerateForFacetAndSearchNoMatch() { | ||
Filter f = new Filter(List.of(new Facet("phs000007", "FHS", "", null, null, "study_ids_dataset_ids", null)), "smoke"); | ||
QueryParamPair pair = subject.generateFilterQuery(f, Pageable.unpaged()); | ||
|
||
List<Integer> actual = template.queryForList(pair.query(), pair.params(), Integer.class); | ||
List<Integer> expected = List.of(); | ||
|
||
Assertions.assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
void shouldGenerateForFHSFacet() { | ||
Filter f = new Filter(List.of(new Facet("phs000007", "FHS", "", null, null, "study_ids_dataset_ids", null)), ""); | ||
QueryParamPair pair = subject.generateFilterQuery(f, Pageable.unpaged()); | ||
|
||
List<Integer> actual = template.queryForList(pair.query(), pair.params(), Integer.class); | ||
List<Integer> expected = List.of(229, 232, 235); | ||
|
||
Assertions.assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
void shouldGenerateForFacetAndSearchMatch() { | ||
Filter f = new Filter(List.of(new Facet("phs002715", "NSRR", "", null, null, "study_ids_dataset_ids", null)), "smoke"); | ||
QueryParamPair pair = subject.generateFilterQuery(f, Pageable.unpaged()); | ||
|
||
List<Integer> actual = template.queryForList(pair.query(), pair.params(), Integer.class); | ||
List<Integer> expected = List.of(249); | ||
|
||
Assertions.assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
void shouldGenerateForNSRRFacet() { | ||
Filter f = new Filter(List.of(new Facet("phs002715", "NSRR", "", null, null, "study_ids_dataset_ids", null)), ""); | ||
QueryParamPair pair = subject.generateFilterQuery(f, Pageable.unpaged()); | ||
|
||
List<Integer> actual = template.queryForList(pair.query(), pair.params(), Integer.class); | ||
List<Integer> expected = List.of(248, 249); | ||
|
||
Assertions.assertEquals(expected, actual); | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
src/test/java/edu/harvard/dbmi/avillach/dictionary/filter/FilterQueryGeneratorTest.java
This file was deleted.
Oops, something went wrong.