Skip to content
Snippets Groups Projects
Commit 8fecc34b authored by adityab3's avatar adityab3
Browse files

Updated JUnit tests for preregistration health information

parent 895cf4b6
No related branches found
No related tags found
1 merge request!6Uc91v2
......@@ -7,9 +7,12 @@ package edu.ncsu.csc.itrust.unit.action;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.action.AddPreRegisteredPatientAction;
import edu.ncsu.csc.itrust.beans.PatientBean;
import edu.ncsu.csc.itrust.beans.HealthRecord;
import edu.ncsu.csc.itrust.beans.forms.HealthRecordForm;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.dao.mysql.AuthDAO;
import edu.ncsu.csc.itrust.dao.mysql.PatientDAO;
import edu.ncsu.csc.itrust.dao.mysql.HealthRecordsDAO;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
import edu.ncsu.csc.itrust.exception.FormValidationException;
......@@ -21,16 +24,24 @@ public class AddPreRegisterPatientActionTest extends TestCase {
private DAOFactory factory = TestDAOFactory.getTestInstance();
private PatientDAO patientDAO = TestDAOFactory.getTestInstance().getPatientDAO();
private AuthDAO authDAO = TestDAOFactory.getTestInstance().getAuthDAO();
private HealthRecordsDAO healthDAO = TestDAOFactory.getTestInstance().getHealthRecordsDAO();
private TestDataGenerator gen = new TestDataGenerator();
private AddPreRegisteredPatientAction action;
private HealthRecordForm defaultHRF;
/**
* Sets up defaults
*/
@Override
protected void setUp() throws Exception {
gen.clearAllTables();
action = new AddPreRegisteredPatientAction(factory, 0L);
action = new AddPreRegisteredPatientAction(factory, 0L);
defaultHRF = new HealthRecordForm();
defaultHRF.setIsSmoker("1");
defaultHRF.setHeight("");
defaultHRF.setWeight("");
}
/**
......@@ -55,7 +66,12 @@ public class AddPreRegisterPatientActionTest extends TestCase {
p.setIcState("AK");
p.setIcPhone("1122334455");
long mid = action.addPatient(p);
HealthRecordForm h = new HealthRecordForm();
h.setHeight("100");
h.setWeight("100");
h.setIsSmoker("1");
long mid = action.addPatient(p, h);
PatientBean p2 = patientDAO.getPatient(mid);
assertEquals(p.getFirstName(), p2.getFirstName());
......@@ -73,6 +89,11 @@ public class AddPreRegisterPatientActionTest extends TestCase {
assertEquals(p.getIcCity(), p2.getIcCity());
assertEquals(p.getIcState(), p.getIcState());
assertEquals(p.getIcPhone(), p.getIcPhone());
HealthRecord h2 = healthDAO.getAllHealthRecords(mid).get(0);
assertEquals(Double.parseDouble(h.getHeight()), h2.getHeight());
assertEquals(Double.parseDouble(h.getWeight()), h2.getWeight());
assertEquals(h.getIsSmoker() == "1", h2.isSmoker());
assertEquals(Role.PREREGISTEREDPATIENT, authDAO.getUserRole(mid));
}
......@@ -89,7 +110,7 @@ public class AddPreRegisterPatientActionTest extends TestCase {
// maybe not needed
try {
action.addPatient(p);
action.addPatient(p, defaultHRF);
fail("Invalid email");
} catch (FormValidationException e) {
......@@ -105,8 +126,9 @@ public class AddPreRegisterPatientActionTest extends TestCase {
p2.setLastName("Cricket");
p2.setEmail("make.awish@gmail.com");
p2.setPassword("password");
action.addPatient(p2);
try {
action.addPatient(p2, defaultHRF);
} catch (Exception e) {e.printStackTrace();}
PatientBean p3 = new PatientBean();
p3.setFirstName("Make");
......@@ -115,7 +137,7 @@ public class AddPreRegisterPatientActionTest extends TestCase {
p3.setPassword("password");
try {
action.addPatient(p3);
action.addPatient(p3, defaultHRF);
fail("Duplicate email");
} catch (ITrustException e) { }
}
......
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