Skip to content
Snippets Groups Projects
Commit 920ac251 authored by Matthew Williams's avatar Matthew Williams
Browse files

Fix tests and simplify actions

parent d40b0b1b
No related branches found
No related tags found
1 merge request!22Merge UC92 into Master
...@@ -4,6 +4,7 @@ import java.util.ArrayList; ...@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import edu.ncsu.csc.itrust.Messages;
import edu.ncsu.csc.itrust.beans.OfficeVisitBean; import edu.ncsu.csc.itrust.beans.OfficeVisitBean;
import edu.ncsu.csc.itrust.beans.PatientBean; import edu.ncsu.csc.itrust.beans.PatientBean;
import edu.ncsu.csc.itrust.beans.PatientVisitBean; import edu.ncsu.csc.itrust.beans.PatientVisitBean;
...@@ -23,18 +24,16 @@ import edu.ncsu.csc.itrust.exception.ITrustException; ...@@ -23,18 +24,16 @@ import edu.ncsu.csc.itrust.exception.ITrustException;
public class ViewPreRegisteredPatientListAction { public class ViewPreRegisteredPatientListAction {
private long loggedInMID; private long loggedInMID;
private PatientDAO patientDAO; private PatientDAO patientDAO;
private ArrayList<PatientBean> PreRegisteredPatients; private List<PatientBean> PreRegisteredPatients;
/** /**
* Set up defaults * Set up defaults
* @param factory The DAOFactory used to create the DAOs used in this action. * @param factory The DAOFactory used to create the DAOs used in this action.
* @param loggedInMID The MID of the person viewing the office visits. * @param loggedInMID The MID of the person viewing the office visits.
*/ */
public ViewPreRegisteredPatientListAction(DAOFactory factory, long loggedInMID) { public ViewPreRegisteredPatientListAction(DAOFactory factory) {
this.patientDAO = factory.getPatientDAO(); this.patientDAO = factory.getPatientDAO();
PreRegisteredPatients = new ArrayList<PatientBean>();
} }
...@@ -43,38 +42,18 @@ public class ViewPreRegisteredPatientListAction { ...@@ -43,38 +42,18 @@ public class ViewPreRegisteredPatientListAction {
* *
* @throws ITrustException * @throws ITrustException
*/ */
private void getPreRegisteredFromPatientsTable() throws ITrustException { public List<PatientBean> getPreRegisteredPatients() throws ITrustException {
try { try {
List<PatientBean> plist = patientDAO.getAllPreRegisteredPatients();
PreRegisteredPatients = patientDAO.getAllPreRegisteredPatients();
for(PatientBean pb : plist) { if (PreRegisteredPatients != null) {
return PreRegisteredPatients;
PreRegisteredPatients.add(pb); } else {
throw new ITrustException("getAllPreRegisteredPatients() has returned null");
} }
}
catch (DBException dbe) { } catch (DBException dbe) {
throw new ITrustException(dbe.getMessage()); throw new ITrustException(dbe.getMessage());
} }
} }
/**
* Get the list of patients an HCP has had office visits with
*
* @return the list of patients an HCP has had office visits with
* @throws DBException
*/
public List<PatientBean> getPreRegisteredPatients() throws DBException {
try {
getPreRegisteredFromPatientsTable();
}
catch (ITrustException ie) {
//TODO
}
return PreRegisteredPatients;
}
} }
package edu.ncsu.csc.itrust.unit.action; package edu.ncsu.csc.itrust.unit.action;
import junit.framework.TestCase; import junit.framework.TestCase;
import edu.ncsu.csc.itrust.action.ViewPersonnelAction; import edu.ncsu.csc.itrust.action.ViewPreRegisteredPatientListAction;
import edu.ncsu.csc.itrust.beans.PatientBean; import edu.ncsu.csc.itrust.beans.PatientBean;
import edu.ncsu.csc.itrust.dao.DAOFactory; import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.exception.ITrustException;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
import java.util.List;
public class ViewPreRegisteredPatientListActionTest extends TestCase { public class ViewPreRegisteredPatientListActionTest extends TestCase {
private DAOFactory factory = TestDAOFactory.getTestInstance(); private DAOFactory factory = TestDAOFactory.getTestInstance();
...@@ -25,14 +27,14 @@ public class ViewPreRegisteredPatientListActionTest extends TestCase { ...@@ -25,14 +27,14 @@ public class ViewPreRegisteredPatientListActionTest extends TestCase {
public void testViewPatients() throws Exception { public void testViewPatients() throws Exception {
action = new ViewPreRegisteredPatientListAction(factory); action = new ViewPreRegisteredPatientListAction(factory);
List<PatientBean> pb = action.getPreRegisteredPatients(); List<PatientBean> pb = action.getPreRegisteredPatients();
assertEquals(pb.get(0) == 4); assertEquals(pb.get(0).getMID(), 4);
} }
public void testNoPersonnel() throws Exception { public void testNoPersonnel() throws Exception {
action = new ViewPreRegisteredPatientListAction(factory); action = new ViewPreRegisteredPatientListAction(factory);
List<PatientBean> pb = action.getPreRegisteredPatients(); List<PatientBean> pb = action.getPreRegisteredPatients();
for (PatientBean p : pb) { for (PatientBean p : pb) {
if (p.id() == "90000000") { if (p.getMID() == 90000000) {
fail("This id should not exist in the list"); fail("This id should not exist in the list");
} }
} }
......
...@@ -24,7 +24,7 @@ public class ActivatePatientTest extends TestCase { ...@@ -24,7 +24,7 @@ public class ActivatePatientTest extends TestCase {
public void testActivateNewPatient() throws Exception { public void testActivateNewPatient() throws Exception {
long pid = patientDAO.addEmptyPatient(); long pid = patientDAO.addEmptyPatient();
assertEquals("PreRegisteredPatient", patientDAO.getRole(pid)); assertEquals("PreRegisteredPatient", patientDAO.getRole(pid));
activatePatient(pid); patientDAO.activatePatient(pid);
assertEquals("patient", patientDAO.getRole(pid)); assertEquals("patient", patientDAO.getRole(pid));
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment