From 8fecc34bb5c017631ab1c093b73acaa86b3cc4ee Mon Sep 17 00:00:00 2001 From: Aditya Bhansali <adityab3@illinois.edu> Date: Sun, 15 Nov 2020 06:55:26 -0600 Subject: [PATCH] Updated JUnit tests for preregistration health information --- .../AddPreRegisterPatientActionTest.java | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/iTrust/test/edu/ncsu/csc/itrust/unit/action/AddPreRegisterPatientActionTest.java b/iTrust/test/edu/ncsu/csc/itrust/unit/action/AddPreRegisterPatientActionTest.java index 4e336fd..fadb9cd 100644 --- a/iTrust/test/edu/ncsu/csc/itrust/unit/action/AddPreRegisterPatientActionTest.java +++ b/iTrust/test/edu/ncsu/csc/itrust/unit/action/AddPreRegisterPatientActionTest.java @@ -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) { } } -- GitLab