Skip to content
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

Add additional tests for SearchResultsService #1333

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,11 @@
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.junit.*;
import org.junit.runner.RunWith;
import org.openelisglobal.BaseWebContextSensitiveTest;
import org.openelisglobal.common.provider.query.PatientSearchResults;
import org.openelisglobal.patient.service.PatientService;
Expand All @@ -19,9 +19,18 @@
import org.openelisglobal.search.service.SearchResultsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.junit4.rules.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule;

@RunWith(JUnitParamsRunner.class)
public class SearchResultsServiceTest extends BaseWebContextSensitiveTest {

@ClassRule
public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule();

@Rule
public final SpringMethodRule springMethodRule = new SpringMethodRule();

@Autowired
PatientService patientService;

Expand All @@ -47,90 +56,120 @@ public void tearDown() {
personService.deleteAll(personService.getAll());
}

private Object[] parametersForGetSearchResults_shouldGetSearchResultsFromDB() {
return new Object[] { new Object[] { "Jo", "Do", "12/12/1992", "M" }, new Object[] { "Jo", null, null, null },
new Object[] { null, "Do", null, null }, new Object[] { null, null, "12/12/1992", null },
new Object[] { null, null, null, "M" } };
}

private Object[] parametersForGetSearchResultsExact_shouldGetExactSearchResultsFromDB() {
return new Object[] { new Object[] { "John", "Doe", "12/12/1992", "M" },
new Object[] { "John", null, null, null }, new Object[] { null, "Doe", null, null },
new Object[] { null, null, "12/12/1992", null }, new Object[] { null, null, null, "M" } };
}

private Object[] parametersForGetSearchResults_shouldGetSearchResultsFromLuceneIndexes() {
return new Object[] { new Object[] { "Johm", "Doee", "12/12/1992", "M" },
new Object[] { "Johm", null, null, null }, new Object[] { null, "Doee", null, null },
new Object[] { null, null, "12/12/1992", null }, new Object[] { null, null, null, "M" } };
}

private Object[] parametersForGetSearchResultsExact_shouldGetExactSearchResultsFromLuceneIndexes() {
return new Object[] { new Object[] { "John", "Doe", "12/12/1992", "M" },
new Object[] { "John", null, null, null }, new Object[] { null, "Doe", null, null },
new Object[] { null, null, "12/12/1992", null }, new Object[] { null, null, null, "M" } };
}

@Test
public void getSearchResults_shouldGetSearchResultsFromDB() throws Exception {
@Parameters
public void getSearchResults_shouldGetSearchResultsFromDB(String searchFirstName, String searchLastName,
String searchDateOfBirth, String searchGender) throws Exception {
String firstName = "John";
String lastname = "Doe";
String dob = "12/12/1992";
String gender = "M";
Patient pat = createPatient(firstName, lastname, dob, gender);
String patientId = patientService.insert(pat);

String searchFirstName = "Jo";
String searchLastName = "Do";

List<PatientSearchResults> searchResults = DBSearchResultsServiceImpl.getSearchResults(searchLastName,
searchFirstName, null, null, null, null, null, null, dob, gender);
searchFirstName, null, null, null, null, null, null, searchDateOfBirth, searchGender);

Assert.assertEquals(1, searchResults.size());
PatientSearchResults result = searchResults.get(0);
Assert.assertEquals(patientId, result.getPatientID());
Assert.assertEquals(firstName, result.getFirstName());
Assert.assertEquals(lastname, result.getLastName());
Assert.assertEquals(dob, result.getBirthdate());
Assert.assertEquals(gender, result.getGender());
}

@Test
public void getSearchResultsExact_shouldGetExactSearchResultsFromDB() throws Exception {
@Parameters
public void getSearchResultsExact_shouldGetExactSearchResultsFromDB(String searchFirstName, String searchLastName,
String searchDateOfBirth, String searchGender) throws Exception {
String firstName = "John";
String lastname = "Doe";
String dob = "12/12/1992";
String gender = "M";
Patient pat = createPatient(firstName, lastname, dob, gender);
String patientId = patientService.insert(pat);

List<PatientSearchResults> searchResults = DBSearchResultsServiceImpl.getSearchResultsExact(lastname, firstName,
null, null, null, null, null, null, dob, gender);
List<PatientSearchResults> searchResults = DBSearchResultsServiceImpl.getSearchResultsExact(searchLastName,
searchFirstName, null, null, null, null, null, null, searchDateOfBirth, searchGender);

Assert.assertEquals(1, searchResults.size());
PatientSearchResults result = searchResults.get(0);
Assert.assertEquals(patientId, result.getPatientID());
Assert.assertEquals(firstName, result.getFirstName());
Assert.assertEquals(lastname, result.getLastName());
Assert.assertEquals(dob, result.getBirthdate());
Assert.assertEquals(gender, result.getGender());
}

@Test
public void getSearchResults_shouldGetSearchResultsFromLuceneIndexes() throws Exception {
@Parameters
public void getSearchResults_shouldGetSearchResultsFromLuceneIndexes(String searchFirstName, String searchLastName,
String searchDateOfBirth, String searchGender) throws Exception {
String firstName = "John";
String lastname = "Doe";
String dob = "12/12/1992";
String gender = "M";
Patient pat = createPatient(firstName, lastname, dob, gender);
String patientId = patientService.insert(pat);

String searchFirstName = "Johm";
String searchLastName = "Doee";

List<PatientSearchResults> searchResults = luceneSearchResultsServiceImpl.getSearchResults(searchLastName,
searchFirstName, null, null, null, null, null, null, dob, gender);
searchFirstName, null, null, null, null, null, null, searchDateOfBirth, searchGender);

Assert.assertEquals(1, searchResults.size());
PatientSearchResults result = searchResults.get(0);
Assert.assertEquals(patientId, result.getPatientID());
Assert.assertEquals(firstName, result.getFirstName());
Assert.assertEquals(lastname, result.getLastName());
Assert.assertEquals(dob, result.getBirthdate());
Assert.assertEquals(gender, result.getGender());
}

@Test
public void getSearchResultsExact_shouldGetExactSearchResultsFromLuceneIndexes() throws Exception {
@Parameters
public void getSearchResultsExact_shouldGetExactSearchResultsFromLuceneIndexes(String searchFirstName,
String searchLastName, String searchDateOfBirth, String searchGender) throws Exception {
String firstName = "John";
String lastname = "Doe";
String dob = "12/12/1992";
String gender = "M";
Patient pat = createPatient(firstName, lastname, dob, gender);
String patientId = patientService.insert(pat);

List<PatientSearchResults> searchResults = luceneSearchResultsServiceImpl.getSearchResultsExact(lastname,
firstName, null, null, null, null, null, null, dob, gender);
List<PatientSearchResults> searchResults = luceneSearchResultsServiceImpl.getSearchResultsExact(searchLastName,
searchFirstName, null, null, null, null, null, null, searchDateOfBirth, searchGender);

Assert.assertEquals(1, searchResults.size());
PatientSearchResults result = searchResults.get(0);
Assert.assertEquals(patientId, result.getPatientID());
Assert.assertEquals(firstName, result.getFirstName());
Assert.assertEquals(lastname, result.getLastName());
Assert.assertEquals(dob, result.getBirthdate());
Assert.assertEquals(gender, result.getGender());
}

private Patient createPatient(String firstName, String LastName, String birthDate, String gender)
Expand Down
Loading