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