repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/EmailUtilTest.java
package edu.ncsu.csc.itrust.unit; import junit.framework.TestCase; import edu.ncsu.csc.itrust.EmailUtil; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.model.old.beans.Email; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; public class EmailUtilTest extends TestCase { public void testSendEmail() throws Exception { // Note: this test can be deleted once you switch to a "real" email util try { new EmailUtil(EvilDAOFactory.getEvilInstance()).sendEmail(new Email()); fail("Exception should have been thrown"); } catch (DBException e) { assertEquals(EvilDAOFactory.MESSAGE, e.getExtendedMessage()); } } }
667
29.363636
74
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/ErrorListTest.java
package edu.ncsu.csc.itrust.unit; import junit.framework.TestCase; import edu.ncsu.csc.itrust.exception.ErrorList; public class ErrorListTest extends TestCase { public void testToString() throws Exception { ErrorList errorList = new ErrorList(); // test add if not null errorList.addIfNotNull("a"); errorList.addIfNotNull(""); errorList.addIfNotNull("b"); errorList.addIfNotNull(null); String toString = "["; // test iterator too for (String str : errorList) { toString += str + ", "; } toString = toString.substring(0, toString.length() - 2) + "]"; assertEquals(toString, errorList.toString()); } }
631
26.478261
64
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/HtmlEncoderTest.java
package edu.ncsu.csc.itrust.unit; import edu.ncsu.csc.itrust.HtmlEncoder; import junit.framework.TestCase; public class HtmlEncoderTest extends TestCase { public void testEscapeCharacters() throws Exception { assertEquals("&lt;tag&gt;", HtmlEncoder.encode("<tag>")); assertEquals("&lt;tag&gt;&lt;/tag&gt;", HtmlEncoder.encode("<tag></tag>")); assertEquals("<br />", HtmlEncoder.encode("\n")); assertEquals("&lt;&lt;tag&gt;&gt;\"Lots of text!\"&lt;&lt;/tag&gt;&gt;", HtmlEncoder.encode("<<tag>>\"Lots of text!\"<</tag>>")); } public void testOffSite() { assertFalse(HtmlEncoder.URLOnSite("http://www.google.com")); } }
640
31.05
77
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/LocalizationTest.java
package edu.ncsu.csc.itrust.unit; import java.util.Locale; import edu.ncsu.csc.itrust.Localization; import junit.framework.TestCase; public class LocalizationTest extends TestCase { public void testLocalization() { Locale l = Localization.instance().getCurrentLocale(); assert (l != null); } }
305
18.125
56
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/MessagesTest.java
package edu.ncsu.csc.itrust.unit; import edu.ncsu.csc.itrust.Messages; import junit.framework.TestCase; public class MessagesTest extends TestCase { public void testGetString() { assertEquals("Requested", Messages.getString("ReportRequestBean.requested")); assertEquals("!50000!", Messages.getString("50000")); } }
325
22.285714
79
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/ParameterUtilTest.java
package edu.ncsu.csc.itrust.unit; import java.util.HashMap; import java.util.Map; import edu.ncsu.csc.itrust.ParameterUtil; import junit.framework.TestCase; public class ParameterUtilTest extends TestCase { @SuppressWarnings("unchecked") public void testConvertMap() throws Exception { @SuppressWarnings("rawtypes") Map paramMap = new HashMap(); paramMap.put("param1", new String[] { "a" }); paramMap.put("param2", new String[] { null }); paramMap.put("param3", null); HashMap<String, String> convertedMap = ParameterUtil.convertMap(paramMap); assertEquals(3, convertedMap.entrySet().size()); assertEquals("a", convertedMap.get("param1")); assertNull(convertedMap.get("param2")); assertNull(convertedMap.get("param3")); } }
750
30.291667
76
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/XmlGeneratorTest.java
package edu.ncsu.csc.itrust.unit; import edu.ncsu.csc.itrust.XmlGenerator; import junit.framework.TestCase; import java.util.ArrayList; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** * XmlGeneratorTest */ public class XmlGeneratorTest extends TestCase { /** * testXmlEmpty */ public void testXmlEmpty() { ArrayList<ArrayList<String>> testdata = new ArrayList<ArrayList<String>>(); ArrayList<String> headers = new ArrayList<String>(); Document emptyDoc = XmlGenerator.generateXml(headers, testdata); NodeList list = emptyDoc.getChildNodes(); assertEquals(list.getLength(), 1); assertEquals(list.item(0).getNodeName(), "PatientReport"); } /** * testtwoPatient */ public void testtwoPatient() { ArrayList<ArrayList<String>> testdata = new ArrayList<ArrayList<String>>(); ArrayList<String> headers = new ArrayList<String>(); // set up test headers headers.add("Name"); headers.add("Age"); headers.add("sex"); // set up test patient ArrayList<String> patient1 = new ArrayList<String>(); patient1.add("bob joe"); // test space to _ patient1.add("23"); patient1.add("Male"); testdata.add(patient1); ArrayList<String> patient2 = new ArrayList<String>(); patient2.add("william"); // test space to _ patient2.add("21"); patient2.add("Male"); testdata.add(patient2); Document two = XmlGenerator.generateXml(headers, testdata); Node head = two.getFirstChild(); // document System.out.println(head.getNodeName()); NodeList list = head.getChildNodes(); System.out.println(list.getLength() + " " + list.item(0).getNodeName() + " "); assertEquals(2, list.getLength()); assertEquals("Patient", list.item(0).getNodeName()); assertEquals("PatientReport", head.getNodeName()); } }
1,792
25.761194
80
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ActivityFeedActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.sql.SQLException; import java.sql.Timestamp; import java.text.SimpleDateFormat; import edu.ncsu.csc.itrust.action.ActivityFeedAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.model.old.beans.TransactionBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.enums.TransactionType; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import junit.framework.TestCase; import java.util.Date; import java.util.List; public class ActivityFeedActionTest extends TestCase { private ActivityFeedAction action; private DAOFactory factory; private long mid = 1L; TestDataGenerator gen; @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); gen.standardData(); this.factory = TestDAOFactory.getTestInstance(); this.action = new ActivityFeedAction(factory, mid); } public void testGetTransactions() throws FormValidationException, SQLException { try { List<TransactionBean> beans = action.getTransactions(new Date(), 1); assertTrue(beans.size() < 20); } catch (DBException e) { fail(); } } public void testGetMessageAsSentence() { Date dNow = new Date(); Timestamp tsNow = new Timestamp(dNow.getTime()); Timestamp tsYesterday = new Timestamp(dNow.getTime() - 1000 * 60 * 60 * 24); Timestamp tsLongAgo = new Timestamp(dNow.getTime() - 1000 * 60 * 60 * 24 * 10); new SimpleDateFormat(); String msg; msg = action.getMessageAsSentence("", tsNow, TransactionType.PATIENT_CREATE); assertTrue(msg.contains(TransactionType.PATIENT_CREATE.getActionPhrase())); msg = action.getMessageAsSentence("", tsNow, TransactionType.PATIENT_DISABLE); assertTrue(msg.contains(TransactionType.PATIENT_DISABLE.getActionPhrase())); msg = action.getMessageAsSentence("", tsNow, TransactionType.DEMOGRAPHICS_VIEW); assertTrue(msg.contains(TransactionType.DEMOGRAPHICS_VIEW.getActionPhrase())); msg = action.getMessageAsSentence("", tsYesterday, TransactionType.PATIENT_HEALTH_INFORMATION_EDIT); assertTrue(msg.contains(TransactionType.PATIENT_HEALTH_INFORMATION_EDIT.getActionPhrase())); msg = action.getMessageAsSentence("", tsLongAgo, TransactionType.PATIENT_HEALTH_INFORMATION_VIEW); assertTrue(msg.contains(TransactionType.PATIENT_HEALTH_INFORMATION_VIEW.getActionPhrase())); msg = action.getMessageAsSentence("", tsLongAgo, TransactionType.OFFICE_VISIT_VIEW); assertTrue(msg.contains(TransactionType.OFFICE_VISIT_VIEW.getActionPhrase())); } /** * Verifies that certain transactions from the DLHCP are hidden in the * activity feed per use case 43. * * @throws Exception */ public void testHiddenActivityFromDLHCP() throws Exception { gen.clearAllTables(); gen.standardData(); action = new ActivityFeedAction(TestDAOFactory.getTestInstance(), 2L); List<TransactionBean> accesses = action.getTransactions(new Date(), 1); for (TransactionBean tb : accesses) if (tb.getRole() != null && tb.getRole().equals("DLHCP")) { assertFalse(tb.getTransactionType() == TransactionType.DEMOGRAPHICS_VIEW); assertFalse(tb.getTransactionType() == TransactionType.DEMOGRAPHICS_EDIT); assertFalse(tb.getTransactionType() == TransactionType.OFFICE_VISIT_CREATE); assertFalse(tb.getTransactionType() == TransactionType.OFFICE_VISIT_EDIT); assertFalse(tb.getTransactionType() == TransactionType.OFFICE_VISIT_VIEW); assertFalse(tb.getTransactionType() == TransactionType.RISK_FACTOR_VIEW); assertFalse(tb.getTransactionType() == TransactionType.PATIENT_HEALTH_INFORMATION_EDIT); assertFalse(tb.getTransactionType() == TransactionType.PATIENT_HEALTH_INFORMATION_VIEW); assertFalse(tb.getTransactionType() == TransactionType.PRESCRIPTION_REPORT_VIEW); assertFalse(tb.getTransactionType() == TransactionType.COMPREHENSIVE_REPORT_ADD); assertFalse(tb.getTransactionType() == TransactionType.COMPREHENSIVE_REPORT_VIEW); assertFalse(tb.getTransactionType() == TransactionType.LAB_PROCEDURE_ADD); assertFalse(tb.getTransactionType() == TransactionType.LAB_PROCEDURE_EDIT); assertFalse(tb.getTransactionType() == TransactionType.LAB_PROCEDURE_REMOVE); assertFalse(tb.getTransactionType() == TransactionType.PRECONFIRM_PRESCRIPTION_RENEWAL); assertFalse(tb.getTransactionType() == TransactionType.PRESCRIPTION_ADD); assertFalse(tb.getTransactionType() == TransactionType.PRESCRIPTION_EDIT); assertFalse(tb.getTransactionType() == TransactionType.PATIENT_REMINDERS_VIEW); assertFalse(tb.getTransactionType() == TransactionType.EMERGENCY_REPORT_CREATE); assertFalse(tb.getTransactionType() == TransactionType.EMERGENCY_REPORT_VIEW); } } }
4,879
45.037736
102
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/AddApptActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.SQLException; import java.sql.Timestamp; import java.util.List; import edu.ncsu.csc.itrust.action.AddApptAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.ApptBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import junit.framework.TestCase; public class AddApptActionTest extends TestCase { private AddApptAction action; private DAOFactory factory; private long mid = 1L; private long hcpId = 9000000000L; TestDataGenerator gen; @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); gen.standardData(); this.factory = TestDAOFactory.getTestInstance(); this.action = new AddApptAction(this.factory, this.hcpId); } public void testAddAppt() throws FormValidationException, SQLException, DBException { ApptBean b = new ApptBean(); b.setApptType("General Checkup"); b.setHcp(hcpId); b.setPatient(mid); b.setDate(new Timestamp(System.currentTimeMillis() + (10 * 60 * 1000))); b.setComment(null); assertTrue(action.addAppt(b, true).startsWith("Success")); } public void testAddAppt2() throws FormValidationException, SQLException, DBException { ApptBean b = new ApptBean(); b.setApptType("General Checkup"); b.setHcp(hcpId); b.setPatient(mid); Timestamp t = new Timestamp(System.currentTimeMillis() - (10 * 60 * 1000)); b.setDate(t); b.setComment("Test Appiontment"); assertEquals("The scheduled date of this Appointment (" + t + ") has already passed.", action.addAppt(b, true)); } public void testGetName() throws ITrustException { assertEquals("Kelly Doctor", action.getName(hcpId)); } public void testGetName2() throws ITrustException { assertEquals("Random Person", action.getName(mid)); } public void testAddConflicts() throws SQLException, FormValidationException, FileNotFoundException, IOException, DBException { gen.clearAllTables(); gen.appointmentType(); ApptBean a = new ApptBean(); a.setApptType("General Checkup"); a.setHcp(hcpId); a.setPatient(mid); Timestamp t = new Timestamp(System.currentTimeMillis() + (10 * 60 * 1000)); a.setDate(t); a.setComment("Test Appiontment"); ApptBean b = new ApptBean(); b.setApptType("General Checkup"); b.setHcp(hcpId); b.setPatient(mid); Timestamp t2 = new Timestamp(System.currentTimeMillis() + (20 * 60 * 1000)); b.setDate(t2); b.setComment("Test Appiontment"); String resultA = action.addAppt(a, false); String resultB = action.addAppt(b, false); assertTrue(resultA.contains("Success")); assertTrue(resultB.contains("conflict")); } public void testGetConflicts() throws SQLException, FormValidationException, FileNotFoundException, IOException, DBException { gen.clearAllTables(); gen.appointmentType(); ApptBean a = new ApptBean(); a.setApptType("General Checkup"); a.setHcp(hcpId); a.setPatient(mid); Timestamp t = new Timestamp(System.currentTimeMillis() + (10 * 60 * 1000)); a.setDate(t); a.setComment("Test Appiontment"); ApptBean b = new ApptBean(); b.setApptType("General Checkup"); b.setHcp(hcpId); b.setPatient(mid); Timestamp t2 = new Timestamp(System.currentTimeMillis() + (20 * 60 * 1000)); b.setDate(t2); b.setComment("Test Appiontment"); action.addAppt(a, true); action.addAppt(b, true); List<ApptBean> conflicts = action.getAllConflicts(hcpId); assertEquals(2, conflicts.size()); List<ApptBean> conflictForA; conflictForA = action.getConflictsForAppt(hcpId, a); assertEquals(2, conflictForA.size()); } }
3,921
29.640625
114
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/AddApptRequestActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.sql.SQLException; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.List; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.AddApptRequestAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.model.old.beans.ApptBean; import edu.ncsu.csc.itrust.model.old.beans.ApptRequestBean; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class AddApptRequestActionTest extends TestCase { private AddApptRequestAction action; private TestDataGenerator gen = new TestDataGenerator(); @Override protected void setUp() throws Exception { gen.clearAllTables(); gen.standardData(); gen.apptRequestConflicts(); action = new AddApptRequestAction(TestDAOFactory.getTestInstance()); } public void testAddApptRequest() throws Exception { ApptBean b = new ApptBean(); b.setApptType("General Checkup"); b.setHcp(9000000010L); b.setPatient(2L); String time = "01:45 PM"; Calendar cal = Calendar.getInstance(); SimpleDateFormat fo = new SimpleDateFormat("MM/dd/yyyy"); cal.add(Calendar.DAY_OF_YEAR, 7); time = fo.format(cal.getTime()) + " " + time; fo = new SimpleDateFormat("MM/dd/yyyy hh:mm aa"); Date d = fo.parse(time); b.setDate(new Timestamp(d.getTime())); ApptRequestBean req = new ApptRequestBean(); req.setRequestedAppt(b); String expected = "The appointment you requested conflicts with other existing appointments."; assertEquals(expected, action.addApptRequest(req)); expected = "Your appointment request has been saved and is pending."; cal.set(2012, 7, 20, 18, 45, 0); req.getRequestedAppt().setDate(new Timestamp(cal.getTimeInMillis())); assertEquals(expected, action.addApptRequest(req)); } public void testGetNextAvailableAppts() throws SQLException, ParseException, DBException { ApptBean b = new ApptBean(); b.setApptType("General Checkup"); b.setHcp(9000000000L); b.setPatient(2L); String time = "01:45 PM"; Calendar cal = Calendar.getInstance(); SimpleDateFormat fo = new SimpleDateFormat("MM/dd/yyyy"); cal.add(Calendar.DAY_OF_YEAR, 7); @SuppressWarnings("unused") SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm aa"); time = fo.format(cal.getTime()) + " " + time; fo = new SimpleDateFormat("MM/dd/yyyy hh:mm aa"); Date d = fo.parse(time); b.setDate(new Timestamp(d.getTime())); List<ApptBean> next = action.getNextAvailableAppts(3, b); assertEquals(3, next.size()); cal.clear(); time = "03:30 PM"; cal = Calendar.getInstance(); fo = new SimpleDateFormat("MM/dd/yyyy"); cal.add(Calendar.DAY_OF_YEAR, 7); sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm aa"); time = fo.format(cal.getTime()) + " " + time; fo = new SimpleDateFormat("MM/dd/yyyy hh:mm aa"); d = fo.parse(time); cal.clear(Calendar.MILLISECOND); Timestamp e1 = new Timestamp(d.getTime()); cal.clear(); time = "05:30 PM"; cal = Calendar.getInstance(); fo = new SimpleDateFormat("MM/dd/yyyy"); cal.add(Calendar.DAY_OF_YEAR, 7); sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm aa"); time = fo.format(cal.getTime()) + " " + time; fo = new SimpleDateFormat("MM/dd/yyyy hh:mm aa"); d = fo.parse(time); cal.clear(Calendar.MILLISECOND); Timestamp e2 = new Timestamp(d.getTime()); cal.clear(); time = "06:15 PM"; cal = Calendar.getInstance(); fo = new SimpleDateFormat("MM/dd/yyyy"); cal.add(Calendar.DAY_OF_YEAR, 7); sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm aa"); time = fo.format(cal.getTime()) + " " + time; fo = new SimpleDateFormat("MM/dd/yyyy hh:mm aa"); d = fo.parse(time); cal.clear(Calendar.MILLISECOND); Timestamp e3 = new Timestamp(d.getTime()); assertEquals(e1, next.get(0).getDate()); assertEquals(e2, next.get(1).getDate()); assertEquals(e3, next.get(2).getDate()); } }
4,018
32.214876
96
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/AddDrugListActionTest.java
/** * Tests AddDrugListAction for importing NDC information. */ package edu.ncsu.csc.itrust.unit.action; import java.io.ByteArrayInputStream; import java.io.InputStream; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.AddDrugListAction.SkipDuplicateDrugStrategy; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.dao.mysql.NDCodesDAO; import edu.ncsu.csc.itrust.action.AddDrugListAction; import edu.ncsu.csc.itrust.action.EventLoggingAction; import edu.ncsu.csc.itrust.action.AddDrugListAction.OverwriteDuplicateDrugStrategy; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class AddDrugListActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private AddDrugListAction action; private TestDataGenerator gen; /* * Four lines selected from the text download of the fall 2011 version of * the FDA NDC database */ private String inputDrugs1 = "0573-0150 HUMAN OTC DRUG ADVIL IBUPROFEN TABLET, COATED ORAL 19840518 NDA NDA018989 Pfizer Consumer Healthcare IBUPROFEN 200 mg/1 Nonsteroidal Anti-inflammatory Drug [EPC], Cyclooxygenase Inhibitors [MoA], Nonsteroidal Anti-inflammatory Compounds [Chemical/Ingredient] \n" + "50458-513 HUMAN PRESCRIPTION DRUG TYLENOL with Codeine ACETAMINOPHEN AND CODEINE PHOSPHATE TABLET ORAL 19770817 ANDA ANDA085055 Janssen Pharmaceuticals, Inc. ACETAMINOPHEN; CODEINE PHOSPHATE 300; 30 mg/1; mg/1 CIII\n" + "10544-591 HUMAN PRESCRIPTION DRUG OxyContin OXYCODONE HYDROCHLORIDE TABLET, FILM COATED, EXTENDED RELEASE ORAL 20100126 NDA NDA020553 Blenheim Pharmacal, Inc. OXYCODONE HYDROCHLORIDE 10 mg/1 Opioid Agonist [EPC], Full Opioid Agonists [MoA] CII\n" + "11523-7197 HUMAN OTC DRUG Claritin LORATADINE SOLUTION ORAL 20110301 NDA NDA020641 Schering Plough Healthcare Products Inc. LORATADINE 5 mg/5mL \n"; private String inputDrugs2 = "0573-0150 HUMAN OTC DRUG New Advil IBUPROFEN TABLET, COATED ORAL 19840518 NDA NDA018989 Pfizer Consumer Healthcare IBUPROFEN 200 mg/1 Nonsteroidal Anti-inflammatory Drug [EPC], Cyclooxygenase Inhibitors [MoA], Nonsteroidal Anti-inflammatory Compounds [Chemical/Ingredient] \n" + "0574-0230 HUMAN OTC DRUG New Drug IBUPROFEN TABLET, COATED ORAL 19840518 NDA NDA018989 Pfizer Consumer Healthcare IBUPROFEN 200 mg/1 Nonsteroidal Anti-inflammatory Drug [EPC], Cyclooxygenase Inhibitors [MoA], Nonsteroidal Anti-inflammatory Compounds [Chemical/Ingredient] \n" + "11523-7197 HUMAN OTC DRUG Totally Legal Drug LORATADINE SOLUTION ORAL 20110301 NDA NDA020641 Schering Plough Healthcare Products Inc. LORATADINE 5 mg/5mL \n"; public AddDrugListActionTest() { gen = new TestDataGenerator(); } /** * Sets up defaults */ @Override protected void setUp() throws Exception { gen.clearAllTables(); } public void testLoadFile() throws Exception { InputStream is = new ByteArrayInputStream(inputDrugs1.getBytes()); action = new AddDrugListAction(new SkipDuplicateDrugStrategy(), factory, new EventLoggingAction(factory), 9000000001L); action.loadFile(is); NDCodesDAO ndCodesDAO = factory.getNDCodesDAO(); assertEquals(4, ndCodesDAO.getAllNDCodes().size()); assertNotNull(ndCodesDAO.getNDCode("05730150")); assertEquals("ADVIL", ndCodesDAO.getNDCode("05730150").getDescription()); assertNotNull(ndCodesDAO.getNDCode("50458513")); assertEquals("TYLENOL with Codeine", ndCodesDAO.getNDCode("50458513").getDescription()); assertNotNull(ndCodesDAO.getNDCode("10544591")); assertEquals("OxyContin", ndCodesDAO.getNDCode("10544591").getDescription()); assertNotNull(ndCodesDAO.getNDCode("115237197")); assertEquals("Claritin", ndCodesDAO.getNDCode("115237197").getDescription()); } public void testRenameDrugs() throws Exception { InputStream is = new ByteArrayInputStream(inputDrugs1.getBytes()); action = new AddDrugListAction(new SkipDuplicateDrugStrategy(), factory, new EventLoggingAction(factory), 9000000001L); action.loadFile(is); NDCodesDAO ndCodesDAO = factory.getNDCodesDAO(); assertEquals(4, ndCodesDAO.getAllNDCodes().size()); assertNotNull(ndCodesDAO.getNDCode("05730150")); assertEquals("ADVIL", ndCodesDAO.getNDCode("05730150").getDescription()); assertNotNull(ndCodesDAO.getNDCode("50458513")); assertEquals("TYLENOL with Codeine", ndCodesDAO.getNDCode("50458513").getDescription()); assertNotNull(ndCodesDAO.getNDCode("10544591")); assertEquals("OxyContin", ndCodesDAO.getNDCode("10544591").getDescription()); assertNotNull(ndCodesDAO.getNDCode("115237197")); assertEquals("Claritin", ndCodesDAO.getNDCode("115237197").getDescription()); is = new ByteArrayInputStream(inputDrugs2.getBytes()); action = new AddDrugListAction(new OverwriteDuplicateDrugStrategy(), factory, new EventLoggingAction(factory), 9000000001L); action.loadFile(is); assertEquals(5, ndCodesDAO.getAllNDCodes().size()); assertNotNull(ndCodesDAO.getNDCode("05730150")); assertEquals("New Advil", ndCodesDAO.getNDCode("05730150").getDescription()); assertNotNull(ndCodesDAO.getNDCode("50458513")); assertEquals("TYLENOL with Codeine", ndCodesDAO.getNDCode("50458513").getDescription()); assertNotNull(ndCodesDAO.getNDCode("10544591")); assertEquals("OxyContin", ndCodesDAO.getNDCode("10544591").getDescription()); assertNotNull(ndCodesDAO.getNDCode("115237197")); assertEquals("Totally Legal Drug", ndCodesDAO.getNDCode("115237197").getDescription()); assertNotNull(ndCodesDAO.getNDCode("05740230")); assertEquals("New Drug", ndCodesDAO.getNDCode("05740230").getDescription()); } }
5,667
52.980952
309
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/AddERespActionTest.java
/** * Tests for AddPatientAction */ package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.AddERespAction; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.enums.Role; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class AddERespActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen; private AddERespAction action; /** * Sets up defaults */ @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); gen.standardData(); action = new AddERespAction(factory, 9000000000L); } /** * Tests adding a new ER * * @throws Exception */ public void testAddER() throws Exception { gen.clearAllTables(); PersonnelBean person = new PersonnelBean(); person.setRole(Role.ER); person.setFirstName("Para"); person.setLastName("Medic"); person.setEmail("Paramedic@itrust.com"); long newMID = action.add(person); assertEquals(person.getMID(), newMID); } }
1,243
24.387755
65
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/AddHCPActionTest.java
/** * Tests AddHCPAction in that the validator is checked and the proper DAOs are hit. * * This tests is an example of using Mock Objects. If you haven't covered this in class (yet, or at all), then * disregard this class. If you are trying to learn about unit testing with Mock Objects, this is a great * class to start with. */ package edu.ncsu.csc.itrust.unit.action; import edu.ncsu.csc.itrust.action.AddHCPAction; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.model.old.enums.Role; import edu.ncsu.csc.itrust.unit.testutils.ActionTestWithMocks; import static org.easymock.classextension.EasyMock.*; public class AddHCPActionTest extends ActionTestWithMocks { private AddHCPAction action; private PersonnelBean personnel; /** * Sets up defaults */ @Override protected void setUp() throws Exception { // Step 0. Initialize the mocks and other necessary objects. super.initMocks(); // Step 1. Initialize any other classes we need. personnel = new PersonnelBean(); personnel.setFirstName("Cosmo"); personnel.setLastName("Kramer"); personnel.setEmail("cosmo@kramer.com"); personnel.setRole(Role.HCP); } /** * Tests adding a new HCP * * @throws Exception * */ public void testAddHCP() throws Exception { // Step 2. For each test, set up the expectations of what will be called // (started in initMocks) expect(personnelDAO.addEmptyPersonnel(Role.HCP)).andReturn(56L).once(); personnelDAO.editPersonnel(personnel); expectLastCall().once(); // Step 3. Exit recording mode, go into playback mode control.replay(); // Don't forget this! // Step 3. Actually run the method under test, checking its return value action = new AddHCPAction(factory, 9000000000L); // this lines needs to // be AFTER the // replay() long newMID = action.add(personnel); assertEquals(56L, newMID); // Step 4. Verify the mocks were hit as you expected control.verify(); // Don't forget this! } }
2,018
30.546875
110
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/AddLTActionTest.java
/** * Tests AddHCPAction in that the validator is checked and the proper DAOs are hit. * * This tests is an example of using Mock Objects. If you haven't covered this in class (yet, or at all), then * disregard this class. If you are trying to learn about unit testing with Mock Objects, this is a great * class to start with. */ package edu.ncsu.csc.itrust.unit.action; import edu.ncsu.csc.itrust.action.AddLTAction; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.model.old.enums.Role; import edu.ncsu.csc.itrust.unit.testutils.ActionTestWithMocks; import static org.easymock.classextension.EasyMock.*; public class AddLTActionTest extends ActionTestWithMocks { private AddLTAction action; private PersonnelBean personnel; /** * Sets up defaults */ @Override protected void setUp() throws Exception { // Step 0. Initialize the mocks and other necessary objects. super.initMocks(); // Step 1. Initialize any other classes we need. personnel = new PersonnelBean(); personnel.setFirstName("Cosmo"); personnel.setLastName("Kramer"); personnel.setEmail("cosmo@kramer.com"); personnel.setRole(Role.LT); } /** * Tests adding a new LT * * @throws Exception * */ public void testAddLT() throws Exception { // Step 2. For each test, set up the expectations of what will be called // (started in initMocks) expect(personnelDAO.addEmptyPersonnel(Role.LT)).andReturn(5000000001L).once(); personnelDAO.editPersonnel(personnel); expectLastCall().once(); // Step 3. Exit recording mode, go into playback mode control.replay(); // Don't forget this! // Step 3. Actually run the method under test, checking its return value action = new AddLTAction(factory, 5000000002L); // this lines needs to // be AFTER the replay() long newMID = action.add(personnel); assertEquals(5000000001L, newMID); // Step 4. Verify the mocks were hit as you expected control.verify(); // Don't forget this! } }
2,007
30.873016
110
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/AddPHAActionTest.java
/** * Tests AddHCPAction in that the validator is checked and the proper DAOs are hit. * * This tests is an example of using Mock Objects. If you haven't covered this in class (yet, or at all), then * disregard this class. If you are trying to learn about unit testing with Mock Objects, this is a great * class to start with. */ package edu.ncsu.csc.itrust.unit.action; import edu.ncsu.csc.itrust.action.AddPHAAction; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.enums.Role; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.ActionTestWithMocks; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class AddPHAActionTest extends ActionTestWithMocks { private DAOFactory factory = TestDAOFactory.getTestInstance(); private PersonnelBean personnel; private TestDataGenerator gen; /** * Sets up defaults */ @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); personnel = new PersonnelBean(); personnel.setFirstName("Bob"); personnel.setLastName("Blah"); personnel.setEmail("bobblah@blarg.com"); personnel.setRole(Role.PHA); } /** * Tests adding a new PHA * * @throws Exception * */ public void testAddPHA() throws Exception { AddPHAAction action = new AddPHAAction(factory, 7000000000L); long newMID = action.add(personnel); assertEquals(7000000000L, newMID); } }
1,548
29.372549
110
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/AddPatientActionTest.java
/** * Tests for AddPatientAction */ package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.AddPatientAction; import edu.ncsu.csc.itrust.model.old.beans.PatientBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.dao.mysql.AuthDAO; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class AddPatientActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen; private AddPatientAction action; /** * Sets up defaults */ @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.transactionLog(); gen.hcp0(); action = new AddPatientAction(factory, 9000000000L); } /** * Tests adding a new patient * * @throws Exception */ public void testAddPatient() throws Exception { AuthDAO authDAO = factory.getAuthDAO(); // Add a dependent PatientBean p = new PatientBean(); p.setFirstName("Jiminy"); p.setLastName("Cricket"); p.setEmail("make.awish@gmail.com"); long newMID = action.addDependentPatient(p, 102, 9000000000L); assertEquals(p.getMID(), newMID); assertTrue(authDAO.isDependent(newMID)); // Add a non-dependent p.setFirstName("Chuck"); p.setLastName("Cheese"); p.setEmail("admin@chuckecheese.com"); newMID = action.addPatient(p, 9000000000L); assertEquals(p.getMID(), newMID); assertFalse(authDAO.isDependent(newMID)); } }
1,563
25.965517
65
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/AddPatientFileActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import edu.ncsu.csc.itrust.action.AddPatientFileAction; import edu.ncsu.csc.itrust.exception.AddPatientFileException; import edu.ncsu.csc.itrust.exception.CSVFormatException; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.dao.mysql.AuthDAO; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import junit.framework.TestCase; /** * Tests adding a patient file * */ @SuppressWarnings("unused") public class AddPatientFileActionTest extends TestCase { String fileDirectory = "testing-files/sample_patientupload/"; @Override protected void setUp() throws Exception { } /** * Test when you have valid data * * @throws CSVFormatException * @throws AddPatientFileException * @throws FileNotFoundException */ public void testValidData() throws CSVFormatException, AddPatientFileException, FileNotFoundException { DAOFactory prodDAO = DAOFactory.getProductionInstance(); AuthDAO authDAO = prodDAO.getAuthDAO(); InputStream testFile = new FileInputStream(fileDirectory + "HCPPatientUploadValidData.csv"); AddPatientFileAction apfa = new AddPatientFileAction(testFile, null, 0); assertEquals(3, apfa.getPatients().size()); assertFalse(apfa.getErrors().hasErrors()); } /** * Tests with invalid data * * @throws CSVFormatException * @throws AddPatientFileException * @throws FileNotFoundException */ public void testInvalidData() throws CSVFormatException, AddPatientFileException, FileNotFoundException { DAOFactory prodDAO = DAOFactory.getProductionInstance(); AuthDAO authDAO = prodDAO.getAuthDAO(); InputStream testFile = new FileInputStream(fileDirectory + "HCPPatientUploadInvalidData.csv"); AddPatientFileAction apfa = new AddPatientFileAction(testFile, null, 0); assertEquals(1, apfa.getPatients().size()); assertTrue(apfa.getErrors().hasErrors()); } /** * Test adding a duplicate field * * @throws CSVFormatException * @throws AddPatientFileException * @throws FileNotFoundException */ @SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE") public void testDuplicateField() throws CSVFormatException, AddPatientFileException, FileNotFoundException { DAOFactory prodDAO = DAOFactory.getProductionInstance(); AuthDAO authDAO = prodDAO.getAuthDAO(); InputStream testFile = new FileInputStream(fileDirectory + "HCPPatientUploadDuplicateField.csv"); AddPatientFileAction apfa = null; try { apfa = new AddPatientFileAction(testFile, null, 0); fail(); } catch (AddPatientFileException e) { assertNull(apfa); assertTrue(e instanceof AddPatientFileException); } } /** * Tests with an invalid header * * @throws CSVFormatException * @throws AddPatientFileException * @throws FileNotFoundException */ @SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE") public void testInvalidHeader() throws CSVFormatException, AddPatientFileException, FileNotFoundException { DAOFactory prodDAO = DAOFactory.getProductionInstance(); AuthDAO authDAO = prodDAO.getAuthDAO(); InputStream testFile = new FileInputStream(fileDirectory + "HCPPatientUploadInvalidField.csv"); AddPatientFileAction apfa = null; try { apfa = new AddPatientFileAction(testFile, null, 0); fail(); } catch (AddPatientFileException e) { assertNull(apfa); } } /** * Tests when you have a required field missing * * @throws CSVFormatException * @throws AddPatientFileException * @throws FileNotFoundException */ @SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE") public void testRequiredFieldMissing() throws CSVFormatException, AddPatientFileException, FileNotFoundException { DAOFactory prodDAO = DAOFactory.getProductionInstance(); AuthDAO authDAO = prodDAO.getAuthDAO(); InputStream testFile = new FileInputStream(fileDirectory + "HCPPatientUploadRequiredFieldMissing.csv"); AddPatientFileAction apfa = null; try { apfa = new AddPatientFileAction(testFile, null, 0); fail(); } catch (AddPatientFileException e) { assertNull(apfa); } } }
4,164
32.32
115
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/AddRemoteMonitoringDataActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.AddRemoteMonitoringDataAction; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.RemoteMonitoringDataBean; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; /** * AddRemoteMonitoringDataActionTest */ public class AddRemoteMonitoringDataActionTest extends TestCase { AddRemoteMonitoringDataAction action; private TestDataGenerator gen; @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); gen.hcp0(); gen.patient1(); gen.patient2(); action = new AddRemoteMonitoringDataAction(TestDAOFactory.getTestInstance(), 1, 1); } /** * testAddRemoteMOnitoringData * * @throws Exception */ public void testAddRemoteMonitoringData() throws Exception { try { RemoteMonitoringDataBean b = new RemoteMonitoringDataBean(); b.setGlucoseLevel(80); b.setSystolicBloodPressure(80); b.setDiastolicBloodPressure(80); action.addRemoteMonitoringData(b); } catch (FormValidationException e) { fail(); } } /** * testAddRemoteMonitoringDataUAP * * @throws Exception */ public void testAddRemoteMonitoringDataUAP() throws Exception { gen.uap1(); gen.remoteMonitoringUAP(); AddRemoteMonitoringDataAction actionUAP = new AddRemoteMonitoringDataAction(TestDAOFactory.getTestInstance(), Long.parseLong("8000000009"), 2); try { RemoteMonitoringDataBean b = new RemoteMonitoringDataBean(); b.setGlucoseLevel(80); b.setSystolicBloodPressure(80); b.setDiastolicBloodPressure(80); actionUAP.addRemoteMonitoringData(b); } catch (FormValidationException e) { fail(); } } /** * testAddRemoteMonitoringDataGlucoseOnly * * @throws Exception */ public void testAddRemoteMonitoringDataGlucoseOnly() throws Exception { try { RemoteMonitoringDataBean b = new RemoteMonitoringDataBean(); b.setGlucoseLevel(80); action.addRemoteMonitoringData(b); } catch (FormValidationException e) { fail(); } } /** * testAddRemoteMonitoringDataGlucoseOnlyUAP * * @throws Exception */ public void testAddRemoteMonitoringDataGlucoseOnlyUAP() throws Exception { gen.uap1(); gen.remoteMonitoringUAP(); AddRemoteMonitoringDataAction actionUAP = new AddRemoteMonitoringDataAction(TestDAOFactory.getTestInstance(), Long.parseLong("8000000009"), 2); try { RemoteMonitoringDataBean b = new RemoteMonitoringDataBean(); b.setGlucoseLevel(80); actionUAP.addRemoteMonitoringData(b); } catch (FormValidationException e) { fail(); } } /** * testAddRemoteMonitoringDataBloodPressureOnly * * @throws Exception */ public void testAddRemoteMonitoringDataBloodPressureOnly() throws Exception { try { RemoteMonitoringDataBean b = new RemoteMonitoringDataBean(); b.setSystolicBloodPressure(100); b.setDiastolicBloodPressure(80); action.addRemoteMonitoringData(b); } catch (FormValidationException e) { fail(); } } /** * testAddRemoteMonitoringDataBloodPressureOnlyUAP * * @throws Exception */ public void testAddRemoteMonitoringDataBloodPressureOnlyUAP() throws Exception { gen.uap1(); gen.remoteMonitoringUAP(); AddRemoteMonitoringDataAction actionUAP = new AddRemoteMonitoringDataAction(TestDAOFactory.getTestInstance(), Long.parseLong("8000000009"), 2); try { RemoteMonitoringDataBean b = new RemoteMonitoringDataBean(); b.setSystolicBloodPressure(100); b.setDiastolicBloodPressure(80); actionUAP.addRemoteMonitoringData(b); } catch (FormValidationException e) { fail(); } } /** * testAddRemoteMonitoringWeightDataOnly * * @throws Exception */ public void testAddRemoteMonitoringWeightDataOnly() throws Exception { try { RemoteMonitoringDataBean b = new RemoteMonitoringDataBean(); b.setWeight(100); action.addRemoteMonitoringData(b); } catch (FormValidationException e) { fail(); } } /** * testAddRemoteMonitoringPedometerReadingDataOnly * * @throws Exception */ public void testAddRemoteMonitoringPedometerReadingDataOnly() throws Exception { try { RemoteMonitoringDataBean b = new RemoteMonitoringDataBean(); b.setPedometerReading(1234); action.addRemoteMonitoringData(b); } catch (FormValidationException e) { fail(); } } /** * testAddRemoteMonitoringExternalDataOnly * * @throws Exception */ public void testAddRemoteMonitoringExternalDataOnly() throws Exception { try { RemoteMonitoringDataBean b = new RemoteMonitoringDataBean(); b.setWeight(122); b.setPedometerReading(1234); action.addRemoteMonitoringData(b); } catch (FormValidationException e) { fail(); } } /** * testAddRemoteMonitoringHeightWeightDataOnly * * @throws Exception */ public void testAddRemoteMonitoringHeightWeightDataOnly() throws Exception { try { RemoteMonitoringDataBean b = new RemoteMonitoringDataBean(); b.setHeight(155.2f); b.setWeight(140.0f); action.addRemoteMonitoringData(b); } catch (FormValidationException e) { fail(); } } /** * testAddBadRemoteMonitoringData * * @throws Exception */ public void testAddBadRemoteMonitoringData() throws Exception { RemoteMonitoringDataBean b = new RemoteMonitoringDataBean(); try { b.setSystolicBloodPressure(39); b.setDiastolicBloodPressure(100); action.addRemoteMonitoringData(b); fail(); } catch (FormValidationException e) { // TODO } try { b = new RemoteMonitoringDataBean(); b.setSystolicBloodPressure(240); b.setDiastolicBloodPressure(151); b.setGlucoseLevel(100); action.addRemoteMonitoringData(b); fail(); } catch (FormValidationException e) { // TODO } try { b = new RemoteMonitoringDataBean(); b.setSystolicBloodPressure(40); b.setDiastolicBloodPressure(150); b.setGlucoseLevel(1000); action.addRemoteMonitoringData(b); fail(); } catch (FormValidationException e) { // TODO } try { b = new RemoteMonitoringDataBean(); b.setSystolicBloodPressure(-5); b.setDiastolicBloodPressure(20); b.setGlucoseLevel(0); action.addRemoteMonitoringData(b); fail(); } catch (FormValidationException e) { // TODO } b = new RemoteMonitoringDataBean(); b.setSystolicBloodPressure(100); b.setDiastolicBloodPressure(80); b.setGlucoseLevel(100); for (int i = 0; i < 10; i++) action.addRemoteMonitoringData(b); try { b = new RemoteMonitoringDataBean(); b.setSystolicBloodPressure(100); b.setDiastolicBloodPressure(80); b.setGlucoseLevel(100); action.addRemoteMonitoringData(b); fail(); // Should throw an exception - 11 entries. } catch (ITrustException e) { String s = e.getMessage(); assertTrue(s.startsWith("Patient ")); assertTrue(s.endsWith(" entries for today cannot exceed 10.")); } try { b = new RemoteMonitoringDataBean(); b.setWeight(122); b.setPedometerReading(1233); action.addRemoteMonitoringData(b); action.addRemoteMonitoringData(b); fail(); // Should throw an exception - 2 entries } catch (ITrustException e) { String s = e.getMessage(); assertTrue(s.startsWith("Patient ")); assertTrue(s.endsWith(" entries for today cannot exceed 1.")); } } /** * testAddBadRemoteMonitoringWerightData * * @throws Exception */ public void testAddBadRemoteMonitoringWeightData() throws Exception { try { RemoteMonitoringDataBean b = new RemoteMonitoringDataBean(); b.setWeight(100); action.addRemoteMonitoringData(b); action.addRemoteMonitoringData(b); fail(); } catch (ITrustException e) { assertEquals("Patient weight entries for today cannot exceed 1.", e.getMessage()); } } /** * testAddBadRemoteMonitoringPedometerReadingData * * @throws Exception */ public void testAddBadRemoteMonitoringPedometerReadingData() throws Exception { try { RemoteMonitoringDataBean b = new RemoteMonitoringDataBean(); b.setPedometerReading(100); action.addRemoteMonitoringData(b); action.addRemoteMonitoringData(b); fail(); } catch (ITrustException e) { assertEquals("Patient pedometer reading entries for today cannot exceed 1.", e.getMessage()); } } /** * testRepresentativeReportStatus * * @throws Exception */ public void testRepresentativeReportStatus() throws Exception { action = new AddRemoteMonitoringDataAction(TestDAOFactory.getTestInstance(), 2, 1); try { RemoteMonitoringDataBean b = new RemoteMonitoringDataBean(); b.setPedometerReading(100); action.addRemoteMonitoringData(b); } catch (ITrustException e) { fail(); } } /** * testAddBadRemoteMonitoringGlucoseLevelData * * @throws Exception */ public void testAddBadRemoteMonitoringGlucoseLevelData() throws Exception { try { RemoteMonitoringDataBean b = new RemoteMonitoringDataBean(); b.setGlucoseLevel(100); for (int i = 0; i < 12; i++) action.addRemoteMonitoringData(b); fail(); } catch (ITrustException e) { assertEquals("Patient glucose level entries for today cannot exceed 10.", e.getMessage()); } } }
9,266
25.553009
111
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/AddUAPActionTest.java
/** * Tests for AddUAPAction */ package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.AddUAPAction; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class AddUAPActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen; private AddUAPAction action; /** * Sets up defaults */ @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); gen.hcp0(); action = new AddUAPAction(factory, 9000000000L); } /** * Tests adding a new UAP * * @throws Exception */ public void testAddUAP() throws Exception { PersonnelBean p = new PersonnelBean(); p.setFirstName("Cosmo"); p.setLastName("Kramer"); p.setEmail("cosmo@kramer.com"); long newMID = action.add(p); assertEquals(p.getMID(), newMID); } }
1,091
23.818182
65
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ApptBeanTest.java
package edu.ncsu.csc.itrust.unit.action; import edu.ncsu.csc.itrust.model.old.beans.ApptBean; import junit.framework.TestCase; public class ApptBeanTest extends TestCase { public void testApptEquals() { ApptBean b = new ApptBean(); b.setApptID(3); ApptBean a = new ApptBean(); a.setApptID(3); assertTrue(a.equals(b)); } }
338
18.941176
52
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ChangePasswordActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.ChangePasswordAction; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class ChangePasswordActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen = new TestDataGenerator(); private ChangePasswordAction action; @Override public void setUp() throws Exception { super.setUp(); gen.clearAllTables(); gen.standardData(); action = new ChangePasswordAction(factory); } public void testChangePassword() throws Exception { String response1 = action.changePassword(1L, "pw", "pass1", "pass1"); String response2 = action.changePassword(1L, "pass1", "pw1", "pw1"); String response3 = action.changePassword(1L, "pass1", "password", "password"); String response4 = action.changePassword(1L, "shallnotpass", "pass1", "pass1"); assertTrue(response1.contains("Password Changed")); assertTrue(response2.contains("Invalid password")); assertTrue(response3.contains("Invalid password")); assertTrue(response4.contains("Invalid password")); } }
1,274
34.416667
81
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ChangeSessionTimeoutActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.ChangeSessionTimeoutAction; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class ChangeSessionTimeoutActionTest extends TestCase { ChangeSessionTimeoutAction action = new ChangeSessionTimeoutAction(TestDAOFactory.getTestInstance()); public void testNotANumber() throws Exception { try { action.changeSessionTimeout("a"); fail("exception should have been thrown"); } catch (FormValidationException e) { assertEquals(1, e.getErrorList().size()); assertEquals("That is not a number", e.getErrorList().get(0)); } } public void testBadNumber() throws Exception { try { action.changeSessionTimeout("0"); fail("exception should have been thrown"); } catch (FormValidationException e) { assertEquals(1, e.getErrorList().size()); assertEquals("Must be a number greater than 0", e.getErrorList().get(0)); } } public void testFullChange() throws Exception { TestDataGenerator gen = new TestDataGenerator(); gen.timeout(); assertEquals(20, action.getSessionTimeout()); action.changeSessionTimeout("21"); assertEquals(21, action.getSessionTimeout()); } }
1,354
32.875
102
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/DeclareHCPActionExceptionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.DeclareHCPAction; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; public class DeclareHCPActionExceptionTest extends TestCase { private DeclareHCPAction action; @Override protected void setUp() throws Exception { action = new DeclareHCPAction(EvilDAOFactory.getEvilInstance(), 2L); } public void testDeclareMalformed() throws Exception { try { action.declareHCP("not a number"); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("HCP's MID not a number", e.getMessage()); } } public void testUnDeclareMalformed() throws Exception { try { action.undeclareHCP("not a number"); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("HCP's MID not a number", e.getMessage()); } } }
964
26.571429
70
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/DeclareHCPActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.util.List; import edu.ncsu.csc.itrust.action.DeclareHCPAction; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.model.old.beans.TransactionBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import junit.framework.TestCase; public class DeclareHCPActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen = new TestDataGenerator(); private DeclareHCPAction action; @Override protected void setUp() throws Exception { gen.clearAllTables(); gen.patient2(); gen.hcp0(); gen.hcp3(); action = new DeclareHCPAction(factory, 2L); } public void testGetDeclared() throws Exception { List<PersonnelBean> decs = action.getDeclaredHCPS(); assertEquals(1, decs.size()); assertEquals(9000000003L, decs.get(0).getMID()); } public void testDeclareNormal() throws Exception { assertEquals("HCP successfully declared", action.declareHCP("9000000000")); List<PersonnelBean> decs = action.getDeclaredHCPS(); assertEquals(2, decs.size()); assertEquals(9000000000L, decs.get(0).getMID()); } public void testUnDeclareNormal() throws Exception { assertEquals("HCP successfully undeclared", action.undeclareHCP("9000000003")); List<PersonnelBean> decs = action.getDeclaredHCPS(); assertEquals(0, decs.size()); } public void testDeclareAlreadyDeclared() throws Exception { try { action.declareHCP("9000000003"); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("HCP 9000000003 has already been declared for patient 2", e.getMessage()); } List<PersonnelBean> decs = action.getDeclaredHCPS(); assertEquals(1, decs.size()); assertEquals(9000000003L, decs.get(0).getMID()); // Assert the transaction List<TransactionBean> transList = factory.getTransactionDAO().getAllTransactions(); assertEquals(0, transList.size()); } public void testUnDeclareNotDeclared() throws Exception { assertEquals("HCP not undeclared", action.undeclareHCP("9000000000")); List<PersonnelBean> decs = action.getDeclaredHCPS(); assertEquals(1, decs.size()); // Assert the transaction List<TransactionBean> transList = factory.getTransactionDAO().getAllTransactions(); assertEquals(0, transList.size()); } public void testDeclareAdmin() throws Exception { gen.admin1(); try { action.declareHCP("9000000001"); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("This user is not a licensed healthcare professional!", e.getMessage()); } } }
2,809
33.268293
90
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/DrugInteractionActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.util.List; import edu.ncsu.csc.itrust.action.DrugInteractionAction; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.DrugInteractionBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import junit.framework.TestCase; public class DrugInteractionActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen = new TestDataGenerator(); private DAOFactory evilFactory = EvilDAOFactory.getEvilInstance(); private DrugInteractionAction action; @Override protected void setUp() throws Exception { super.setUp(); gen.clearAllTables(); action = new DrugInteractionAction(factory); } @Override protected void tearDown() throws Exception { super.tearDown(); } public void testReportInteraction() throws Exception { gen.ndCodes(); String response = action.reportInteraction("548684985", "081096", "May potentiate the risk of bleeding in patients."); assertSame(response, "Interaction recorded successfully"); } /** * testDeleteInteraction * * @throws Exception */ public void testDeleteInteraction() throws Exception { gen.drugInteractions(); String response = action.deleteInteraction("009042407", "548680955"); assertSame(response, "Interaction deleted successfully"); } /** * testGetInteractions * * @throws Exception */ public void testGetInteractions() throws Exception { gen.drugInteractions(); List<DrugInteractionBean> beans = action.getInteractions("009042407"); assertEquals(beans.size(), 1); assertTrue(beans.get(0).getDescription() .equals("May increase the risk of pseudotumor cerebri, or benign intracranial hypertension.")); assertTrue(beans.get(0).getFirstDrug().equals("009042407")); assertTrue(beans.get(0).getSecondDrug().equals("548680955")); } /** * testGetInteractions2 * * @throws Exception */ public void testGetInteractions2() throws Exception { gen.standardData(); action.reportInteraction("009042407", "081096", "Tetra and Aspirin"); action.reportInteraction("009042407", "647641512", "Tetra and Prio"); action.reportInteraction("548684985", "647641512", "Cital and Prio"); List<DrugInteractionBean> beans = action.getInteractions("647641512"); assertEquals(beans.size(), 2); assertTrue(beans.get(0).getDescription().equals("Tetra and Prio")); assertTrue(beans.get(0).getFirstDrug().equals("009042407")); assertTrue(beans.get(0).getSecondDrug().equals("647641512")); assertTrue(beans.get(1).getDescription().equals("Cital and Prio")); assertTrue(beans.get(1).getFirstDrug().equals("548684985")); assertTrue(beans.get(1).getSecondDrug().equals("647641512")); } /** * testReportSameDrugsInteraction * * @throws Exception */ public void testReportSameDrugsInteraction() throws Exception { gen.ndCodes(); String response = action.reportInteraction("548684985", "548684985", "Double dose"); assertEquals("Interactions can only be recorded between two different drugs", response); } /** * testReportAlreadyAdded * * @throws Exception */ public void testReportAlreadyAdded() throws Exception { gen.ndCodes(); try { String response = action.reportInteraction("548684985", "081096", "May potentiate the risk of bleeding in patients."); assertSame(response, "Interaction recorded successfully"); action.reportInteraction("548684985", "081096", "May possibly potentiate the risk of bleeding in patients."); } catch (ITrustException e) { assertSame(e.getMessage(), "Error: Interaction between these drugs already exists."); } } /** * testEvilDAOFactory * * @throws Exception */ public void testEvilDAOFactory() throws Exception { DrugInteractionAction actionEvil = new DrugInteractionAction(evilFactory); gen.drugInteractions(); try { actionEvil.deleteInteraction("009042407", "548680955"); fail(); } catch (ITrustException e) { assertSame("A database exception has occurred. Please see the log in the " + "console for stacktrace", e.getMessage()); } try { actionEvil.getInteractions("009042407"); fail(); } catch (ITrustException e) { assertSame("A database exception has occurred. Please see the log in the " + "console for stacktrace", e.getMessage()); } } }
4,562
30.909091
105
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/EditApptActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.sql.SQLException; import java.sql.Timestamp; import java.util.Calendar; import java.util.Date; import java.util.List; import edu.ncsu.csc.itrust.action.EditApptAction; import edu.ncsu.csc.itrust.action.ViewMyApptsAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.ApptBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import junit.framework.TestCase; public class EditApptActionTest extends TestCase { private EditApptAction editAction; private EditApptAction evilAction; private ViewMyApptsAction viewAction; private DAOFactory factory; private DAOFactory evilFactory; private long hcpId = 9000000000L; @Override protected void setUp() throws Exception { TestDataGenerator gen = new TestDataGenerator(); gen.clearAllTables(); gen.hcp0(); gen.patient42(); gen.appointment(); gen.appointmentType(); gen.uc22(); this.factory = TestDAOFactory.getTestInstance(); this.evilFactory = EvilDAOFactory.getEvilInstance(); this.evilAction = new EditApptAction(this.evilFactory, this.hcpId); this.editAction = new EditApptAction(this.factory, this.hcpId); this.viewAction = new ViewMyApptsAction(this.factory, this.hcpId); } public void testRemoveAppt() throws Exception { List<ApptBean> appts = viewAction.getMyAppointments(); int size = appts.size(); assertEquals("Success: Appointment removed", editAction.removeAppt(appts.get(0))); assertEquals(size - 1, viewAction.getMyAppointments().size()); editAction.removeAppt(appts.get(0)); } public void testGetAppt() throws Exception, DBException { List<ApptBean> appts = viewAction.getMyAppointments(); ApptBean b1 = appts.get(0); ApptBean b2 = editAction.getAppt(b1.getApptID()); ApptBean b3 = new ApptBean(); b3 = editAction.getAppt(1234567891); assertTrue(b3 == null); assertEquals(b1.getApptID(), b2.getApptID()); assertEquals(b1.getApptType(), b2.getApptType()); assertEquals(b1.getComment(), b2.getComment()); assertEquals(b1.getHcp(), b2.getHcp()); assertEquals(b1.getPatient(), b2.getPatient()); assertEquals(b1.getClass(), b2.getClass()); assertEquals(b1.getDate(), b2.getDate()); try { evilAction.getAppt(b1.getApptID()); } catch (DBException e) { // success! } try { evilAction.removeAppt(b1); } catch (DBException e) { // success! } } /** * testGetName * * @throws ITrustException */ public void testGetName() throws ITrustException { assertEquals("Kelly Doctor", editAction.getName(hcpId)); assertEquals("Bad Horse", editAction.getName(42)); } /** * testEditAppt * * @throws DBException * @throws SQLException * @throws FormValidationException */ public void testEditAppt() throws DBException, SQLException, FormValidationException { List<ApptBean> appts = viewAction.getAllMyAppointments(); ApptBean orig = appts.get(0); ApptBean b = new ApptBean(); b.setApptID(orig.getApptID()); b.setDate(orig.getDate()); b.setApptType(orig.getApptType()); b.setHcp(orig.getHcp()); b.setPatient(orig.getPatient()); b.setComment("New comment!"); String s = editAction.editAppt(b, true); assertTrue(s.contains("The scheduled date of this appointment")); assertTrue(s.contains("has already passed")); Date d = new Date(); boolean changed = false; for (ApptBean aBean : appts) { b = new ApptBean(); b.setApptID(aBean.getApptID()); b.setDate(aBean.getDate()); b.setApptType(aBean.getApptType()); b.setHcp(aBean.getHcp()); b.setPatient(aBean.getPatient()); b.setComment("New comment!"); d.setTime(aBean.getDate().getTime()); if (d.after(new Date())) { s = editAction.editAppt(b, true); assertEquals("Success: Appointment changed", s); changed = true; break; } } if (!changed) fail(); } /** * testEditApptConflict * * @throws Exception */ public void testEditApptConflict() throws Exception { Calendar c = Calendar.getInstance(); c.add(Calendar.DATE, 12); c.set(Calendar.HOUR, 9); c.set(Calendar.AM_PM, Calendar.AM); c.set(Calendar.MINUTE, 45); List<ApptBean> appts = viewAction.getMyAppointments(); ApptBean orig = appts.get(0); ApptBean b = new ApptBean(); b.setApptID(orig.getApptID()); b.setDate(new Timestamp(c.getTimeInMillis())); b.setApptType(orig.getApptType()); b.setHcp(orig.getHcp()); b.setPatient(orig.getPatient()); String s = editAction.editAppt(b, false); assertTrue(s.contains("conflict")); } /** * testEvilFactory * * @throws DBException * @throws SQLException * @throws FormValidationException */ public void testEvilFactory() throws DBException, SQLException, FormValidationException { this.editAction = new EditApptAction(EvilDAOFactory.getEvilInstance(), this.hcpId); List<ApptBean> appts = viewAction.getMyAppointments(); ApptBean x = appts.get(0); try { editAction.editAppt(x, true); } catch (DBException e) { // this should pass if DBexception is thrown } try { editAction.editAppt(x, true); } catch (DBException e) { // this should pass if DBexception is thrown } try { assertEquals(null, editAction.getAppt(x.getApptID())); } catch (DBException e) { // this should pass if DBexception is thrown } } }
5,607
27.04
90
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/EditApptTypeTest.java
package edu.ncsu.csc.itrust.unit.action; import java.sql.SQLException; import edu.ncsu.csc.itrust.action.EditApptTypeAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.model.old.beans.ApptTypeBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import junit.framework.TestCase; public class EditApptTypeTest extends TestCase { private EditApptTypeAction action; private DAOFactory factory; private long adminId = 9000000001L; @Override protected void setUp() throws Exception { TestDataGenerator gen = new TestDataGenerator(); gen.clearAllTables(); gen.standardData(); this.factory = TestDAOFactory.getTestInstance(); this.action = new EditApptTypeAction(this.factory, this.adminId); } public void testGetApptTypes() throws SQLException, DBException { assertEquals(6, action.getApptTypes().size()); } public void testAddApptType() throws SQLException, FormValidationException, DBException { ApptTypeBean a = new ApptTypeBean(); a.setName("Test"); a.setDuration(30); assertTrue(action.addApptType(a).startsWith("Success")); assertEquals(7, action.getApptTypes().size()); } public void testAddApptType2() throws SQLException, FormValidationException, DBException { ApptTypeBean a = new ApptTypeBean(); a.setName("General Checkup"); a.setDuration(30); assertTrue(action.addApptType(a).equals("Appointment Type: General Checkup already exists.")); } public void testEditApptType() throws SQLException, FormValidationException, DBException { ApptTypeBean a = new ApptTypeBean(); a.setName("General Checkup"); a.setDuration(30); assertTrue(action.editApptType(a).startsWith("Success")); } public void testEditApptType2() throws SQLException, FormValidationException, DBException { ApptTypeBean a = new ApptTypeBean("General Checkup", 45); assertEquals("Appointment Type: General Checkup already has a duration of 45 minutes.", action.editApptType(a)); } public void testAddApptTypeLengthZero() throws SQLException, DBException { ApptTypeBean a = new ApptTypeBean(); a.setName("Test"); a.setDuration(0); try { action.addApptType(a); } catch (FormValidationException e) { // Exception is good. return; } assertTrue(false); } public void testEditNonExistentApptType() throws SQLException, FormValidationException, DBException { ApptTypeBean a = new ApptTypeBean(); a.setName("NonExistent"); a.setDuration(30); assertEquals("Appointment Type: " + a.getName() + " you are trying to update does not exist.", action.editApptType(a)); } }
2,767
30.454545
114
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/EditMonitoringListActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.EditMonitoringListAction; import edu.ncsu.csc.itrust.model.old.beans.TelemedicineBean; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class EditMonitoringListActionTest extends TestCase { EditMonitoringListAction action; private TestDataGenerator gen; @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); gen.hcp0(); gen.patient1(); action = new EditMonitoringListAction(TestDAOFactory.getTestInstance(), 9000000000L); } public void testAddToRemoveFromList() throws Exception { TelemedicineBean tBean = new TelemedicineBean(); assertTrue(action.addToList(1L, tBean)); assertFalse(action.addToList(1L, tBean)); assertTrue(action.removeFromList(1L)); assertFalse(action.removeFromList(1L)); } public void testIsPatientInList() throws Exception { TelemedicineBean tBean = new TelemedicineBean(); action.addToList(1L, tBean); assertTrue(action.isPatientInList(1)); assertFalse(action.isPatientInList(2)); } }
1,191
31.216216
87
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/EditPatientActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.EditPatientAction; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.PatientBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.dao.mysql.AuthDAO; import edu.ncsu.csc.itrust.model.old.dao.mysql.PatientDAO; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import edu.ncsu.csc.itrust.exception.FormValidationException; public class EditPatientActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen = new TestDataGenerator(); private EditPatientAction action; @Override protected void setUp() throws Exception { gen.clearAllTables(); gen.patient2(); action = new EditPatientAction(factory, 9000000000L, "2"); } public void testConstructNormal() throws Exception { assertEquals(2L, action.getPid()); } public void testNonExistent() throws Exception { try { action = new EditPatientAction(factory, 0L, "200"); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("Patient does not exist", e.getMessage()); } } public void testEditRepresentatives() throws Exception { action = new EditPatientAction(factory, 2l, "2"); PatientDAO po = new PatientDAO(factory); PatientBean pb = po.getPatient(2); assertEquals("Andy", pb.getFirstName()); assertEquals("Programmer", pb.getLastName()); assertEquals("0", pb.getFatherMID()); pb.setFatherMID("1"); assertEquals("1", pb.getFatherMID()); action.updateInformation(pb); PatientBean pb2 = po.getPatient(2); assertEquals("Andy", pb2.getFirstName()); assertEquals("Programmer", pb2.getLastName()); assertEquals("1", pb2.getFatherMID()); } public void testEditCOD() throws Exception { gen.patient1(); action = new EditPatientAction(factory, 1L, "1"); PatientDAO po = TestDAOFactory.getTestInstance().getPatientDAO(); PatientBean pb = po.getPatient(1l); assertEquals("Random", pb.getFirstName()); assertEquals("", pb.getCauseOfDeath()); assertEquals("", pb.getDateOfDeathStr()); pb.setCauseOfDeath("79.1"); pb.setDateOfDeathStr("01/03/2006"); action.updateInformation(pb); PatientBean pb2 = po.getPatient(1l); assertEquals("Random", pb2.getFirstName()); assertEquals("79.1", pb2.getCauseOfDeath()); assertEquals("01/03/2006", pb2.getDateOfDeathStr()); } public void testInvalidDates() throws Exception { gen.patient3(); action = new EditPatientAction(factory, 3L, "3"); PatientDAO po = TestDAOFactory.getTestInstance().getPatientDAO(); PatientBean pb = po.getPatient(3l); try { pb.setCauseOfDeath("79.1"); pb.setDateOfDeathStr("01/03/2050"); action.updateInformation(pb); fail("exception should have been thrown on invalid date of death"); } catch (FormValidationException e) { // test passes, exception should have been thrown } try { pb.setDateOfBirthStr("01/03/2050"); action.updateInformation(pb); fail("exception should have been thrown on invalid date of birth"); } catch (FormValidationException e) { // test passes, exception should have been thrown } } public void testWrongFormat() throws Exception { try { action = new EditPatientAction(factory, 0L, "hello!"); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("Patient ID is not a number: hello!", e.getMessage()); } } public void testNull() throws Exception { try { action = new EditPatientAction(factory, 0L, null); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("Patient ID is not a number: null", e.getMessage()); } } public void testGetPatientLogged() throws Exception { PatientBean patient = action.getPatient(); assertEquals(2L, patient.getMID()); } public void testDeactivateActivate() throws Exception { gen.patient1(); action = new EditPatientAction(factory, 1L, "1"); PatientDAO po = TestDAOFactory.getTestInstance().getPatientDAO(); action.deactivate(1L); PatientBean pb1 = po.getPatient(1l); assertFalse(pb1.getDateOfDeactivationStr().equals("")); action.activate(); PatientBean pb2 = po.getPatient(1l); assertTrue(pb2.getDateOfDeactivationStr().equals("")); } public void testIsDependent() throws Exception { // Check that patient 2 is not a dependent assertFalse(action.isDependent()); // Change patient 2's dependency status AuthDAO authDAO = factory.getAuthDAO(); authDAO.setDependent(2L, true); // Check that patient 2 is a dependent assertTrue(action.isDependent()); } public void testSetDependent() throws Exception { // 2 represents 1, but not 4 gen.patient1(); gen.patient4(); // Add patient 4 to be represented by patient 2 PatientDAO patientDAO = new PatientDAO(factory); patientDAO.addRepresentative(2L, 4L); // Ensure the representatives were added correctly assertEquals(2, patientDAO.getRepresented(2L).size()); // Make patient 2 a dependent assertTrue(action.setDependent(true)); // Assert that no more patients are represented by patient 2 assertTrue(patientDAO.getRepresented(2L).isEmpty()); // Check patient 2's dependency status AuthDAO authDAO = factory.getAuthDAO(); assertTrue(authDAO.isDependent(2L)); // Make patient 2 not a dependent assertTrue(action.setDependent(false)); // Check that patient 2 is not a dependent assertFalse(authDAO.isDependent(2L)); } }
5,620
31.491329
70
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/EditPersonnelActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.EditPersonnelAction; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class EditPersonnelActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen = new TestDataGenerator(); private EditPersonnelAction personnelEditor; @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); } public void testNotAuthorized() throws Exception { gen.standardData(); try { personnelEditor = new EditPersonnelAction(factory, 9000000000L, "9000000003"); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("You can only edit your own demographics!", e.getMessage()); } } public void testNotAuthorized2() throws Exception { gen.standardData(); try { personnelEditor = new EditPersonnelAction(factory, 9000000000L, "9000000001"); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("You are not authorized to edit this record!", e.getMessage()); } } public void testNonExistent() throws Exception { try { personnelEditor = new EditPersonnelAction(factory, 0L, "8999999999"); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("Personnel does not exist", e.getMessage()); } } public void testWrongFormat() throws Exception { try { gen.hcp0(); personnelEditor = new EditPersonnelAction(factory, 0L, "hello!"); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("Personnel ID is not a number: For input string: \"hello!\"", e.getMessage()); } } public void testNull() throws Exception { try { gen.hcp0(); personnelEditor = new EditPersonnelAction(factory, 0L, null); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("Personnel ID is not a number: null", e.getMessage()); } } public void testUpdateInformation() throws Exception { gen.uap1(); personnelEditor = new EditPersonnelAction(factory, 8000000009L, "8000000009"); PersonnelBean j = factory.getPersonnelDAO().getPersonnel(8000000009l); j.setStreetAddress2("second line"); personnelEditor.updateInformation(j, 8000000009L); j = factory.getPersonnelDAO().getPersonnel(8000000009l); assertEquals("second line", j.getStreetAddress2()); } }
2,741
32.439024
94
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/EditRepresentativesActionTest.java
package edu.ncsu.csc.itrust.unit.action; import static edu.ncsu.csc.itrust.unit.testutils.JUnitiTrustUtils.assertTransactionsNone; import java.util.List; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.EditRepresentativesAction; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.PatientBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class EditRepresentativesActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen = new TestDataGenerator(); private EditRepresentativesAction action; @Override protected void setUp() throws Exception { gen.clearAllTables(); gen.patient1(); // 2 represents 1, but not 4 gen.patient2(); gen.patient4(); gen.multiplePatients_old(); } public void testGetRepresentatives() throws Exception { action = new EditRepresentativesAction(factory, 9000000000L, "2"); List<PatientBean> reps = action.getRepresented(2L); assertEquals(1, reps.size()); assertEquals(1L, reps.get(0).getMID()); } public void testAddRepresentee() throws Exception { action = new EditRepresentativesAction(factory, 9000000000L, "2"); action.addRepresentee("4"); List<PatientBean> reps = action.getRepresented(2); assertEquals(2, reps.size()); assertEquals(4L, reps.get(1).getMID()); } public void testRemoveRepresentee() throws Exception { action = new EditRepresentativesAction(factory, 9000000000L, "2"); action.removeRepresentee("1"); List<PatientBean> reps = action.getRepresented(2); assertEquals(0, reps.size()); } public void testAddNotNumber() throws Exception { action = new EditRepresentativesAction(factory, 9000000000L, "2"); assertEquals("MID not a number", action.addRepresentee("a")); assertEquals("MID not a number", action.removeRepresentee("a")); } public void testRemoveNothing() throws Exception { action = new EditRepresentativesAction(factory, 9000000000L, "2"); assertEquals("No change made", action.removeRepresentee("2")); assertTransactionsNone(); assertEquals(1, action.getRepresented(2).size()); } public void testCannotRepresentSelf() throws Exception { action = new EditRepresentativesAction(factory, 9000000000L, "2"); try { action.addRepresentee("2"); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("This user cannot represent themselves.", e.getMessage()); } assertTransactionsNone(); assertEquals(1, action.getRepresented(2).size()); } public void testNotAPatient() throws Exception { action = new EditRepresentativesAction(factory, 9000000000L, "2"); assertEquals("No change made", action.removeRepresentee("9000000000")); assertTransactionsNone(); assertEquals(1, action.getRepresented(2).size()); } public void testCheckIfPatientIsActive() throws ITrustException { action = new EditRepresentativesAction(factory, 9000000000L, "2"); assertFalse(action.checkIfPatientIsActive(9000000000L)); assertFalse(action.checkIfPatientIsActive(0L)); } public void testGetRepresentativeName() throws Exception { action = new EditRepresentativesAction(factory, 9000000000L, "2"); assertEquals("Andy Programmer", action.getRepresentativeName()); } /** * Tests that non patients cannot add representatives */ public void testNonPatientAddRepresentative() { try { action = new EditRepresentativesAction(factory, 9000000000L, "2"); action.addRepresentee("9000000071"); fail("Representee is not a patient"); } catch (ITrustException e) { assertTrue(e.getMessage().contains("This user is not a patient")); } } }
3,795
33.509091
89
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/EventLoggingActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.sql.SQLException; import edu.ncsu.csc.itrust.action.EventLoggingAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.model.old.beans.TransactionBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.dao.mysql.TransactionDAO; import edu.ncsu.csc.itrust.model.old.enums.TransactionType; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import junit.framework.TestCase; import java.util.List; public class EventLoggingActionTest extends TestCase { private EventLoggingAction action; private DAOFactory factory; private long mid = 1L; @Override protected void setUp() throws Exception { TestDataGenerator gen = new TestDataGenerator(); gen.clearAllTables(); factory = TestDAOFactory.getTestInstance(); action = new EventLoggingAction(factory); } public void testGetTransactions() throws FormValidationException, SQLException { try { action.logEvent(TransactionType.LOGIN_FAILURE, mid, 0, ""); TransactionDAO dao = factory.getTransactionDAO(); List<TransactionBean> all = dao.getAllTransactions(); boolean passes = false; for (TransactionBean log : all) { if (log.getLoggedInMID() == mid && log.getTransactionType() == TransactionType.LOGIN_FAILURE) { passes = true; break; } } if (!passes) { fail(); } } catch (DBException e) { fail(); } } }
1,580
28.830189
99
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/FindExpertActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.FindExpertAction; import edu.ncsu.csc.itrust.model.old.beans.CustomComparator; import edu.ncsu.csc.itrust.model.old.beans.HospitalBean; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class FindExpertActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen = new TestDataGenerator(); private FindExpertAction fea; private PersonnelBean person, person1; @Override protected void setUp() throws Exception { fea = new FindExpertAction(factory); gen.clearAllTables(); person = new PersonnelBean(); person1 = new PersonnelBean(); person1.setMID(40L); person.setMID(900000000L); } /** * Tests that you can find all of the experts you should be able to */ public void testFindExperts() { List<HospitalBean> hospitals = new ArrayList<HospitalBean>(); HospitalBean realHospital = new HospitalBean(); HospitalBean anotherHospital = new HospitalBean(); hospitals.add(realHospital); hospitals.add(anotherHospital); // Test a single result assertTrue(fea.findExperts(hospitals, "ob/gyn").size() == 1); CustomComparator c = new CustomComparator(); int apple = c.compare(person, person1); // tests compares two PersonnelBeans from the CustomComparator class // using the compare method assertTrue((900000000 - 40) == apple); } /** * Tests that you can filter out the hospitals */ public void testFilterHospitals() { HospitalBean hospitalZero = new HospitalBean(); HospitalBean hospitalOne = new HospitalBean(); HospitalBean blankHospital = new HospitalBean(); HospitalBean nullHospital = new HospitalBean(); List<HospitalBean> hospitals = new ArrayList<HospitalBean>(); hospitalZero.setHospitalZip("00000"); hospitalOne.setHospitalZip("11111"); hospitalOne.setHospitalZip(null); hospitals.add(hospitalZero); hospitals.add(hospitalOne); hospitals.add(blankHospital); hospitals.add(nullHospital); assertTrue(fea.filterHospitals(hospitals, "00000", 5).size() == 1); assertTrue(fea.filterHospitals(hospitals, "00001", 4).size() == 1); assertTrue(fea.filterHospitals(hospitals, "00011", 3).size() == 1); assertTrue(fea.filterHospitals(hospitals, "00111", 2).size() == 1); assertTrue(fea.filterHospitals(hospitals, "01111", 1).size() == 1); } /** * Tests that you can find hospitals by their specialty */ public void testFindHospitalsBySpecialty() { assertTrue(fea.findHospitalsBySpecialty("ob/gyn", "00000", 5).size() == 0); } }
2,845
30.977528
77
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/GenerateCalendarActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.sql.SQLException; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Hashtable; import java.util.List; import java.util.Date; import edu.ncsu.csc.itrust.action.AddApptAction; import edu.ncsu.csc.itrust.action.GenerateCalendarAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.model.old.beans.ApptBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import junit.framework.TestCase; public class GenerateCalendarActionTest extends TestCase { private GenerateCalendarAction action; private DAOFactory factory; private long mId = 2L; private long hcpId = 9000000000L; @Override protected void setUp() throws Exception { super.setUp(); TestDataGenerator gen = new TestDataGenerator(); gen.clearAllTables(); gen.standardData(); this.factory = TestDAOFactory.getTestInstance(); this.action = new GenerateCalendarAction(factory, mId); } public void testGetApptsTable() throws SQLException, DBException { Hashtable<Integer, ArrayList<ApptBean>> aTable = action .getApptsTable(Calendar.getInstance().get(Calendar.MONTH), Calendar.getInstance().get(Calendar.YEAR)); assertTrue(aTable.containsKey(5)); assertTrue(aTable.containsKey(18)); assertTrue(aTable.containsKey(28)); } public void testGetSend() throws SQLException, DBException { action.getApptsTable(Calendar.getInstance().get(Calendar.MONTH), Calendar.getInstance().get(Calendar.YEAR)); List<ApptBean> aList = action.getSend(); SimpleDateFormat year = new SimpleDateFormat("yyyy"); SimpleDateFormat month = new SimpleDateFormat("-MM"); Date now = Calendar.getInstance().getTime(); Timestamp FirstDayOfMonth = Timestamp.valueOf("" + year.format(now) + month.format(now) + "-01 00:00:00"); Timestamp LastDayOfMonth = Timestamp.valueOf("" + year.format(now) + month.format(now) + "-31 23:59:59"); for (int i = 0; i < aList.size(); i++) { assertTrue(aList.get(i).getDate().after(FirstDayOfMonth)); assertTrue(aList.get(i).getDate().before(LastDayOfMonth)); } } /** * testGetConflicts * * @throws Exception */ public void testGetConflicts() throws Exception { TestDataGenerator gen = new TestDataGenerator(); gen.clearAllTables(); gen.hcp0(); gen.patient2(); gen.appointmentType(); Calendar startDate = Calendar.getInstance(); startDate.set(Calendar.HOUR, 0); startDate.setTimeInMillis(startDate.getTimeInMillis() + 1000 * 60 * 60 * 24); ApptBean b = new ApptBean(); b.setApptType("General Checkup"); b.setHcp(hcpId); b.setPatient(mId); b.setDate(new Timestamp(startDate.getTimeInMillis() + (10 * 60 * 1000))); b.setComment(null); AddApptAction schedAction = new AddApptAction(factory, hcpId); try { assertTrue(schedAction.addAppt(b, true).startsWith("Success")); } catch (FormValidationException e1) { fail(); } b = new ApptBean(); b.setApptType("Physical"); b.setHcp(hcpId); b.setPatient(01L); b.setDate(new Timestamp(startDate.getTimeInMillis() + (20 * 60 * 1000))); b.setComment(null); try { assertTrue(schedAction.addAppt(b, true).startsWith("Success")); } catch (FormValidationException e) { fail(); } b = new ApptBean(); b.setApptType("Colonoscopy"); b.setHcp(hcpId); b.setPatient(mId); b.setDate(new Timestamp(startDate.getTimeInMillis() + (60 * 60 * 1000))); b.setComment(null); try { assertTrue(schedAction.addAppt(b, true).startsWith("Success")); } catch (FormValidationException e) { fail(); } this.action = new GenerateCalendarAction(factory, hcpId); action.getApptsTable(startDate.get(Calendar.MONTH), startDate.get(Calendar.YEAR)); boolean conflicts[] = action.getConflicts(); assertTrue(conflicts[0]); assertTrue(conflicts[1]); assertFalse(conflicts[2]); } }
4,075
30.114504
110
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/GetUserNameActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.GetUserNameAction; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class GetUserNameActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen = new TestDataGenerator(); @Override protected void setUp() throws Exception { gen.clearAllTables(); } public void testCorrectFormat() throws Exception { gen.hcp0(); assertEquals("Kelly Doctor", new GetUserNameAction(factory).getUserName("9000000000")); } public void testWrongFormat() throws Exception { gen.hcp0(); try { new GetUserNameAction(factory).getUserName("90000000aaa01"); fail("Exception should have been thrown"); } catch (ITrustException e) { assertEquals("MID not in correct form", e.getMessage()); } } }
1,062
30.264706
89
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/GroupReportActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.util.ArrayList; import java.util.List; import edu.ncsu.csc.itrust.action.GroupReportAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.model.old.beans.GroupReportBean; import edu.ncsu.csc.itrust.model.old.beans.PatientBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.report.DemographicReportFilter; import edu.ncsu.csc.itrust.report.MedicalReportFilter.MedicalReportFilterType; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import edu.ncsu.csc.itrust.report.ReportFilter; import edu.ncsu.csc.itrust.report.DemographicReportFilter.DemographicReportFilterType; import junit.framework.TestCase; public class GroupReportActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen = new TestDataGenerator(); private GroupReportAction action; @Override protected void setUp() throws Exception { gen.clearAllTables(); gen.standardData(); action = new GroupReportAction(factory, 1l); } public void testGenerateReport() { List<ReportFilter> f = new ArrayList<ReportFilter>(); f.add(new DemographicReportFilter(DemographicReportFilterType.LAST_NAME, "Person", factory)); GroupReportBean res = action.generateReport(f); assertTrue(res.getPatients().size() == 1); assertEquals(1L, res.getPatients().get(0).getMID()); } public void testGetComprehensiveDemographicInfo() throws DBException { PatientBean b = factory.getPatientDAO().getPatient(2L); for (DemographicReportFilterType filterType : DemographicReportFilterType.values()) { String res = action.getComprehensiveDemographicInfo(b, filterType); switch (filterType) { case GENDER: assertEquals("Male", res); break; case LAST_NAME: assertEquals("Programmer", res); break; case FIRST_NAME: assertEquals("Andy", res); break; case CONTACT_EMAIL: assertEquals("andy.programmer@gmail.com", res); break; case STREET_ADDR: assertEquals("344 Bob Street ", res); break; case CITY: assertEquals("Raleigh", res); break; case STATE: assertEquals("NC", res); break; case ZIP: assertEquals("27607", res); break; case PHONE: assertEquals("555-555-5555", res); break; case EMER_CONTACT_NAME: assertEquals("Mr Emergency", res); break; case EMER_CONTACT_PHONE: assertEquals("555-555-5551", res); break; case INSURE_NAME: assertEquals("IC", res); break; case INSURE_ADDR: assertEquals("Street1 Street2", res); break; case INSURE_CITY: assertEquals("City", res); break; case INSURE_STATE: assertEquals("PA", res); break; case INSURE_ZIP: assertEquals("19003-2715", res); break; case INSURE_PHONE: assertEquals("555-555-5555", res); break; case INSURE_ID: assertEquals("1", res); break; case PARENT_FIRST_NAME: assertEquals("Random\n", res); break; case PARENT_LAST_NAME: assertEquals("Person\n", res); break; case CHILD_FIRST_NAME: assertEquals("Baby\nBaby\nBaby\nBaby\n", res); break; case CHILD_LAST_NAME: assertEquals("Programmer\nA\nB\nC\n", res); break; case SIBLING_FIRST_NAME: assertEquals("Care\nNoRecords\nBowser\nPrincess\n", res); break; case SIBLING_LAST_NAME: assertEquals("Needs\nHas\nKoopa\nPeach\n", res); break; default: break; } } } public void testGetComprehensiveMedicalInfo() throws DBException { PatientBean b = factory.getPatientDAO().getPatient(2L); for (MedicalReportFilterType filterType : MedicalReportFilterType.values()) { String res = action.getComprehensiveMedicalInfo(b, filterType); switch (filterType) { case ALLERGY: assertEquals("\n664662530\n", res); break; default: break; } } } }
3,961
27.710145
95
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/GroupReportGeneratorActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.easymock.classextension.EasyMock; import edu.ncsu.csc.itrust.action.GroupReportGeneratorAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.report.DemographicReportFilter; import edu.ncsu.csc.itrust.report.PersonnelReportFilter; import edu.ncsu.csc.itrust.report.ReportFilter; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import junit.framework.TestCase; public class GroupReportGeneratorActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen = new TestDataGenerator(); private GroupReportGeneratorAction gpga; @Override protected void setUp() throws Exception { gen.clearAllTables(); gen.standardData(); } /** * testGenerateReport * @throws DBException */ public void testGenerateReport() throws DBException { List<ReportFilter> filters = new ArrayList<ReportFilter>(); filters.add(new DemographicReportFilter(DemographicReportFilter.filterTypeFromString("DEACTIVATED"), "exclude", factory)); filters.add(new PersonnelReportFilter(PersonnelReportFilter.filterTypeFromString("DLHCP"), "Gandalf Stormcrow", factory)); gpga = new GroupReportGeneratorAction(factory, filters, 1l); gpga.generateReport(); assertEquals(2, gpga.getReportFilterTypes().size()); assertEquals(2, gpga.getReportFilterValues().size()); assertEquals("DEACTIVATED", gpga.getReportFilterTypes().get(0).toString()); assertEquals("exclude", gpga.getReportFilterValues().get(0)); assertEquals("DECLARED HCP", gpga.getReportFilterTypes().get(1).toString()); assertEquals("Gandalf Stormcrow", gpga.getReportFilterValues().get(1)); int deactivatedIndex = gpga.getReportHeaders().indexOf("DEACTIVATED"); int DHCPIndex = gpga.getReportHeaders().indexOf("DECLARED HCP"); for (int i = 0; i < gpga.getReportData().size(); i++) { assertEquals("", gpga.getReportData().get(i).get(deactivatedIndex)); assertEquals("Gandalf Stormcrow\n", gpga.getReportData().get(i).get(DHCPIndex)); } } /** * testParseFilters * @throws DBException */ public void testParseFilters() throws DBException { HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class); org.easymock.EasyMock.expect(request.getParameter("demoparams")).andReturn("MID").anyTimes(); org.easymock.EasyMock.expect(request.getParameter("medparams")).andReturn("ALLERGY").anyTimes(); org.easymock.EasyMock.expect(request.getParameter("persparams")).andReturn(" ").anyTimes(); org.easymock.EasyMock.expect(request.getParameter("MID")).andReturn("1").anyTimes(); org.easymock.EasyMock.expect(request.getParameterValues("ALLERGY")).andReturn(new String[0]).anyTimes(); org.easymock.EasyMock.expect(request.getParameter("ALLERGY")).andReturn(" ").anyTimes(); EasyMock.replay(request); GroupReportGeneratorAction grga = new GroupReportGeneratorAction(factory, request, 1l); grga.getReportData(); } }
3,206
40.649351
113
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/LoginFailureActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.LoginFailureAction; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class LoginFailureActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private DAOFactory evil = EvilDAOFactory.getEvilInstance(); private TestDataGenerator gen; private LoginFailureAction action; @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); action = new LoginFailureAction(factory, "192.168.1.1"); } public void testNormalLoginFailureSequence() throws Exception { assertTrue(action.isValidForLogin()); assertEquals("Login failed, attempt 1", action.recordLoginFailure()); assertTrue(action.isValidForLogin()); assertEquals("Login failed, attempt 2", action.recordLoginFailure()); assertTrue(action.isValidForLogin()); assertEquals("Login failed, attempt 3", action.recordLoginFailure()); assertFalse(action.isValidForLogin()); } public void testRecordLoginFailureEvil() throws Exception { action = new LoginFailureAction(evil, "192.168.1.1"); assertEquals("A database exception has occurred. Please see the log in the " + "console for stacktrace", action.recordLoginFailure()); } public void testIsValidForLoginEvil() throws Exception { action = new LoginFailureAction(evil, "192.168.1.1"); assertEquals(false, action.isValidForLogin()); } public void testNeedsCaptcha() throws Exception { assertEquals(0, action.getFailureCount()); assertFalse(action.needsCaptcha()); action.recordLoginFailure(); assertFalse(action.needsCaptcha()); action.recordLoginFailure(); assertFalse(action.needsCaptcha()); assertEquals(2, action.getFailureCount()); action.recordLoginFailure(); assertTrue(action.needsCaptcha()); assertEquals(3, action.getFailureCount()); action.resetFailures(); assertFalse(action.needsCaptcha()); assertEquals(0, action.getFailureCount()); } public void testSetCaptcha() throws Exception { action.setCaptcha(true); assertEquals(true, action.isValidForLogin()); } public void testEvilFactory() throws Exception { action = new LoginFailureAction(evil, "192.168.1.1"); assertEquals(false, action.needsCaptcha()); assertEquals(0, action.getFailureCount()); } }
2,541
32.447368
106
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ManageHospitalAssignmentsActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.io.IOException; import java.sql.SQLException; import java.util.List; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.ManageHospitalAssignmentsAction; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.HospitalBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; /** * ManageHospitalAssignmentsActionTest */ public class ManageHospitalAssignmentsActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private DAOFactory evil = EvilDAOFactory.getEvilInstance(); private ManageHospitalAssignmentsAction action; private ManageHospitalAssignmentsAction ltAction; private TestDataGenerator gen = new TestDataGenerator(); private final static long performingAdmin = 9000000001L; private final static long hcp0 = 9000000000L; private final static long lt0 = 5000000000L; private final static String hosp0 = "1"; private final static String hosp1 = "9191919191"; private final static String hosp2 = "8181818181"; @Override protected void setUp() throws Exception { gen.clearAllTables(); gen.hcp0(); gen.admin1(); gen.hospitals(); gen.clearHospitalAssignments(); gen.ltData0(); action = new ManageHospitalAssignmentsAction(factory, performingAdmin); ltAction = new ManageHospitalAssignmentsAction(factory, lt0); } private String doAssignment() throws ITrustException { return action.assignHCPToHospital("" + hcp0, hosp0); } private String doAssignment(String hospitalID) throws ITrustException { return action.assignHCPToHospital("" + hcp0, hospitalID); } /** * testAssignHCPToHospital * * @throws ITrustException */ public void testAssignHCPToHospital() throws ITrustException { assertEquals("HCP successfully assigned.", doAssignment()); List<HospitalBean> h = action.getAssignedHospitals("" + hcp0); assertEquals(1, h.size()); assertEquals("1", h.get(0).getHospitalID()); } /** * testAssignHCPToHospitalEvil */ public void testAssignHCPToHospitalEvil() { action = new ManageHospitalAssignmentsAction(evil, performingAdmin); try { action.getAssignedHospitals("" + hcp0); fail(); } catch (ITrustException e) { assertEquals(EvilDAOFactory.MESSAGE, e.getExtendedMessage()); } } /** * testAssignDuplicate * * @throws ITrustException */ public void testAssignDuplicate() throws ITrustException { assertEquals("HCP successfully assigned.", doAssignment()); try { doAssignment(); fail("testAssignDuplicate failed: assignHCPToHospital should have thrown exception"); } catch (ITrustException e) { assertEquals("HCP 9000000000 already assigned to hospital 1", e.getMessage()); } } /** * testRemovePersonnelAssignmentToHospital * * @throws ITrustException */ public void testRemovePersonnelAssignmentToHospital() throws ITrustException { doAssignment(); assertEquals("HCP successfully unassigned", action.removeHCPAssignmentToHospital("" + hcp0, hosp0)); assertEquals(0, action.getAssignedHospitals("" + hcp0).size()); } /** * testRemoveNonAssigned * * @throws ITrustException */ public void testRemoveNonAssigned() throws ITrustException { assertEquals("HCP not unassigned", action.removeHCPAssignmentToHospital("" + hcp0, hosp0)); } /** * testRemoveAll * * @throws ITrustException * @throws Exception */ public void testRemoveAll() throws ITrustException, Exception { doAssignment(); doAssignment(hosp1); doAssignment(hosp2); assertEquals(3, action.getAssignedHospitals("" + hcp0).size()); assertEquals(3, action.removeAllAssignmentsFromHCP("" + hcp0)); assertEquals(0, action.getAssignedHospitals("" + hcp0).size()); } /** * testRemoveAllEvil */ public void testRemoveAllEvil() { action = new ManageHospitalAssignmentsAction(evil, performingAdmin); try { action.removeAllAssignmentsFromHCP("" + hcp0); fail(); } catch (ITrustException e) { // TODO } } /** * testRemoveAllUnassigned * * @throws ITrustException */ public void testRemovaAllUnassigned() throws ITrustException { assertEquals(0, action.removeAllAssignmentsFromHCP("" + hcp0)); } /** * testCheckHCPIDBadMID */ public void testCheckHCPIDBadMID() { try { action.checkHCPID("90000000001"); fail(); } catch (ITrustException e) { // TODO } } /** * testCheckHCPID * * @throws ITrustException */ public void testCheckHCPID() throws ITrustException { assertEquals(9000000000L, action.checkHCPID("9000000000")); } /** * testCheckHCPIDStringMID */ public void testCheckHCPIDStringMID() { try { action.checkHCPID("f"); fail(); } catch (ITrustException e) { // TODO } } /** * testCheckHCPIDEvil */ public void testCheckHCPIDEvil() { try { action = new ManageHospitalAssignmentsAction(evil, performingAdmin); action.checkHCPID("9000000000"); fail(); } catch (ITrustException e) { // TODO } } /** * testGetAvailableHospitals * * @throws ITrustException */ public void testGetAvailableHospitals() throws ITrustException { assertSame(9, action.getAvailableHospitals("9000000000").size()); } /** * testGetAvailableHospitalsBadMID */ public void testGetAvailableHospitalsBadMID() { try { action.getAvailableHospitals("f"); fail(); } catch (ITrustException e) { // TODO } } /** * testGetAssignedHospitalsBadMID */ public void testGetAssignedHospitalsBadMID() { try { action.getAssignedHospitals("f"); fail(); } catch (ITrustException e) { // TODO } } /** * testAssignHCPToHospitalBadID */ public void testAssignHCPToHospitalBadID() { try { action.assignHCPToHospital("f", "1"); fail(); } catch (ITrustException e) { // TODO } } /** * testRemoveHCPtoHospitalBADID */ public void testRemoveHCPtoHospitalBadID() { try { action.removeHCPAssignmentToHospital("f", "1"); fail(); } catch (ITrustException e) { // TODO } } /** * testRemoveHCPAssignmentsBadID */ public void testRemoveHCPAssignmentsBadID() { try { action.removeAllAssignmentsFromHCP("l"); fail(); } catch (ITrustException e) { // TODO } } /** * New Method to check and make sure LTs only have 1 hospital * * @throws ITrustException * @throws IOException * @throws SQLException */ public void testCheckLTHospital() throws ITrustException, IOException, SQLException { assertTrue(ltAction.checkLTHospital("5000000001")); gen.clearHospitalAssignments(); assertFalse(ltAction.checkLTHospital("5000000001")); } /** * This method checks to make sure checkLTHospital method can correctly * handle and illegal MID. */ public void testCheckLTIDStringMID() { try { assertFalse(ltAction.checkLTHospital("ABCD")); fail(); } catch (ITrustException e) { // TODO } } }
7,075
23.068027
102
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/PatientBaseActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.base.PatientBaseAction; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; public class PatientBaseActionTest extends TestCase { public void testEvilDatabase() { try { new PatientBaseAction(EvilDAOFactory.getEvilInstance(), "2222"); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("A database exception has occurred. Please see the log in the console for stacktrace", e.getMessage()); } } }
623
30.2
102
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/PatientRoomAssignmentActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.PatientRoomAssignmentAction; import edu.ncsu.csc.itrust.model.old.beans.PatientBean; import edu.ncsu.csc.itrust.model.old.beans.WardRoomBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.dao.mysql.WardDAO; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; /** */ public class PatientRoomAssignmentActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen = new TestDataGenerator(); private PatientRoomAssignmentAction action; private WardDAO wardDAO; private PatientBean patient = new PatientBean(); @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); gen.standardData(); wardDAO = new WardDAO(factory); } /** * testassignPatient * * @throws Exception */ public void testassignPatient() throws Exception { WardRoomBean rm = new WardRoomBean(1, 1, 1, "test", "clean"); wardDAO.removeWardRoom(rm.getRoomID()); action = new PatientRoomAssignmentAction(factory); action.assignPatientToRoom(rm, 1); assertEquals(0, wardDAO.getAllWardRoomsByWardID(0).size()); wardDAO.removeWardRoom(rm.getRoomID()); patient.setMID(1L); action.assignPatientToRoom(rm, patient); } }
1,454
30.630435
65
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/PayBillActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.PayBillAction; import edu.ncsu.csc.itrust.action.ViewMyBillingAction; import edu.ncsu.csc.itrust.model.old.beans.BillingBean; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class PayBillActionTest extends TestCase { private ViewMyBillingAction assistantAction; private long mid = 311L; // Sean Ford private PayBillAction action; private BillingBean billBean; @Override public void setUp() throws Exception { super.setUp(); TestDataGenerator gen = new TestDataGenerator(); gen.clearAllTables(); gen.standardData(); gen.uc60(); assistantAction = new ViewMyBillingAction(TestDAOFactory.getTestInstance(), this.mid); billBean = assistantAction.getAllMyBills().get(1); action = new PayBillAction(TestDAOFactory.getTestInstance(), billBean.getBillID()); } public void testPayBillWithCC() throws Exception { String testCC = "4539592576502361"; String thirtyOne = "1234567890123456789012345678901"; assertEquals("The field for Credit Card Type must be filled.", action.payBillWithCC(null, null, null, null, null)); assertEquals("Invalid Credit Card number.", action.payBillWithCC("11", null, "Visa", null, null)); assertEquals("The field for Credit Card Holder must be filled.", action.payBillWithCC(testCC, null, "Visa", null, null)); assertEquals("The Credit Card Holder must be 30 characters or shorter.", action.payBillWithCC(testCC, thirtyOne, "Visa", null, null)); assertEquals("The field for Credit Card Type must be filled.", action.payBillWithCC(testCC, "Bob", "null", null, null)); assertEquals("The field for the Credit Card Type must be 20 or shorter.", action.payBillWithCC(testCC, "Bob", thirtyOne, null, null)); assertEquals("The field for Billing Address must be filled.", action.payBillWithCC(testCC, "Bob", "Visa", null, null)); assertEquals("The fields for Billing Address must be 120 characters or shorter.", action.payBillWithCC(testCC, "Bob", "Visa", thirtyOne + thirtyOne + thirtyOne + thirtyOne + thirtyOne, null)); assertEquals("The field for CVV must be filled.", action.payBillWithCC(testCC, "Bob", "Visa", "123 Fake St", null)); assertEquals("Invalid CVV code.", action.payBillWithCC(testCC, "Bob", "Visa", "123 Fake St", "abc")); assertNull(action.payBillWithCC(testCC, "Bob", "Visa", "123 Fake St.", "111")); billBean = action.getBill(); assertFalse(billBean.isInsurance()); assertEquals("Submitted", billBean.getStatus()); } public void testPayBillWithIns() throws Exception { String eT = "555-555-5555"; String t1 = "123456789012345678901"; assertEquals("The field for Insurance Holder must be filled.", action.payBillWithIns(null, null, null, null, null, null, null, null, null)); assertEquals("The field for Insurance Provider must be filled.", action.payBillWithIns("Bob", null, null, null, null, null, null, null, null)); assertEquals("The Insurance Provider must be 20 characters or shorter.", action.payBillWithIns("Bob", t1, null, null, null, null, null, null, null)); assertEquals("The field for Insurance Policy ID must be filled.", action.payBillWithIns("Bob", "Blue Cross", null, null, null, null, null, null, null)); assertEquals("Insurance IDs must consist of alphanumeric characters.", action.payBillWithIns("Bob", "Blue Crosss", "!@#%?", null, null, null, null, null, null)); assertEquals("The field for Insurance Address 1 must be filled.", action.payBillWithIns("Bob", "Blue Cross", "132345", null, null, null, null, null, null)); assertEquals("The field for Insurnace Address 1 must be 20 characters or shorter.", action.payBillWithIns("Bob", "Blue Cross", "132345", t1, null, null, null, null, null)); assertEquals("The field for Insurance Address 2 must be filled.", action.payBillWithIns("Bob", "Blue Cross", "132345", "123 Fake St.", null, null, null, null, null)); assertEquals("The field for Insurnace Address 2 must 20 characters or shorter.", action.payBillWithIns("Bob", "Blue Cross", "132345", "123 Fake St.", t1, null, null, null, null)); assertEquals("The field for Insurance City must be filled.", action.payBillWithIns("Bob", "Blue Cross", "132345", "123 Fake St.", "123 Faker St.", null, null, null, null)); assertEquals("The field for Insurance City must be 20 characters or shorter.", action.payBillWithIns("Bob", "Blue Cross", "132345", "123 Fake St.", "123 Faker St.", t1, null, null, null)); assertEquals("The field for Insurance State must be filled.", action.payBillWithIns("Bob", "Blue Cross", "132345", "123 Fake St.", "123 Faker St.", "Raleigh", null, null, null)); assertEquals("The field for Insurance State must be 2 characters.", action.payBillWithIns("Bob", "Blue Cross", "132345", "123 Fake St.", "123 Faker St.", "Raleigh", "NCS", null, null)); assertEquals("The field for Insurance Zip must be filled.", action.payBillWithIns("Bob", "Blue Cross", "132345", "123 Fake St.", "123 Faker St.", "Raleigh", "NC", null, null)); assertEquals("The field for Insurance Phone must be filled.", action.payBillWithIns("Bob", "Blue Cross", "132345", "123 Fake St.", "123 Faker St.", "Raleigh", "NC", "27606", null)); assertEquals("Insurance Phone Number must match the form \"XXX-XXX-XXXX\"", action.payBillWithIns("Bob", "Blue Cross", "132345", "123 Fake St.", "123 Faker St.", "Raleigh", "NC", "27606", "1")); assertNull(action.payBillWithIns("Bob", "Blue Cross", "132345", "123 Fake St.", "123 Faker St.", "Raleigh", "NC", "27606", eT)); billBean = action.getBill(); assertEquals(1, billBean.getSubmissions()); assertTrue(billBean.isInsurance()); assertEquals("Pending", billBean.getStatus()); } }
5,870
55.451923
114
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ResetPasswordActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.util.List; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.ResetPasswordAction; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.Email; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.dao.mysql.FakeEmailDAO; import edu.ncsu.csc.itrust.model.old.validate.ValidationFormat; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class ResetPasswordActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private DAOFactory evil = EvilDAOFactory.getEvilInstance(); private FakeEmailDAO feDAO = factory.getFakeEmailDAO(); private ResetPasswordAction action; private TestDataGenerator gen; @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); action = new ResetPasswordAction(factory); } public void testCheckMID() throws Exception { gen.patient1(); gen.hcp0(); assertEquals("empty", 0, action.checkMID("")); assertEquals("null", 0, action.checkMID(null)); assertEquals("not a number", 0, action.checkMID("a")); assertEquals("non-existant", 0, action.checkMID("200")); assertEquals("existant", 1, action.checkMID("1")); assertEquals("existant", 9000000000L, action.checkMID("9000000000")); } public void testCheckMIDEvil() throws Exception { action = new ResetPasswordAction(evil); assertEquals(0l, action.checkMID("")); } public void testCheckMIDEvil2() throws Exception { action = new ResetPasswordAction(evil); assertEquals(0l, action.checkMID("a")); } public void testCheckRole() throws Exception { gen.patient2(); gen.hcp0(); gen.uap1(); assertEquals("patient", action.checkRole(2L, "patient")); assertEquals("hcp", action.checkRole(9000000000L, "hcp")); assertEquals("uap", action.checkRole(8000000009L, "uap")); assertEquals(null, action.checkRole(0L, "admin")); assertEquals(null, action.checkRole(0L, "HCP")); } public void testCheckWrongRole() { try { action.checkRole(9000000000L, "patient"); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("User does not exist with the designated role", e.getMessage()); } } public void testCheckAnswerNull() throws Exception { assertEquals("empty", null, action.checkAnswerNull("")); assertEquals("null", null, action.checkAnswerNull(null)); assertEquals("answer", action.checkAnswerNull("answer")); } public void testGetSecurityQuestion() throws Exception { gen.patient1(); gen.hcp0(); assertEquals("what is your favorite color?", action.getSecurityQuestion(1l)); assertEquals("first letter?", action.getSecurityQuestion(9000000000L)); assertEquals("first letter?", action.getSecurityQuestion(9000000000L)); } public void testGetSecurityQuestionEvil() throws Exception { action = new ResetPasswordAction(EvilDAOFactory.getEvilInstance()); assertEquals("", action.getSecurityQuestion(1l)); } public void testResetPassword() throws Exception { gen.patient1(); gen.hcp0(); assertEquals("Answer did not match", action.resetPassword(1L, "patient", "wrong", "12345678", "12345678", "127.0.0.1")); assertEquals("Answer did not match", action.resetPassword(9000000000L, "hcp", "wrong", "12345678", "12345678", "127.0.0.1")); assertEquals("Invalid role", action.resetPassword(9000000000L, "a", "a", "12345678", "12345678", "127.0.0.1")); assertEquals("Password changed", action.resetPassword(1L, "patient", "blue", "12345678", "12345678", "127.0.0.1")); List<Email> list = feDAO.getAllEmails(); assertTrue(list.get(0).getBody().contains("Dear Random Person,")); assertTrue(list.get(0).getBody().contains("You have chosen to change your iTrust password for user 1")); assertEquals("Role mismatch", action.resetPassword(9000000000L, "uap", "a", "12345678", "12345678", "127.0.0.1")); } public void testResetForHCP() throws Exception { gen.hcp0(); assertEquals("Password changed", action.resetPassword(9000000000L, "hcp", "a", "12345678", "12345678", "127.0.0.1")); List<Email> list = feDAO.getAllEmails(); assertTrue(list.get(0).getBody().contains("Dear Kelly Doctor,")); assertTrue( list.get(0).getBody().contains("You have chosen to change your iTrust password for user 9000000000")); } public void testValidatePasswordNull() throws Exception { gen.patient1(); try { action.resetPassword(1L, "patient", "blue", null, "12345678", "127.0.0.1"); fail("exception should have been thrown"); } catch (FormValidationException e) { assertEquals("Password cannot be empty", e.getErrorList().get(0)); assertEquals(1, e.getErrorList().size()); } } public void testValidatePasswordEmpty() throws Exception { gen.patient1(); try { action.resetPassword(1L, "patient", "blue", "", "12345678", "127.0.0.1"); fail("exception should have been thrown"); } catch (FormValidationException e) { assertEquals("Password cannot be empty", e.getErrorList().get(0)); assertEquals(1, e.getErrorList().size()); } } public void testValidatePasswordWrong() throws Exception { gen.patient1(); try { action.resetPassword(1L, "patient", "blue", "1234567", "12345678", "127.0.0.1"); fail("exception should have been thrown"); } catch (FormValidationException e) { assertEquals("Passwords don't match", e.getErrorList().get(0)); assertEquals("Password must be in the following format: " + ValidationFormat.PASSWORD.getDescription(), e.getErrorList().get(1)); assertEquals(2, e.getErrorList().size()); } } }
5,847
36.487179
113
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ReviewsActionTest.java
package edu.ncsu.csc.itrust.unit.action; import static org.junit.Assert.*; import java.util.Date; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import edu.ncsu.csc.itrust.action.ReviewsAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.model.old.beans.ReviewsBean; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; /** * Verify the effectiveness of the ReviewsAction class. */ public class ReviewsActionTest { /** constant id's for testing */ private static final long PID1 = 9000000000L, PID2 = 9000000003L, MID = 42L; private static ReviewsAction act; private static ReviewsBean beanValid, beanInvalid; private static final String REVDESC = "I don't know what just happened."; private static final Date REVDATE = new java.sql.Date(new Date().getTime()); private static final double AVGRATING = 2.5; private static final int LISTLEN = 4; /** * Set up for the rest of the tests * * @throws Exception */ @Before public void setUp() throws Exception { act = new ReviewsAction(TestDAOFactory.getTestInstance(), MID); TestDataGenerator gen = new TestDataGenerator(); gen.clearAllTables(); gen.standardData(); gen.uc61reviews(); beanValid = new ReviewsBean(); beanValid.setMID(MID); beanValid.setPID(PID1); beanValid.setDescriptiveReview(REVDESC); beanValid.setDateOfReview(REVDATE); beanValid.setRating(2); beanInvalid = new ReviewsBean(); beanInvalid.setMID(MID); beanInvalid.setPID(PID2); beanInvalid.setDescriptiveReview(REVDESC); beanInvalid.setDateOfReview(REVDATE); beanInvalid.setRating(2); } @After public void tearDown() throws Exception { } /** * Tests that when a ReviewsBean is added it truly is valid. */ @Test public final void testAddReviewValid() { try { assertTrue(act.addReview(beanValid)); } catch (DBException e) { fail(); } } /** * Test to make sure that you are able to get a correct ReviewsBean. */ @Test public final void testGetReviews() { // check to make sure that the list size is the same try { List<ReviewsBean> l = act.getReviews(PID1); assertEquals(LISTLEN, l.size()); } catch (DBException e) { fail(); } } /** * Test to make sure that you are able to get a correct Rating for average * rating. */ @Test public final void testGetAverageRating() { try { assertTrue(AVGRATING == act.getAverageRating(PID1)); } catch (DBException e) { fail(); } } /** * Test to ensure you can get a physician */ @Test public void testGetPhysician() { try { PersonnelBean physician = act.getPhysician(9000000000L); assertEquals("Kelly", physician.getFirstName()); assertEquals("Doctor", physician.getLastName()); assertEquals("hcp", physician.getRoleString()); } catch (DBException e) { fail("Physician exists"); } } /** * Tests that a patient can rate his physician */ @Test public void testIsAbleToRate() { try { assertTrue(act.isAbleToRate(PID1)); } catch (DBException d) { fail("DBException"); } } }
3,217
23.564885
77
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/SearchUsersActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.util.List; import edu.ncsu.csc.itrust.action.EditPatientAction; import edu.ncsu.csc.itrust.action.SearchUsersAction; import edu.ncsu.csc.itrust.model.old.beans.PatientBean; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import junit.framework.TestCase; /** * SearchUsersActionTest */ public class SearchUsersActionTest extends TestCase { private TestDataGenerator gen = new TestDataGenerator(); private DAOFactory factory = TestDAOFactory.getTestInstance(); private DAOFactory evil = EvilDAOFactory.getEvilInstance(); @Override public void setUp() throws Exception { gen.clearAllTables(); gen.standardData(); } /** * testSearchForPatienstWithName */ public void testSearchForPatientsWithName() { SearchUsersAction act = new SearchUsersAction(factory, 9000000000L); List<PatientBean> patients = act.searchForPatientsWithName("Random", "Person"); assertEquals("Random Person", patients.get(0).getFullName()); } /** * testSearchForPatietnsWithName2 */ public void testSearchForPatientsWithName2() { SearchUsersAction act = new SearchUsersAction(factory, 9000000003L); List<PatientBean> patient = act.searchForPatientsWithName("Andy", "Programmer"); assertEquals("Andy Programmer", patient.get(0).getFullName()); } /** * testSearchForPatientsWithName3 */ public void testSearchForPatientsWithName3() { SearchUsersAction act = new SearchUsersAction(factory, 9000000003L); List<PatientBean> patient = act.searchForPatientsWithName("", ""); assertEquals(0, patient.size()); } /** * testFuzzySearchForPatient1 */ public void testFuzzySearchForPatient1() { SearchUsersAction act = new SearchUsersAction(factory, 9000000003L); List<PatientBean> patient = act.fuzzySearchForPatients("Andy"); assertEquals("Andy Programmer", patient.get(0).getFullName()); } /** * testFuzzySearchForPatient2 */ public void testFuzzySearchForPatient2() { SearchUsersAction act = new SearchUsersAction(factory, 9000000003L); List<PatientBean> patient = act.fuzzySearchForPatients("nd grammer"); assertEquals("Andy Programmer", patient.get(0).getFullName()); } /** * testFuzzySearchForPatient3 */ public void testFuzzySearchForPatient3() { SearchUsersAction act = new SearchUsersAction(factory, 9000000003L); List<PatientBean> patient = act.fuzzySearchForPatients("2"); assertEquals("Andy Programmer", patient.get(0).getFullName()); } public void testFuzzySearchForPatientDeactivated() { SearchUsersAction act = new SearchUsersAction(factory, 9000000003L); List<PatientBean> patient = act.fuzzySearchForPatients("314159"); assertEquals(patient.size(), 0); } /** * testFuzzySearchForPatientDeactivatedOverride */ public void testFuzzySearchForPatientDeactivatedOverride() { SearchUsersAction act = new SearchUsersAction(factory, 9000000003L); List<PatientBean> patient = act.fuzzySearchForPatients("314159", true); assertEquals("Fake Baby", patient.get(0).getFullName()); } /** * testSearchForPersonnelWithName */ public void testSearchForPersonnelWithName() { SearchUsersAction act = new SearchUsersAction(factory, 9000000000L); List<PersonnelBean> personnel = act.searchForPersonnelWithName("Kelly", "Doctor"); assertEquals("Kelly Doctor", personnel.get(0).getFullName()); } /** * testSearchForPersonnelWithName2 */ public void testSearchForPersonnelWithName2() { SearchUsersAction act = new SearchUsersAction(factory, 9000000003L); List<PersonnelBean> personnel = act.searchForPersonnelWithName("", ""); assertEquals(0, personnel.size()); } /** * testSearchForPersonnelWithName3 */ public void testSearchForPersonnelWithName3() { SearchUsersAction act = new SearchUsersAction(evil, 2L); List<PersonnelBean> personnel = act.searchForPersonnelWithName("null", "null"); assertEquals(null, personnel); } @Override public void tearDown() throws Exception { } /** * testZeroPatients * * @throws Exception */ public void testZeroPatients() throws Exception { SearchUsersAction action = new SearchUsersAction(factory, 9990000000L); List<PatientBean> patients = action.searchForPatientsWithName("A", "B"); assertNotNull(patients); assertEquals(0, patients.size()); } public void testDeactivated() throws Exception { SearchUsersAction action = new SearchUsersAction(factory, 9990000000L); EditPatientAction dis = new EditPatientAction(factory, 1L, "1"); dis.deactivate(1L); List<PatientBean> deact = action.getDeactivated(); assertEquals(2, deact.size()); assertNotNull(deact.get(0).getDateOfDeactivationStr()); assertNotNull(deact.get(1).getDateOfDeactivationStr()); } /** * testFuzzySearchForExpert */ public void testFuzzySearchForExpert() { SearchUsersAction act = new SearchUsersAction(factory, 9000000003L); List<PersonnelBean> patient = act.fuzzySearchForExperts("Andy"); assertEquals(0, patient.size()); patient = act.fuzzySearchForExperts("Gandal"); assertEquals(1, patient.size()); assertEquals("Gandalf", patient.get(0).getFirstName()); } }
5,338
31.754601
84
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/SendMessageActionTest.java
package edu.ncsu.csc.itrust.unit.action; import edu.ncsu.csc.itrust.action.SendMessageAction; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.MessageBean; import edu.ncsu.csc.itrust.model.old.beans.PatientBean; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.dao.mysql.MessageDAO; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import java.sql.SQLException; import java.sql.Timestamp; import java.util.GregorianCalendar; import java.util.List; import junit.framework.TestCase; public class SendMessageActionTest extends TestCase { private DAOFactory factory; private GregorianCalendar gCal; private MessageDAO messageDAO; private SendMessageAction smAction; private TestDataGenerator gen; private long patientId; private long hcpId; @Override protected void setUp() throws Exception { super.setUp(); gen = new TestDataGenerator(); gen.clearAllTables(); gen.standardData(); patientId = 2L; hcpId = 9000000000L; factory = TestDAOFactory.getTestInstance(); messageDAO = new MessageDAO(this.factory); smAction = new SendMessageAction(this.factory, this.patientId); gCal = new GregorianCalendar(); } public void testSendMessage() throws ITrustException, SQLException, FormValidationException { String body = "UNIT TEST - SendMessageActionText"; MessageBean mBean = new MessageBean(); Timestamp timestamp = new Timestamp(this.gCal.getTimeInMillis()); mBean.setFrom(this.patientId); mBean.setTo(this.hcpId); mBean.setSubject(body); mBean.setSentDate(timestamp); mBean.setBody(body); this.smAction.sendMessage(mBean); List<MessageBean> mbList = this.messageDAO.getMessagesForMID(this.hcpId); assertEquals(15, mbList.size()); MessageBean mBeanDB = mbList.get(0); assertEquals(body, mBeanDB.getBody()); } public void testGetPatientName() throws ITrustException { assertEquals("Andy Programmer", this.smAction.getPatientName(this.patientId)); } public void testGetPersonnelName() throws ITrustException { assertEquals("Kelly Doctor", this.smAction.getPersonnelName(this.hcpId)); } public void testGetMyRepresentees() throws ITrustException { List<PatientBean> pbList = smAction.getMyRepresentees(); assertEquals(7, pbList.size()); assertEquals("Random Person", pbList.get(0).getFullName()); assertEquals("05/10/1950", pbList.get(0).getDateOfBirthStr()); assertEquals("Care Needs", pbList.get(1).getFullName()); assertEquals("Baby Programmer", pbList.get(2).getFullName()); assertEquals("Baby A", pbList.get(3).getFullName()); assertEquals("Baby B", pbList.get(4).getFullName()); assertEquals("Baby C", pbList.get(5).getFullName()); assertEquals(7, pbList.size()); assertEquals("Sandy Sky", pbList.get(6).getFullName()); } public void testGetMyDLHCPs() throws ITrustException { List<PersonnelBean> pbList = this.smAction.getDLHCPsFor(this.patientId); assertEquals(1, pbList.size()); } public void testGetMyDLHCPs2() throws ITrustException { List<PersonnelBean> pbList = this.smAction.getMyDLHCPs(); assertEquals(1, pbList.size()); } public void testGetDLCHPsFor() throws ITrustException { List<PersonnelBean> pbList = this.smAction.getDLHCPsFor(this.patientId); assertEquals(1, pbList.size()); } }
3,505
32.075472
94
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/SetSecurityQuestionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.SetSecurityQuestionAction; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.SecurityQA; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class SetSecurityQuestionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private DAOFactory evil = EvilDAOFactory.getEvilInstance(); private TestDataGenerator gen; private SetSecurityQuestionAction action; @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); } public void testNotUserID() throws Exception { try { action = new SetSecurityQuestionAction(factory, 500L); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("MID 500 is not a user!", e.getMessage()); } } public void testBadConnection() throws Exception { gen.patient2(); try { action = new SetSecurityQuestionAction(evil, 2L); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals(EvilDAOFactory.MESSAGE, e.getExtendedMessage()); } } public void testRetriveInformation() throws Exception { gen.patient2(); action = new SetSecurityQuestionAction(factory, 2L); SecurityQA qa = action.retrieveInformation(); assertEquals("how you doin?", qa.getQuestion()); assertEquals("good", qa.getAnswer()); } public void testUpdateInformationCorrectly() throws Exception { gen.patient2(); action = new SetSecurityQuestionAction(factory, 2L); SecurityQA qa = action.retrieveInformation(); qa.setAnswer("12345678"); qa.setConfirmAnswer("12345678"); qa.setQuestion("12345678"); action.updateInformation(qa); qa = action.retrieveInformation(); assertEquals("12345678", qa.getAnswer()); assertEquals("12345678", qa.getQuestion()); } }
2,110
31.984375
65
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/UpdateHospitalListActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.UpdateHospitalListAction; import edu.ncsu.csc.itrust.model.old.beans.HospitalBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; /** * UpdateHospitalListActionTest */ public class UpdateHospitalListActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private UpdateHospitalListAction action; private TestDataGenerator gen = new TestDataGenerator(); private long performingAdmin = 9000000001L; @Override protected void setUp() throws Exception { action = new UpdateHospitalListAction(factory, performingAdmin); gen.clearAllTables(); gen.admin1(); gen.hospitals(); } private String getAddHospitalSuccessString(HospitalBean proc) { return "Success: " + proc.getHospitalID() + " - " + proc.getHospitalName() + " added"; } /** * KILLS-- M FAIL: edu.ncsu.csc.itrust.action.UpdateHospitalListAction:35: * changed return value (areturn) */ public void testEvilFactory() { action = new UpdateHospitalListAction(EvilDAOFactory.getEvilInstance(), 0L); HospitalBean db = new HospitalBean("2223", "ananana"); try { String x = action.addHospital(db); assertEquals("A database exception has occurred. Please see the log in the console for stacktrace", x); } catch (Exception e) { // TODO } } /** * KILLS-- M FAIL: edu.ncsu.csc.itrust.action.UpdateHospitalListAction:49: * changed return value (areturn) */ public void testEvilFactory2() { action = new UpdateHospitalListAction(EvilDAOFactory.getEvilInstance(), 0L); HospitalBean db = new HospitalBean("2223", "ananana"); try { String x = action.updateInformation(db); assertEquals("A database exception has occurred. Please see the log in the console for stacktrace", x); } catch (Exception e) { // TODO } } private void addEmpty(String id) throws Exception { HospitalBean hosp = new HospitalBean(id, " "); assertEquals(getAddHospitalSuccessString(hosp), action.addHospital(hosp)); hosp = factory.getHospitalsDAO().getHospital(id); assertEquals(" ", hosp.getHospitalName()); } /** * testAddHospital * * @throws Exception */ public void testAddHospital() throws Exception { String id = "9999999999"; String name = "testAddHospital Hospital"; HospitalBean hosp = new HospitalBean(id, name); assertEquals(getAddHospitalSuccessString(hosp), action.addHospital(hosp)); hosp = factory.getHospitalsDAO().getHospital(id); assertEquals(name, hosp.getHospitalName()); } /** * Kills: M FAIL: edu.ncsu.csc.itrust.action.UpdateHospitalListAction:27: * CP[64] "added hospital " -> "___jumble___" M FAIL: * edu.ncsu.csc.itrust.action.UpdateHospitalListAction:27: 0L -> 1L */ public void testAddHospital2() throws Exception { String id = "88888888"; String name = "Test Hospital"; HospitalBean hosp = new HospitalBean(id, name); assertEquals(getAddHospitalSuccessString(hosp), action.addHospital(hosp)); hosp = factory.getHospitalsDAO().getHospital(id); assertEquals(name, hosp.getHospitalName()); } /** * testAddDuplicate * * @throws Exception */ public void testAddDuplicate() throws Exception { String id = "0000000000"; String name0 = "hospital 0"; HospitalBean hosp = new HospitalBean(id, name0); assertEquals(getAddHospitalSuccessString(hosp), action.addHospital(hosp)); hosp.setHospitalName("hospital 1"); assertEquals("Error: Hospital already exists.", action.addHospital(hosp)); hosp = factory.getHospitalsDAO().getHospital(id); assertEquals(name0, hosp.getHospitalName()); } /** * testUpdatreICDInformation * * @throws Exception */ public void testUpdateICDInformation0() throws Exception { String id = "8888888888"; String name = "new hospital 8..."; HospitalBean hosp = new HospitalBean(id); addEmpty(id); hosp.setHospitalName(name); assertEquals("Success: 1 row(s) updated", action.updateInformation(hosp)); hosp = factory.getHospitalsDAO().getHospital(id); assertEquals(name, hosp.getHospitalName()); } /** * testUpdateNonExistent * * @throws Exception */ public void testUpdateNonExistent() throws Exception { String id = "9999999999"; HospitalBean hosp = new HospitalBean(id, "shouldn't be here"); assertEquals("Error: Hospital not found.", action.updateInformation(hosp)); assertEquals(null, factory.getHospitalsDAO().getHospital(id)); assertEquals(9, factory.getHospitalsDAO().getAllHospitals().size()); } /** * testAddAddress * * @throws Exception */ public void testAddAddress() throws Exception { String id = "9999999999"; HospitalBean hosp = new HospitalBean(id, "shouldn't be here", "Address", "City", "ST", "00000-0000"); action.addHospital(hosp); hosp = factory.getHospitalsDAO().getHospital(id); assertEquals("Address", hosp.getHospitalAddress()); assertEquals("City", hosp.getHospitalCity()); assertEquals("ST", hosp.getHospitalState()); assertEquals("00000-0000", hosp.getHospitalZip()); } /** * testUpdateAddress * * @throws Exception */ public void testUpdateAddress() throws Exception { String id = "8888888888"; String name = "new hospital 8..."; HospitalBean hosp = new HospitalBean(id, name, "Address", "City", "ST", "00000-0000"); addEmpty(id); hosp.setHospitalName(name); assertEquals("Success: 1 row(s) updated", action.updateInformation(hosp)); hosp = factory.getHospitalsDAO().getHospital(id); assertEquals("Address", hosp.getHospitalAddress()); assertEquals("City", hosp.getHospitalCity()); assertEquals("ST", hosp.getHospitalState()); assertEquals("00000-0000", hosp.getHospitalZip()); } }
5,877
31.837989
106
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/UpdateNDCodeListActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.UpdateNDCodeListAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.model.old.beans.MedicationBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; /** * UpdateNDCodeListActionTest */ public class UpdateNDCodeListActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private UpdateNDCodeListAction action; private final static long performingAdmin = 9000000001L; private TestDataGenerator gen = new TestDataGenerator(); @Override protected void setUp() throws Exception { action = new UpdateNDCodeListAction(factory, performingAdmin); gen.clearAllTables(); gen.admin1(); gen.ndCodes(); } private String getAddCodeSuccessString(MedicationBean proc) { return "Success: " + proc.getNDCode() + " - " + proc.getDescription() + " added"; } /** * testEvilFactory */ public void testEvilFactory() { action = new UpdateNDCodeListAction(EvilDAOFactory.getEvilInstance(), 0L); MedicationBean mb = new MedicationBean(); mb.setDescription("description"); mb.setNDCode("3657"); try { String x = action.addNDCode(mb); assertEquals("A database exception has occurred. Please see the log in the console for stacktrace", x); } catch (Exception e) { // TODO } try { String x = action.updateInformation(mb); assertEquals("A database exception has occurred. Please see the log in the console for stacktrace", x); } catch (Exception e) { // TODO } try { String x = action.removeNDCode(mb); assertEquals("A database exception has occurred. Please see the log in the console for stacktrace", x); } catch (Exception e) { // TODO } } private void addEmpty(String code) throws Exception { MedicationBean med = new MedicationBean(code, " "); assertEquals(getAddCodeSuccessString(med), action.addNDCode(med)); med = factory.getNDCodesDAO().getNDCode(code); assertEquals(" ", med.getDescription()); } /** * testAddNDCode * * @throws Exception */ public void testAddNDCode() throws Exception { final String code = "999999999"; final String desc = "UpdateNDCodeListActionTest testAddNDCode"; MedicationBean proc = new MedicationBean(code, desc); assertEquals(getAddCodeSuccessString(proc), action.addNDCode(proc)); proc = factory.getNDCodesDAO().getNDCode(code); assertEquals(desc, proc.getDescription()); } /** * testAddDuplicate * * @throws DBException * @throws FormValidationException */ public void testAddDuplicate() throws DBException, FormValidationException { final String code = "999999999"; final String descrip0 = "description 0"; MedicationBean proc = new MedicationBean(code, descrip0); assertEquals(getAddCodeSuccessString(proc), action.addNDCode(proc)); proc.setDescription("description 1"); assertEquals("Error: Code already exists.", action.addNDCode(proc)); proc = factory.getNDCodesDAO().getNDCode(code); assertEquals(descrip0, proc.getDescription()); } /** * testUpdateNDInformation0 * * @throws Exception */ public void testUpdateNDInformation0() throws Exception { final String code = "888888888"; final String desc = "new descrip 0"; MedicationBean proc = new MedicationBean(code); addEmpty(code); proc.setDescription(desc); assertEquals("Success: 1 row(s) updated", action.updateInformation(proc)); proc = factory.getNDCodesDAO().getNDCode(code); assertEquals(desc, proc.getDescription()); } /** * testUpdateNonExistent * * @throws Exception */ public void testUpdateNonExistent() throws Exception { final String code = "999999999"; MedicationBean proc = new MedicationBean(code, "shouldnt be here"); assertEquals("Error: Code not found.", action.updateInformation(proc)); assertEquals(null, factory.getNDCodesDAO().getNDCode(code)); assertEquals(5, factory.getNDCodesDAO().getAllNDCodes().size()); } /** * testRemoveNDCode * * @throws Exception */ public void testRemoveNDCode() throws Exception { final String code = "999999999"; final String desc = "UpdateNDCodeListActionTest testAddNDCode"; MedicationBean proc = new MedicationBean(code, desc); assertEquals(getAddCodeSuccessString(proc), action.addNDCode(proc)); proc = factory.getNDCodesDAO().getNDCode(code); assertEquals(desc, proc.getDescription()); action.removeNDCode(proc); assertNull(factory.getNDCodesDAO().getNDCode(code)); } /** * testRemoveNonExistent * * @throws Exception */ public void testRemoveNonExistent() throws Exception { final String code = "999999999"; MedicationBean proc = new MedicationBean(code, "shouldnt be here"); assertEquals("Drug does not exist or already has been removed from the database.", action.removeNDCode(proc)); assertEquals(null, factory.getNDCodesDAO().getNDCode(code)); assertEquals(5, factory.getNDCodesDAO().getAllNDCodes().size()); } }
5,224
31.453416
112
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/UpdateORCListActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.UpdateReasonCodeListAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.model.old.beans.MedicationBean; import edu.ncsu.csc.itrust.model.old.beans.OverrideReasonBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; /** * UpdateORCListActionTest */ public class UpdateORCListActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private UpdateReasonCodeListAction action; private final static long performingAdmin = 9000000001L; private TestDataGenerator gen = new TestDataGenerator(); @Override protected void setUp() throws Exception { action = new UpdateReasonCodeListAction(factory, performingAdmin); gen.clearAllTables(); gen.admin1(); } @SuppressWarnings("unused") private String getAddCodeSuccessString(MedicationBean proc) { return "Success: " + proc.getNDCode() + " - " + proc.getDescription() + " added"; } /** * testEvilFacotry */ public void testEvilFactory() { action = new UpdateReasonCodeListAction(EvilDAOFactory.getEvilInstance(), 0L); OverrideReasonBean mb = new OverrideReasonBean(); mb.setDescription("description"); mb.setORCode("00010"); try { String x = action.addORCode(mb); assertEquals("A database exception has occurred. Please see the log in the console for stacktrace", x); } catch (Exception e) { // TODO } try { String x = action.updateInformation(mb); assertEquals("A database exception has occurred. Please see the log in the console for stacktrace", x); } catch (Exception e) { // TODO } } private void addEmpty(String code) throws Exception { OverrideReasonBean orc = new OverrideReasonBean(code, "0"); String result = action.addORCode(orc); assert (result.contains("Success")); orc = factory.getORCodesDAO().getORCode(code); assertEquals("0", orc.getDescription()); } /** * testAddORCode * * @throws Exception */ public void testAddORCode() throws Exception { final String code = "99998"; final String desc = "UpdateORCodeListActionTest testAddORCode"; OverrideReasonBean orb = new OverrideReasonBean(code, desc); /* * DO NOT REMOVE! This must be stored in a variable. DO NO QUESTION THE * JAVA! */ String result = action.addORCode(orb); assert (result.contains("Success")); orb = factory.getORCodesDAO().getORCode(code); assertEquals(desc, orb.getDescription()); } /** * testAddDuplicate * * @throws DBException * @throws FormValidationException */ public void testAddDuplicate() throws DBException, FormValidationException { final String code = "99997"; final String descrip0 = "description 0"; OverrideReasonBean orc = new OverrideReasonBean(code, descrip0); String result = action.addORCode(orc); assert (result.contains("Success")); orc.setDescription("description 1"); result = action.addORCode(orc); assertEquals("Error: Code already exists.", result); orc = factory.getORCodesDAO().getORCode(code); assertEquals(descrip0, orc.getDescription()); } /** * testUpdateNDInformation0 * * @throws Exception */ public void testUpdateNDInformation0() throws Exception { final String code = "88888"; final String desc = "new descrip 0"; OverrideReasonBean orc = new OverrideReasonBean(code); addEmpty(code); orc.setDescription(desc); String result = action.updateInformation(orc); assertEquals("Success: 1 row(s) updated", result); orc = factory.getORCodesDAO().getORCode(code); assertEquals(desc, orc.getDescription()); } /** * testUpdateNonExistent * * @throws Exception */ public void testUpdateNonExistent() throws Exception { final String code = "99996"; OverrideReasonBean orc = new OverrideReasonBean(code, "shouldnt be here"); String result = action.updateInformation(orc); assertEquals("Error: Code not found.", result); OverrideReasonBean orc2 = new OverrideReasonBean("99995", "Test"); String result2 = action.addORCode(orc2); assert (result2.contains("Success")); assertEquals(null, factory.getORCodesDAO().getORCode(code)); assertEquals(1, factory.getORCodesDAO().getAllORCodes().size()); } }
4,494
30
106
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/UpdateReasonCodeListActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.UpdateNDCodeListAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.model.old.beans.MedicationBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; /** * UpdateReasonCodeListActionTest */ public class UpdateReasonCodeListActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private UpdateNDCodeListAction action; private final static long performingAdmin = 9000000001L; private TestDataGenerator gen = new TestDataGenerator(); @Override protected void setUp() throws Exception { action = new UpdateNDCodeListAction(factory, performingAdmin); gen.clearAllTables(); gen.admin1(); gen.ndCodes(); } private String getAddCodeSuccessString(MedicationBean proc) { return "Success: " + proc.getNDCode() + " - " + proc.getDescription() + " added"; } /** * testEvilFactory */ public void testEvilFactory() { action = new UpdateNDCodeListAction(EvilDAOFactory.getEvilInstance(), 0L); MedicationBean mb = new MedicationBean(); mb.setDescription("description"); mb.setNDCode("3657"); try { String x = action.addNDCode(mb); assertEquals("A database exception has occurred. Please see the log in the console for stacktrace", x); } catch (Exception e) { // TODO } try { String x = action.updateInformation(mb); assertEquals("A database exception has occurred. Please see the log in the console for stacktrace", x); } catch (Exception e) { // TODO } } private void addEmpty(String code) throws Exception { MedicationBean med = new MedicationBean(code, " "); assertEquals(getAddCodeSuccessString(med), action.addNDCode(med)); med = factory.getNDCodesDAO().getNDCode(code); assertEquals(" ", med.getDescription()); } /** * testAddNDCode * * @throws Exception */ public void testAddNDCode() throws Exception { final String code = "999999999"; final String desc = "UpdateNDCodeListActionTest testAddNDCode"; MedicationBean proc = new MedicationBean(code, desc); assertEquals(getAddCodeSuccessString(proc), action.addNDCode(proc)); proc = factory.getNDCodesDAO().getNDCode(code); assertEquals(desc, proc.getDescription()); } /** * testAddDuplicate * * @throws DBException * @throws FormValidationException */ public void testAddDuplicate() throws DBException, FormValidationException { final String code = "999999999"; final String descrip0 = "description 0"; MedicationBean proc = new MedicationBean(code, descrip0); assertEquals(getAddCodeSuccessString(proc), action.addNDCode(proc)); proc.setDescription("description 1"); assertEquals("Error: Code already exists.", action.addNDCode(proc)); proc = factory.getNDCodesDAO().getNDCode(code); assertEquals(descrip0, proc.getDescription()); } /** * testUpdateNDInformation0 * * @throws Exception */ public void testUpdateNDInformation0() throws Exception { final String code = "888888888"; final String desc = "new descrip 0"; MedicationBean proc = new MedicationBean(code); addEmpty(code); proc.setDescription(desc); assertEquals("Success: 1 row(s) updated", action.updateInformation(proc)); proc = factory.getNDCodesDAO().getNDCode(code); assertEquals(desc, proc.getDescription()); } /** * testUpdateNonExistent * * @throws Exception */ public void testUpdateNonExistent() throws Exception { final String code = "999999999"; MedicationBean proc = new MedicationBean(code, "shouldnt be here"); assertEquals("Error: Code not found.", action.updateInformation(proc)); assertEquals(null, factory.getNDCodesDAO().getNDCode(code)); assertEquals(5, factory.getNDCodesDAO().getAllNDCodes().size()); } }
4,044
31.620968
106
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/VerifyClaimActionTest.java
package edu.ncsu.csc.itrust.unit.action; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.sql.Timestamp; import java.util.Date; import org.junit.After; import org.junit.Before; import org.junit.Test; import edu.ncsu.csc.itrust.action.VerifyClaimAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.model.old.beans.BillingBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.dao.mysql.BillingDAO; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class VerifyClaimActionTest { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen = new TestDataGenerator(); private VerifyClaimAction subject; private BillingDAO init = factory.getBillingDAO(); private BillingBean b1; private static final long PATIENT_MID = 42L; @Before public void setUp() throws Exception { gen.clearAllTables(); b1 = new BillingBean(); b1.setAmt(40); b1.setInsAddress1("123 else drive"); b1.setInsAddress2(" "); b1.setInsCity("Durham"); b1.setInsHolderName("dad"); b1.setInsID("1234"); b1.setInsPhone("333-333-3333"); b1.setInsProviderName("Cigna"); b1.setInsState("NC"); b1.setInsZip("27607"); b1.setPatient(PATIENT_MID); b1.setStatus(BillingBean.PENDING); b1.setSubTime(new Timestamp(new Date().getTime())); b1.setBillID((int) init.addBill(b1)); init.editBill(b1); subject = new VerifyClaimAction(factory, b1.getBillID()); } @After public void tearDown() throws Exception { } @Test public void testGetBill() { assertEquals("123 else drive", subject.getBill().getInsAddress1()); assertEquals("dad", subject.getBill().getInsHolderName()); assertEquals(40, subject.getBill().getAmt()); } @Test public void testDenyClaim() { subject.denyClaim(); try { b1 = init.getBillId(b1.getBillID()); } catch (DBException e) { e.printStackTrace(); fail(); } assertEquals(BillingBean.DENIED, b1.getStatus()); } @Test public void testApproveClaim() { subject.approveClaim(); try { b1 = init.getBillId(b1.getBillID()); } catch (DBException e) { e.printStackTrace(); fail(); } assertEquals(BillingBean.APPROVED, b1.getStatus()); } @Test public void testEvilAction() { EvilDAOFactory evil = new EvilDAOFactory(); VerifyClaimAction evilAction = new VerifyClaimAction(evil, b1.getBillID()); assertEquals(null, evilAction.getBill()); } }
2,606
26.15625
77
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ViewApptRequestsActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.util.List; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.ViewApptRequestsAction; import edu.ncsu.csc.itrust.model.old.beans.ApptRequestBean; import edu.ncsu.csc.itrust.model.old.beans.MessageBean; import edu.ncsu.csc.itrust.model.old.dao.mysql.MessageDAO; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class ViewApptRequestsActionTest extends TestCase { private ViewApptRequestsAction action; private TestDataGenerator gen = new TestDataGenerator(); private MessageDAO mDAO; @Override protected void setUp() throws Exception { gen.clearAllTables(); gen.standardData(); gen.apptRequestConflicts(); action = new ViewApptRequestsAction(9000000000L, TestDAOFactory.getTestInstance()); mDAO = TestDAOFactory.getTestInstance().getMessageDAO(); } public void testGetApptRequests() throws Exception { List<ApptRequestBean> list = action.getApptRequests(); assertEquals(1, list.size()); assertEquals(2L, list.get(0).getRequestedAppt().getPatient()); } public void testAcceptApptRequest() throws Exception { List<ApptRequestBean> list = action.getApptRequests(); assertEquals(1, list.size()); assertEquals(2L, list.get(0).getRequestedAppt().getPatient()); String res = action.acceptApptRequest(list.get(0).getRequestedAppt().getApptID()); assertEquals("The appointment request you selected has been accepted and scheduled.", res); list = action.getApptRequests(); assertEquals(1, list.size()); assertEquals(2L, list.get(0).getRequestedAppt().getPatient()); assertTrue(list.get(0).isAccepted()); List<MessageBean> msgs = mDAO.getMessagesForMID(list.get(0).getRequestedAppt().getPatient()); assertEquals(list.get(0).getRequestedAppt().getHcp(), msgs.get(0).getFrom()); assertTrue(msgs.get(0).getBody().contains("has been accepted.")); } public void testRejectApptRequest() throws Exception { List<ApptRequestBean> list = action.getApptRequests(); assertEquals(1, list.size()); assertEquals(2L, list.get(0).getRequestedAppt().getPatient()); String res = action.rejectApptRequest(list.get(0).getRequestedAppt().getApptID()); assertEquals("The appointment request you selected has been rejected.", res); list = action.getApptRequests(); assertEquals(1, list.size()); assertEquals(2L, list.get(0).getRequestedAppt().getPatient()); assertFalse(list.get(0).isAccepted()); List<MessageBean> msgs = mDAO.getMessagesForMID(list.get(0).getRequestedAppt().getPatient()); assertEquals(list.get(0).getRequestedAppt().getHcp(), msgs.get(0).getFrom()); assertTrue(msgs.get(0).getBody().contains("has been rejected.")); } }
2,740
41.169231
95
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ViewClaimsActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import junit.framework.TestCase; import org.junit.After; import org.junit.Before; import org.junit.Test; import edu.ncsu.csc.itrust.action.ViewClaimsAction; import edu.ncsu.csc.itrust.model.old.beans.BillingBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.dao.mysql.BillingDAO; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class ViewClaimsActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen = new TestDataGenerator(); private ViewClaimsAction subject; private BillingDAO init = factory.getBillingDAO(); private BillingBean b1; private BillingBean b2; private static final long PATIENT_MID = 2L; private static final int OV_ID = 3; private static final long DOCTOR_MID = 9000000000L; @Override @Before public void setUp() throws Exception { gen.clearAllTables(); gen.standardData(); b1 = new BillingBean(); b1.setAmt(40); b1.setApptID(OV_ID); b1.setBillID(1); b1.setInsAddress1("123 else drive"); b1.setInsAddress2(" "); b1.setInsCity("Durham"); b1.setInsHolderName("dad"); b1.setInsID("1234"); b1.setInsPhone("333-333-3333"); b1.setInsProviderName("Cigna"); b1.setInsState("NC"); b1.setInsZip("27607"); b1.setPatient(PATIENT_MID); b1.setStatus(BillingBean.PENDING); b1.setSubTime(new Timestamp(new Date().getTime())); b1.setInsurance(true); b2 = new BillingBean(); b2.setAmt(40); b2.setApptID(OV_ID); b2.setBillID(1); b2.setHcp(DOCTOR_MID); b2.setInsAddress1("123 else drive"); b2.setInsAddress2(" "); b2.setInsCity("Durham"); b2.setInsHolderName("dad"); b2.setInsID("1234"); b2.setInsPhone("333-333-3333"); b2.setInsProviderName("Blue Cross"); b2.setInsState("NC"); b2.setInsZip("27607"); b2.setPatient(PATIENT_MID); b2.setStatus(BillingBean.PENDING); b2.setSubTime(new Timestamp(new Date().getTime())); b2.setInsurance(true); b1.setBillID((int) init.addBill(b1)); init.editBill(b1); b2.setBillID((int) init.addBill(b2)); init.editBill(b2); subject = new ViewClaimsAction(factory); } @Override @After public void tearDown() throws Exception { } @Test public void testGetClaims() { List<BillingBean> list = subject.getClaims(); assertEquals(2, list.size()); assertEquals("Cigna", list.get(0).getInsProviderName()); assertEquals("Blue Cross", list.get(1).getInsProviderName()); } @Test public void testGetSubmitter() { assertEquals("Andy Programmer", subject.getSubmitter(b1)); assertEquals("Andy Programmer", subject.getSubmitter(b2)); } @Test public void testGetDate() { assertEquals(new SimpleDateFormat("MM/dd/YYYY").format(new Date()), subject.getDate(b1).toString()); assertEquals(new SimpleDateFormat("MM/dd/YYYY").format(new Date()), subject.getDate(b2).toString()); } @Test public void testEvilAction() { EvilDAOFactory evil = new EvilDAOFactory(); ViewClaimsAction evilAction = new ViewClaimsAction(evil); assertEquals(null, evilAction.getClaims()); assertEquals(null, evilAction.getSubmitter(b1)); } }
3,373
28.33913
102
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ViewHelperActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.sql.SQLException; import edu.ncsu.csc.itrust.action.ViewHelperAction; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.exception.ITrustException; import junit.framework.TestCase; public class ViewHelperActionTest extends TestCase { @Override protected void setUp() throws Exception { } public void testUpdateUserPrefs() throws FormValidationException, SQLException, ITrustException { assertTrue(ViewHelperAction.calculateColor("000000", "FFFFFF", 0).equals("000000")); assertTrue(ViewHelperAction.calculateColor("000000", "FFFFFF", 1.0).equals("FFFFFF")); assertTrue(ViewHelperAction.calculateColor("000000", "FFFFFF", 0.5).equals("7F7F7F")); } }
756
33.409091
98
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ViewMyAccessLogActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.ViewMyAccessLogAction; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.model.old.beans.TransactionBean; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class ViewMyAccessLogActionTest extends TestCase { ViewMyAccessLogAction action; private TestDataGenerator gen; @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); gen.hcp0(); gen.hcp3(); gen.hcp8(); gen.er4(); gen.uap1(); gen.admin1(); gen.patient1(); gen.patient2(); gen.patient23(); gen.patient24(); action = new ViewMyAccessLogAction(TestDAOFactory.getTestInstance(), 2L); } public void testNoProblems() throws Exception { String today = new SimpleDateFormat("MM/dd/yyyy").format(new Date()); List<TransactionBean> accesses = action.getAccesses(today, today, null, false); assertEquals(0, accesses.size()); } public void testNoProblemsDependentLog() throws Exception { action = new ViewMyAccessLogAction(TestDAOFactory.getTestInstance(), 24L); String today = new SimpleDateFormat("MM/dd/yyyy").format(new Date()); List<TransactionBean> accesses = action.getAccesses(today, today, "23", false); assertEquals(0, accesses.size()); } public void testGetAccessesIllegalUser() throws Exception { action = new ViewMyAccessLogAction(TestDAOFactory.getTestInstance(), 24L); String today = new SimpleDateFormat("MM/dd/yyyy").format(new Date()); try { action.getAccesses(today, today, "2", false); fail("exception should have been thrown"); } catch (FormValidationException e) { assertEquals(1, e.getErrorList().size()); assertEquals("Log to View.", e.getErrorList().get(0)); } } public void testGetAccessesBadData() throws Exception { gen.transactionLog(); List<TransactionBean> accesses = action.getAccesses(null, null, null, false); assertEquals(5, accesses.size()); for (TransactionBean t : accesses) { assertEquals(9000000000L, t.getLoggedInMID()); assertEquals(2L, t.getSecondaryMID()); assertEquals("Viewed patient records", t.getAddedInfo()); } // note: the actual bounding is not done here, see the DAO test try { action.getAccesses("", "", null, false); fail("exception should have been thrown"); } catch (FormValidationException e) { assertEquals(1, e.getErrorList().size()); assertEquals("Enter dates in MM/dd/yyyy", e.getErrorList().get(0)); } } public void testGetAccessesByRole() throws Exception { gen.transactionLog3(); action = new ViewMyAccessLogAction(TestDAOFactory.getTestInstance(), 1L); List<TransactionBean> accesses = action.getAccesses(null, null, null, true); assertEquals("Emergency Responder", accesses.get(0).getRole()); assertEquals("LHCP", accesses.get(1).getRole()); assertEquals("LHCP", accesses.get(2).getRole()); assertEquals("LHCP", accesses.get(3).getRole()); assertEquals("Personal Health Representative", accesses.get(4).getRole()); assertEquals("UAP", accesses.get(5).getRole()); } /** * Verifies that none of the transactions returned in the access log are the * patient's DLHCP per use case 8 * * @throws Exception */ public void testDLHCPAccessesHidden() throws Exception { gen.transactionLog3(); action = new ViewMyAccessLogAction(TestDAOFactory.getTestInstance(), 1L); List<TransactionBean> accesses = action.getAccesses(null, null, null, true); for (TransactionBean tb : accesses) assertFalse(tb.getRole().equals("DLHCP")); } public void testDefaultNoList() throws Exception { String today = new SimpleDateFormat("MM/dd/yyyy").format(new Date()); assertEquals(today, action.getDefaultStart(new ArrayList<TransactionBean>())); assertEquals(today, action.getDefaultEnd(new ArrayList<TransactionBean>())); } public void testDefaultWithList() throws Exception { String today = new SimpleDateFormat("MM/dd/yyyy").format(new Date()); ArrayList<TransactionBean> list = new ArrayList<TransactionBean>(); TransactionBean t = new TransactionBean(); t.setTimeLogged(new Timestamp(System.currentTimeMillis())); list.add(t); assertEquals(today, action.getDefaultStart(list)); assertEquals(today, action.getDefaultEnd(list)); } }
4,527
35.224
81
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ViewMyApptsActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.sql.SQLException; import edu.ncsu.csc.itrust.action.ViewMyApptsAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import junit.framework.TestCase; public class ViewMyApptsActionTest extends TestCase { private ViewMyApptsAction action; private DAOFactory factory; private long mid = 1L; private long hcpId = 9000000000L; @Override protected void setUp() throws Exception { TestDataGenerator gen = new TestDataGenerator(); gen.clearAllTables(); gen.standardData(); this.factory = TestDAOFactory.getTestInstance(); this.action = new ViewMyApptsAction(this.factory, this.hcpId); } public void testGetMyAppointments() throws SQLException, DBException { assertEquals(15, action.getAllMyAppointments().size()); } public void testGetName() throws ITrustException { assertEquals("Kelly Doctor", action.getName(hcpId)); } public void testGetName2() throws ITrustException { assertEquals("Random Person", action.getName(mid)); } }
1,248
29.463415
71
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ViewMyBillingActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.sql.SQLException; import edu.ncsu.csc.itrust.action.ViewMyBillingAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import junit.framework.TestCase; public class ViewMyBillingActionTest extends TestCase { private ViewMyBillingAction action; private long mid = 311L; // Sean Ford @Override public void setUp() throws Exception { super.setUp(); TestDataGenerator gen = new TestDataGenerator(); gen.clearAllTables(); gen.standardData(); gen.uc60(); action = new ViewMyBillingAction(TestDAOFactory.getTestInstance(), this.mid); } public void testGetMyUnpaidBills() throws DBException, SQLException { assertEquals(1, action.getMyUnpaidBills().size()); } public void testGetAllMyBills() throws DBException, SQLException { assertEquals(2, action.getAllMyBills().size()); } }
985
27.171429
79
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ViewMyMessagesActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.sql.SQLException; import java.text.ParseException; import java.util.List; import edu.ncsu.csc.itrust.action.ViewMyMessagesAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.MessageBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.dao.mysql.MessageDAO; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import junit.framework.TestCase; /** * ViewMyMessagesActionTest */ public class ViewMyMessagesActionTest extends TestCase { private ViewMyMessagesAction action; private ViewMyMessagesAction action2; private ViewMyMessagesAction evilAction; private DAOFactory factory; private DAOFactory evilFactory; private long mId = 2L; private long hcpId = 9000000000L; @Override protected void setUp() throws Exception { super.setUp(); TestDataGenerator gen = new TestDataGenerator(); gen.clearAllTables(); gen.standardData(); this.factory = TestDAOFactory.getTestInstance(); this.evilFactory = EvilDAOFactory.getEvilInstance(); this.action = new ViewMyMessagesAction(this.factory, this.mId); this.action2 = new ViewMyMessagesAction(this.factory, this.hcpId); this.evilAction = new ViewMyMessagesAction(this.evilFactory, this.mId); } /** * testGetAllMyMessages * * @throws SQLException * @throws DBException */ public void testGetAllMyMessages() throws SQLException, DBException { List<MessageBean> mbList = action.getAllMyMessages(); assertEquals(1, mbList.size()); // Should send a message and recheck later. } /** * testGetPatientName * * @throws ITrustException */ public void testGetPatientName() throws ITrustException { assertEquals("Andy Programmer", action.getName(this.mId)); } /** * testGetPersonnelName * * @throws ITrustException */ public void testGetPersonnelName() throws ITrustException { assertEquals("Kelly Doctor", action.getPersonnelName(this.hcpId)); } /** * testGetAllMyMessagesTimeAscending * * @throws DBException * @throws SQLException */ public void testGetAllMyMessagesTimeAscending() throws DBException, SQLException { List<MessageBean> mbList = action2.getAllMyMessagesTimeAscending(); assertEquals(14, mbList.size()); assertTrue(mbList.get(0).getSentDate().before(mbList.get(1).getSentDate())); } /** * testGetAllMyMessagesNameAscending * * @throws DBException * @throws SQLException */ public void testGetAllMyMessagesNameAscending() throws DBException, SQLException { List<MessageBean> mbList = action2.getAllMyMessagesNameAscending(); List<MessageBean> mbList2 = action.getAllMyMessagesNameAscending(); assertEquals(14, mbList.size()); assertEquals(1, mbList2.size()); try { assertTrue( action2.getName(mbList.get(0).getFrom()).compareTo(action2.getName(mbList.get(13).getFrom())) >= 0); } catch (ITrustException e) { // TODO } } /** * testGetAllMyMessagesNameDescending * * @throws DBException * @throws SQLException */ public void testGetAllMyMessagesNameDescending() throws DBException, SQLException { List<MessageBean> mbList = action2.getAllMyMessagesNameDescending(); List<MessageBean> mbList2 = action.getAllMyMessagesNameDescending(); assertEquals(14, mbList.size()); assertEquals(1, mbList2.size()); try { assertTrue( action2.getName(mbList.get(13).getFrom()).compareTo(action2.getName(mbList.get(0).getFrom())) >= 0); } catch (ITrustException e) { // TODO } } /** * testGetAllMySentMessages * * @throws DBException * @throws SQLException */ public void testGetAllMySentMessages() throws DBException, SQLException { List<MessageBean> mbList = action2.getAllMySentMessages(); assertEquals(2, mbList.size()); } /** * testGetAllMyMessagesFromTimeAscending * * @throws DBException * @throws SQLException */ public void testGetAllMyMessagesFromTimeAscending() throws DBException, SQLException { List<MessageBean> mbList = action2.getAllMySentMessagesTimeAscending(); assertEquals(2, mbList.size()); assertTrue(mbList.get(0).getSentDate().before(mbList.get(1).getSentDate())); } /** * testGetAllMyMessagesFromNameAscending * * @throws DBException * @throws SQLException */ public void testGetAllMyMessagesFromNameAscending() throws DBException, SQLException { List<MessageBean> mbList = action2.getAllMySentMessagesNameAscending(); List<MessageBean> mbList2 = action.getAllMySentMessagesNameAscending(); assertEquals(2, mbList.size()); assertEquals(3, mbList2.size()); try { assertTrue( action2.getName(mbList.get(0).getFrom()).compareTo(action2.getName(mbList.get(1).getFrom())) >= 0); } catch (ITrustException e) { // TODO } } /** * testGetAllMyMessagesFromNameDescending * * @throws DBException * @throws SQLException */ public void testGetAllMyMessagesFromNameDescending() throws DBException, SQLException { List<MessageBean> mbList = action2.getAllMySentMessagesNameDescending(); List<MessageBean> mbList2 = action.getAllMySentMessagesNameDescending(); assertEquals(2, mbList.size()); assertEquals(3, mbList2.size()); try { assertTrue( action2.getName(mbList.get(1).getFrom()).compareTo(action2.getName(mbList.get(0).getFrom())) >= 0); } catch (ITrustException e) { // TODO } } /** * testUpdateRead * * @throws ITrustException * @throws SQLException * @throws FormValidationException */ public void testUpdateRead() throws ITrustException, SQLException, FormValidationException { List<MessageBean> mbList = action.getAllMyMessages(); assertEquals(0, mbList.get(0).getRead()); action.setRead(mbList.get(0)); mbList = action.getAllMyMessages(); assertEquals(1, mbList.get(0).getRead()); } /** * testAddMessage * * @throws SQLException * @throws DBException */ public void testAddMessage() throws SQLException, DBException { MessageDAO test = new MessageDAO(factory); List<MessageBean> mbList = action.getAllMyMessages(); test.addMessage(mbList.get(0)); mbList = action.getAllMyMessages(); assertEquals(2, mbList.size()); } /** * testFilterMessages * * @throws SQLException * @throws ITrustException * @throws ParseException */ public void testFilterMessages() throws SQLException, ITrustException, ParseException { List<MessageBean> mbList = action2.getAllMyMessages(); mbList = action2.filterMessages(mbList, "Random Person,Appointment,Appointment,Lab,01/01/2010,01/31/2010"); assertEquals(1, mbList.size()); } /** * testGetUnreadCount * * @throws DBException * @throws SQLException */ public void testGetUnreadCount() throws DBException, SQLException { assertEquals(1, action.getUnreadCount()); assertEquals(12, action2.getUnreadCount()); } /** * testGetCCdMessages * * @throws DBException * @throws SQLException */ public void testGetCCdMessages() throws DBException, SQLException { assertEquals(0, action.getCCdMessages(1).size()); } /** * testThrowsExceptions * * @throws DBException */ public void testThrowsExceptions() throws DBException { List<MessageBean> resultList = null; try { resultList = evilAction.getAllMyMessages(); fail(); } catch (DBException e) { assertNull(resultList); } catch (SQLException e) { assertNull(resultList); } resultList = null; try { resultList = evilAction.getAllMyMessagesNameAscending(); fail(); } catch (DBException e) { assertNull(resultList); } catch (SQLException e) { assertNull(resultList); } resultList = null; try { resultList = evilAction.getAllMySentMessages(); fail(); } catch (DBException e) { assertNull(resultList); } catch (SQLException e) { assertNull(resultList); } } }
8,082
24.660317
109
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ViewMyRemoteMonitoringListActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.util.List; import java.text.DateFormat; import java.text.SimpleDateFormat; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.ViewMyRemoteMonitoringListAction; import edu.ncsu.csc.itrust.model.old.beans.RemoteMonitoringDataBean; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; /** * ViewMyRemoteMonitoringListActionTest */ public class ViewMyRemoteMonitoringListActionTest extends TestCase { ViewMyRemoteMonitoringListAction action; private TestDataGenerator gen; @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); gen.hcp0(); gen.patient1(); action = new ViewMyRemoteMonitoringListAction(TestDAOFactory.getTestInstance(), 9000000000L); } /** * testGetPatientData * * @throws Exception */ public void testGetPatientData() throws Exception { gen.remoteMonitoring3(); List<RemoteMonitoringDataBean> data = action.getPatientsData(); assertEquals(1L, data.get(0).getPatientMID()); assertEquals(160, data.get(0).getSystolicBloodPressure()); assertEquals(110, data.get(0).getDiastolicBloodPressure()); assertEquals(60, data.get(0).getGlucoseLevel()); assertTrue(data.get(0).getTime().toString().contains("08:00:00")); assertEquals(1L, data.get(1).getPatientMID()); assertEquals(100, data.get(1).getSystolicBloodPressure()); assertEquals(70, data.get(1).getDiastolicBloodPressure()); assertEquals(90, data.get(1).getGlucoseLevel()); assertTrue(data.get(1).getTime().toString().contains("07:15:00")); assertEquals(1L, data.get(2).getPatientMID()); assertEquals(90, data.get(2).getSystolicBloodPressure()); assertEquals(60, data.get(2).getDiastolicBloodPressure()); assertEquals(80, data.get(2).getGlucoseLevel()); assertTrue(data.get(2).getTime().toString().contains("05:30:00")); assertEquals(5L, data.get(3).getPatientMID()); assertEquals(0, data.get(3).getSystolicBloodPressure()); assertEquals(0, data.get(3).getDiastolicBloodPressure()); assertEquals(0, data.get(3).getGlucoseLevel()); assertNull(data.get(3).getTime()); gen.remoteMonitoring3(); data = action.getPatientDataWithoutLogging(); assertEquals(1L, data.get(0).getPatientMID()); assertEquals(160, data.get(0).getSystolicBloodPressure()); assertEquals(110, data.get(0).getDiastolicBloodPressure()); assertEquals(60, data.get(0).getGlucoseLevel()); assertTrue(data.get(0).getTime().toString().contains("08:00:00")); assertEquals(1L, data.get(1).getPatientMID()); assertEquals(100, data.get(1).getSystolicBloodPressure()); assertEquals(70, data.get(1).getDiastolicBloodPressure()); assertEquals(90, data.get(1).getGlucoseLevel()); assertTrue(data.get(1).getTime().toString().contains("07:15:00")); assertEquals(1L, data.get(2).getPatientMID()); assertEquals(90, data.get(2).getSystolicBloodPressure()); assertEquals(60, data.get(2).getDiastolicBloodPressure()); assertEquals(80, data.get(2).getGlucoseLevel()); assertTrue(data.get(2).getTime().toString().contains("05:30:00")); assertEquals(5L, data.get(3).getPatientMID()); assertEquals(0, data.get(3).getSystolicBloodPressure()); assertEquals(0, data.get(3).getDiastolicBloodPressure()); assertEquals(0, data.get(3).getGlucoseLevel()); assertNull(data.get(3).getTime()); } /** * testGetPatientDataByDate * * @throws Exception */ public void testGetPatientDataByDate() throws Exception { gen.remoteMonitoring3(); DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); java.util.Date date = new java.util.Date(); String currentDate = dateFormat.format(date); List<RemoteMonitoringDataBean> data = action.getPatientDataByDate(1L, currentDate, currentDate); assertEquals(1L, data.get(0).getPatientMID()); assertEquals(160, data.get(0).getSystolicBloodPressure()); assertEquals(110, data.get(0).getDiastolicBloodPressure()); assertEquals(60, data.get(0).getGlucoseLevel()); assertTrue(data.get(0).getTime().toString().contains("08:00:00")); assertEquals(2L, data.get(0).getReporterMID()); assertEquals(1L, data.get(1).getPatientMID()); assertEquals(100, data.get(1).getSystolicBloodPressure()); assertEquals(70, data.get(1).getDiastolicBloodPressure()); assertEquals(90, data.get(1).getGlucoseLevel()); assertTrue(data.get(1).getTime().toString().contains("07:15:00")); assertEquals(8000000009L, data.get(1).getReporterMID()); assertEquals(1L, data.get(2).getPatientMID()); assertEquals(90, data.get(2).getSystolicBloodPressure()); assertEquals(60, data.get(2).getDiastolicBloodPressure()); assertEquals(80, data.get(2).getGlucoseLevel()); assertTrue(data.get(2).getTime().toString().contains("05:30:00")); assertEquals(1L, data.get(2).getReporterMID()); } /** * testGetPatientDataByType * * @throws Exception */ public void testGetPatientDataByType() throws Exception { gen.remoteMonitoring5(); List<RemoteMonitoringDataBean> data = action.getPatientDataByType(1L, "weight"); assertEquals(1L, data.get(0).getPatientMID()); assertEquals(180.0f, data.get(0).getWeight()); assertTrue(data.get(0).getTime().toString().contains("08:19:00")); assertEquals(1L, data.get(0).getReporterMID()); assertEquals(1L, data.get(1).getPatientMID()); assertEquals(177.0f, data.get(1).getWeight()); assertTrue(data.get(1).getTime().toString().contains("07:48:00")); assertEquals(2L, data.get(1).getReporterMID()); assertEquals(1L, data.get(2).getPatientMID()); assertEquals(186.5f, data.get(2).getWeight()); assertTrue(data.get(2).getTime().toString().contains("07:17:00")); assertEquals(1L, data.get(2).getReporterMID()); } /** * testIllegalGetPatientDataByDate1 * * @throws Exception */ public void testIllegalGetPatientDataByDate1() throws Exception { DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); java.util.Date date = new java.util.Date(); String currentDate = dateFormat.format(date); try { List<RemoteMonitoringDataBean> data = action.getPatientDataByDate(1L, currentDate, "01/01/2009"); fail("Start Date is After End Date, Illegal!"); // Here to remove warning about data not being read data.get(0).getPatientMID(); } catch (Exception e) { // TODO } } /** * testGetPatientName * * @throws Exception */ public void testGetPatientName() throws Exception { assertEquals("Random Person", action.getPatientName(1L)); } }
6,518
35.418994
100
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ViewMyReportRequestsActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.util.List; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.ViewMyReportRequestsAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.ReportRequestBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class ViewMyReportRequestsActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private DAOFactory evilFactory = EvilDAOFactory.getEvilInstance(); private ViewMyReportRequestsAction action; @Override protected void setUp() throws Exception { TestDataGenerator gen = new TestDataGenerator(); gen.clearAllTables(); gen.patient2(); gen.hcp0(); gen.admin1(); gen.fakeEmail(); gen.reportRequests(); } public void testGetReportRequests3() throws Exception { action = new ViewMyReportRequestsAction(factory, 9000000000L); List<ReportRequestBean> list = action.getAllReportRequestsForRequester(); assertEquals(6, list.size()); assertEquals(ReportRequestBean.Requested, list.get(0).getStatus()); } public void testGetEvilReportRequest() throws Exception { action = new ViewMyReportRequestsAction(evilFactory, 9000000000L); try { action.getReportRequest(1); fail("exception should have been thrown"); } catch (ITrustException ex) { DBException dbe = (DBException) ex; assertEquals(EvilDAOFactory.MESSAGE, dbe.getSQLException().getMessage()); } } public void testGetReportRequestForID3() throws Exception { action = new ViewMyReportRequestsAction(factory, 9000000000L); ReportRequestBean b = action.getReportRequest(3); assertEquals(3, b.getID()); assertEquals(9000000000L, b.getRequesterMID()); assertEquals(2, b.getPatientMID()); assertEquals("01/03/2008 12:00", b.getRequestedDateString()); } public void testGetReportRequestForID4() throws Exception { action = new ViewMyReportRequestsAction(factory, 9000000000L); ReportRequestBean b = action.getReportRequest(4); assertEquals(4, b.getID()); assertEquals(9000000000L, b.getRequesterMID()); assertEquals(2, b.getPatientMID()); assertEquals("01/04/2008 12:00", b.getRequestedDateString()); assertEquals("03/04/2008 12:00", b.getViewedDateString()); assertEquals(ReportRequestBean.Viewed, b.getStatus()); } public void testInsertReport1() throws Exception { action = new ViewMyReportRequestsAction(evilFactory, 9000000000L); try { action.addReportRequest(0); fail("Should have throw exception"); } catch (ITrustException e) { DBException dbe = (DBException) e; assertEquals(EvilDAOFactory.MESSAGE, dbe.getSQLException().getMessage()); } } public void testInsertReport2() throws Exception { action = new ViewMyReportRequestsAction(factory, 9000000000L); long id = action.addReportRequest(2); ReportRequestBean b2 = action.getReportRequest((int) id); assertEquals(9000000000L, b2.getRequesterMID()); assertEquals(2, b2.getPatientMID()); assertEquals(ReportRequestBean.Requested, b2.getStatus()); } public void testSetViewedToZero() throws Exception { action = new ViewMyReportRequestsAction(factory, 9000000000L); try { action.setViewed(0); fail("Should have throw exception"); } catch (ITrustException ex) { assertEquals("A database exception has occurred. Please see the log in the console for stacktrace", ex.getMessage()); } } public void testGetLongStatus() throws Exception { ViewMyReportRequestsAction action = new ViewMyReportRequestsAction(factory, 2L); TestDataGenerator gen = new TestDataGenerator(); gen.admin1(); assertEquals("Request was requested on 01/01/2008 12:00 by Kelly Doctor", action.getLongStatus(1L)); assertEquals( "Request was requested on 01/04/2008 12:00 by Kelly Doctor, and viewed on 03/04/2008 12:00 by Kelly Doctor", action.getLongStatus(4L)); } }
4,103
35.972973
112
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ViewNumberOfPendingAppointmentsActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.sql.SQLException; import java.util.List; import edu.ncsu.csc.itrust.action.ViewApptRequestsAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.model.old.beans.ApptRequestBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import junit.framework.TestCase; @SuppressWarnings("unused") public class ViewNumberOfPendingAppointmentsActionTest extends TestCase { private ViewApptRequestsAction action; private DAOFactory factory; private long mid = 1L; private long hcpId = 9000000000L; @Override protected void setUp() throws Exception { TestDataGenerator gen = new TestDataGenerator(); gen.clearAllTables(); gen.standardData(); gen.pendingAppointmentAlert(); this.factory = TestDAOFactory.getTestInstance(); this.action = new ViewApptRequestsAction(this.hcpId, this.factory); } public void testGetNumRequest() throws SQLException, DBException { List<ApptRequestBean> reqs = action.getApptRequests(); assertEquals(1, action.getNumRequests(reqs)); } }
1,196
29.692308
73
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ViewPatientActionTest.java
package edu.ncsu.csc.itrust.unit.action; import static org.junit.Assert.*; import java.util.List; import org.junit.Before; import org.junit.Test; import edu.ncsu.csc.itrust.action.ViewPatientAction; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.PatientBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class ViewPatientActionTest { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen = new TestDataGenerator(); private ViewPatientAction action; @Before public void setUp() throws Exception { gen.clearAllTables(); gen.patient2(); action = new ViewPatientAction(factory, 2L, "2"); } @Test public void testGetViewablePatients() { List<PatientBean> list = null; try { list = action.getViewablePatients(); } catch (ITrustException e) { fail(); } if (list == null) { fail(); } else { assertEquals(1, list.size()); } } @Test public void testGetPatient() { PatientBean bean1 = null; try { bean1 = action.getPatient("2"); } catch (ITrustException e) { fail(); } if (bean1 == null) fail(); assertEquals(bean1.getMID(), 2L); // and just test that the right record // came back PatientBean bean2 = null; try { bean2 = action.getPatient("1"); } catch (ITrustException e) { assertNull(bean2); } PatientBean bean3 = null; try { bean3 = action.getPatient("a"); } catch (ITrustException e) { assertNull(bean3); } } }
1,649
21.297297
74
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ViewPersonnelActionTest.java
package edu.ncsu.csc.itrust.unit.action; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.ViewPersonnelAction; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class ViewPersonnelActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private ViewPersonnelAction action; private TestDataGenerator gen; @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); gen.patient4(); gen.hcp3(); } public void testViewPersonnel() throws Exception { action = new ViewPersonnelAction(factory, 4L); PersonnelBean hcp = action.getPersonnel("9000000003"); assertEquals(9000000003L, hcp.getMID()); } public void testNoPersonnel() throws Exception { action = new ViewPersonnelAction(factory, 4L); try { action.getPersonnel("9000000000"); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("No personnel record exists for this MID", e.getMessage()); } } public void testNotANumber() throws Exception { action = new ViewPersonnelAction(factory, 4L); try { action.getPersonnel("a"); fail("exception should have been thrown"); } catch (ITrustException e) { assertEquals("MID not a number", e.getMessage()); } } }
1,546
28.75
75
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ViewReportActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.util.List; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.ViewReportAction; import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.model.old.beans.PatientBean; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; public class ViewReportActionTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private ViewReportAction action = new ViewReportAction(factory, 2L); private TestDataGenerator gen; @Override protected void setUp() throws Exception { gen = new TestDataGenerator(); gen.clearAllTables(); gen.hcp0(); gen.patient2(); } public void testGetDeclaredHCPs() throws Exception { gen.hcp3(); List<PersonnelBean> list = action.getDeclaredHCPs(2L); assertEquals(1, list.size()); } public void testGetPersonnel() throws ITrustException { PersonnelBean bean = action.getPersonnel(9000000000L); assertEquals("Kelly Doctor", bean.getFullName()); assertEquals("surgeon", bean.getSpecialty()); } public void testGetPatientl() throws ITrustException { PatientBean bean = action.getPatient(2L); assertEquals("Andy Programmer", bean.getFullName()); } }
1,405
29.565217
69
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/action/ZipCodeActionTest.java
package edu.ncsu.csc.itrust.unit.action; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.SQLException; import java.util.List; import edu.ncsu.csc.itrust.action.ZipCodeAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import junit.framework.TestCase; public class ZipCodeActionTest extends TestCase { private ZipCodeAction zipCodeAction; private TestDataGenerator gen = new TestDataGenerator(); private long loggedInMID = 2; @Override protected void setUp() throws FileNotFoundException, SQLException, IOException { gen = new TestDataGenerator(); zipCodeAction = new ZipCodeAction(TestDAOFactory.getTestInstance(), loggedInMID); gen.clearAllTables(); gen.standardData(); } public void testGetExperts() throws DBException { System.out.println("Begin testGetExperts"); List<PersonnelBean> physicians = zipCodeAction.getExperts("Surgeon", "10453", "250", 0l); assertEquals(0, physicians.size()); System.out.println(physicians.size()); for (PersonnelBean pb : physicians) { System.out.println(pb.getFullName()); } physicians = zipCodeAction.getExperts("Surgeon", "10453", "500", 0l); System.out.println(physicians.size()); for (PersonnelBean pb : physicians) { System.out.println(pb.getFullName()); } System.out.println("End testGetExperts"); physicians.get(0).getFullName().equals("Kelly Doctor"); } }
1,573
33.977778
91
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/AllergyBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import java.text.SimpleDateFormat; import edu.ncsu.csc.itrust.model.old.beans.AllergyBean; import junit.framework.TestCase; public class AllergyBeanTest extends TestCase { public void testFirstFound() throws Exception { AllergyBean allergy = new AllergyBean(); allergy.setFirstFound(new SimpleDateFormat("MM/dd/yyyy").parse("05/19/1984")); assertEquals("05/19/1984", allergy.getFirstFoundStr()); } public void testGetID() { AllergyBean allergy = new AllergyBean(); allergy.setId(7l); assertEquals(7l, allergy.getId()); allergy.setDescription("testing"); assertEquals("testing", allergy.toString()); } public void testInvalidFirstFound() { AllergyBean allergy = new AllergyBean(); allergy.setFirstFound(null); assertEquals("", allergy.getFirstFoundStr()); } }
831
27.689655
80
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/ApptRequestBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import edu.ncsu.csc.itrust.model.old.beans.ApptBean; import edu.ncsu.csc.itrust.model.old.beans.ApptRequestBean; import junit.framework.TestCase; public class ApptRequestBeanTest extends TestCase { private ApptRequestBean req; private ApptBean apt; @Override protected void setUp() throws Exception { req = new ApptRequestBean(); apt = new ApptBean(); } public void testGetRequestedAppt() { ApptBean b = req.getRequestedAppt(); assertNull(b); req.setRequestedAppt(apt); b = req.getRequestedAppt(); assertEquals(apt, b); } public void testPending() { assertTrue(req.isPending()); req.setPending(false); assertFalse(req.isPending()); req.setPending(true); assertTrue(req.isPending()); } public void testAccepted() { assertFalse(req.isAccepted()); req.setPending(false); assertFalse(req.isAccepted()); req.setAccepted(true); assertTrue(req.isAccepted()); req.setAccepted(false); assertFalse(req.isAccepted()); } }
1,006
21.886364
59
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/BeanLoaderTest.java
package edu.ncsu.csc.itrust.unit.bean; import edu.ncsu.csc.itrust.model.old.beans.loaders.AllergyBeanLoader; import edu.ncsu.csc.itrust.model.old.beans.loaders.FamilyBeanLoader; import edu.ncsu.csc.itrust.model.old.beans.loaders.HospitalBeanLoader; import edu.ncsu.csc.itrust.model.old.beans.loaders.MedicationBeanLoader; import edu.ncsu.csc.itrust.model.old.beans.loaders.OperationalProfileLoader; import edu.ncsu.csc.itrust.model.old.beans.loaders.RemoteMonitoringListsBeanLoader; import edu.ncsu.csc.itrust.model.old.beans.loaders.ReportRequestBeanLoader; import edu.ncsu.csc.itrust.model.old.beans.loaders.TransactionBeanLoader; import junit.framework.TestCase; public class BeanLoaderTest extends TestCase { public void testLoadParameters() throws Exception { try { new AllergyBeanLoader().loadParameters(null, null); fail("Should have thrown Exception"); } catch (IllegalStateException ex) { assertEquals("unimplemented!", ex.getMessage()); } try { new FamilyBeanLoader("self").loadParameters(null, null); fail("Should have thrown Exception"); } catch (IllegalStateException ex) { assertEquals("unimplemented!", ex.getMessage()); } try { new HospitalBeanLoader().loadParameters(null, null); fail("Should have thrown Exception"); } catch (IllegalStateException ex) { assertEquals("unimplemented!", ex.getMessage()); } try { new MedicationBeanLoader().loadParameters(null, null); fail("Should have thrown Exception"); } catch (IllegalStateException ex) { assertEquals("unimplemented!", ex.getMessage()); } try { new OperationalProfileLoader().loadParameters(null, null); fail("Should have thrown Exception"); } catch (IllegalStateException ex) { assertEquals("unimplemented!", ex.getMessage()); } try { new RemoteMonitoringListsBeanLoader().loadParameters(null, null); fail("Should have thrown Exception"); } catch (IllegalStateException ex) { assertEquals("unimplemented!", ex.getMessage()); } try { new ReportRequestBeanLoader().loadParameters(null, null); fail("Should have thrown Exception"); } catch (IllegalStateException ex) { assertEquals("unimplemented!", ex.getMessage()); } try { new TransactionBeanLoader().loadParameters(null, null); fail("Should have thrown Exception"); } catch (IllegalStateException ex) { assertEquals("unimplemented!", ex.getMessage()); } } }
2,416
30.802632
83
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/BillingBeanLoaderTest.java
package edu.ncsu.csc.itrust.unit.bean; import static org.easymock.EasyMock.expect; import static org.easymock.classextension.EasyMock.createControl; import static org.junit.Assert.*; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.util.Date; import java.util.List; import org.easymock.classextension.IMocksControl; import org.junit.After; import org.junit.Before; import org.junit.Test; import edu.ncsu.csc.itrust.model.old.beans.BillingBean; import edu.ncsu.csc.itrust.model.old.beans.loaders.BillingBeanLoader; public class BillingBeanLoaderTest { private IMocksControl ctrl; private ResultSet rs; private BillingBeanLoader load; @Before public void setUp() throws Exception { ctrl = createControl(); rs = ctrl.createMock(ResultSet.class); load = new BillingBeanLoader(); } @After public void tearDown() throws Exception { } @Test public void testLoadList() throws SQLException { List<BillingBean> l = load.loadList(rs); assertEquals(0, l.size()); } @Test public void testLoadSingle() { try { // this just sets the value for a method call (kinda hard coding I // assume) expect(rs.getInt("billID")).andReturn(2).once(); expect(rs.getInt("appt_id")).andReturn(6).once(); expect(rs.getLong("PatientID")).andReturn(311L).once(); expect(rs.getLong("HCPID")).andReturn(90000001L).once(); expect(rs.getInt("amt")).andReturn(40).once(); expect(rs.getString("status")).andReturn("Unsubmitted").once(); expect(rs.getString("ccHolderName")).andReturn("Sean Ford").once(); expect(rs.getString("billingAddress")).andReturn("123 Fake Street").once(); expect(rs.getString("ccType")).andReturn("Visa").once(); expect(rs.getString("ccNumber")).andReturn("1111-1111-1111-1111").once(); expect(rs.getString("cvv")).andReturn("111").once(); expect(rs.getString("insHolderName")).andReturn("Sean Ford").once(); expect(rs.getString("insID")).andReturn("123456").once(); expect(rs.getString("insProviderName")).andReturn("Blue Cross").once(); expect(rs.getString("insAddress1")).andReturn("123 Fake St.").once(); expect(rs.getString("insAddress2")).andReturn("123 Faker St.").once(); expect(rs.getString("insCity")).andReturn("Raleigh").once(); expect(rs.getString("insState")).andReturn("NC").once(); expect(rs.getString("insZip")).andReturn("27606").once(); expect(rs.getString("insPhone")).andReturn("555-555-5555").once(); expect(rs.getInt("submissions")).andReturn(1).once(); expect(rs.getDate("billTimeS")).andReturn(new java.sql.Date(new Date(0).getTime())); expect(rs.getTimestamp("subTime")).andReturn(new Timestamp(new Date(0).getTime())); expect(rs.getBoolean("isInsurance")).andReturn(true); ctrl.replay(); BillingBean r = load.loadSingle(rs); assertEquals(2, r.getBillID()); assertEquals(6, r.getApptID()); assertEquals(311, r.getPatient()); assertEquals(90000001, r.getHcp()); assertEquals(40, r.getAmt()); assertEquals("Unsubmitted", r.getStatus()); assertEquals("Sean Ford", r.getCcHolderName()); assertEquals("123 Fake Street", r.getBillingAddress()); assertEquals("Visa", r.getCcType()); assertEquals("1111-1111-1111-1111", r.getCcNumber()); assertEquals("111", r.getCvv()); assertEquals("Sean Ford", r.getInsHolderName()); assertEquals("123456", r.getInsID()); assertEquals("Blue Cross", r.getInsProviderName()); assertEquals("123 Fake St.", r.getInsAddress1()); assertEquals("123 Faker St.", r.getInsAddress2()); assertEquals("Raleigh", r.getInsCity()); assertEquals("NC", r.getInsState()); assertEquals("27606", r.getInsZip()); assertEquals("555-555-5555", r.getInsPhone()); assertEquals(1, r.getSubmissions()); assertTrue(r.isInsurance()); assertEquals(new Timestamp(0).getTime(), r.getBillTime().getTime()); assertEquals(new Timestamp(0).getTime(), r.getSubTime().getTime()); } catch (SQLException e) { // TODO } } @Test public void testLoadParameters() { try { load.loadParameters(null, null); fail(); } catch (Exception e) { } } }
4,105
33.79661
87
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/DistanceComparatorTest.java
package edu.ncsu.csc.itrust.unit.bean; import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.ZipCodeAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.model.old.beans.DistanceComparator; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.dao.mysql.PersonnelDAO; import edu.ncsu.csc.itrust.unit.DBBuilder; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; /** * Test comparing the distances * */ public class DistanceComparatorTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen; private ZipCodeAction action; private ZipCodeAction action2; /** * Gets all of the standard data and initializes 2 zipcode actions */ @Override protected void setUp() throws IOException, SQLException { gen = new TestDataGenerator(); gen.clearAllTables(); gen.standardData(); action = new ZipCodeAction(factory, 2L); action2 = new ZipCodeAction(factory, 3L); } /** * Tests comparing two things */ public void testComparator() { PersonnelDAO dao = new PersonnelDAO(factory); List<PersonnelBean> list = new ArrayList<PersonnelBean>(); try { list = dao.getAllPersonnel(); } catch (DBException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { if (list.size() != 0) Collections.sort(list, new DistanceComparator(action, "27587")); } catch (Exception e) { fail(); } } /** * Tests when we have an evil factory we get an exception */ public void testComparatorEvil() { EvilDAOFactory evil = new EvilDAOFactory(); PersonnelDAO dao = new PersonnelDAO(factory); List<PersonnelBean> list = new ArrayList<PersonnelBean>(); try { list = dao.getAllPersonnel(); } catch (DBException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ZipCodeAction evilAction = new ZipCodeAction(evil, 2); try { DistanceComparator evilCompare = new DistanceComparator(evilAction, "27587"); assertEquals(-1, evilCompare.compare(list.get(0), list.get(1))); } catch (Exception e) { fail(); } } /** * Tests that we get an error when we drop the tables and try to compare * stuff */ public void testError() { DBBuilder builder = new DBBuilder(); DistanceComparator dist = new DistanceComparator(action2, "27587"); PersonnelBean bean1 = new PersonnelBean(); PersonnelBean bean2 = new PersonnelBean(); try { builder.dropTables(); // drop all tables in the DB dist.compare(bean1, bean2); } catch (Exception e) { assertNull(bean1); } try { builder.createTables(); // now put them back so future tests aren't // broken } catch (Exception e) { fail(); } } }
3,086
26.078947
80
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/EmailBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import java.sql.Timestamp; import java.util.Arrays; import java.util.Date; import edu.ncsu.csc.itrust.model.old.beans.Email; import junit.framework.TestCase; public class EmailBeanTest extends TestCase { private final Date date = new Date(100000L); public void testMakeStr() throws Exception { Email email = new Email(); email.setToList(Arrays.asList("first", "second")); assertEquals("first,second", email.getToListStr()); } public void testEquals() throws Exception { Email email1 = getTestEmail(); Email email2 = getTestEmail(); assertEquals(email1, email2); assertTrue(email1.equals(email2)); email1.setToList(Arrays.asList("first", "second", "thrd")); assertFalse(email1.equals(email2)); email1.setToList(Arrays.asList("first", "second")); assertFalse(email1.equals(email2)); email2.setSubject(""); assertFalse(email1.equals(email2)); } public void testToList() throws Exception { Email email = getTestEmail(); assertEquals(3, email.getToList().size()); } public void testAttributes() throws Exception { Email email = getTestEmail(); assertEquals("this is the body", email.getBody()); assertEquals("from address", email.getFrom()); assertEquals("this is the subject", email.getSubject()); assertEquals(100000L, email.getTimeAdded().getTime()); } public void testGetHashCode() throws Exception { Email email = getTestEmail(); assertEquals(42, email.hashCode()); } private Email getTestEmail() { Email email = new Email(); email.setBody("this is the body"); email.setFrom("from address"); email.setSubject("this is the subject"); email.setToList(Arrays.asList("first", "second", "third")); email.setTimeAdded(new Timestamp(date.getTime())); return email; } }
1,783
27.774194
61
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/GroupReportBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import java.util.ArrayList; import java.util.List; import edu.ncsu.csc.itrust.model.old.beans.GroupReportBean; import edu.ncsu.csc.itrust.model.old.beans.PatientBean; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.dao.mysql.PatientDAO; import edu.ncsu.csc.itrust.report.DemographicReportFilter; import edu.ncsu.csc.itrust.report.DemographicReportFilter.DemographicReportFilterType; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import edu.ncsu.csc.itrust.report.ReportFilter; import junit.framework.TestCase; public class GroupReportBeanTest extends TestCase { private GroupReportBean bean; private TestDataGenerator gen = new TestDataGenerator(); private DAOFactory factory = TestDAOFactory.getTestInstance(); private PatientDAO pDAO = factory.getPatientDAO(); @Override protected void setUp() throws Exception { gen.clearAllTables(); gen.standardData(); List<PatientBean> p = new ArrayList<PatientBean>(); p.add(pDAO.getPatient(1L)); List<ReportFilter> f = new ArrayList<ReportFilter>(); f.add(new DemographicReportFilter(DemographicReportFilterType.LAST_NAME, "Person", factory)); bean = new GroupReportBean(p, f); } public void testGetPatients() { List<PatientBean> p = bean.getPatients(); assertTrue(p.size() == 1); assertTrue(p.get(0).getMID() == 1L); } public void testGetFilters() { List<ReportFilter> f = bean.getFilters(); assertTrue(f.size() == 1); assertEquals(DemographicReportFilterType.LAST_NAME, ((DemographicReportFilter) f.get(0)).getFilterType()); } public void testGetFilterStrings() { List<String> f = bean.getFilterStrings(); assertTrue(f.size() == 1); assertEquals("Filter by LAST NAME with value Person", f.get(0)); } public void testGetPatientNames() { List<String> p = bean.getPatientNames(); assertTrue(p.size() == 1); assertEquals("Random Person", p.get(0)); } }
2,014
32.583333
108
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/HCPLinkBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import edu.ncsu.csc.itrust.model.old.beans.HCPLinkBean; import junit.framework.TestCase; public class HCPLinkBeanTest extends TestCase { public void testGetDrug() throws Exception { HCPLinkBean hl = new HCPLinkBean(); hl.setDrug("Penicillin"); hl.setCode("blah"); assertEquals("Penicillin", hl.getDrug()); assertEquals("blah", hl.getCode()); } public void testGetPresciberMID() { HCPLinkBean hl = new HCPLinkBean(); hl.setPrescriberMID(900000000); assertEquals(900000000, hl.getPrescriberMID()); } public void testChecked() { HCPLinkBean hl = new HCPLinkBean(); hl.setChecked(true); assertTrue(hl.isChecked()); } }
686
24.444444
55
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/HospitalBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import edu.ncsu.csc.itrust.model.old.beans.HospitalBean; import junit.framework.TestCase; /** */ public class HospitalBeanTest extends TestCase { /** * testHospitalBean * * @throws Exception */ public void testHospitalBean() throws Exception { HospitalBean h = new HospitalBean(); h.setHospitalID("id"); h.setHospitalName("name"); assertEquals("id", h.getHospitalID()); assertEquals("name", h.getHospitalName()); assertEquals(42, h.hashCode()); } /** * testFullConstrcutor * * @throws Exception */ public void testFullConstructor() throws Exception { HospitalBean h = new HospitalBean("id", "name", "address", "city", "ST", "12345-6789"); assertEquals("id", h.getHospitalID()); assertEquals("name", h.getHospitalName()); assertEquals("address", h.getHospitalAddress()); assertEquals("city", h.getHospitalCity()); assertEquals("ST", h.getHospitalState()); assertEquals("12345-6789", h.getHospitalZip()); assertEquals(42, h.hashCode()); } }
1,035
24.9
89
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/MedicationBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import edu.ncsu.csc.itrust.model.old.beans.MedicationBean; import junit.framework.TestCase; public class MedicationBeanTest extends TestCase { private MedicationBean med; @Override protected void setUp() throws Exception { med = new MedicationBean(); med.setDescription("blah"); med.setNDCode("blah blah"); } public void testPrescriptionEquals() throws Exception { med = new MedicationBean(); med.setDescription("blah"); med.setNDCode("blah blah"); MedicationBean med2 = new MedicationBean(); med2.setDescription("blah"); med2.setNDCode("blah blah"); assertEquals(med2, med); } public void testGetFormatted() { med = new MedicationBean(); med.setNDCode("9283777777"); assertEquals("92837-77777", med.getNDCodeFormatted()); } public void testShortCode() { med = new MedicationBean(); med.setNDCode("1"); assertEquals("1", med.getNDCodeFormatted()); } }
940
23.128205
58
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/OverrideReasonBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import edu.ncsu.csc.itrust.model.old.beans.OverrideReasonBean; import junit.framework.TestCase; public class OverrideReasonBeanTest extends TestCase { private OverrideReasonBean orb; public void testPrescriptionEquals() throws Exception { orb = new OverrideReasonBean(); orb.setDescription("blah"); orb.setORCode("00001"); orb.setID(1); orb.setPresID(2); OverrideReasonBean orb2 = new OverrideReasonBean(); orb2.setDescription("blah"); orb2.setORCode("00001"); orb2.setID(1); orb2.setPresID(2); assertTrue(orb2.equals(orb)); } }
598
22.96
62
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/PatientBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import java.text.SimpleDateFormat; import java.util.Date; import junit.framework.TestCase; import edu.ncsu.csc.itrust.DateUtil; import edu.ncsu.csc.itrust.model.old.beans.PatientBean; import edu.ncsu.csc.itrust.model.old.enums.BloodType; public class PatientBeanTest extends TestCase { private Date today; @Override protected void setUp() throws Exception { today = new Date(); } public void testAgeZero() throws Exception { PatientBean baby = new PatientBean(); baby.setDateOfBirthStr(new SimpleDateFormat("MM/dd/yyyy").format(today)); assertEquals(0, baby.getAge()); } public void testAge10() throws Exception { PatientBean kid = new PatientBean(); kid.setDateOfBirthStr(DateUtil.yearsAgo(10)); assertEquals(10, kid.getAge()); } public void testBean() { PatientBean p = new PatientBean(); p.setBloodType(BloodType.ABNeg); p.setDateOfBirthStr("bad date"); p.setCity("Raleigh"); p.setState("NC"); p.setZip("27613-1234"); p.setIcCity("Raleigh"); p.setIcState("NC"); p.setIcZip("27613-1234"); p.setSecurityQuestion("Question"); p.setSecurityAnswer("Answer"); p.setPassword("password"); p.setConfirmPassword("confirm"); assertEquals(BloodType.ABNeg, p.getBloodType()); assertNull(p.getDateOfBirth()); assertEquals(-1, p.getAge()); assertEquals("Raleigh, NC 27613-1234", p.getIcAddress3()); assertEquals("Raleigh, NC 27613-1234", p.getStreetAddress3()); assertEquals("Question", p.getSecurityQuestion()); assertEquals("Answer", p.getSecurityAnswer()); assertEquals("password", p.getPassword()); assertEquals("confirm", p.getConfirmPassword()); } }
1,658
28.625
75
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/PersonnelBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import java.util.List; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import java.util.LinkedList; import junit.framework.TestCase; public class PersonnelBeanTest extends TestCase { public void testPersonnelBeanSecurity() { PersonnelBean p = new PersonnelBean(); PersonnelBean p1 = new PersonnelBean(); PersonnelBean p2 = new PersonnelBean(); p.setPassword("password"); p.setConfirmPassword("confirm"); p.setSecurityQuestion("Question"); p.setSecurityAnswer("Answer"); assertEquals("confirm", p.getConfirmPassword()); assertEquals("password", p.getPassword()); assertEquals("Question", p.getSecurityQuestion()); assertEquals("Answer", p.getSecurityAnswer()); p.setFirstName("John"); p.setLastName("Doe"); p.setEmail("email@email.com"); p.setPhone("828-464-3333"); p.setSpecialty("Special"); assertEquals("John", p.getFirstName()); assertEquals("Doe", p.getLastName()); assertEquals("John Doe", p.getFullName()); assertEquals("email@email.com", p.getEmail()); assertEquals("828-464-3333", p.getPhone()); assertEquals("828-464-3333", p.getPhone()); assertEquals("Special", p.getSpecialty()); p.setCity("City"); p.setState("NC"); p.setZip("28658-2760"); assertEquals("City", p.getCity()); assertEquals("NC", p.getState()); assertEquals("28658-2760", p.getZip()); p.setZip(""); assertEquals("", p.getZip()); p.setMID(000001); p1.setMID(000002); assertEquals(000001, p.getMID()); List<PersonnelBean> list = new LinkedList<PersonnelBean>(); list.add(p); list.add(p1); assertEquals(0, p.getIndexIn(list)); assertEquals(1, p1.getIndexIn(list)); assertEquals(-1, p2.getIndexIn(list)); } }
1,729
24.820896
61
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/RatingComparatorTest.java
package edu.ncsu.csc.itrust.unit.bean; import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import junit.framework.TestCase; import edu.ncsu.csc.itrust.action.ReviewsAction; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean; import edu.ncsu.csc.itrust.model.old.beans.RatingComparator; import edu.ncsu.csc.itrust.model.old.dao.DAOFactory; import edu.ncsu.csc.itrust.model.old.dao.mysql.PersonnelDAO; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; /** * Tests the comparator for ratings * */ public class RatingComparatorTest extends TestCase { private DAOFactory factory = TestDAOFactory.getTestInstance(); private TestDataGenerator gen; private ReviewsAction action; /** * Gets the standard data and initializes a review action */ @Override protected void setUp() throws IOException, SQLException { gen = new TestDataGenerator(); gen.clearAllTables(); gen.standardData(); action = new ReviewsAction(factory, 2L); } /** * Tests the comparator of two things */ public void testComparator() { PersonnelDAO dao = new PersonnelDAO(factory); List<PersonnelBean> list = new ArrayList<PersonnelBean>(); try { list = dao.getAllPersonnel(); } catch (DBException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { if (list.size() != 0) Collections.sort(list, new RatingComparator(action)); } catch (Exception e) { fail(); } } }
1,630
25.306452
65
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/RecordsReleaseBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import java.sql.Timestamp; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import edu.ncsu.csc.itrust.model.old.beans.RecordsReleaseBean; import junit.framework.TestCase; public class RecordsReleaseBeanTest extends TestCase { private RecordsReleaseBean bean; @Override protected void setUp() throws Exception { bean = new RecordsReleaseBean(); } public void testReleaseID() { long testID = 0L; bean.setReleaseID(testID); assertEquals(testID, bean.getReleaseID()); testID = 5L; bean.setReleaseID(testID); assertEquals(testID, bean.getReleaseID()); } public void testPid() { long testID = 0L; bean.setPid(testID); assertEquals(testID, bean.getPid()); testID = 5L; bean.setPid(testID); assertEquals(testID, bean.getPid()); } public void testReleaseHospitalID() { String testID = "0"; bean.setReleaseHospitalID(testID); assertEquals(testID, bean.getReleaseHospitalID()); testID = "5"; bean.setReleaseHospitalID(testID); assertEquals(testID, bean.getReleaseHospitalID()); } public void testRecHospitalName() { String testName = "Test Hospital"; bean.setRecHospitalName(testName); assertEquals(testName, bean.getRecHospitalName()); testName = "Test Hospital 2"; bean.setRecHospitalName(testName); assertEquals(testName, bean.getRecHospitalName()); } public void testRecHospitalAddress() { String testAddress = "0 Test Drive"; bean.setRecHospitalAddress(testAddress); assertEquals(testAddress, bean.getRecHospitalAddress()); testAddress = "5 Test Drive"; bean.setRecHospitalAddress(testAddress); assertEquals(testAddress, bean.getRecHospitalAddress()); } public void testDocFirstName() { String testName = "Stupid"; bean.setDocFirstName(testName); assertEquals(testName, bean.getDocFirstName()); testName = "Cool"; bean.setDocFirstName(testName); assertEquals(testName, bean.getDocFirstName()); } public void testDocLastName() { String testName = "Stupid"; bean.setDocLastName(testName); assertEquals(testName, bean.getDocLastName()); testName = "Cool"; bean.setDocLastName(testName); assertEquals(testName, bean.getDocLastName()); } public void testDocPhone() { String testPhone = "000-000-0000"; bean.setDocPhone(testPhone); assertEquals(testPhone, bean.getDocPhone()); testPhone = "111-111-1111"; bean.setDocPhone(testPhone); assertEquals(testPhone, bean.getDocPhone()); } public void testDocEmail() { String testEmail = "a@a.com"; bean.setDocEmail(testEmail); assertEquals(testEmail, bean.getDocEmail()); testEmail = "b@b.com"; bean.setDocEmail(testEmail); assertEquals(testEmail, bean.getDocEmail()); } public void testJustification() { String testJustification = "Justify Test1"; bean.setJustification(testJustification); assertEquals(testJustification, bean.getJustification()); testJustification = "Justify Test2"; bean.setJustification(testJustification); assertEquals(testJustification, bean.getJustification()); } public void testStatus() { // Test pending status int testStatus = 0; String statusMsg = "Pending"; bean.setStatus(testStatus); assertEquals(testStatus, bean.getStatus()); assertEquals(statusMsg, bean.getStatusStr()); // Test approved status testStatus = 1; statusMsg = "Approved"; bean.setStatus(testStatus); assertEquals(testStatus, bean.getStatus()); assertEquals(statusMsg, bean.getStatusStr()); // Test denied status testStatus = 2; statusMsg = "Denied"; bean.setStatus(testStatus); assertEquals(testStatus, bean.getStatus()); assertEquals(statusMsg, bean.getStatusStr()); // Test invalid status number testStatus = 3; statusMsg = ""; bean.setStatus(testStatus); assertEquals(testStatus, bean.getStatus()); assertEquals(statusMsg, bean.getStatusStr()); } public void testDateRequested() { Timestamp testDate = new Timestamp(Calendar.getInstance().getTimeInMillis()); bean.setDateRequested(testDate); DateFormat df = new SimpleDateFormat("MM/dd/yyyy"); String testDateString = df.format(testDate); assertEquals(testDate, bean.getDateRequested()); assertEquals(testDateString, bean.getDateRequestedStr()); } }
4,252
25.917722
79
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/ReportRequestBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import edu.ncsu.csc.itrust.model.old.beans.ReportRequestBean; import junit.framework.TestCase; public class ReportRequestBeanTest extends TestCase { public void testReportRequestBean() throws Exception { ReportRequestBean b = new ReportRequestBean(); assertEquals(0L, b.getID()); // test setters b.setID(1); b.setRequesterMID(2); b.setPatientMID(3); b.setRequestedDateString("01/01/2008 12:00"); b.setViewedDateString("03/03/2008 12:00"); b.setStatus(ReportRequestBean.Requested); // confirm with getters assertEquals(1, b.getID()); assertEquals(2, b.getRequesterMID()); assertEquals(3, b.getPatientMID()); assertEquals("01/01/2008 12:00", b.getRequestedDateString()); assertEquals("03/03/2008 12:00", b.getViewedDateString()); assertEquals(ReportRequestBean.Requested, b.getStatus()); } public void testBadRequestedDate() throws Exception { ReportRequestBean b = new ReportRequestBean(); b.setRequestedDate(null); assertNull(b.getRequestedDate()); b.setRequestedDateString("bad format"); assertNull(b.getRequestedDate()); } }
1,118
29.243243
63
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/ReviewsBeanLoaderTest.java
package edu.ncsu.csc.itrust.unit.bean; import static org.easymock.classextension.EasyMock.createControl; import static org.junit.Assert.*; import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import static org.easymock.EasyMock.expect; import org.easymock.classextension.IMocksControl; import org.junit.After; import org.junit.Before; import org.junit.Test; import edu.ncsu.csc.itrust.model.old.beans.ReviewsBean; import edu.ncsu.csc.itrust.model.old.beans.loaders.ReviewsBeanLoader; /** * Test of the ReviewsBeanLoader, for creating/building a ReviewsBean */ public class ReviewsBeanLoaderTest { private IMocksControl ctrl; private ResultSet rs; private ReviewsBeanLoader load; private ReviewsBean bean; private static final long TPID = 90000001, TMID = 2; private static final int TRATING = 5; private static final Date TREVDATE = new java.sql.Date(new Date(0).getTime()); private static final String TDESCREV = "This doctor was fantifirrific!"; @Before public void setUp() throws Exception { ctrl = createControl(); rs = ctrl.createMock(ResultSet.class); load = new ReviewsBeanLoader(); bean = new ReviewsBean(); } @After public void tearDown() throws Exception { // unused currently } /** * Test the ReviewsBeanLoader's loadList() method * * @throws SQLException */ @Test public void testLoadList() throws SQLException { List<ReviewsBean> l = load.loadList(rs); assertEquals(0, l.size()); } /** * Test the ReviewsBeanLoader loadSingle() method. */ @Test public void testLoadSingle() { try { // set-up the ResultSet expect(rs.getLong("mid")).andReturn(TMID).once(); expect(rs.getLong("pid")).andReturn(TPID).once(); expect(rs.getInt("rating")).andReturn(TRATING).once(); expect(rs.getDate("reviewdate")).andReturn(TREVDATE).once(); expect(rs.getString("descriptivereview")).andReturn(TDESCREV).once(); expect(rs.getString("title")).andReturn("Bad Service").once(); ctrl.replay(); // load the bean bean = load.loadSingle(rs); // check all fields in bean are loaded properly assertEquals(TMID, bean.getMID()); assertEquals(TPID, bean.getPID()); assertEquals(TRATING, bean.getRating()); assertEquals(TREVDATE, bean.getDateOfReview()); assertEquals(TDESCREV, bean.getDescriptiveReview()); assertEquals("Bad Service", bean.getTitle()); } catch (SQLException e) { fail(); } } /** * Tests the ReviewsBeanLoader loadParameter() method. */ @Test public void testLoadParameters() { try { load.loadParameters(null, null); fail(); } catch (Exception e) { } } }
2,646
25.207921
79
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/SurveyBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import edu.ncsu.csc.itrust.model.old.beans.SurveyBean; import junit.framework.TestCase; public class SurveyBeanTest extends TestCase { public void testSurveyBean() throws Exception { SurveyBean b = new SurveyBean(); assertEquals(0L, b.getVisitID()); // test setters b.setVisitID(1L); b.setSurveyDateString("01/02/2008 12:34"); b.setWaitingRoomMinutes(100); b.setExamRoomMinutes(10); b.setVisitSatisfaction(1); b.setTreatmentSatisfaction(5); // confirm with getters assertEquals(1L, b.getVisitID()); assertEquals("01/02/2008 12:34", b.getSurveyDateString()); assertEquals(100, b.getWaitingRoomMinutes()); assertEquals(10, b.getExamRoomMinutes()); assertEquals(1, b.getVisitSatisfaction()); assertEquals(5, b.getTreatmentSatisfaction()); } }
819
26.333333
60
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/SurveyResultBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import edu.ncsu.csc.itrust.model.old.beans.SurveyResultBean; import junit.framework.TestCase; /** * * */ public class SurveyResultBeanTest extends TestCase { public void testSurveyResultBean() { // build a bean and stuff in some data SurveyResultBean b = new SurveyResultBean(); b.setHCPMID(55L); b.setHCPFirstName("Alfred"); b.setHCPLastName("Kinsey"); b.setHCPhospital("Kinsey Institute for Research in Sex, Gender and Reproduction"); b.setHCPspecialty("Sexual Behavior"); b.setHCPaddress1("1 Big O Street"); b.setHCPaddress2("Obsession Suite"); b.setHCPcity("Bloomington"); b.setHCPstate("IN"); b.setHCPzip("47401"); b.setAvgExamRoomMinutes(55.55F); b.setAvgWaitingRoomMinutes(44.44F); b.setAvgVisitSatisfaction(2.2F); b.setAvgTreatmentSatisfaction(3.3F); b.setPercentSatisfactionResults(25.25F); // now test the getters assertEquals(55L, b.getHCPMID()); assertEquals("Alfred", b.getHCPFirstName()); assertEquals("Kinsey", b.getHCPLastName()); assertEquals("Kinsey Institute for Research in Sex, Gender and Reproduction", b.getHCPhospital()); assertEquals("Sexual Behavior", b.getHCPspecialty()); assertEquals("1 Big O Street", b.getHCPaddress1()); assertEquals("Obsession Suite", b.getHCPaddress2()); assertEquals("Bloomington", b.getHCPcity()); assertEquals("IN", b.getHCPstate()); assertEquals("47401", b.getHCPzip()); assertEquals(55.55F, b.getAvgExamRoomMinutes()); assertEquals(44.44F, b.getAvgWaitingRoomMinutes()); assertEquals(2.2F, b.getAvgVisitSatisfaction()); assertEquals(3.3F, b.getAvgTreatmentSatisfaction()); assertEquals(25.25F, b.getPercentSatisfactionResults()); } }
1,707
31.846154
100
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/TelemedicineBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import edu.ncsu.csc.itrust.model.old.beans.TelemedicineBean; import junit.framework.TestCase; public class TelemedicineBeanTest extends TestCase { TelemedicineBean tBean; @Override protected void setUp() throws Exception { tBean = new TelemedicineBean(); } public void testHeight() throws Exception { tBean.setHeightAllowed(true); assertTrue(tBean.isHeightAllowed()); } public void testWeight() throws Exception { tBean.setWeightAllowed(false); assertTrue(!tBean.isWeightAllowed()); } public void testGlucoseLevel() throws Exception { tBean.setGlucoseLevelAllowed(true); assertTrue(tBean.isGlucoseLevelAllowed()); } }
687
22.724138
60
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/VisitFlagBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import edu.ncsu.csc.itrust.model.old.beans.VisitFlag; import junit.framework.TestCase; public class VisitFlagBeanTest extends TestCase { public void testSetTypeAndValue() { VisitFlag vf = new VisitFlag("typeonly"); vf.setType("a type"); vf.setValue("the value"); assertEquals("a type", vf.getType()); assertEquals("the value", vf.getValue()); } }
401
24.125
53
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/WardBeanLoaderTest.java
package edu.ncsu.csc.itrust.unit.bean; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import junit.framework.TestCase; import org.easymock.classextension.IMocksControl; import org.junit.Test; import edu.ncsu.csc.itrust.model.old.beans.WardBean; import edu.ncsu.csc.itrust.model.old.beans.loaders.WardBeanLoader; import static org.easymock.EasyMock.expect; import static org.easymock.classextension.EasyMock.createControl; /** * WardBeanLoaderTest */ public class WardBeanLoaderTest extends TestCase { private IMocksControl ctrl; java.util.List<WardBean> list = new ArrayList<WardBean>(); ResultSet rs; WardBeanLoader wbl = new WardBeanLoader(); /** * setUp */ @Override protected void setUp() throws Exception { ctrl = createControl(); rs = ctrl.createMock(ResultSet.class); } /** * testLoadList */ @Test public void testLoadList() { try { list = wbl.loadList(rs); } catch (SQLException e) { // TODO } assertEquals(0, list.size()); } /** * testloadSingle */ public void testloadSingle() { try { expect(rs.getLong("WardID")).andReturn(1L).once(); expect(rs.getString("RequiredSpecialty")).andReturn("specialty").once(); expect(rs.getLong("InHospital")).andReturn(1L).once(); ctrl.replay(); wbl.loadSingle(rs); } catch (SQLException e) { // TODO } } /** * testLoadParameters */ public void testLoadParameters() { try { wbl.loadParameters(null, null); fail(); } catch (IllegalStateException e) { // TODO } catch (SQLException e) { // TODO } assertTrue(true); } }
1,614
18
75
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/WardBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import edu.ncsu.csc.itrust.model.old.beans.WardBean; import junit.framework.TestCase; /** * WardBeanTest */ public class WardBeanTest extends TestCase { WardBean testBean; WardBean testBean2; WardBean testBean3; /** * setUp */ @Override public void setUp() { testBean = new WardBean(0, "", 0); testBean2 = new WardBean(0, "", 0); testBean3 = new WardBean(0, "", 0); } /** * testWardID */ public void testWardID() { testBean.setWardID(1); assertEquals(testBean.getWardID(), 1L); } /** * testSpecialty */ public void testSpecialty() { testBean.setRequiredSpecialty("special"); assertEquals(testBean.getRequiredSpecialty(), "special"); } /** * testInHospital */ public void testInHospital() { testBean.setInHospital(1); assertEquals(testBean.getInHospital(), 1L); } /** * testEquals */ public void testEquals() { assertTrue(testBean2.equals(testBean3)); } }
967
15.133333
59
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/WardRoomBeanLoaderTest.java
package edu.ncsu.csc.itrust.unit.bean; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import junit.framework.TestCase; import org.easymock.classextension.IMocksControl; import org.junit.Test; import edu.ncsu.csc.itrust.model.old.beans.WardRoomBean; import edu.ncsu.csc.itrust.model.old.beans.loaders.WardRoomBeanLoader; import static org.easymock.EasyMock.expect; import static org.easymock.classextension.EasyMock.createControl; /** * WardRoomBeanLoader */ public class WardRoomBeanLoaderTest extends TestCase { private IMocksControl ctrl; java.util.List<WardRoomBean> list = new ArrayList<WardRoomBean>(); ResultSet rs; WardRoomBeanLoader wbl = new WardRoomBeanLoader(); /** * setUp */ @Override protected void setUp() throws Exception { ctrl = createControl(); rs = ctrl.createMock(ResultSet.class); } /** * testLoadList */ @Test public void testLoadList() { try { list = wbl.loadList(rs); } catch (SQLException e) { // TODO } assertEquals(0, list.size()); } /** * testloadSingle */ public void testloadSingle() { try { expect(rs.getLong("RoomID")).andReturn(1L).once(); expect(rs.getLong("OccupiedBy")).andReturn(1L).once(); expect(rs.getLong("InWard")).andReturn(1L).once(); expect(rs.getString("roomName")).andReturn("CleanRoom").once(); expect(rs.getString("Status")).andReturn("Clean").once(); ctrl.replay(); wbl.loadSingle(rs); } catch (SQLException e) { // TODO } } /** * testLoadParameters */ public void testLoadParameters() { try { wbl.loadParameters(null, null); fail(); } catch (Exception e) { // TODO } assertTrue(true); } }
1,695
19.190476
70
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/WardRoomBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import edu.ncsu.csc.itrust.model.old.beans.WardRoomBean; import junit.framework.TestCase; /** * WardRoomBeanTest */ public class WardRoomBeanTest extends TestCase { WardRoomBean wrb1; WardRoomBean wrb2; WardRoomBean wrb3; /** * setUp */ @Override public void setUp() { wrb1 = new WardRoomBean(0L, 0L, 0L, "", ""); wrb2 = new WardRoomBean(0L, 0L, 0L, "", ""); wrb3 = new WardRoomBean(0L, 0L, 0L, "", ""); } /** * testRoomID */ public void testRoomID() { wrb1.setRoomID(1L); assertEquals(1L, wrb1.getRoomID()); } /** * testOccupiedBy */ public void testOccupiedBy() { wrb1.setOccupiedBy(1L); assertTrue(1L == wrb1.getOccupiedBy()); } /** * testInWard */ public void testInWard() { wrb1.setInWard(1L); assertTrue(1L == wrb1.getInWard()); } /** * testRoomName */ public void testRoomName() { wrb1.setRoomName("name"); assertTrue(wrb1.getRoomName().equals("name")); } /** * testRoomStatus */ public void testRoomStatus() { wrb1.setStatus("name"); assertTrue(wrb1.getStatus().equals("name")); } /** * testEquals */ public void testEquals() { assertTrue(wrb2.equals(wrb3)); } }
1,204
15.506849
56
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/ZipCodeBeanTest.java
package edu.ncsu.csc.itrust.unit.bean; import edu.ncsu.csc.itrust.model.old.beans.ZipCodeBean; import edu.ncsu.csc.itrust.model.old.enums.State; import junit.framework.TestCase; /** * Test for ZipCodeBean */ public class ZipCodeBeanTest extends TestCase { /** * Test for a bean. */ public void testBean() { ZipCodeBean bean = new ZipCodeBean(); bean.setCity("Wake Forest"); bean.setFullState("North Carolina"); bean.setState(State.NC); bean.setLatitude("69.5"); bean.setLongitude("35.5"); bean.setZip("27587"); assertTrue(bean.getCity().equals("Wake Forest")); assertTrue(bean.getFullState().equals("North Carolina")); assertTrue(bean.getLatitude().equals("69.5")); assertTrue(bean.getLongitude().equals("35.5")); assertTrue(bean.getZip().equals("27587")); assertTrue(bean.getState() == State.NC); } }
840
26.129032
59
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/bean/ZipCodeLoaderTest.java
package edu.ncsu.csc.itrust.unit.bean; import static org.easymock.EasyMock.expect; import static org.easymock.classextension.EasyMock.createControl; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import org.easymock.classextension.IMocksControl; import org.junit.Before; import org.junit.Test; import edu.ncsu.csc.itrust.model.old.beans.ZipCodeBean; import edu.ncsu.csc.itrust.model.old.beans.loaders.ZipCodeLoader; import junit.framework.TestCase; public class ZipCodeLoaderTest extends TestCase { private IMocksControl ctrl; private ResultSet rs; private ZipCodeLoader load; @Override @Before public void setUp() throws Exception { ctrl = createControl(); rs = ctrl.createMock(ResultSet.class); load = new ZipCodeLoader(); } @Test public void testLoadList() throws SQLException { List<ZipCodeBean> l = load.loadList(rs); assertEquals(0, l.size()); } @Test public void testLoadSingle() { try { // this just sets the value for a method call (kinda hard coding I // assume) expect(rs.getString("zip")).andReturn("27587"); expect(rs.getString("state")).andReturn("NC"); expect(rs.getString("latitude")).andReturn("65.5"); expect(rs.getString("longitude")).andReturn("30"); expect(rs.getString("city")).andReturn("Wake Forest"); expect(rs.getString("full_state")).andReturn("North Carolina"); ctrl.replay(); ZipCodeBean r = load.loadSingle(rs); assertEquals("27587", r.getZip()); assertEquals(edu.ncsu.csc.itrust.model.old.enums.State.NC, r.getState()); assertEquals("65.5", r.getLatitude()); assertEquals("30", r.getLongitude()); assertEquals("Wake Forest", r.getCity()); assertEquals("North Carolina", r.getFullState()); } catch (SQLException e) { // TODO } } }
1,787
26.090909
76
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/cptcode/CPTCodeControllerTest.java
package edu.ncsu.csc.itrust.unit.controller.cptcode; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.SQLException; import java.util.List; import javax.sql.DataSource; import org.junit.Assert; import org.mockito.Mockito; import edu.ncsu.csc.itrust.controller.cptcode.CPTCodeController; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.model.ConverterDAO; import edu.ncsu.csc.itrust.model.cptcode.CPTCode; import edu.ncsu.csc.itrust.model.cptcode.CPTCodeMySQL; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import junit.framework.TestCase; public class CPTCodeControllerTest extends TestCase { TestDataGenerator gen; DataSource ds; @Override public void setUp() throws FileNotFoundException, SQLException, IOException{ ds = ConverterDAO.getDataSource(); gen = new TestDataGenerator(); gen.clearAllTables(); } public void testConstructor(){ // test testing constructor CPTCodeController controller = new CPTCodeController(ds); Assert.assertNotNull(controller); controller = new CPTCodeController(); controller.setMySQL(new CPTCodeMySQL(ds)); } public void testAdd(){ CPTCodeController controller = new CPTCodeController(ds); Assert.assertNotNull(controller); // add a CPTCode controller.add(new CPTCode("1234B", "name1")); // verify List<CPTCode> codeList = controller.getCodesWithFilter("1234B"); Assert.assertEquals(1, codeList.size()); Assert.assertEquals("1234B", codeList.get(0).getCode()); Assert.assertEquals("name1", codeList.get(0).getName()); // try to add again controller.add(new CPTCode("1234B", "name2")); // verify it wasn't added codeList = controller.getCodesWithFilter("1234B"); Assert.assertEquals(1, codeList.size()); Assert.assertEquals("1234B", codeList.get(0).getCode()); Assert.assertEquals("name1", codeList.get(0).getName()); // try to add a garbage code controller.add(new CPTCode("fkhdskh432432", "name2")); // verify it wasn't added codeList = controller.getCodesWithFilter("fkhdskh432432"); Assert.assertEquals(0, codeList.size()); // cleanup controller.remove("1234B"); } public void testEdit(){ CPTCodeController controller = new CPTCodeController(ds); Assert.assertNotNull(controller); // add a CPTCode controller.add(new CPTCode("1234C", "name1")); // verify List<CPTCode> codeList = controller.getCodesWithFilter("1234C"); Assert.assertEquals(1, codeList.size()); Assert.assertEquals("1234C", codeList.get(0).getCode()); Assert.assertEquals("name1", codeList.get(0).getName()); // edit the code controller.edit(new CPTCode("1234C", "name2")); // verify codeList = controller.getCodesWithFilter("1234C"); Assert.assertEquals(1, codeList.size()); Assert.assertEquals("1234C", codeList.get(0).getCode()); Assert.assertEquals("name2", codeList.get(0).getName()); // edit with garbage controller.edit(new CPTCode("1234C", "name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2")); // verify that nothing changed codeList = controller.getCodesWithFilter("1234C"); Assert.assertEquals(1, codeList.size()); Assert.assertEquals("1234C", codeList.get(0).getCode()); Assert.assertEquals("name2", codeList.get(0).getName()); // edit a nonexistent code controller.edit(new CPTCode("1234D", "name2")); // verify that code wasn't added codeList = controller.getCodesWithFilter("1234D"); Assert.assertEquals(0, codeList.size()); // cleanup controller.remove("1234C"); } public void testRemove(){ CPTCodeController controller = new CPTCodeController(ds); Assert.assertNotNull(controller); // add a CPTCode controller.add(new CPTCode("1234E", "name1")); // verify List<CPTCode> codeList = controller.getCodesWithFilter("1234E"); Assert.assertEquals(1, codeList.size()); Assert.assertEquals("1234E", codeList.get(0).getCode()); Assert.assertEquals("name1", codeList.get(0).getName()); // remove it controller.remove("1234E"); // verify codeList = controller.getCodesWithFilter("1234E"); Assert.assertEquals(0, codeList.size()); // remove nonexistent code controller.remove("1234E"); // make sure it's still gone codeList = controller.getCodesWithFilter("1234E"); Assert.assertEquals(0, codeList.size()); } public void testGetters(){ CPTCodeController controller = new CPTCodeController(ds); Assert.assertNotNull(controller); // add a CPTCode controller.add(new CPTCode("1234F", "name1")); // verify List<CPTCode> codeList = controller.getCodesWithFilter("1234F"); Assert.assertEquals(1, codeList.size()); Assert.assertEquals("1234F", codeList.get(0).getCode()); Assert.assertEquals("name1", codeList.get(0).getName()); CPTCode code = controller.getCodeByID("1234F"); Assert.assertEquals("1234F", code.getCode()); Assert.assertEquals("name1", code.getName()); } public void testSQLErrors() throws SQLException, FormValidationException{ DataSource mockDS = mock(DataSource.class); CPTCodeController controller = new CPTCodeController(mockDS); controller = spy(controller); CPTCodeMySQL mockData = mock(CPTCodeMySQL.class); controller.setMySQL(mockData); when(mockData.getByCode(Mockito.anyString())).thenThrow(new SQLException()); controller.getCodeByID("b"); when(mockData.add(Mockito.anyObject())).thenThrow(new SQLException()); controller.add(new CPTCode("garbage", "garbage")); when(mockData.update(Mockito.anyObject())).thenThrow(new SQLException()); controller.edit(new CPTCode("garbage", "garbage")); when(mockData.delete(Mockito.anyObject())).thenThrow(new SQLException()); controller.remove("garbage"); when(mockData.getCodesWithFilter(Mockito.anyObject())).thenThrow(new SQLException()); controller.getCodesWithFilter("garbage"); } }
6,890
39.063953
230
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/cptcode/CPTCodeFormTest.java
package edu.ncsu.csc.itrust.unit.controller.cptcode; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.SQLException; import java.util.List; import javax.sql.DataSource; import org.junit.Assert; import org.junit.Test; import edu.ncsu.csc.itrust.controller.cptcode.CPTCodeController; import edu.ncsu.csc.itrust.controller.cptcode.CPTCodeForm; import edu.ncsu.csc.itrust.model.ConverterDAO; import edu.ncsu.csc.itrust.model.cptcode.CPTCode; import edu.ncsu.csc.itrust.model.cptcode.CPTCodeMySQL; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import junit.framework.TestCase; public class CPTCodeFormTest extends TestCase { TestDataGenerator gen; DataSource ds; @Override public void setUp() throws FileNotFoundException, SQLException, IOException{ ds = ConverterDAO.getDataSource(); gen = new TestDataGenerator(); gen.clearAllTables(); } @Test public void testCPTCodeForm(){ // test constructor CPTCodeForm form = new CPTCodeForm(); CPTCodeController controller = new CPTCodeController(); controller.setMySQL(new CPTCodeMySQL(ds)); form = new CPTCodeForm(controller); Assert.assertEquals("", form.getSearch()); Assert.assertFalse(form.getDisplayCodes()); // test fields form.setSearch("1"); Assert.assertEquals("1", form.getSearch()); form.setCptCode(new CPTCode("code2", "name2")); Assert.assertEquals("code2", form.getCptCode().getCode()); Assert.assertEquals("name2", form.getCptCode().getName()); form.setCode("code3"); form.setDescription("name3"); Assert.assertEquals("code3", form.getCode()); Assert.assertEquals("name3", form.getDescription()); form.setDisplayCodes(true); Assert.assertTrue(form.getDisplayCodes()); form.fillInput("code4", "name4"); Assert.assertEquals("code4", form.getCode()); Assert.assertEquals("name4", form.getDescription()); // test add form.fillInput("1234A", "desc"); form.add(); form.fillInput("1234A", "desc"); form.setSearch("1234A"); List<CPTCode> codeList = form.getCodesWithFilter(); Assert.assertEquals(1, codeList.size()); Assert.assertEquals("1234A", codeList.get(0).getCode()); Assert.assertEquals("desc", codeList.get(0).getName()); // test update form.setDescription("newDesc"); form.update(); form.fillInput("1234A", "newDesc"); codeList = form.getCodesWithFilter(); Assert.assertEquals(1, codeList.size()); Assert.assertEquals("1234A", codeList.get(0).getCode()); Assert.assertEquals("newDesc", codeList.get(0).getName()); // test delete form.delete(); codeList = form.getCodesWithFilter(); Assert.assertEquals(0, codeList.size()); } }
3,011
34.023256
80
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/emergencyRecord/EmergencyRecordControllerTest.java
package edu.ncsu.csc.itrust.unit.controller.emergencyRecord; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.SQLException; import java.util.List; import javax.sql.DataSource; import org.junit.Assert; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; import edu.ncsu.csc.itrust.controller.emergencyRecord.EmergencyRecordController; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.model.ConverterDAO; import edu.ncsu.csc.itrust.model.diagnosis.Diagnosis; import edu.ncsu.csc.itrust.model.emergencyRecord.EmergencyRecord; import edu.ncsu.csc.itrust.model.immunization.Immunization; import edu.ncsu.csc.itrust.model.old.beans.AllergyBean; import edu.ncsu.csc.itrust.model.old.dao.mysql.AllergyDAO; import edu.ncsu.csc.itrust.model.old.enums.TransactionType; import edu.ncsu.csc.itrust.model.prescription.Prescription; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory; import edu.ncsu.csc.itrust.webutils.SessionUtils; import junit.framework.TestCase; public class EmergencyRecordControllerTest extends TestCase { EmergencyRecordController c; @Mock private SessionUtils mockSessionUtils; private DataSource ds; @Override public void setUp() throws DBException, FileNotFoundException, SQLException, IOException { ds = ConverterDAO.getDataSource(); AllergyDAO allergyData = TestDAOFactory.getTestInstance().getAllergyDAO(); mockSessionUtils = Mockito.mock(SessionUtils.class); c = new EmergencyRecordController(ds, allergyData); c = spy(c); c.setSessionUtils(mockSessionUtils); doNothing().when(c).logTransaction(any(), any()); TestDataGenerator gen = new TestDataGenerator(); gen.clearAllTables(); gen.ndCodes(); gen.ndCodes1(); gen.ndCodes100(); gen.ndCodes2(); gen.ndCodes3(); gen.ndCodes4(); gen.uc21(); } @Test public void testLoadRecord() { // loads the record for Sandy Sky EmergencyRecord r; Assert.assertNotNull(r = c.loadRecord("201")); Assert.assertNotNull(r); Assert.assertEquals("Sandy Sky", r.getName()); Assert.assertEquals(24, r.getAge()); Assert.assertEquals("Male", r.getGender()); Assert.assertEquals("Susan Sky-Walker", r.getContactName()); Assert.assertEquals("444-332-4309", r.getContactPhone()); Assert.assertEquals("O-", r.getBloodType()); // test prescriptions List<Prescription> pList = r.getPrescriptions(); Assert.assertEquals(2, pList.size()); Assert.assertEquals("63739-291", pList.get(0).getCode()); Assert.assertEquals("48301-3420", pList.get(1).getCode()); // test allergies // the order in the list isn't specified so this gets gross, sorry List<AllergyBean> aList = r.getAllergies(); Assert.assertEquals(2, aList.size()); boolean found = false; for (int i = 0; i < aList.size(); i++) { if ("Pollen".equals(aList.get(i).getDescription())) { found = true; break; } } if (!found) { Assert.fail(); } found = false; for (int i = 0; i < aList.size(); i++) { if ("Penicillin".equals(aList.get(i).getDescription())) { found = true; break; } } if (!found) { Assert.fail(); } // test diagnoses List<Diagnosis> dList = r.getDiagnoses(); Assert.assertEquals(2, dList.size()); Assert.assertEquals("J00", dList.get(0).getCode()); Assert.assertEquals("J45", dList.get(1).getCode()); // test immunizations List<Immunization> iList = r.getImmunizations(); Assert.assertEquals(1, iList.size()); Assert.assertEquals("90715", iList.get(0).getCptCode().getCode()); } @Test public void testNoDataSource() { try { new EmergencyRecordController(); Assert.fail(); } catch (DBException e) { // yay, we passed } } @Test public void testInvalidPatient() { Assert.assertNull(c.loadRecord("-1")); Assert.assertNull(c.loadRecord("a")); c.logViewEmergencyRecord(); } @Test public void testLogViewEmergencyRecord() { Mockito.when(mockSessionUtils.getCurrentPatientMID()).thenReturn("9"); // 9 is arbitrary c.logViewEmergencyRecord(); verify(c, times(1)).logTransaction(TransactionType.EMERGENCY_REPORT_VIEW, null); } }
4,389
29.699301
91
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/hospital/HospitalControllerTest.java
package edu.ncsu.csc.itrust.unit.controller.hospital; import java.util.List; import javax.sql.DataSource; import org.junit.Assert; import org.junit.Test; import edu.ncsu.csc.itrust.controller.hospital.HospitalController; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.model.ConverterDAO; import edu.ncsu.csc.itrust.model.hospital.Hospital; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import junit.framework.TestCase; public class HospitalControllerTest extends TestCase { private HospitalController hc; private DataSource ds; private TestDataGenerator gen; //remove when ApptType, Patient, and other files are finished @Override public void setUp() throws Exception { ds = ConverterDAO.getDataSource(); hc = new HospitalController(ds); //remove when these modules are built and can be called gen = new TestDataGenerator(); gen.hospitals(); } @Test public void testHospitalInList() throws DBException{ List<Hospital> all = hc.getHospitalList(); String test = hc.HospitalNameForID("1"); for(int i=0; i<all.size(); i++){ if(all.get(i).getHospitalID() == "1"){ Assert.assertEquals(test, all.get(i).getHospitalName()); } } } }
1,251
26.822222
94
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/icdCode/ICDCodeControllerTest.java
package edu.ncsu.csc.itrust.unit.controller.icdCode; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.SQLException; import java.util.List; import javax.sql.DataSource; import org.junit.Assert; import org.mockito.Mockito; import edu.ncsu.csc.itrust.controller.icdcode.ICDCodeController; import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.model.ConverterDAO; import edu.ncsu.csc.itrust.model.icdcode.ICDCode; import edu.ncsu.csc.itrust.model.icdcode.ICDCodeMySQL; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import junit.framework.TestCase; public class ICDCodeControllerTest extends TestCase { TestDataGenerator gen; DataSource ds; @Override public void setUp() throws FileNotFoundException, SQLException, IOException{ ds = ConverterDAO.getDataSource(); gen = new TestDataGenerator(); gen.clearAllTables(); } public void testConstructor(){ ICDCodeController controller = new ICDCodeController(ds); Assert.assertNotNull(controller); controller = new ICDCodeController(); controller.setSQLData(new ICDCodeMySQL(ds)); } public void testAdd(){ ICDCodeController controller = new ICDCodeController(ds); Assert.assertNotNull(controller); // add an ICD code controller.add(new ICDCode("B11", "name1", true)); // verify List<ICDCode> codeList = controller.getCodesWithFilter("B11"); Assert.assertEquals(1, codeList.size()); Assert.assertEquals("B11", codeList.get(0).getCode()); Assert.assertEquals("name1", codeList.get(0).getName()); // try to add again controller.add(new ICDCode("B11", "name1", true)); // verify it wasn't added codeList = controller.getCodesWithFilter("B11"); Assert.assertEquals(1, codeList.size()); Assert.assertEquals("B11", codeList.get(0).getCode()); Assert.assertEquals("name1", codeList.get(0).getName()); // try to add garbage code controller.add(new ICDCode("fdsafdsafds", "name2", true)); // verify it wasn't added Assert.assertNull(controller.getCodeByID("fdsafdsafds")); // cleanup controller.remove("B11"); } public void testEdit(){ ICDCodeController controller = new ICDCodeController(ds); Assert.assertNotNull(controller); // add an ICD code controller.add(new ICDCode("C11", "name1", true)); // verify List<ICDCode> codeList = controller.getCodesWithFilter("C11"); Assert.assertEquals(1, codeList.size()); Assert.assertEquals("C11", codeList.get(0).getCode()); Assert.assertEquals("name1", codeList.get(0).getName()); // edit the code controller.edit(new ICDCode("C11", "name2", false)); // verify Assert.assertEquals("name2", controller.getCodeByID("C11").getName()); // edit with garbage controller.edit(new ICDCode("C11", "name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2", false)); // verify Assert.assertEquals("name2", controller.getCodeByID("C11").getName()); // edit a nonexistent code controller.edit(new ICDCode("C22", "name3", true)); // verify not added Assert.assertNull(controller.getCodeByID("C22")); // cleanup controller.remove("C11"); } public void testRemove(){ ICDCodeController controller = new ICDCodeController(ds); Assert.assertNotNull(controller); // test deleting nonexistent code controller.remove("garbage"); } public void testSQLErrors() throws SQLException, FormValidationException{ DataSource mockDS = mock(DataSource.class); ICDCodeController controller = new ICDCodeController(mockDS); controller = spy(controller); ICDCodeMySQL mockData = mock(ICDCodeMySQL.class); controller.setSQLData(mockData); when(mockData.getByCode(Mockito.anyString())).thenThrow(new SQLException()); controller.getCodeByID("b"); when(mockData.add(Mockito.anyObject())).thenThrow(new SQLException()); controller.add(new ICDCode("garbage", "garbage", true)); when(mockData.update(Mockito.anyObject())).thenThrow(new SQLException()); controller.edit(new ICDCode("garbage", "garbage", true)); when(mockData.delete(Mockito.anyObject())).thenThrow(new SQLException()); controller.remove("garbage"); when(mockData.getCodesWithFilter(Mockito.anyObject())).thenThrow(new SQLException()); controller.getCodesWithFilter("garbage"); } }
5,030
38
200
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/icdCode/ICDCodeFormTest.java
package edu.ncsu.csc.itrust.unit.controller.icdCode; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.SQLException; import java.util.List; import javax.sql.DataSource; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import edu.ncsu.csc.itrust.controller.icdcode.ICDCodeController; import edu.ncsu.csc.itrust.controller.icdcode.ICDCodeForm; import edu.ncsu.csc.itrust.model.ConverterDAO; import edu.ncsu.csc.itrust.model.icdcode.ICDCode; import edu.ncsu.csc.itrust.model.icdcode.ICDCodeMySQL; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; import junit.framework.TestCase; public class ICDCodeFormTest extends TestCase { TestDataGenerator gen; DataSource ds; @Override public void setUp() throws FileNotFoundException, SQLException, IOException{ ds = ConverterDAO.getDataSource(); gen = new TestDataGenerator(); gen.clearAllTables(); } @Test public void testICDCodeForm(){ // test constructor ICDCodeForm form = new ICDCodeForm(); ICDCodeController controller = new ICDCodeController(); controller.setSQLData(new ICDCodeMySQL(ds)); form = new ICDCodeForm(controller); Assert.assertEquals("", form.getSearch()); Assert.assertFalse(form.getDisplayCodes()); // test fields form.setCode("1"); Assert.assertEquals("1", form.getCode()); form.setDescription("2"); Assert.assertEquals("2", form.getDescription()); form.setDisplayCodes(true); Assert.assertTrue(form.getDisplayCodes()); form.setIsChronic(true); Assert.assertTrue(form.getIsChronic()); form.setSearch("3"); Assert.assertEquals("3", form.getSearch()); form.setIcdCode(new ICDCode("code", "desc", true)); Assert.assertEquals("code", form.getIcdCode().getCode()); Assert.assertEquals("desc", form.getIcdCode().getName()); // test add form.fillInput("A11", "name1", false); form.add(); form.setSearch("A11"); form.fillInput("A11", "name1", false); List<ICDCode> codeList = form.getCodesWithFilter(); Assert.assertEquals(1, codeList.size()); Assert.assertEquals("A11", codeList.get(0).getCode()); Assert.assertEquals("name1", codeList.get(0).getName()); // test update form.setDescription("newDesc"); form.update(); form.fillInput("A11", "newDesc", false); codeList = form.getCodesWithFilter(); Assert.assertEquals(1, codeList.size()); Assert.assertEquals("A11", codeList.get(0).getCode()); Assert.assertEquals("newDesc", codeList.get(0).getName()); // test delete form.delete(); codeList = form.getCodesWithFilter(); Assert.assertEquals(0, codeList.size()); } }
2,968
33.126437
80
java
iTrust
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/immunization/ImmunizationControllerTest.java
package edu.ncsu.csc.itrust.unit.controller.immunization; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import java.sql.SQLException; import javax.sql.DataSource; import org.junit.Test; import edu.ncsu.csc.itrust.controller.immunization.ImmunizationController; import edu.ncsu.csc.itrust.exception.DBException; import edu.ncsu.csc.itrust.model.ConverterDAO; import edu.ncsu.csc.itrust.model.cptcode.CPTCode; import edu.ncsu.csc.itrust.model.immunization.Immunization; import edu.ncsu.csc.itrust.model.immunization.ImmunizationMySQL; import junit.framework.TestCase; public class ImmunizationControllerTest extends TestCase { private DataSource ds; @Override public void setUp(){ ds = ConverterDAO.getDataSource(); } @Test public void testDiabolicals() throws DBException, SQLException{ ImmunizationController controller = new ImmunizationController(ds); ImmunizationMySQL sql = spy(new ImmunizationMySQL(ds)); controller.setSQL(sql); Immunization i = new Immunization(); i.setCptCode(new CPTCode("90044", "blah")); when(sql.add(i)).thenThrow(new NullPointerException()); controller.add(i); when(sql.update(i)).thenThrow(new NullPointerException()); controller.edit(i); when(sql.remove(0)).thenThrow(new SQLException()); controller.remove(0); when(sql.remove(1)).thenThrow(new NullPointerException()); controller.remove(1); when(sql.getImmunizationsForOfficeVisit(1)).thenThrow(new NullPointerException()); controller.getImmunizationsByOfficeVisit("1"); when(sql.getCodeName("9")).thenThrow(new SQLException()); controller.getCodeName("9"); } }
1,766
34.34
90
java