Skip to content

Commit

Permalink
Add additional tests for SearchResultsServiceTest
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul6603 committed Dec 2, 2024
1 parent 35e75ae commit 93bd95a
Showing 1 changed file with 59 additions and 20 deletions.
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

0 comments on commit 93bd95a

Please sign in to comment.