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/controller/immunization/ImmunizationFormTest.java
|
package edu.ncsu.csc.itrust.unit.controller.immunization;
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 edu.ncsu.csc.itrust.controller.immunization.ImmunizationController;
import edu.ncsu.csc.itrust.controller.immunization.ImmunizationForm;
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.cptcode.CPTCodeMySQL;
import edu.ncsu.csc.itrust.model.immunization.Immunization;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisitMySQL;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.webutils.SessionUtils;
import junit.framework.TestCase;
public class ImmunizationFormTest extends TestCase {
private TestDataGenerator gen;
private DataSource ds;
private OfficeVisitMySQL ovSql;
private SessionUtils utils;
@Override
public void setUp() throws FileNotFoundException, SQLException, IOException{
ds = ConverterDAO.getDataSource();
ovSql = new OfficeVisitMySQL(ds);
utils = spy(SessionUtils.getInstance());
gen = new TestDataGenerator();
gen.clearAllTables();
gen.uc11();
}
public void testForm() throws DBException, SQLException{
// set the office visit id in the session
long ovID = ovSql.getAll().get(0).getVisitID();
when(utils.getSessionVariable("officeVisitId")).thenReturn((Long) ovID);
// make the form
ImmunizationForm form = new ImmunizationForm();
form = new ImmunizationForm(null, null, utils, null);
form = new ImmunizationForm(null, null, utils, ds);
// fill input
form.fillInput("0", new CPTCode("90717", "Typhoid Vaccine"));
Assert.assertEquals(0, form.getImmunization().getId());
Assert.assertEquals("90717", form.getImmunization().getCode());
Assert.assertEquals("Typhoid Vaccine", form.getImmunization().getName());
Assert.assertEquals(ovID, form.getImmunization().getVisitId());
form.add();
List<Immunization> iList = form.getImmunizationsByOfficeVisit(Long.toString(ovID));
Assert.assertEquals(1, iList.size());
Assert.assertEquals("90717", iList.get(0).getCode());
form.setImmunization(iList.get(0));
form.getImmunization().setCptCode(new CPTCode("99214", ""));
form.edit();
iList = form.getImmunizationsByOfficeVisit(Long.toString(ovID));
Assert.assertEquals(1, iList.size());
Assert.assertEquals("99214", iList.get(0).getCode());
Assert.assertEquals("Typhoid Vaccine", form.getCodeName("90717"));
List<CPTCode> cptList = form.getCPTCodes();
Assert.assertEquals(2, cptList.size());
form.setImmunization(iList.get(0));
form.remove(Long.toString(form.getImmunization().getId()));
Assert.assertEquals(0, form.getImmunizationsByOfficeVisit(Long.toString(ovID)).size());
ImmunizationController mockImmunizationController = spy(new ImmunizationController(ds));
CPTCodeMySQL mockCPTCodeSQL = spy(new CPTCodeMySQL(ds));
form = new ImmunizationForm(mockImmunizationController, mockCPTCodeSQL, utils, ds);
when(mockImmunizationController.getImmunizationsByOfficeVisit(Long.toString(ovID))).thenThrow(new DBException(new SQLException()));
when(mockCPTCodeSQL.getAll()).thenThrow(new SQLException());
Assert.assertEquals(0, form.getCPTCodes().size());
Assert.assertEquals(0, form.getImmunizationsByOfficeVisit(Long.toString(ovID)).size());
}
}
| 3,909
| 41.967033
| 139
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/labProcedure/LabProcedureControllerTest.java
|
package edu.ncsu.csc.itrust.unit.controller.labProcedure;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.sql.DataSource;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import edu.ncsu.csc.itrust.controller.labProcedure.LabProcedureController;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.labProcedure.LabProcedure;
import edu.ncsu.csc.itrust.model.labProcedure.LabProcedure.LabProcedureStatus;
import edu.ncsu.csc.itrust.model.labProcedure.LabProcedureData;
import edu.ncsu.csc.itrust.model.labProcedure.LabProcedureMySQL;
import edu.ncsu.csc.itrust.model.old.enums.TransactionType;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.webutils.SessionUtils;
/**
* Unit tests for LabProcedureController.
*
* @author mwreesjo
*/
public class LabProcedureControllerTest {
@Mock
private SessionUtils mockSessionUtils;
@Mock
private LabProcedureData mockData;
private DataSource ds;
private LabProcedureController controller;
private TestDataGenerator gen;
private LabProcedure procedure;
@Before
public void setUp() throws FileNotFoundException, SQLException, IOException {
ds = ConverterDAO.getDataSource();
gen = new TestDataGenerator();
gen.clearAllTables();
controller = new LabProcedureController(ds);
mockSessionUtils = Mockito.mock(SessionUtils.class);
mockData = Mockito.mock(LabProcedureData.class);
procedure = new LabProcedure();
procedure.setCommentary("commentary");
procedure.setIsRestricted(true);
procedure.setLabProcedureID(8L);
procedure.setLabTechnicianID(9L);
procedure.setOfficeVisitID(10L);
procedure.setPriority(3);
procedure.setResults("results!");
procedure.setStatus(1L);
procedure.setUpdatedDate(new Timestamp(100L));
}
@After
public void tearDown() throws FileNotFoundException, SQLException, IOException {
gen.clearAllTables();
}
/**
* Tests happy path retrieval of one lab procedure.
*/
@Test
public void testGetLabProceduresByLabTechnicianSingleResult()
throws FileNotFoundException, SQLException, IOException {
gen.labProcedure0();
gen.labProcedure5();
List<LabProcedure> procs = null;
try {
procs = controller.getLabProceduresByLabTechnician("5000000001");
} catch (DBException e) {
fail("Shouldn't throw exception when getting lab procedures");
}
Assert.assertEquals(1, procs.size());
LabProcedure procedure = procs.get(0);
Assert.assertEquals("This is a lo pri lab procedure", procedure.getCommentary());
Assert.assertEquals("Foobar", procedure.getResults());
Assert.assertTrue(procedure.getLabTechnicianID() == 5000000001L);
Assert.assertTrue(procedure.getOfficeVisitID() == 4);
Assert.assertTrue(procedure.getPriority() == 3);
Assert.assertEquals("Pending", procedure.getStatus().getName());
}
/**
* Tests that getLabProceduresByLabTechnician() returns the correct lab
* procedures in the correct order
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
@Test
public void testGetLabProceduresByLabTechnicianMultipleResults()
throws FileNotFoundException, SQLException, IOException {
// Order should be lab procedure 1, 4, 3, 2, 0 based on the sort order
// defined in S7 in UC26
// (priority lo->hi, then date old->new)
genLabProcedures0To5();
List<LabProcedure> procs = null;
try {
procs = controller.getLabProceduresByLabTechnician("5000000001");
} catch (DBException e) {
fail("Shouldn't throw exception when getting lab procedures");
}
Assert.assertEquals(5, procs.size());
Assert.assertTrue(procs.get(0).getPriority() == 1);
Assert.assertTrue(procs.get(1).getPriority() == 2);
Assert.assertTrue(procs.get(2).getPriority() == 3);
Assert.assertEquals("In testing status", procs.get(2).getCommentary());
Assert.assertEquals("In received status", procs.get(3).getCommentary());
Assert.assertEquals("This is a lo pri lab procedure", procs.get(4).getCommentary());
}
/**
* Tests that getLabProceduresByOfficeVisit() returns the correct lab
* procedures in the correct order
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
@Test
public void testGetLabProceduresByOfficeVisit() throws FileNotFoundException, SQLException, IOException {
// Should return lab procedures 4, 3, 2 in that order
genLabProcedures0To5();
List<LabProcedure> procs = null;
try {
procs = controller.getLabProceduresByOfficeVisit("3");
} catch (DBException e) {
fail("Shouldn't throw exception when getting lab procedures");
}
Assert.assertTrue(procs.size() == 3);
Assert.assertTrue(procs.get(0).getPriority() == 2);
Assert.assertTrue(procs.get(1).getPriority() == 3);
Assert.assertTrue(procs.get(2).getPriority() == 3);
Assert.assertEquals("In completed status", procs.get(0).getCommentary());
Assert.assertEquals("In testing status", procs.get(1).getCommentary());
Assert.assertEquals("In received status", procs.get(2).getCommentary());
}
@Test
public void testGetCompletedLabProceduresByOfficeVisit() throws FileNotFoundException, SQLException, IOException {
// Should only return labProcedure4
genLabProcedures0To5();
List<LabProcedure> procs = null;
try {
procs = controller.getCompletedLabProceduresByOfficeVisit("3");
} catch (DBException e) {
fail("Shouldn't throw exception when getting lab procedures");
}
Assert.assertEquals(1, procs.size());
Assert.assertEquals("In completed status", procs.get(0).getCommentary());
Assert.assertEquals(new Long(5L), procs.get(0).getLabProcedureID());
}
@Test
public void testGetNonCompletedLabProceduresByOfficeVisit()
throws FileNotFoundException, SQLException, IOException {
// Should return labProcedure{2, 3}
genLabProcedures0To5();
List<LabProcedure> procs = null;
try {
procs = controller.getNonCompletedLabProceduresByOfficeVisit("3");
} catch (DBException e) {
fail("Shouldn't throw exception when getting lab procedures");
}
Assert.assertEquals(2, procs.size());
Assert.assertEquals("In testing status", procs.get(0).getCommentary());
Assert.assertEquals(new Long(4L), procs.get(0).getLabProcedureID());
Assert.assertEquals("In received status", procs.get(1).getCommentary());
Assert.assertEquals(new Long(3L), procs.get(1).getLabProcedureID());
}
/**
* Tests that getPendingLabProceduresByTechnician() returns only and all
* pending lab procedures.
*/
@Test
public void testGetPendingLabProceduresByTechnician() throws FileNotFoundException, SQLException, IOException {
genLabProcedures0To5();
List<LabProcedure> procs = null;
try {
procs = controller.getPendingLabProceduresByTechnician("5000000001");
} catch (DBException e) {
fail("Shouldn't throw exception when getting lab procedures");
}
Assert.assertTrue(procs.size() == 1);
LabProcedure pending = procs.get(0);
Assert.assertEquals("This is a lo pri lab procedure", pending.getCommentary());
Assert.assertEquals("Foobar", pending.getResults());
Assert.assertTrue(pending.getLabTechnicianID() == 5000000001L);
Assert.assertTrue(pending.getOfficeVisitID() == 4);
Assert.assertTrue(pending.getPriority() == 3);
Assert.assertEquals("Pending", pending.getStatus().getName());
}
/**
* Tests that getInTransitLabProceduresByTechnician() returns only and all
* in transit lab procedures.
*/
@Test
public void testGetInTransitLabProceduresByTechnician() throws FileNotFoundException, SQLException, IOException {
genLabProcedures0To5();
List<LabProcedure> procs = null;
try {
procs = controller.getInTransitLabProceduresByTechnician("5000000001");
} catch (DBException e) {
fail("Shouldn't throw exception when getting lab procedures");
}
Assert.assertEquals(1, procs.size());
LabProcedure inTransit = procs.get(0);
Assert.assertEquals("A hi pri lab procedure", inTransit.getCommentary());
Assert.assertEquals("Results are important", inTransit.getResults());
Assert.assertTrue(inTransit.getLabTechnicianID() == 5000000001L);
Assert.assertTrue(inTransit.getOfficeVisitID() == 4);
Assert.assertTrue(inTransit.getPriority() == 1);
Assert.assertEquals("In transit", inTransit.getStatus().getName());
}
/**
* Tests that getReceivedLabProceduresByTechnician() returns only and all
* received lab procedures.
*/
@Test
public void testGetReceivedLabProceduresByTechnician() throws FileNotFoundException, SQLException, IOException {
genLabProcedures0To5();
List<LabProcedure> procs = null;
try {
procs = controller.getReceivedLabProceduresByTechnician("5000000001");
} catch (DBException e) {
fail("Shouldn't throw exception when getting lab procedures");
}
Assert.assertEquals(1, procs.size());
LabProcedure received = procs.get(0);
Assert.assertEquals("Received", received.getStatus().getName());
}
/**
* Tests that getTestingLabProceduresByTechnician() returns only and all
* testing lab procedures.
*/
@Test
public void testGetTestingLabProceduresByTechnician() throws FileNotFoundException, SQLException, IOException {
genLabProcedures0To5();
List<LabProcedure> procs = null;
try {
procs = controller.getTestingLabProceduresByTechnician("5000000001");
} catch (DBException e) {
fail("Shouldn't throw exception when getting lab procedures");
}
Assert.assertEquals(1, procs.size());
LabProcedure testing = procs.get(0);
Assert.assertEquals("Testing", testing.getStatus().getName());
}
/**
* Tests that getCompletedLabProceduresByTechnician() returns only and all
* completed lab procedures.
*/
@Test
public void getCompletedLabProceduresByTechnician() throws FileNotFoundException, SQLException, IOException {
genLabProcedures0To5();
List<LabProcedure> procs = null;
try {
procs = controller.getCompletedLabProceduresByTechnician("5000000001");
} catch (DBException e) {
fail("Shouldn't throw exception when getting lab procedures");
}
Assert.assertEquals(1, procs.size());
LabProcedure completed = procs.get(0);
Assert.assertEquals("Completed", completed.getStatus().getName());
}
/**
* Tests that setLabProcedureToReceivedStatus() correctly sets queries,
* updates, and persists the lab procedure with given ID.
* @throws FormValidationException
*
* @throws IOException
* @throws SQLException
* @throws FileNotFoundException
*/
@Test
public void testSetLabProcedureToReceivedStatus() throws DBException, FormValidationException {
DataSource mockDS = mock(DataSource.class);
controller = new LabProcedureController(mockDS);
controller = spy(controller);
procedure.setStatus(LabProcedureStatus.IN_TRANSIT.getID());
LabProcedureData mockData = mock(LabProcedureData.class);
controller.setLabProcedureData(mockData);
when(mockData.getByID(Mockito.anyLong())).thenReturn(procedure);
when(mockData.update(procedure)).thenReturn(true);
controller.setLabProcedureToReceivedStatus("" + procedure.getLabProcedureID());
verify(mockData, times(1)).update(procedure);
verify(controller, times(1)).printFacesMessage(Mockito.eq(FacesMessage.SEVERITY_INFO), Mockito.anyString(),
Mockito.anyString(), Mockito.anyString());
Assert.assertEquals(LabProcedureStatus.RECEIVED, procedure.getStatus());
}
/**
* Tests that setLabProcedureToReceivedStatus() prints a faces message when
* a DBException occurs.
* @throws FormValidationException
*/
@Test
public void testSetLabProcedureToReceivedStatusDBException() throws DBException, FormValidationException {
DataSource mockDS = mock(DataSource.class);
controller = new LabProcedureController(mockDS);
controller = spy(controller);
procedure.setStatus(LabProcedureStatus.IN_TRANSIT.getID());
LabProcedureData mockData = mock(LabProcedureData.class);
controller.setLabProcedureData(mockData);
when(mockData.getByID(Mockito.anyLong())).thenThrow(new DBException(null));
when(mockData.update(procedure)).thenReturn(false);
controller.setLabProcedureToReceivedStatus("" + procedure.getLabProcedureID());
verify(mockData, times(0)).update(procedure);
verify(controller, times(1)).printFacesMessage(Mockito.eq(FacesMessage.SEVERITY_ERROR), Mockito.anyString(),
Mockito.anyString(), Mockito.anyString());
Assert.assertEquals(LabProcedureStatus.IN_TRANSIT, procedure.getStatus());
}
/**
* Tests that setLabProcedureToReceivedStatus() prints a faces message when
* an Exception occurs.
* @throws FormValidationException
*/
@Test
public void testSetLabProcedureToReceivedStatusException() throws DBException, FormValidationException {
DataSource mockDS = mock(DataSource.class);
controller = new LabProcedureController(mockDS);
controller = spy(controller);
procedure.setStatus(LabProcedureStatus.IN_TRANSIT.getID());
LabProcedureData mockData = mock(LabProcedureData.class);
controller.setLabProcedureData(mockData);
// Any unchecked exception will do
when(mockData.getByID(Mockito.anyLong())).thenThrow(new NullPointerException());
when(mockData.update(procedure)).thenReturn(false);
controller.setLabProcedureToReceivedStatus("" + procedure.getLabProcedureID());
verify(mockData, times(0)).update(procedure);
verify(controller, times(1)).printFacesMessage(Mockito.eq(FacesMessage.SEVERITY_ERROR), Mockito.anyString(),
Mockito.anyString(), Mockito.anyString());
Assert.assertEquals(LabProcedureStatus.IN_TRANSIT, procedure.getStatus());
}
/**
* Tests that add() correctly adds a lab procedure.
* @throws FormValidationException
*/
@Test
public void testAdd() throws SQLException, DBException, FormValidationException {
DataSource mockDS = mock(DataSource.class);
LabProcedureData mockData = mock(LabProcedureData.class);
when(mockData.add(Mockito.any(LabProcedure.class))).thenReturn(true);
when(mockSessionUtils.getSessionUserRole()).thenReturn("hcp");
when(mockSessionUtils.getSessionLoggedInMID()).thenReturn("9000000001");
controller = spy(new LabProcedureController(mockDS));
controller.setSessionUtils(mockSessionUtils);
controller.setLabProcedureData(mockData);
Mockito.doNothing().when(controller).logTransaction(any(), Mockito.anyString());
controller.add(procedure);
verify(controller).printFacesMessage(Mockito.eq(FacesMessage.SEVERITY_INFO), Mockito.anyString(),
Mockito.anyString(), Mockito.anyString());
verify(controller).logTransaction(TransactionType.LAB_RESULTS_CREATE, procedure.getLabProcedureCode());
}
/**
* Tests that add() catches Exceptions TODO: test this more thoroughly?
* @throws FormValidationException
*/
@Test
public void testAddWithDBException() throws SQLException, DBException, FormValidationException {
DataSource mockDS = mock(DataSource.class);
controller = new LabProcedureController(mockDS);
controller.setSessionUtils(mockSessionUtils);
controller = spy(controller);
LabProcedureData mockData = mock(LabProcedureData.class);
controller.setLabProcedureData(mockData);
when(mockSessionUtils.getSessionUserRole()).thenReturn("hcp");
when(mockData.add(Mockito.any(LabProcedure.class))).thenThrow(new DBException(null));
controller.add(procedure);
verify(controller).printFacesMessage(Mockito.eq(FacesMessage.SEVERITY_ERROR), Mockito.anyString(),
Mockito.anyString(), Mockito.anyString());
}
/**
* Tests that edit() correctly edits a lab procedure. TODO: test this more
* thoroughly?
* @throws FormValidationException
*/
@Test
public void testEdit() throws SQLException, DBException, FormValidationException {
DataSource mockDS = mock(DataSource.class);
controller = new LabProcedureController(mockDS);
controller = spy(controller);
LabProcedureData mockData = mock(LabProcedureData.class);
controller.setLabProcedureData(mockData);
when(mockData.update(Mockito.any(LabProcedure.class))).thenReturn(true);
controller.edit(procedure);
verify(controller).printFacesMessage(Mockito.eq(FacesMessage.SEVERITY_INFO), Mockito.anyString(),
Mockito.anyString(), Mockito.anyString());
}
/**
* Tests that remove() correctly removes a lab procedure. TODO: test this
* more thoroughly?
*/
@Test
public void testRemove() throws SQLException, DBException {
DataSource mockDS = mock(DataSource.class);
controller = new LabProcedureController(mockDS);
controller = spy(controller);
LabProcedureData mockData = mock(LabProcedureData.class);
controller.setLabProcedureData(mockData);
when(mockData.removeLabProcedure(1L)).thenReturn(true);
controller.remove("1");
verify(mockData, times(1)).removeLabProcedure(1L);
verify(controller).printFacesMessage(Mockito.eq(FacesMessage.SEVERITY_INFO), Mockito.anyString(),
Mockito.anyString(), Mockito.anyString());
}
/**
* Tests that get() correctly retrieves a lab procedure.
*/
@Test
public void testGet() throws Exception {
gen.labProcedure0();
controller = spy(controller);
Mockito.doNothing().when(controller).printFacesMessage(any(), any(), any(), any());
LabProcedure proc = controller.getLabProcedureByID("1");
Assert.assertNotNull(proc);
Assert.assertEquals(5000000001L, proc.getLabTechnicianID().longValue());
proc = controller.getLabProcedureByID("-1");
Assert.assertNull(proc);
proc = controller.getLabProcedureByID("aa");
Assert.assertNull(proc);
verify(controller).printFacesMessage(eq(FacesMessage.SEVERITY_ERROR), any(), any(), any());
}
/**
* Tests that remove() throws correct exception for invalid ID argument
*/
@Test
public void testRemoveInvalidID() throws SQLException, FileNotFoundException, IOException {
genLabProcedures0To5();
DataSource mockDS = Mockito.mock(DataSource.class);
LabProcedureData mockData = Mockito.mock(LabProcedureMySQL.class);
when(mockDS.getConnection()).thenReturn(ds.getConnection());
controller = Mockito.spy(new LabProcedureController(mockDS));
controller.remove("foo");
Mockito.verify(controller, times(1)).printFacesMessage(Mockito.any(), Mockito.anyString(), Mockito.anyString(),
Mockito.anyString());
Mockito.verifyZeroInteractions(mockDS);
Mockito.verifyZeroInteractions(mockData);
}
/**
* Tests controller constructor. TODO: doesn't actually test much
*/
@Test
public void testLabProcedure() {
controller = new LabProcedureController();
Assert.assertNotNull(controller);
}
@Test
public void testRecordResults() {
controller = spy(controller);
procedure.setStatus(LabProcedureStatus.TESTING.getID());
try {
controller.recordResults(procedure);
} catch (DBException e) {
fail("Should not throw DBException when calling recordResults()");
e.printStackTrace();
}
Assert.assertEquals(LabProcedureStatus.PENDING, procedure.getStatus());
try {
Mockito.verify(controller, times(1)).edit(procedure);
Mockito.verify(controller, times(1)).updateStatusForReceivedList(Mockito.anyString());
} catch (DBException e) {
fail("Mockito couldn't verify controller method called, DBException thrown");
e.printStackTrace();
}
}
/**
* The controller should log that each lab procedure for the office visit in
* the session has been viewed by the loggedInMID.
*/
@Test
public void testLogViewLabProcedure() throws DBException {
List<LabProcedure> procs = new ArrayList<>(2);
procs.add(procedure);
LabProcedure second = new LabProcedure();
second.setLabProcedureCode("33333-4");
procs.add(second);
controller = spy(controller);
when(mockSessionUtils.getCurrentOfficeVisitId()).thenReturn(2L);
Mockito.doNothing().when(controller).logTransaction(any(), any());
when(controller.getLabProceduresByOfficeVisit("2")).thenReturn(procs);
controller.setSessionUtils(mockSessionUtils);
controller.setLabProcedureData(mockData);
controller.logViewLabProcedure();
verify(controller, times(2)).logTransaction(any(), Mockito.anyString());
}
@Test
public void testLogViewLabProcedureNoOfficeVisitSelected() throws DBException {
controller = spy(controller);
when(mockSessionUtils.getCurrentOfficeVisitId()).thenReturn(null);
Mockito.doNothing().when(controller).logTransaction(any(), any());
controller.setSessionUtils(mockSessionUtils);
controller.setLabProcedureData(mockData);
controller.logViewLabProcedure();
verify(controller, times(0)).logTransaction(any(), any());
}
/**
* The controller should log when a lab technician has viewed his/her queue
* of lab procedures.
*/
@Test
public void testLogLabTechnicianViewLabProcedureQueue() {
controller = spy(controller);
when(mockSessionUtils.getSessionLoggedInMIDLong()).thenReturn(new Long(4L));
Mockito.doNothing().when(controller).logTransaction(any(), any(), any(), any());
controller.setSessionUtils(mockSessionUtils);
controller.setLabProcedureData(mockData);
controller.logLabTechnicianViewLabProcedureQueue();
verify(controller, times(1)).logTransaction(TransactionType.LAB_RESULTS_VIEW_QUEUE, new Long(4), null, null);
}
/**
* Generates lab procedures 0, 1, 2, 3, 4, 5 with TestDataGenerator.
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
private void genLabProcedures0To5() throws FileNotFoundException, SQLException, IOException {
gen.labProcedure0();
gen.labProcedure1();
gen.labProcedure2();
gen.labProcedure3();
gen.labProcedure4();
gen.labProcedure5();
}
}
| 22,014
| 36.250423
| 115
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/loincCode/LOINCCodeControllerTest.java
|
package edu.ncsu.csc.itrust.unit.controller.loincCode;
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.controller.loinccode.LoincCodeController;
import edu.ncsu.csc.itrust.exception.DBException;
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.model.loinccode.LOINCCode;
import edu.ncsu.csc.itrust.model.loinccode.LOINCCodeMySQL;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import junit.framework.TestCase;
public class LOINCCodeControllerTest 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(){
LoincCodeController controller = new LoincCodeController(ds);
Assert.assertNotNull(controller);
controller = new LoincCodeController();
controller.setSQLData(new LOINCCodeMySQL(ds));
}
public void testAdd(){
LoincCodeController controller = new LoincCodeController(ds);
Assert.assertNotNull(controller);
// add an ICD code
controller.add(new LOINCCode("1-1", "name1", "kind"));
// verify
List<LOINCCode> codeList = controller.getCodesWithFilter("1-1");
Assert.assertEquals(1, codeList.size());
Assert.assertEquals("1-1", codeList.get(0).getCode());
Assert.assertEquals("name1", codeList.get(0).getComponent());
Assert.assertEquals("kind", codeList.get(0).getKindOfProperty());
// try to add again
controller.add(new LOINCCode("1-1", "name1", "kind"));
// verify it wasn't added
codeList = controller.getCodesWithFilter("1-1");
Assert.assertEquals(1, codeList.size());
Assert.assertEquals("1-1", codeList.get(0).getCode());
Assert.assertEquals("name1", codeList.get(0).getComponent());
Assert.assertEquals("kind", codeList.get(0).getKindOfProperty());
// try to add garbage code
controller.add(new LOINCCode("fda", "name1", "kind"));
// verify it wasn't added
Assert.assertNull(controller.getCodeByID("fda"));
// cleanup
controller.remove("1-1");
}
public void testEdit(){
LoincCodeController controller = new LoincCodeController(ds);
Assert.assertNotNull(controller);
// add an ICD code
controller.add(new LOINCCode("2-2", "name1", "kind"));
// verify
List<LOINCCode> codeList = controller.getCodesWithFilter("2-2");
Assert.assertEquals(1, codeList.size());
Assert.assertEquals("2-2", codeList.get(0).getCode());
Assert.assertEquals("name1", codeList.get(0).getComponent());
// edit the code
controller.edit(new LOINCCode("2-2", "name2", "kind"));
// verify
Assert.assertEquals("name2", controller.getCodeByID("2-2").getComponent());
// edit with garbage
controller.edit(new LOINCCode("2-2", "name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2", "kind"));
// verify
Assert.assertEquals("name2", controller.getCodeByID("2-2").getComponent());
// edit a nonexistent code
controller.edit(new LOINCCode("3-3", "name3", "kind"));
// verify not added
Assert.assertNull(controller.getCodeByID("3-3"));
// cleanup
controller.remove("2-2");
}
public void testRemove(){
LoincCodeController controller = new LoincCodeController(ds);
Assert.assertNotNull(controller);
// test deleting nonexistent code
controller.remove("garbage");
}
public void testSQLErrors() throws SQLException, FormValidationException, DBException{
DataSource mockDS = mock(DataSource.class);
LoincCodeController controller = new LoincCodeController(mockDS);
controller = spy(controller);
LOINCCodeMySQL mockData = mock(LOINCCodeMySQL.class);
controller.setSQLData(mockData);
when(mockData.getByCode(Mockito.anyString())).thenThrow(new DBException(null));
controller.getCodeByID("b");
when(mockData.add(Mockito.anyObject())).thenThrow(new DBException(null));
controller.add(new LOINCCode("garbage", "garbage", "garbage"));
when(mockData.update(Mockito.anyObject())).thenThrow(new DBException(null));
controller.edit(new LOINCCode("garbage", "garbage", "garbage"));
when(mockData.delete(Mockito.anyObject())).thenThrow(new SQLException());
controller.remove("garbage");
when(mockData.getCodesWithFilter(Mockito.anyObject())).thenThrow(new SQLException());
controller.getCodesWithFilter("garbage");
}
}
| 5,497
| 39.725926
| 183
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/loincCode/LOINCCodeFormTest.java
|
package edu.ncsu.csc.itrust.unit.controller.loincCode;
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.loinccode.LoincCodeController;
import edu.ncsu.csc.itrust.controller.loinccode.LoincCodeForm;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.loinccode.LOINCCode;
import edu.ncsu.csc.itrust.model.loinccode.LOINCCodeMySQL;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import junit.framework.TestCase;
public class LOINCCodeFormTest 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 testForm(){
// test constructor
LoincCodeForm form = new LoincCodeForm();
LoincCodeController controller = new LoincCodeController();
controller.setSQLData(new LOINCCodeMySQL(ds));
form = new LoincCodeForm(controller);
Assert.assertEquals("", form.getSearch());
Assert.assertFalse(form.getDisplayCodes());
// test fields
form.setCode("code");
Assert.assertEquals("code", form.getCode());
form.setComponent("comp");
Assert.assertEquals("comp", form.getComponent());
form.setDisplayCodes(true);
Assert.assertTrue(form.getDisplayCodes());
form.setKindOfProperty("kind");
Assert.assertEquals("kind", form.getKindOfProperty());
form.setLoincCode(new LOINCCode("code1", "comp1", "kind1"));
Assert.assertEquals("code1", form.getLoincCode().getCode());
form.setMethodType("method");
Assert.assertEquals("method", form.getMethodType());
form.setScaleType("scale");
Assert.assertEquals("scale", form.getScaleType());
form.setSearch("search");
Assert.assertEquals("search", form.getSearch());
form.setSystem("sys");
Assert.assertEquals("sys", form.getSystem());
form.setTimeAspect("time");
Assert.assertEquals("time", form.getTimeAspect());
// test add
form.fillInput("1-2", "comp", "kind", "time", "sys", "scale", "method");
form.add();
form.setSearch("1-2");
form.fillInput("1-2", "comp", "kind", "time", "sys", "scale", "method");
List<LOINCCode> codeList = form.getCodesWithFilter();
Assert.assertEquals(1, codeList.size());
Assert.assertEquals("1-2", codeList.get(0).getCode());
Assert.assertEquals("comp", codeList.get(0).getComponent());
// test update
form.fillInput("1-2", "comp2", "kind", "time", "sys", "scale", "method");
form.update();
form.setSearch("1-2");
form.fillInput("1-2", "comp2", "kind", "time", "sys", "scale", "method");
codeList = form.getCodesWithFilter();
Assert.assertEquals(1, codeList.size());
Assert.assertEquals("1-2", codeList.get(0).getCode());
Assert.assertEquals("comp2", codeList.get(0).getComponent());
// test delete
form.delete();
codeList = form.getCodesWithFilter();
Assert.assertEquals(0, codeList.size());
}
}
| 3,543
| 35.163265
| 81
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/medicalProcedure/MedicalProcedureControllerTest.java
|
package edu.ncsu.csc.itrust.unit.controller.medicalProcedure;
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.medicalProcedure.MedicalProcedureController;
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.medicalProcedure.MedicalProcedure;
import edu.ncsu.csc.itrust.model.medicalProcedure.MedicalProcedureMySQL;
import junit.framework.TestCase;
public class MedicalProcedureControllerTest extends TestCase {
private DataSource ds;
@Override
public void setUp(){
ds = ConverterDAO.getDataSource();
}
@Test
public void testDiabolicals() throws DBException, SQLException{
MedicalProcedureController controller = new MedicalProcedureController(ds);
MedicalProcedureMySQL sql = spy(new MedicalProcedureMySQL(ds));
controller.setSQL(sql);
MedicalProcedure i = new MedicalProcedure();
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.getMedicalProceduresForOfficeVisit(1)).thenThrow(new NullPointerException());
controller.getMedicalProceduresByOfficeVisit("1");
when(sql.getCodeName("9")).thenThrow(new SQLException());
controller.getCodeName("9");
}
}
| 1,830
| 35.62
| 94
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/medicalProcedure/MedicalProcedureFormTest.java
|
package edu.ncsu.csc.itrust.unit.controller.medicalProcedure;
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.controller.medicalProcedure.MedicalProcedureController;
import edu.ncsu.csc.itrust.controller.medicalProcedure.MedicalProcedureForm;
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.cptcode.CPTCodeMySQL;
import edu.ncsu.csc.itrust.model.medicalProcedure.MedicalProcedure;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisitMySQL;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.webutils.SessionUtils;
import junit.framework.TestCase;
public class MedicalProcedureFormTest extends TestCase {
private TestDataGenerator gen;
private DataSource ds;
private OfficeVisitMySQL ovSql;
private SessionUtils utils;
@Override
public void setUp() throws FileNotFoundException, SQLException, IOException{
ds = ConverterDAO.getDataSource();
ovSql = new OfficeVisitMySQL(ds);
utils = spy(SessionUtils.getInstance());
gen = new TestDataGenerator();
gen.clearAllTables();
gen.uc11();
}
public void testForm() throws DBException, SQLException{
// set the office visit id in the session
long ovID = ovSql.getAll().get(0).getVisitID();
when(utils.getSessionVariable("officeVisitId")).thenReturn((Long) ovID);
// make the form
MedicalProcedureForm form = new MedicalProcedureForm();
form = new MedicalProcedureForm(null, null, utils, null);
form = new MedicalProcedureForm(null, null, utils, ds);
// fill input
form.fillInput("0", new CPTCode("90717", "Typhoid Vaccine"));
Assert.assertEquals(0, form.getMedicalProcedure().getId());
Assert.assertEquals("90717", form.getMedicalProcedure().getCode());
Assert.assertEquals("Typhoid Vaccine", form.getMedicalProcedure().getName());
Assert.assertEquals(ovID, form.getMedicalProcedure().getOfficeVisitId());
form.add();
List<MedicalProcedure> iList = form.getMedicalProceduresByOfficeVisit(Long.toString(ovID));
Assert.assertEquals(1, iList.size());
Assert.assertEquals("90717", iList.get(0).getCode());
form.setMedicalProcedure(iList.get(0));
form.getMedicalProcedure().setCptCode(new CPTCode("99214", ""));
form.edit();
iList = form.getMedicalProceduresByOfficeVisit(Long.toString(ovID));
Assert.assertEquals(1, iList.size());
Assert.assertEquals("99214", iList.get(0).getCode());
Assert.assertEquals("Typhoid Vaccine", form.getCodeName("90717"));
List<CPTCode> cptList = form.getCPTCodes();
Assert.assertEquals(2, cptList.size());
form.setMedicalProcedure(iList.get(0));
form.remove(Long.toString(form.getMedicalProcedure().getId()));
Assert.assertEquals(0, form.getMedicalProceduresByOfficeVisit(Long.toString(ovID)).size());
MedicalProcedureController mockMedicalProcedureController = spy(new MedicalProcedureController(ds));
CPTCodeMySQL mockCPTCodeSQL = spy(new CPTCodeMySQL(ds));
form = new MedicalProcedureForm(mockMedicalProcedureController, mockCPTCodeSQL, utils, ds);
when(mockCPTCodeSQL.getAll()).thenThrow(new SQLException());
Assert.assertEquals(0, form.getCPTCodes().size());
}
}
| 3,888
| 41.736264
| 108
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/ndcCode/NDCCodeControllerTest.java
|
package edu.ncsu.csc.itrust.unit.controller.ndcCode;
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.ndcode.NDCCodeController;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.ndcode.NDCCode;
import edu.ncsu.csc.itrust.model.ndcode.NDCCodeMySQL;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import junit.framework.TestCase;
public class NDCCodeControllerTest 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(){
NDCCodeController controller = new NDCCodeController(ds);
Assert.assertNotNull(controller);
controller = new NDCCodeController();
controller.setSQLData(new NDCCodeMySQL(ds));
}
public void testAdd(){
NDCCodeController controller = new NDCCodeController(ds);
Assert.assertNotNull(controller);
// add an NDC code
controller.add(new NDCCode("1-1", "name1"));
// verify
List<NDCCode> codeList = controller.getCodesWithFilter("1-1");
Assert.assertEquals(1, codeList.size());
Assert.assertEquals("1-1", codeList.get(0).getCode());
Assert.assertEquals("name1", codeList.get(0).getDescription());
// try to add again
controller.add(new NDCCode("1-2", "name1"));
// verify it wasn't added
codeList = controller.getCodesWithFilter("1-2");
Assert.assertEquals(1, codeList.size());
Assert.assertEquals("1-2", codeList.get(0).getCode());
Assert.assertEquals("name1", codeList.get(0).getDescription());
// try to add garbage code
controller.add(new NDCCode("fdsafdsafds", "name2"));
// verify it wasn't added
Assert.assertNull(controller.getCodeByID("fdsafdsafds"));
// cleanup
controller.remove("1-2");
}
public void testEdit(){
NDCCodeController controller = new NDCCodeController(ds);
Assert.assertNotNull(controller);
// add an NDC code
controller.add(new NDCCode("2-1", "name1"));
// verify
List<NDCCode> codeList = controller.getCodesWithFilter("2-1");
Assert.assertEquals(1, codeList.size());
Assert.assertEquals("2-1", codeList.get(0).getCode());
Assert.assertEquals("name1", codeList.get(0).getDescription());
// edit the code
controller.edit(new NDCCode("2-1", "name2"));
// verify
Assert.assertEquals("name2", controller.getCodeByID("2-1").getDescription());
// edit with garbage
controller.edit(new NDCCode("C11", "name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2name2"));
// verify
Assert.assertEquals("name2", controller.getCodeByID("2-1").getDescription());
// edit a nonexistent code
controller.edit(new NDCCode("2-2", "name3"));
// verify not added
Assert.assertNull(controller.getCodeByID("2-2"));
// cleanup
controller.remove("2-2");
}
public void testRemove(){
NDCCodeController controller = new NDCCodeController(ds);
Assert.assertNotNull(controller);
// test deleting nonexistent code
controller.remove("garbage");
}
public void testSQLErrors() throws SQLException, FormValidationException{
DataSource mockDS = mock(DataSource.class);
NDCCodeController controller = new NDCCodeController(mockDS);
controller = spy(controller);
NDCCodeMySQL mockData = mock(NDCCodeMySQL.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 NDCCode("garbage", "garbage"));
when(mockData.update(Mockito.anyObject())).thenThrow(new SQLException());
controller.edit(new NDCCode("garbage", "garbage"));
when(mockData.delete(Mockito.anyObject())).thenThrow(new SQLException());
controller.remove("garbage");
when(mockData.getCodesWithFilter(Mockito.anyObject())).thenThrow(new SQLException());
controller.getCodesWithFilter("garbage");
}
}
| 5,006
| 37.813953
| 193
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/ndcCode/NDCCodeFormTest.java
|
package edu.ncsu.csc.itrust.unit.controller.ndcCode;
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.ndcode.NDCCodeController;
import edu.ncsu.csc.itrust.controller.ndcode.NDCCodeForm;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.ndcode.NDCCode;
import edu.ncsu.csc.itrust.model.ndcode.NDCCodeMySQL;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import junit.framework.TestCase;
public class NDCCodeFormTest 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 testForm(){
// test constructor
NDCCodeForm form = new NDCCodeForm();
NDCCodeController controller = new NDCCodeController();
controller.setSQLData(new NDCCodeMySQL(ds));
form = new NDCCodeForm(controller);
Assert.assertEquals("", form.getSearch());
Assert.assertFalse(form.getDisplayCodes());
// test fields
form.setCode("code");
Assert.assertEquals("code", form.getCode());
form.setDescription("desc");
Assert.assertEquals("desc", form.getDescription());
form.setDisplayCodes(true);
Assert.assertTrue(form.getDisplayCodes());
form.setNDCCode(new NDCCode("code2", "desc2"));
Assert.assertEquals("code2", form.getNDCCode().getCode());
Assert.assertEquals("desc2", form.getNDCCode().getDescription());
form.setSearch("search");
Assert.assertEquals("search", form.getSearch());
// test add
form.fillInput("1-1", "description");
form.add();
form.setSearch("1-1");
form.fillInput("1-1", "description");
List<NDCCode> codeList = form.getCodesWithFilter();
Assert.assertEquals(1, codeList.size());
Assert.assertEquals("1-1", codeList.get(0).getCode());
Assert.assertEquals("description", codeList.get(0).getDescription());
// test update
form.setDescription("newDesc");
form.update();
form.fillInput("1-1", "newDesc");
codeList = form.getCodesWithFilter();
Assert.assertEquals(1, codeList.size());
Assert.assertEquals("1-1", codeList.get(0).getCode());
Assert.assertEquals("newDesc", codeList.get(0).getDescription());
// test delete
form.delete();
codeList = form.getCodesWithFilter();
Assert.assertEquals(0, codeList.size());
}
}
| 2,874
| 33.638554
| 80
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/officeVisit/OfficeVisitControllerTest.java
|
package edu.ncsu.csc.itrust.unit.controller.officeVisit;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import edu.ncsu.csc.itrust.controller.officeVisit.OfficeVisitController;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.apptType.ApptType;
import edu.ncsu.csc.itrust.model.apptType.ApptTypeData;
import edu.ncsu.csc.itrust.model.apptType.ApptTypeMySQLConverter;
import edu.ncsu.csc.itrust.model.hospital.Hospital;
import edu.ncsu.csc.itrust.model.hospital.HospitalData;
import edu.ncsu.csc.itrust.model.hospital.HospitalMySQLConverter;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisit;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisitData;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisitMySQL;
import edu.ncsu.csc.itrust.model.old.enums.TransactionType;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.webutils.SessionUtils;
import junit.framework.TestCase;
public class OfficeVisitControllerTest extends TestCase {
private static final long DEFAULT_PATIENT_MID = 1L;
private static final long DEFAULT_HCP_MID = 900000000L;
@Spy private OfficeVisitController ovc;
@Spy private OfficeVisitController ovcWithNullDataSource;
@Spy private SessionUtils sessionUtils;
@Mock private HttpServletRequest mockHttpServletRequest;
@Mock private HttpSession mockHttpSession;
@Mock private SessionUtils mockSessionUtils;
private ApptTypeData apptData;
private OfficeVisitData ovData;
private DataSource ds;
private TestDataGenerator gen; // remove when ApptType, Patient, and other
// files are finished
private OfficeVisit testOV;
private LocalDateTime birthDate;
private LocalDateTime babyDate;
private LocalDateTime childDate;
private LocalDateTime adultDate;
@Before
public void setUp() throws Exception {
ds = ConverterDAO.getDataSource();
mockSessionUtils = Mockito.mock(SessionUtils.class);
ovc = Mockito.spy(new OfficeVisitController(ds, mockSessionUtils));
Mockito.doNothing().when(ovc).printFacesMessage(Matchers.any(FacesMessage.Severity.class), Mockito.anyString(),
Mockito.anyString(), Mockito.anyString());
Mockito.doNothing().when(ovc).redirectToBaseOfficeVisit();
apptData = new ApptTypeMySQLConverter(ds);
ovData = new OfficeVisitMySQL(ds);
// remove when these modules are built and can be called
gen = new TestDataGenerator();
gen.appointmentType();
gen.hospitals();
gen.patient1();
gen.uc51();
gen.uc52();
gen.uc53SetUp();
// Setup date
birthDate = ovc.getPatientDOB(DEFAULT_PATIENT_MID).atTime(0, 0);
babyDate = birthDate.plusYears(1);
childDate = birthDate.plusYears(4);
adultDate = birthDate.plusYears(13);
// Setup test OfficeVisit
testOV = new OfficeVisit();
testOV.setPatientMID(DEFAULT_PATIENT_MID);
List<ApptType> types = apptData.getAll();
long apptTypeID = types.get((types.size() - 1)).getID();
testOV.setApptTypeID(apptTypeID);
HospitalData hospitalData = new HospitalMySQLConverter(ds);
List<Hospital> hospitals = hospitalData.getAll();
String locID = hospitals.get((hospitals.size() - 1)).getHospitalID();
testOV.setLocationID(locID);
testOV.setNotes("Hello World!");
testOV.setSendBill(true);
// Default test OV to baby date
testOV.setDate(babyDate);
// Initialize a office visit controller with null data source
ovcWithNullDataSource = new OfficeVisitController(null, sessionUtils);
// Mock HttpServletRequest
mockHttpServletRequest = Mockito.mock(HttpServletRequest.class);
// Mock HttpSession
mockHttpSession = Mockito.mock(HttpSession.class);
}
@Test
public void testRetrieveOfficeVisit() throws DBException {
Assert.assertTrue("Office visit should be added successfully", ovc.addReturnResult(testOV));
// Get the visit ID from the DB
List<OfficeVisit> all = ovData.getAll();
long visitID = -1;
for (int i = 0; i < all.size(); i++) {
OfficeVisit ovI = all.get(i);
boolean bApptType = ovI.getApptTypeID().equals(testOV.getApptTypeID());
boolean bDate = false;
long time = ChronoUnit.MINUTES.between(testOV.getDate(), ovI.getDate());
bDate = (time < 1);
boolean bLoc = (testOV.getLocationID().equals(ovI.getLocationID()));
boolean bNotes = false;
if (testOV.getNotes() == null) {
if (ovI.getNotes() == null)
bNotes = true;
} else {
bNotes = (testOV.getNotes().equals(ovI.getNotes()));
}
boolean bBill = (testOV.getSendBill() == ovI.getSendBill());
if (bApptType && bDate && bLoc && bNotes && bBill) {
visitID = ovI.getVisitID();
}
}
Assert.assertNotEquals(-1L, visitID);
OfficeVisit check = ovc.getVisitByID(Long.toString(visitID));
Assert.assertEquals(testOV.getApptTypeID(), check.getApptTypeID());
long dif = ChronoUnit.MINUTES.between(testOV.getDate(), check.getDate());
Assert.assertTrue(dif < 1);
Assert.assertEquals(testOV.getLocationID(), check.getLocationID());
Assert.assertEquals(testOV.getNotes(), check.getNotes());
Assert.assertEquals(testOV.getSendBill(), check.getSendBill());
testOV.setVisitID(visitID);
testOV.setNotes("testNotes");
ovc.edit(testOV);
}
@Test
public void testAddOfficeVisitWithInvalidDate() throws DBException {
LocalDateTime date = birthDate.minusDays(1);
testOV.setDate(date);
Assert.assertFalse("Office Visit date cannot be set prior to patient birthday", ovc.addReturnResult(testOV));
}
@Test
public void testAddOfficeVisitWithInvalidDateAndFacesContext() throws DBException {
LocalDateTime date = birthDate.minusDays(1);
testOV.setDate(date);
ovc.add(testOV);
}
@Test
public void testAddOfficeVisitWithFacesContext() throws DBException {
ovc.add(testOV);
Mockito.verify(ovc).printFacesMessage(Mockito.eq(FacesMessage.SEVERITY_INFO), Mockito.anyString(),
Mockito.anyString(), Mockito.anyString());
}
@Test
public void testGetOfficeVisitsForPatient() {
Assert.assertEquals(0, ovc.getOfficeVisitsForPatient(Long.toString(DEFAULT_PATIENT_MID)).size());
Assert.assertEquals(0, ovc.getOfficeVisitsForPatient(Long.toString(101L)).size());
Assert.assertEquals(5, ovc.getOfficeVisitsForPatient(Long.toString(102L)).size());
Assert.assertEquals(3, ovc.getOfficeVisitsForPatient(Long.toString(103L)).size());
Assert.assertEquals(3, ovc.getOfficeVisitsForPatient(Long.toString(104L)).size());
}
@Test
public void testGetOfficeVisitsForPatientWithException() {
Assert.assertEquals(0,
ovcWithNullDataSource.getOfficeVisitsForPatient(Long.toString(DEFAULT_PATIENT_MID)).size());
}
@Test
public void testGetOfficeVisitsForPatientWithNullPid() {
Assert.assertEquals(0, ovc.getOfficeVisitsForPatient(null).size());
}
@Test
public void testGetOfficeVisitsForPatientWithHCPPid() {
Assert.assertEquals(0, ovc.getOfficeVisitsForPatient(Long.toString(DEFAULT_HCP_MID)).size());
}
@Test
public void testGetOfficeVisitsForCurrentPatient() {
Mockito.doReturn(Long.toString(DEFAULT_PATIENT_MID)).when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(0, ovc.getOfficeVisitsForCurrentPatient().size());
Mockito.doReturn("101").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(0, ovc.getOfficeVisitsForCurrentPatient().size());
Mockito.doReturn("102").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(5, ovc.getOfficeVisitsForCurrentPatient().size());
Mockito.doReturn("103").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(3, ovc.getOfficeVisitsForCurrentPatient().size());
Mockito.doReturn("104").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(3, ovc.getOfficeVisitsForCurrentPatient().size());
}
@Test
public void testGetOfficeVisitsForCurrentPatientWithInvalidMID() {
Mockito.doReturn(Long.toString(DEFAULT_HCP_MID)).when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(0, ovc.getOfficeVisitsForCurrentPatient().size());
Mockito.doReturn("-1").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(0, ovc.getOfficeVisitsForCurrentPatient().size());
Mockito.doReturn(null).when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(0, ovc.getOfficeVisitsForCurrentPatient().size());
}
@Test
public void testGetAdultOfficeVisitsForCurrentPatient() {
Mockito.doReturn("101").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(0, ovc.getAdultOfficeVisitsForCurrentPatient().size());
Mockito.doReturn("102").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(0, ovc.getAdultOfficeVisitsForCurrentPatient().size());
Mockito.doReturn("103").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(0, ovc.getAdultOfficeVisitsForCurrentPatient().size());
Mockito.doReturn("104").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(3, ovc.getAdultOfficeVisitsForCurrentPatient().size());
}
@Test
public void testGetChildOfficeVisitsForCurrentPatient() {
Mockito.doReturn("101").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(0, ovc.getChildOfficeVisitsForCurrentPatient().size());
Mockito.doReturn("102").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(0, ovc.getChildOfficeVisitsForCurrentPatient().size());
Mockito.doReturn("103").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(2, ovc.getChildOfficeVisitsForCurrentPatient().size());
Mockito.doReturn("104").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(0, ovc.getChildOfficeVisitsForCurrentPatient().size());
}
@Test
public void testGetBabyOfficeVisitsForCurrentPatient() {
Mockito.doReturn("101").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(0, ovc.getBabyOfficeVisitsForCurrentPatient().size());
Mockito.doReturn("102").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(5, ovc.getBabyOfficeVisitsForCurrentPatient().size());
Mockito.doReturn("103").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(1, ovc.getBabyOfficeVisitsForCurrentPatient().size());
Mockito.doReturn("104").when(mockSessionUtils).getCurrentPatientMID();
Assert.assertEquals(0, ovc.getBabyOfficeVisitsForCurrentPatient().size());
}
@Test
public void testGetVisitByIDWithInvalidID() {
Assert.assertNull(ovc.getVisitByID("invalid id"));
Assert.assertNull(ovc.getVisitByID("-1"));
}
@Test
public void testCalculatePatientAge() {
Assert.assertTrue(ovc.isPatientABaby(DEFAULT_PATIENT_MID, birthDate));
Assert.assertFalse(ovc.isPatientAChild(DEFAULT_PATIENT_MID, birthDate));
Assert.assertFalse(ovc.isPatientAnAdult(DEFAULT_PATIENT_MID, birthDate));
Assert.assertTrue(ovc.isPatientABaby(DEFAULT_PATIENT_MID, babyDate));
Assert.assertFalse(ovc.isPatientAChild(DEFAULT_PATIENT_MID, babyDate));
Assert.assertFalse(ovc.isPatientAnAdult(DEFAULT_PATIENT_MID, babyDate));
Assert.assertFalse(ovc.isPatientABaby(DEFAULT_PATIENT_MID, childDate));
Assert.assertTrue(ovc.isPatientAChild(DEFAULT_PATIENT_MID, childDate));
Assert.assertFalse(ovc.isPatientAnAdult(DEFAULT_PATIENT_MID, childDate));
Assert.assertFalse(ovc.isPatientABaby(DEFAULT_PATIENT_MID, adultDate));
Assert.assertFalse(ovc.isPatientAChild(DEFAULT_PATIENT_MID, adultDate));
Assert.assertTrue(ovc.isPatientAnAdult(DEFAULT_PATIENT_MID, adultDate));
}
@Test
public void testCalculatePatientAgeWithNulls() {
Assert.assertFalse(ovc.isPatientABaby(null, birthDate));
Assert.assertFalse(ovc.isPatientABaby(-1L, birthDate));
Assert.assertFalse(ovc.isPatientAChild(null, birthDate));
Assert.assertFalse(ovc.isPatientAChild(-1L, birthDate));
Assert.assertFalse(ovc.isPatientAnAdult(null, birthDate));
Assert.assertFalse(ovc.isPatientAnAdult(-1L, birthDate));
Assert.assertFalse(ovc.isPatientAnAdult(1L, null));
}
@Test
public void testGetSelectedVisit() throws DBException {
// Add a test office visit
ovc.add(testOV);
List<OfficeVisit> officeVisitList = ovData.getAll();
Assert.assertNotNull(officeVisitList);
Assert.assertFalse(officeVisitList.isEmpty());
// Return office visit id in mocked httpServletRequest
OfficeVisit expected = officeVisitList.get(0);
Mockito.doReturn(expected.getVisitID().toString()).when(mockSessionUtils).parseString(Mockito.any());
Mockito.doReturn(expected.getVisitID().toString()).when(mockSessionUtils).getRequestParameter("visitID");
OfficeVisit actual = ovc.getSelectedVisit();
Assert.assertNotNull(actual);
Assert.assertEquals(expected.getPatientMID(), actual.getPatientMID());
Assert.assertEquals(expected.getApptTypeID(), actual.getApptTypeID());
long dif = ChronoUnit.MINUTES.between(expected.getDate(), actual.getDate());
Assert.assertTrue(dif < 1);
Assert.assertEquals(expected.getLocationID(), actual.getLocationID());
Assert.assertEquals(expected.getNotes(), actual.getNotes());
Assert.assertEquals(expected.getSendBill(), actual.getSendBill());
}
@Test
public void testGetSelectedVisitWithNullRequest() {
Mockito.doReturn(null).when(mockSessionUtils).getSessionVariable("visitID");
OfficeVisit ov = ovc.getSelectedVisit();
Assert.assertNull(ov);
}
@Test
public void testGetSelectedVisitWithNullVisitId() {
Mockito.doReturn(null).when(mockSessionUtils).getSessionVariable("visitID");
OfficeVisit ov = ovc.getSelectedVisit();
Assert.assertNull(ov);
}
@Test
public void testHasPatientVisited() {
Assert.assertFalse(ovc.hasPatientVisited("101"));
Assert.assertTrue(ovc.hasPatientVisited("102"));
Assert.assertTrue(ovc.hasPatientVisited("103"));
}
@Test
public void testHasPatientVisitedWithNulls() {
Assert.assertFalse(ovc.hasPatientVisited(null));
Assert.assertFalse(ovc.hasPatientVisited("-1"));
}
@Test
public void testCurrentPatientHasVisited() {
final String MID = "101";
final String PATIENT = "patient";
Mockito.doReturn(PATIENT).when(mockSessionUtils).getSessionUserRole();
Mockito.doReturn(MID).when(mockSessionUtils).getCurrentPatientMID();
Assert.assertFalse(ovc.CurrentPatientHasVisited());
}
@Test
public void testAddReturnGeneratedId() {
long id = ovc.addReturnGeneratedId(testOV);
Assert.assertTrue(id >= 0);
Mockito.verify(ovc).printFacesMessage(Mockito.eq(FacesMessage.SEVERITY_INFO), Mockito.anyString(),
Mockito.anyString(), Mockito.anyString());
}
@Test
public void testLogViewOfficeVisit() {
Mockito.when(mockSessionUtils.getCurrentOfficeVisitId()).thenReturn(2L);
ovc.setSessionUtils(mockSessionUtils);
Mockito.doNothing().when(ovc).logTransaction(Mockito.any(), Mockito.anyString());
ovc.logViewOfficeVisit();
Mockito.verify(ovc, Mockito.times(2)).logTransaction(Mockito.any(), Mockito.anyString());
}
@Test
public void testLogViewOfficeVisitNoneSelected() {
Mockito.when(mockSessionUtils.getCurrentOfficeVisitId()).thenReturn(null);
ovc.setSessionUtils(mockSessionUtils);
ovc.logViewOfficeVisit();
Mockito.verify(ovc, Mockito.times(0)).logTransaction(TransactionType.OFFICE_VISIT_VIEW, new Long(2).toString());
}
}
| 15,424
| 38.857881
| 114
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/officeVisit/OfficeVisitFormTest.java
|
package edu.ncsu.csc.itrust.unit.controller.officeVisit;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.List;
import javax.sql.DataSource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.Spy;
import edu.ncsu.csc.itrust.controller.officeVisit.OfficeVisitController;
import edu.ncsu.csc.itrust.controller.officeVisit.OfficeVisitForm;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.apptType.ApptType;
import edu.ncsu.csc.itrust.model.apptType.ApptTypeData;
import edu.ncsu.csc.itrust.model.apptType.ApptTypeMySQLConverter;
import edu.ncsu.csc.itrust.model.hospital.HospitalData;
import edu.ncsu.csc.itrust.model.hospital.HospitalMySQLConverter;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisit;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import junit.framework.TestCase;
public class OfficeVisitFormTest extends TestCase {
private OfficeVisitForm ovf;
@Spy
private OfficeVisitForm spyovf;
@Spy
private OfficeVisitController ovc;
private ApptTypeData apptData;
private TestDataGenerator gen;
private DataSource ds;
private HospitalData hData;
private OfficeVisit ovBaby;
private OfficeVisit ovChild;
private OfficeVisit ovAdult;
@Spy
private OfficeVisitController mockovc;
private static final Float FLOAT_VALUE = 12.3F;
private static final String BP_VALUE = "140/90";
private static final Integer INTEGER_VALUE = 1;
private static final Integer HDL = 45;
private static final Integer TRI = 350;
private static final Integer LDL = 300;
private static final Float FLOAT_TEST = 11.1F;
private static final String BP_TEST = "190/80";
private static final Integer INTEGER_TEST = 3;
private static final Integer HDL_TEST = 60;
private static final Integer TRI_TEST = 200;
private static final Integer LDL_TEST = 500;
@Before
public void setUp() throws Exception {
ds = ConverterDAO.getDataSource();
apptData = new ApptTypeMySQLConverter(ds);
hData = new HospitalMySQLConverter(ds);
gen = new TestDataGenerator();
ovc = Mockito.spy(new OfficeVisitController(ds));
mockovc = Mockito.mock(OfficeVisitController.class);
// Set up office visits
createOVBaby();
createOVChild();
createOVAdult();
// Generate data
gen = new TestDataGenerator();
gen.appointmentType();
gen.hospitals();
gen.patient1();
gen.uc51();
gen.uc52();
gen.uc53SetUp();
}
private void createOVBaby() {
ovBaby = new OfficeVisit();
ovBaby.setPatientMID(1L);
ovBaby.setLength(FLOAT_VALUE);
ovBaby.setWeight(FLOAT_VALUE);
ovBaby.setHeadCircumference(FLOAT_VALUE);
ovBaby.setHouseholdSmokingStatus(INTEGER_VALUE);
}
private void createOVChild() {
ovChild = new OfficeVisit();
ovChild.setPatientMID(1L);
ovChild.setHeight(FLOAT_VALUE);
ovChild.setWeight(FLOAT_VALUE);
ovChild.setBloodPressure(BP_VALUE);
ovChild.setHouseholdSmokingStatus(INTEGER_VALUE);
}
private void createOVAdult() throws SQLException, FileNotFoundException, IOException, DBException {
ovAdult = new OfficeVisit();
gen.appointmentType();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ovAdult.setApptTypeID(apptList.get(0).getID());
}
ovAdult.setDate(LocalDateTime.now());
ovAdult.setPatientMID(1L);
ovAdult.setVisitID(1L);
ovAdult.setSendBill(true);
ovAdult.setHeight(FLOAT_VALUE);
ovAdult.setWeight(FLOAT_VALUE);
ovAdult.setBloodPressure(BP_VALUE);
ovAdult.setHouseholdSmokingStatus(INTEGER_VALUE);
ovAdult.setPatientSmokingStatus(INTEGER_VALUE);
ovAdult.setHDL(HDL);
ovAdult.setTriglyceride(TRI);
ovAdult.setLDL(LDL);
}
@Test
public void testGetVisitID() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovChild);
ovf = new OfficeVisitForm(mockovc);
ovf.setVisitID(1L);
Assert.assertTrue(1L == ovf.getVisitID());
}
@Test
public void testGetPatientMID() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovChild);
ovf = new OfficeVisitForm(mockovc);
Assert.assertTrue(ovf.getPatientMID().equals(1L));
ovf.setPatientMID(2L);
Assert.assertTrue(ovf.getPatientMID().equals(2L));
}
@Test
public void testGetDate() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovChild);
ovf = new OfficeVisitForm(mockovc);
LocalDateTime test = LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0);
ovf.setDate(test);
Assert.assertTrue(ovf.getDate().equals(test));
}
@Test
public void testGetLocationID() {
final String locationId = "1";
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovChild);
ovf = new OfficeVisitForm(mockovc);
ovf.setLocationID(locationId);
Assert.assertEquals(locationId, ovf.getLocationID());
}
@Test
public void testGetApptTypeID() {
final Long apptTypeId = 1L;
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovChild);
ovf = new OfficeVisitForm(mockovc);
ovf.setApptTypeID(apptTypeId);
Assert.assertEquals(apptTypeId, ovf.getApptTypeID());
}
@Test
public void testGetNotes() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovAdult);
ovf = new OfficeVisitForm(mockovc);
ovf.setNotes("abc");
Assert.assertTrue(ovf.getNotes().equals("abc"));
}
@Test
public void testGetSendBill() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovAdult);
ovf = new OfficeVisitForm(mockovc);
Assert.assertTrue(ovf.getSendBill());
ovf.setSendBill(false);
Assert.assertFalse(ovf.getSendBill());
}
@Test
public void testGetHeight() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovChild);
ovf = new OfficeVisitForm(mockovc);
Assert.assertTrue(ovf.getHeight().equals(FLOAT_VALUE));
ovf.setHeight(FLOAT_TEST);
Assert.assertTrue(ovf.getHeight().equals(FLOAT_TEST));
}
@Test
public void testGetLength() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovBaby);
ovf = new OfficeVisitForm(mockovc);
Assert.assertTrue(ovf.getLength().equals(FLOAT_VALUE));
ovf.setLength(FLOAT_TEST);
Assert.assertTrue(ovf.getLength().equals(FLOAT_TEST));
}
@Test
public void testGetWeight() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovChild);
ovf = new OfficeVisitForm(mockovc);
Assert.assertTrue(ovf.getWeight().equals(FLOAT_VALUE));
ovf.setWeight(FLOAT_TEST);
Assert.assertTrue(ovf.getWeight().equals(FLOAT_TEST));
}
@Test
public void testGetHeadCircumference() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovBaby);
ovf = new OfficeVisitForm(mockovc);
Assert.assertTrue(ovf.getHeadCircumference().equals(FLOAT_VALUE));
ovf.setHeadCircumference(FLOAT_TEST);
Assert.assertTrue(ovf.getHeadCircumference().equals(FLOAT_TEST));
}
@Test
public void testGetBloodPressure() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovChild);
ovf = new OfficeVisitForm(mockovc);
Assert.assertTrue(ovf.getBloodPressure().equals(BP_VALUE));
ovf.setBloodPressure(BP_TEST);
Assert.assertTrue(ovf.getBloodPressure().equals(BP_TEST));
}
@Test
public void testGetHDL() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovAdult);
ovf = new OfficeVisitForm(mockovc);
Assert.assertTrue(ovf.getHDL().equals(HDL));
ovf.setHDL(HDL_TEST);
Assert.assertTrue(ovf.getHDL().equals(HDL_TEST));
}
@Test
public void testGetTriglyceride() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovAdult);
ovf = new OfficeVisitForm(mockovc);
Assert.assertTrue(ovf.getTriglyceride().equals(TRI));
ovf.setTriglyceride(TRI_TEST);
Assert.assertTrue(ovf.getTriglyceride().equals(TRI_TEST));
}
@Test
public void testGetLDL() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovAdult);
ovf = new OfficeVisitForm(mockovc);
Assert.assertTrue(ovf.getLDL().equals(LDL));
ovf.setLDL(LDL_TEST);
Assert.assertTrue(ovf.getLDL().equals(LDL_TEST));
}
@Test
public void testGetHouseholdSmokingStatus() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovAdult);
ovf = new OfficeVisitForm(mockovc);
Assert.assertTrue(ovf.getHouseholdSmokingStatus().equals(INTEGER_VALUE));
ovf.setHouseholdSmokingStatus(INTEGER_TEST);
Assert.assertTrue(ovf.getHouseholdSmokingStatus().equals(INTEGER_TEST));
}
@Test
public void testGetPatientSmokingStatus() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovAdult);
ovf = new OfficeVisitForm(mockovc);
Assert.assertTrue(ovf.getPatientSmokingStatus().equals(INTEGER_VALUE));
ovf.setPatientSmokingStatus(INTEGER_TEST);
Assert.assertTrue(ovf.getPatientSmokingStatus().equals(INTEGER_TEST));
}
@Test
public void testSubmit() {
Mockito.when(mockovc.getSelectedVisit()).thenReturn(ovAdult);
ovf = new OfficeVisitForm(mockovc);
ovf.submit();
Assert.assertTrue(ovf.getHeight().equals(FLOAT_VALUE));
Assert.assertTrue(ovf.getWeight().equals(FLOAT_VALUE));
Assert.assertTrue(ovf.getBloodPressure().equals(BP_VALUE));
Assert.assertTrue(ovf.getHouseholdSmokingStatus().equals(INTEGER_VALUE));
Assert.assertTrue(ovf.getPatientSmokingStatus().equals(INTEGER_VALUE));
Assert.assertTrue(ovf.getHDL().equals(HDL));
Assert.assertTrue(ovf.getTriglyceride().equals(TRI));
Assert.assertTrue(ovf.getLDL().equals(LDL));
}
@Test
public void testIsPatientABaby() {
OfficeVisit ov = new OfficeVisit();
ov.setPatientMID(101L);
ov.setDate(LocalDateTime.of(2013, 6, 1, 0, 0));
Mockito.doReturn(ov).when(ovc).getSelectedVisit();
spyovf = Mockito.spy(new OfficeVisitForm(ovc));
Assert.assertTrue(spyovf.isPatientABaby());
}
@Test
public void testIsPatientAChild() {
OfficeVisit ov = new OfficeVisit();
ov.setPatientMID(101L);
ov.setDate(LocalDateTime.of(2017, 6, 1, 0, 0));
Mockito.doReturn(ov).when(ovc).getSelectedVisit();
spyovf = Mockito.spy(new OfficeVisitForm(ovc));
Assert.assertTrue(spyovf.isPatientAChild());
}
@Test
public void testIsPatientAnAdult() {
OfficeVisit ov = new OfficeVisit();
ov.setPatientMID(101L);
ov.setDate(LocalDateTime.of(2026, 6, 1, 0, 0));
Mockito.doReturn(ov).when(ovc).getSelectedVisit();
spyovf = Mockito.spy(new OfficeVisitForm(ovc));
Assert.assertTrue(spyovf.isPatientAnAdult());
}
}
| 10,223
| 30.653251
| 100
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/prescription/PrescriptionControllerTest.java
|
package edu.ncsu.csc.itrust.unit.controller.prescription;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.sql.DataSource;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Spy;
import edu.ncsu.csc.itrust.controller.prescription.PrescriptionController;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.labProcedure.LabProcedureData;
import edu.ncsu.csc.itrust.model.old.beans.MedicationBean;
import edu.ncsu.csc.itrust.model.old.beans.PatientBean;
import edu.ncsu.csc.itrust.model.old.enums.TransactionType;
import edu.ncsu.csc.itrust.model.prescription.Prescription;
import edu.ncsu.csc.itrust.model.prescription.PrescriptionMySQL;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.webutils.SessionUtils;
public class PrescriptionControllerTest {
@Mock
private SessionUtils mockSessionUtils;
@Mock
private LabProcedureData mockData;
@Spy
private PrescriptionController controller;
@Spy
private DataSource ds;
private TestDataGenerator gen;
@Before
public void setUp() throws FileNotFoundException, SQLException, IOException, DBException {
ds = spy(ConverterDAO.getDataSource());
gen = new TestDataGenerator();
gen.clearAllTables();
gen.uc21();
gen.uc19();
controller = spy(new PrescriptionController(ds));
mockSessionUtils = mock(SessionUtils.class);
controller.setSessionUtils(mockSessionUtils);
mockData = mock(LabProcedureData.class);
}
@After
public void tearDown() throws FileNotFoundException, SQLException, IOException {
gen.clearAllTables();
}
@Test
public void testGetPrescriptionByID() throws SQLException {
assertNull(controller.getPrescriptionByID(null));
verify(controller).printFacesMessage(eq(FacesMessage.SEVERITY_ERROR), anyString(), anyString(), anyString());
assertNull(controller.getPrescriptionByID("-1"));
verify(controller).printFacesMessage(eq(FacesMessage.SEVERITY_ERROR), anyString(), anyString(), anyString());
}
@Test
public void testGetPrescriptionsForCurrentPatient() throws Exception {
doReturn("201").when(mockSessionUtils).getCurrentPatientMID();
assertEquals(3, controller.getPrescriptionsForCurrentPatient().size());
doReturn("invalid id").when(mockSessionUtils).getCurrentPatientMID();
assertEquals(0, controller.getPrescriptionsForCurrentPatient().size());
verify(controller).printFacesMessage(eq(FacesMessage.SEVERITY_ERROR), anyString(), anyString(), anyString());
doReturn("-1").when(mockSessionUtils).getCurrentPatientMID();
assertEquals(0, controller.getPrescriptionsForCurrentPatient().size());
verify(controller).printFacesMessage(eq(FacesMessage.SEVERITY_ERROR), anyString(), anyString(), anyString());
doThrow(SQLException.class).when(ds).getConnection();
doReturn("201").when(mockSessionUtils).getCurrentPatientMID();
assertEquals(0, controller.getPrescriptionsForCurrentPatient().size());
}
@Test
public void testGetListOfRepresentees() throws Exception {
doReturn(null).when(mockSessionUtils).getRepresenteeList();
doReturn(2L).when(mockSessionUtils).getSessionLoggedInMIDLong();
doNothing().when(mockSessionUtils).setRepresenteeList(any());
List<PatientBean> list = controller.getListOfRepresentees();
assertNotNull(list);
}
@Test
public void testExceptions() throws SQLException{
PrescriptionMySQL pSQL = spy(new PrescriptionMySQL(ds));
controller.setSql(pSQL);
Prescription p = new Prescription();
p.setDrugCode(new MedicationBean("1234", "new code"));
p.setInstructions("instructions");
p.setDosage(50);
p.setStartDate(LocalDate.now());
p.setEndDate(LocalDate.now());
controller.add(p);
controller.add(p);
when(pSQL.add(p)).thenThrow(new SQLException());
controller.add(p);
//when(pSQL.update(p)).thenThrow(new SQLException());
controller.edit(p);
controller.remove(1);
}
@Test
public void testLogViewPrescriptionReport() {
when(mockSessionUtils.getCurrentPatientMID()).thenReturn("8"); // arbitrary
doNothing().when(controller).logTransaction(any(), any());
controller.logViewPrescriptionReport();
verify(controller).logTransaction(TransactionType.PRESCRIPTION_REPORT_VIEW, null);
}
@Test
public void testGetCodeName() {
String codeName = "Midichlomaxene";
String codeID = "48301-3420";
assertEquals( codeName, controller.getCodeName(codeID) );
/*codeID = "-1";
controller.getCodeName(codeID);
verify(controller).printFacesMessage(eq(FacesMessage.SEVERITY_ERROR), anyString(), anyString(), anyString());*/
}
@Test
public void getRepParameter() {
controller.getRepParameter();
}
}
| 5,492
| 33.987261
| 113
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/controller/prescription/PrescriptionFormTest.java
|
package edu.ncsu.csc.itrust.unit.controller.prescription;
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.time.LocalDate;
import java.util.List;
import javax.sql.DataSource;
import org.junit.Assert;
import org.junit.Test;
import edu.ncsu.csc.itrust.controller.prescription.PrescriptionController;
import edu.ncsu.csc.itrust.controller.prescription.PrescriptionForm;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.ndcode.NDCCodeMySQL;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisit;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisitMySQL;
import edu.ncsu.csc.itrust.model.old.beans.MedicationBean;
import edu.ncsu.csc.itrust.model.prescription.Prescription;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.webutils.SessionUtils;
import junit.framework.TestCase;
public class PrescriptionFormTest extends TestCase {
private TestDataGenerator gen;
private DataSource ds;
private PrescriptionForm form;
private SessionUtils utils;
private PrescriptionController pc;
private NDCCodeMySQL nData;
private OfficeVisitMySQL ovSql;
@Override
public void setUp() throws FileNotFoundException, SQLException, IOException, DBException{
ds = ConverterDAO.getDataSource();
gen = new TestDataGenerator();
ovSql = new OfficeVisitMySQL(ds);
gen.clearAllTables();
gen.uc11();
utils = spy(SessionUtils.getInstance());
pc = spy(new PrescriptionController(ds));
nData = spy(new NDCCodeMySQL(ds));
}
@Test
public void testEverything() throws DBException, SQLException{
OfficeVisit visit = ovSql.getAll().get(0);
long ovID = visit.getVisitID();
long patientMID = visit.getPatientMID();
long loggedInMID = 9000000000L;
when(utils.getCurrentOfficeVisitId()).thenReturn((Long) ovID);
when(utils.getCurrentPatientMID()).thenReturn(Long.toString(patientMID));
when(utils.getSessionLoggedInMIDLong()).thenReturn((Long) loggedInMID);
form = new PrescriptionForm();
form = new PrescriptionForm(pc, nData, utils, ds);
form.fillInput("0", new MedicationBean("1234", "good meds"), 80, LocalDate.parse("2016-11-17"), LocalDate.parse("2017-11-17"), "take a bunch");
form.add();
List<Prescription> pList = form.getPrescriptionsByOfficeVisit(Long.toString(ovID));
Assert.assertEquals(1, pList.size());
Assert.assertEquals("1234", pList.get(0).getCode());
long prescriptionID = pList.get(0).getId();
form.fillInput(Long.toString(prescriptionID), new MedicationBean("1234", "good meds"), 80, LocalDate.parse("2016-11-17"), LocalDate.parse("2017-11-17"), "take a bunch MORE");
form.edit();
pList = form.getPrescriptionsByOfficeVisit(Long.toString(ovID));
Assert.assertEquals(1, pList.size());
Assert.assertEquals("take a bunch MORE", pList.get(0).getInstructions());
Assert.assertEquals("good meds", form.getCodeName("1234"));
Assert.assertEquals(1, form.getNDCCodes().size());
Assert.assertEquals("1234", form.getNDCCodes().get(0).getCode());
Assert.assertEquals(1, form.getPrescriptionsByPatientID(Long.toString(patientMID)).size());
Assert.assertEquals(0, form.getPrescriptionsForCurrentPatient().size());
form.remove(Long.toString(prescriptionID));
Assert.assertEquals(0, form.getPrescriptionsByOfficeVisit(Long.toString(ovID)).size());
Prescription p = new Prescription();
form.setPrescription(p);
Assert.assertEquals(p, form.getPrescription());
when(pc.getPrescriptionsByOfficeVisit("1")).thenThrow(new DBException(new SQLException()));
Assert.assertEquals(0, form.getPrescriptionsByOfficeVisit("1").size());
when(nData.getAll()).thenThrow(new SQLException());
Assert.assertEquals(0, form.getNDCCodes().size());
}
}
| 4,245
| 41.888889
| 182
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/AutoIncrementTest.java
|
package edu.ncsu.csc.itrust.unit.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.DBUtil;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
/**
* AutoIncrementTest
*/
public class AutoIncrementTest extends TestCase {
@Override
protected void setUp() throws Exception {
Connection conn = null;
PreparedStatement ps = null;
try {
conn = TestDAOFactory.getTestInstance().getConnection();
ps = conn.prepareStatement("DROP TABLE IF EXISTS testincrement");
ps.executeUpdate();
ps.close();
ps = conn.prepareStatement("CREATE TABLE testincrement(id integer auto_increment primary key)");
ps.executeUpdate();
} finally {
DBUtil.closeConnection(conn, ps);
}
}
/**
* testNoIcrementCollision
*
* @throws DBException
*/
public void testNoIncrementCollision() throws DBException {
Connection conn1 = null;
PreparedStatement ps = null;
try {
conn1 = TestDAOFactory.getTestInstance().getConnection();
ps = conn1.prepareStatement("INSERT INTO testincrement VALUES()");
ps.executeUpdate();
doTheSecond();
assertEquals(1L, DBUtil.getLastInsert(conn1));
// See? It's on a per-connection basis. Nothing to worry about.
} catch (SQLException ex) {
// TODO
} finally {
DBUtil.closeConnection(conn1, ps);
}
}
private void doTheSecond() throws SQLException, DBException {
Connection conn2 = null;
PreparedStatement ps = null;
try {
conn2 = TestDAOFactory.getTestInstance().getConnection();
ps = conn2.prepareStatement("INSERT INTO testincrement VALUES()");
ps.executeUpdate();
assertEquals(2L, DBUtil.getLastInsert((conn2)));
} catch (SQLException ex) {
throw ex;
} finally {
DBUtil.closeConnection(conn2, ps);
}
}
@Override
protected void tearDown() throws SQLException {
Connection conn = null;
PreparedStatement ps = null;
try {
conn = TestDAOFactory.getTestInstance().getConnection();
ps = conn.prepareStatement("DROP TABLE IF EXISTS testincrement");
ps.executeUpdate();
} catch (SQLException ex) {
throw ex;
} finally {
DBUtil.closeConnection(conn, ps);
}
}
}
| 2,261
| 25.302326
| 99
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/DAOFactoryTest.java
|
package edu.ncsu.csc.itrust.unit.dao;
import java.sql.SQLException;
import edu.ncsu.csc.itrust.model.old.dao.DAOFactory;
import junit.framework.TestCase;
public class DAOFactoryTest extends TestCase {
// Show that the production driver can't be access during a unit test
public void testRealProductionDriver() throws Exception {
try {
DAOFactory.getProductionInstance().getConnection();
fail("Exception should have been thrown");
} catch (SQLException e) {
assertTrue(e.getMessage().contains("Context Lookup Naming Exception"));
}
}
}
| 556
| 28.315789
| 74
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/DBUtilTest.java
|
package edu.ncsu.csc.itrust.unit.dao;
import static org.easymock.classextension.EasyMock.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import junit.framework.TestCase;
import org.easymock.classextension.IMocksControl;
import edu.ncsu.csc.itrust.DBUtil;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
public class DBUtilTest extends TestCase {
public void testCanAccessProductionDriver() throws Exception {
// Should never be able to do this because JUnit is not running under
// Tomcat
assertFalse(DBUtil.canObtainProductionInstance());
}
public void testClosingNullPS() throws Exception {
Connection conn = TestDAOFactory.getTestInstance().getConnection();
PreparedStatement ps = conn.prepareStatement("SHOW TABLES");
DBUtil.closeConnection(conn, ps);
}
// The following test uses an advanced concept not taught in CSC326 at NCSU
// called Mock Objects.
// Feel free to take a look at how this works, but know that you will not
// need to know mock objects
// to do nearly everything in iTrust. Unless your assignment mentions mock
// objects somewhere, you should
// not need them.
//
// But, if you are interested in a cool unit testing concept, feel free to
// look at this code as an
// example.
//
// This class uses the EasyMock library to manage the mock objects.
// http://easymock.org/
public void testException() throws Exception {
IMocksControl ctrl = createControl();
Connection mockConn = ctrl.createMock(Connection.class);
mockConn.close();
expectLastCall().andThrow(new SQLException("Testing!"));
ctrl.replay();
DBUtil.closeConnection(mockConn, null);
ctrl.verify();
}
}
| 1,702
| 31.132075
| 76
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/WardDAOTest.java
|
package edu.ncsu.csc.itrust.unit.dao;
import static org.easymock.classextension.EasyMock.createControl;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.ITrustException;
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.beans.WardBean;
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.testutils.TestDAOFactory;
import java.sql.SQLException;
import java.util.ArrayList;
import static org.easymock.EasyMock.expect;
import java.util.List;
import org.easymock.classextension.IMocksControl;
/**
* WardDAOTest
*/
public class WardDAOTest extends TestCase {
private DAOFactory factory = TestDAOFactory.getTestInstance();
private DAOFactory factory2;
WardDAO wd1;
WardDAO wd2;
private IMocksControl ctrl;
/**
* setUp
*/
@Override
public void setUp() {
ctrl = createControl();
factory2 = ctrl.createMock(DAOFactory.class);
wd1 = new WardDAO(factory);
wd2 = new WardDAO(factory2);
}
/**
* testgetAllWardsByHospitalID
*/
public void testgetAllWardsByHospitalID() {
List<WardBean> list = new ArrayList<WardBean>();
try {
list = wd1.getAllWardsByHospitalID("1");
assertNotNull(list);
} catch (DBException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.getAllWardsByHospitalID("1");
fail();
} catch (Exception e) {
// TODO
}
}
/**
* testAddWard
*/
public void testAddWard() {
WardBean wb = new WardBean(0L, "name", 0L);
try {
assertTrue(wd1.addWard(wb));
} catch (DBException e) {
// TODO
} catch (ITrustException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.addWard(wb);
fail();
} catch (Exception e) {
// TODO
}
}
/**
* testUpdateWard
*/
public void testUpdateWard() {
WardBean wb = new WardBean(0L, "name", 0L);
try {
assertEquals(0, wd1.updateWard(wb));
} catch (DBException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.updateWard(wb);
fail();
} catch (Exception e) {
// TODO
}
}
/**
* testRemoveWard
*/
public void testRemoveWard() {
try {
wd1.removeWard(1L);
} catch (DBException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.removeWard(1L);
fail();
} catch (Exception e) {
// TODO
}
}
/**
* testgetAllWardRoomsByWardID
*/
public void testgetAllWardRoomsByWardID() {
List<WardRoomBean> list = new ArrayList<WardRoomBean>();
try {
list = wd1.getAllWardRoomsByWardID(1L);
assertNotNull(list);
} catch (DBException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.getAllWardRoomsByWardID(1L);
fail();
} catch (Exception e) {
// TODO
}
}
/**
* testAddWardRoom
*/
public void testAddWardRoom() {
WardRoomBean wb = new WardRoomBean(0, 0, 0, "name1", "status");
try {
assertTrue(wd1.addWardRoom(wb));
} catch (DBException e) {
// TODO
} catch (ITrustException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.addWardRoom(wb);
fail();
} catch (Exception e) {
// TODO
}
}
/**
* testUpdateWardRoom
*/
public void testUpdateWardRoom() {
WardRoomBean wb = new WardRoomBean(0, 0, 0, "name1", "status");
try {
assertEquals(0, wd1.updateWardRoom(wb));
} catch (DBException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.updateWardRoom(wb);
fail();
} catch (Exception e) {
// TODO
}
}
/**
* testRemoveWardRoom
*/
public void testRemoveWardRoom() {
try {
wd1.removeWardRoom(1L);
} catch (DBException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.removeWardRoom(1L);
fail();
} catch (Exception e) {
// TODO
}
}
/**
* testgetAllWardsByHCP
*/
public void testgetAllWardsByHCP() {
List<WardBean> list = new ArrayList<WardBean>();
try {
list = wd1.getAllWardsByHCP(1L);
assertNotNull(list);
} catch (DBException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.getAllWardsByHCP(1L);
fail();
} catch (Exception e) {
// TODO
}
}
/**
* testgetAllHCPsAssignedToWard
*/
public void testgetAllHCPsAssignedToWard() {
List<PersonnelBean> list = new ArrayList<PersonnelBean>();
try {
list = wd1.getAllHCPsAssignedToWard(1L);
assertNotNull(list);
} catch (DBException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.getAllHCPsAssignedToWard(1L);
fail();
} catch (Exception e) {
// TODO
}
}
/**
* testAssignHCPToWard
*/
public void testAssignHCPToWard() {
try {
assertTrue(wd1.assignHCPToWard(1L, 1L));
} catch (DBException e) {
// TODO
} catch (ITrustException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.assignHCPToWard(1L, 1L);
fail();
} catch (Exception e) {
// TODO
}
}
/**
* testRemoveWard2
*/
public void testRemoveWard2() {
try {
assertNotNull(wd1.removeWard(1L, 1L));
} catch (DBException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.removeWard(1L, 1L);
fail();
} catch (Exception e) {
// TODO
}
}
/**
* testUpdateWardRoomOccupant
*/
public void testUpdateWardRoomOccupant() {
WardRoomBean wrb = new WardRoomBean(0, 0, 0, "name", "status");
try {
assertEquals(0, wd1.updateWardRoomOccupant(wrb));
} catch (DBException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.updateWardRoomOccupant(wrb);
fail();
} catch (Exception e) {
// TODO
}
}
/**
* testGetWardRoomsByStatus
*/
public void testGetWardRoomsByStatus() {
List<WardRoomBean> list = new ArrayList<WardRoomBean>();
try {
list = wd1.getWardRoomsByStatus("status", 1L);
assertNotNull(list);
} catch (DBException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.getWardRoomsByStatus("status", 1L);
fail();
} catch (Exception e) {
// TODO
}
}
/**
* testGetWardRoom
*/
public void testGetWardRoom() {
WardRoomBean wrb = new WardRoomBean(0, 0, 0, "name", "status");
try {
wrb = wd1.getWardRoom("0");
assertNull(wrb);
} catch (DBException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.getWardRoom("0");
fail();
} catch (Exception e) {
// TODO
}
}
/**
* testGetHospitalByWard
*/
public void testGetHospitalByWard() {
HospitalBean hb = new HospitalBean();
try {
hb = wd1.getHospitalByWard("name");
assertNull(hb);
} catch (DBException e) {
// TODO
}
try {
expect(factory2.getConnection()).andThrow(new SQLException());
ctrl.replay();
wd2.getHospitalByWard("name");
fail();
} catch (Exception e) {
// TODO
}
}
}
| 7,674
| 17.628641
| 65
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/access/AccessDAOExceptionTest.java
|
package edu.ncsu.csc.itrust.unit.dao.access;
import java.sql.SQLException;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.ITrustException;
import edu.ncsu.csc.itrust.model.old.dao.mysql.AccessDAO;
import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory;
public class AccessDAOExceptionTest extends TestCase {
private AccessDAO evilDAO = EvilDAOFactory.getEvilInstance().getAccessDAO();
@Override
protected void setUp() throws Exception {
}
public void testGetSessionTimeoutException() throws Exception {
try {
evilDAO.getSessionTimeoutMins();
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testSetSessionTimeoutException() throws Exception {
try {
evilDAO.setSessionTimeoutMins(0);
fail("DBException should have been thrown");
} catch (DBException e) {
assertSame(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testDBException() throws Exception {
DBException e = new DBException(null);
assertEquals("No extended information.", e.getExtendedMessage());
e = new DBException(new SQLException("Fake SQL Exception"));
assertEquals("Fake SQL Exception", e.getExtendedMessage());
}
public void testiTrustException() throws Exception {
ITrustException e = new ITrustException(null);
assertEquals("An error has occurred. Please see log for details.", e.getMessage());
assertEquals("No extended information.", e.getExtendedMessage());
}
}
| 1,608
| 31.836735
| 85
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/access/GetSessionTimeoutTest.java
|
package edu.ncsu.csc.itrust.unit.dao.access;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.DBUtil;
import edu.ncsu.csc.itrust.model.old.dao.mysql.AccessDAO;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
/**
*/
public class GetSessionTimeoutTest extends TestCase {
private AccessDAO accessDAO = TestDAOFactory.getTestInstance().getAccessDAO();
private TestDataGenerator gen;
@Override
protected void setUp() throws Exception {
gen = new TestDataGenerator();
gen.timeout();
}
/**
* testChangeTimeout
*
* @throws Exception
*/
public void testChangeTimeout() throws Exception {
assertEquals(20, accessDAO.getSessionTimeoutMins());
accessDAO.setSessionTimeoutMins(5);
assertEquals(5, accessDAO.getSessionTimeoutMins());
}
/**
* testUpdateBadTimeout
*
* @throws Exception
*/
public void testUpdateBadTimeout() throws Exception {
deleteTimeout();
assertEquals(20, accessDAO.getSessionTimeoutMins());
deleteTimeout();
accessDAO.setSessionTimeoutMins(5);
assertEquals(5, accessDAO.getSessionTimeoutMins());
}
private void deleteTimeout() throws SQLException {
Connection conn = null;
PreparedStatement ps = null;
try {
conn = TestDAOFactory.getTestInstance().getConnection();
ps = conn.prepareStatement("DELETE FROM globalvariables WHERE Name='Timeout'");
ps.executeUpdate();
} catch (SQLException ex) {
throw ex;
} finally {
DBUtil.closeConnection(conn, ps);
}
}
}
| 1,628
| 24.857143
| 82
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/allergies/AddAllergiesTest.java
|
package edu.ncsu.csc.itrust.unit.dao.allergies;
import java.util.List;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.model.old.beans.AllergyBean;
import edu.ncsu.csc.itrust.model.old.dao.DAOFactory;
import edu.ncsu.csc.itrust.model.old.dao.mysql.AllergyDAO;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
public class AddAllergiesTest extends TestCase {
private DAOFactory factory = TestDAOFactory.getTestInstance();
private AllergyDAO allergyDAO = factory.getAllergyDAO();
@Override
protected void setUp() throws Exception {
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
gen.patient2();
}
/*
* updated to reflect the new way addAllergy updates allergyDAO.
*/
public void testGetAllergiesFor2() throws Exception {
AllergyBean bean = new AllergyBean();
bean.setPatientID(2);
bean.setNDCode("081096");
bean.setDescription("Aspirin");
assertEquals(2, allergyDAO.getAllergies(2L).size());
allergyDAO.addAllergy(bean);
List<AllergyBean> allergies = allergyDAO.getAllergies(2L);
assertEquals(3, allergies.size());
assertEquals("Aspirin", allergies.get(0).getDescription());
}
}
| 1,229
| 31.368421
| 65
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/allergies/AllergyDAOExceptionTest.java
|
package edu.ncsu.csc.itrust.unit.dao.allergies;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.old.beans.AllergyBean;
import edu.ncsu.csc.itrust.model.old.dao.mysql.AllergyDAO;
import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory;
public class AllergyDAOExceptionTest extends TestCase {
private AllergyDAO evilDAO = EvilDAOFactory.getEvilInstance().getAllergyDAO();
@Override
protected void setUp() throws Exception {
}
/*
* updated to reflect the new way addAllergy updates allergyDAO.
*/
public void testAddAllergyException() throws Exception {
try {
AllergyBean bean = new AllergyBean();
bean.setPatientID(0);
bean.setNDCode("");
bean.setDescription("");
evilDAO.addAllergy(bean);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetAllergyException() throws Exception {
try {
evilDAO.getAllergies(0);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
}
| 1,201
| 28.317073
| 79
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/allergies/GetAllergiesTest.java
|
package edu.ncsu.csc.itrust.unit.dao.allergies;
import java.util.List;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.model.old.beans.AllergyBean;
import edu.ncsu.csc.itrust.model.old.dao.DAOFactory;
import edu.ncsu.csc.itrust.model.old.dao.mysql.AllergyDAO;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
public class GetAllergiesTest extends TestCase {
private DAOFactory factory = TestDAOFactory.getTestInstance();
private AllergyDAO allergyDAO = factory.getAllergyDAO();
@Override
protected void setUp() throws Exception {
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
gen.patient2();
gen.patient1();
}
public void testGetAllergiesFor1() throws Exception {
assertEquals(0, allergyDAO.getAllergies(1L).size());
}
public void testGetAllergiesFor2() throws Exception {
List<AllergyBean> allergies = allergyDAO.getAllergies(2L);
assertEquals(2, allergies.size());
assertEquals("Pollen", allergies.get(0).getDescription());
assertEquals(2, allergies.get(0).getPatientID());
assertEquals("664662530", allergies.get(1).getNDCode());
assertEquals(2, allergies.get(1).getPatientID());
}
}
| 1,236
| 32.432432
| 65
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/appointment/ApptDAOTest.java
|
package edu.ncsu.csc.itrust.unit.dao.appointment;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import edu.ncsu.csc.itrust.model.old.beans.ApptBean;
import edu.ncsu.csc.itrust.model.old.beans.ApptTypeBean;
import edu.ncsu.csc.itrust.model.old.dao.DAOFactory;
import edu.ncsu.csc.itrust.model.old.dao.mysql.ApptDAO;
import edu.ncsu.csc.itrust.model.old.dao.mysql.ApptTypeDAO;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
import junit.framework.TestCase;
public class ApptDAOTest extends TestCase {
private DAOFactory factory = TestDAOFactory.getTestInstance();
private ApptDAO apptDAO = factory.getApptDAO();
private ApptBean a1;
private ApptBean a2;
private ApptBean a3;
long patientMID = 42L;
long doctorMID = 9000000000L;
@Override
protected void setUp() throws Exception {
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
gen.appointmentType();
a1 = new ApptBean();
a1.setDate(new Timestamp(new Date().getTime()));
a1.setApptType("Ultrasound");
a1.setHcp(doctorMID);
a1.setPatient(patientMID);
a2 = new ApptBean();
a2.setDate(new Timestamp(new Date().getTime() + 1000 * 60 * 15)); // 15
// minutes
// later
a2.setApptType("Ultrasound");
a2.setHcp(doctorMID);
a2.setPatient(patientMID);
a3 = new ApptBean();
a3.setDate(new Timestamp(new Date().getTime() + 1000 * 60 * 45)); // 45
// minutes
// later
a3.setApptType("Ultrasound");
a3.setHcp(doctorMID);
a3.setPatient(patientMID);
}
public void testAppointment() throws Exception {
long doctorMID = 9000000000L;
List<ApptBean> conflicts = apptDAO.getAllConflictsForDoctor(doctorMID);
assertEquals(0, conflicts.size());
apptDAO.scheduleAppt(a1);
apptDAO.scheduleAppt(a3);
conflicts = apptDAO.getAllConflictsForDoctor(doctorMID);
assertEquals(0, conflicts.size());
}
public void testAppointmentConflict() throws Exception {
long doctorMID = 9000000000L;
List<ApptBean> conflicts = apptDAO.getAllConflictsForDoctor(doctorMID);
assertEquals(0, conflicts.size());
apptDAO.scheduleAppt(a1);
apptDAO.scheduleAppt(a2);
conflicts = apptDAO.getAllConflictsForDoctor(doctorMID);
assertEquals(2, conflicts.size());
}
public void testAppointmentPatientConflict() throws Exception {
List<ApptBean> conflicts = apptDAO.getAllConflictsForPatient(patientMID);
assertEquals(0, conflicts.size());
apptDAO.scheduleAppt(a1);
apptDAO.scheduleAppt(a2);
conflicts = apptDAO.getAllConflictsForPatient(patientMID);
assertEquals(2, conflicts.size());
}
public void testGetConflictForAppointment() throws Exception {
List<ApptBean> conflicts = apptDAO.getAllHCPConflictsForAppt(doctorMID, a1);
assertEquals(0, conflicts.size());
apptDAO.scheduleAppt(a1);
conflicts = apptDAO.getAllHCPConflictsForAppt(doctorMID, a1);
assertEquals(1, conflicts.size());
ApptBean a1new = conflicts.get(0);
conflicts = apptDAO.getAllHCPConflictsForAppt(doctorMID, a1new);
assertEquals(0, conflicts.size());
apptDAO.scheduleAppt(a2);
conflicts = apptDAO.getAllHCPConflictsForAppt(doctorMID, a1new);
assertEquals(1, conflicts.size());
}
public void testGetPatientConflictForAppointment() throws Exception {
List<ApptBean> conflicts = apptDAO.getAllPatientConflictsForAppt(patientMID, a1);
assertEquals(0, conflicts.size());
apptDAO.scheduleAppt(a1);
conflicts = apptDAO.getAllPatientConflictsForAppt(patientMID, a1);
assertEquals(1, conflicts.size());
ApptBean a1new = conflicts.get(0);
conflicts = apptDAO.getAllHCPConflictsForAppt(doctorMID, a1new);
assertEquals(0, conflicts.size());
apptDAO.scheduleAppt(a2);
conflicts = apptDAO.getAllPatientConflictsForAppt(patientMID, a1new);
assertEquals(1, conflicts.size());
}
public void testGetApptType() throws Exception {
ApptTypeDAO apptTypeDAO = factory.getApptTypeDAO();
ApptTypeBean type = apptTypeDAO.getApptType("Ultrasound");
assertEquals(30, type.getDuration());
assertEquals("Ultrasound", type.getName());
}
}
| 4,168
| 26.248366
| 83
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/appointment/ApptRequestDAOTest.java
|
package edu.ncsu.csc.itrust.unit.dao.appointment;
import java.sql.Timestamp;
import java.util.List;
import junit.framework.TestCase;
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.model.old.beans.ApptTypeBean;
import edu.ncsu.csc.itrust.model.old.dao.DAOFactory;
import edu.ncsu.csc.itrust.model.old.dao.mysql.ApptRequestDAO;
import edu.ncsu.csc.itrust.model.old.dao.mysql.ApptTypeDAO;
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 ApptRequestDAOTest extends TestCase {
private ApptRequestDAO arDAO;
private ApptRequestDAO EvilRequestDAO;
private ApptTypeDAO evilDAO;
private TestDataGenerator gen = new TestDataGenerator();
private DAOFactory evilFactory = EvilDAOFactory.getEvilInstance();
@Override
protected void setUp() throws Exception {
gen.clearAllTables();
gen.standardData();
gen.apptRequestConflicts();
arDAO = TestDAOFactory.getTestInstance().getApptRequestDAO();
EvilRequestDAO = new ApptRequestDAO(evilFactory);
evilDAO = new ApptTypeDAO(evilFactory);
}
public void testGetApptRequestsFor() throws Exception {
List<ApptRequestBean> beans = arDAO.getApptRequestsFor(9000000000L);
assertEquals(1, beans.size());
assertEquals(2L, beans.get(0).getRequestedAppt().getPatient());
assertTrue(beans.get(0).isPending());
try {
EvilRequestDAO.getApptRequestsFor(9000000000L);
fail("WHAT THE HELL THIS EVIL FACTORY DOESN'T WORK");
} catch (DBException e) {
// Success!
}
}
public void testAddApptRequest() throws Exception {
gen.clearAllTables();
ApptBean bean = new ApptBean();
bean.setApptType("General Checkup");
bean.setHcp(9000000000L);
bean.setPatient(2L);
bean.setDate(new Timestamp(System.currentTimeMillis()));
ApptRequestBean req = new ApptRequestBean();
req.setRequestedAppt(bean);
arDAO.addApptRequest(req);
List<ApptRequestBean> reqs = arDAO.getApptRequestsFor(9000000000L);
assertEquals(1, reqs.size());
assertEquals(bean.getPatient(), reqs.get(0).getRequestedAppt().getPatient());
assertTrue(reqs.get(0).isPending());
assertFalse(reqs.get(0).isAccepted());
try {
EvilRequestDAO.addApptRequest(new ApptRequestBean());
fail("WHAT THE HELL THIS EVIL FACTORY DOESN'T WORK");
} catch (DBException e) {
// Success!
}
}
public void testGetApptRequest() throws Exception {
List<ApptRequestBean> beans = arDAO.getApptRequestsFor(9000000000L);
ApptRequestBean b = beans.get(0);
int id = b.getRequestedAppt().getApptID();
ApptRequestBean b2 = arDAO.getApptRequest(id);
assertEquals(b.getRequestedAppt().getApptID(), b2.getRequestedAppt().getApptID());
try {
@SuppressWarnings("unused")
List<ApptRequestBean> test = EvilRequestDAO.getApptRequestsFor(9000000000L);
fail("WHAT THE HELL THIS EVIL FACTORY DOESN'T WORK");
} catch (DBException e) {
// Success!
}
}
public void testUpdateApptRequest() throws Exception {
List<ApptRequestBean> beans = arDAO.getApptRequestsFor(9000000000L);
ApptRequestBean b = beans.get(0);
int id = b.getRequestedAppt().getApptID();
b.setPending(false);
b.setAccepted(true);
arDAO.updateApptRequest(b);
ApptRequestBean b2 = arDAO.getApptRequest(id);
assertEquals(b.getRequestedAppt().getApptID(), b2.getRequestedAppt().getApptID());
assertFalse(b2.isPending());
assertTrue(b2.isAccepted());
try {
EvilRequestDAO.updateApptRequest(b);
fail("WHAT THE HELL THIS EVIL FACTORY DOESN'T WORK");
} catch (DBException e) {
// Success!
}
}
public void testTypeDBExceptions() throws Exception {
ApptTypeBean testBean = new ApptTypeBean();
try {
@SuppressWarnings("unused")
List<ApptTypeBean> beans = evilDAO.getApptTypes();
fail("WHAT THE HELL THIS EVIL FACTORY DOESN'T WORK");
} catch (DBException e) {
// Success!
}
try {
@SuppressWarnings("unused")
ApptTypeBean evilBean = evilDAO.getApptType("Physical");
fail("WHAT THE HELL THIS EVIL FACTORY DOESN'T WORK");
} catch (DBException e) {
// Success!
}
try {
testBean.setName("Physical");
testBean.setDuration(90);
evilDAO.editApptType(testBean);
fail("WHAT THE HELL THIS EVIL FACTORY DOESN'T WORK");
} catch (DBException e) {
// Success!
}
try {
testBean.setName("Uh-ohhh");
testBean.setDuration(90);
evilDAO.addApptType(testBean);
fail("WHAT THE HELL THIS EVIL FACTORY DOESN'T WORK");
} catch (DBException e) {
// Success!
}
};
}
| 4,655
| 30.248322
| 84
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/auth/AddUserTest.java
|
package edu.ncsu.csc.itrust.unit.dao.auth;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.ITrustException;
import edu.ncsu.csc.itrust.model.old.dao.mysql.AuthDAO;
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 AddUserTest extends TestCase {
AuthDAO authDAO = TestDAOFactory.getTestInstance().getAuthDAO();
private TestDataGenerator gen = new TestDataGenerator();
@Override
protected void setUp() throws Exception {
gen.clearAllTables();
}
public void test500Gone() throws Exception {
try {
authDAO.getUserRole(500);
fail("exception should have been thrown");
} catch (ITrustException e) {
assertEquals("User does not exist", e.getMessage());
}
}
public void testAdd500WithHCP() throws Exception {
String password = authDAO.addUser(500L, Role.HCP, "password");
assertEquals(Role.HCP, authDAO.getUserRole(500L));
// Ensure that the password returned is the one given to the method
assertTrue(password.equals("password"));
}
public void testAddWithPatient() throws Exception {
String password = authDAO.addUser(500L, Role.PATIENT, "password");
assertEquals(Role.PATIENT, authDAO.getUserRole(500L));
// Ensure that the password returned is the one given to the method
assertTrue(password.equals("password"));
}
}
| 1,424
| 30.666667
| 69
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/auth/AuthDAOExceptionTest.java
|
package edu.ncsu.csc.itrust.unit.dao.auth;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.old.dao.mysql.AuthDAO;
import edu.ncsu.csc.itrust.model.old.enums.Role;
import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory;
public class AuthDAOExceptionTest extends TestCase {
private AuthDAO evilDAO = EvilDAOFactory.getEvilInstance().getAuthDAO();
@Override
protected void setUp() throws Exception {
}
public void testAddUserException() throws Exception {
try {
evilDAO.addUser(0L, Role.ADMIN, "");
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testCheckUserExistsException() throws Exception {
try {
evilDAO.checkUserExists(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testLoginFailuresException() throws Exception {
try {
evilDAO.getLoginFailures("");
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetUserNameException() throws Exception {
try {
evilDAO.getUserName(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetUserRoleException() throws Exception {
try {
evilDAO.getUserRole(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testRecordLoginFailureException() throws Exception {
try {
evilDAO.recordLoginFailure("");
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testResetPasswordException() throws Exception {
try {
evilDAO.resetPassword(0L, "");
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testSetSecurityQuestionAnswer() throws Exception {
try {
evilDAO.setSecurityQuestionAnswer(null, null, 0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetSecurityAnswer() throws Exception {
try {
evilDAO.getSecurityQuestion(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetSecurityQuestion() throws Exception {
try {
evilDAO.getSecurityAnswer(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testRecordResetPasswordFailure() throws Exception {
try {
evilDAO.recordResetPasswordFailure("");
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testIsDependent() throws Exception {
try {
evilDAO.isDependent(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testSetDependency() throws Exception {
try {
evilDAO.setDependent(0L, true);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
}
| 3,879
| 27.955224
| 74
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/auth/CheckUserActivatedTest.java
|
package edu.ncsu.csc.itrust.unit.dao.auth;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.ITrustException;
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 CheckUserActivatedTest extends TestCase {
AuthDAO authDAO = TestDAOFactory.getTestInstance().getAuthDAO();
private TestDataGenerator gen = new TestDataGenerator();
@Override
protected void setUp() throws Exception {
gen.clearAllTables();
gen.standardData();
}
public void testActivatedUser() throws Exception {
try {
assertFalse(authDAO.getDeactivated(1));
} catch (ITrustException e) {
fail("Exception should not be thrown.");
}
}
public void testDeactivatedUser() throws Exception {
try {
assertTrue(authDAO.getDeactivated(314159));
} catch (ITrustException e) {
fail("Exception should not be thrown.");
}
}
}
| 977
| 26.942857
| 65
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/auth/GetLoginFailureTest.java
|
package edu.ncsu.csc.itrust.unit.dao.auth;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.DBUtil;
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 GetLoginFailureTest extends TestCase {
private DAOFactory factory = TestDAOFactory.getTestInstance();
AuthDAO authDAO = factory.getAuthDAO();
private TestDataGenerator gen = new TestDataGenerator();
private String ipAddr = "192.168.1.1";
@Override
protected void setUp() throws Exception {
gen.clearLoginFailures();
}
public void testGetLoginFailuresNoEntry() throws Exception {
assertEquals(0, authDAO.getLoginFailures(ipAddr));
}
// no need to do it *exactly* if we have -10s and +10s; we don't need that
// level of accuracy
public void testGetLoginFailuresWithEntry5() throws Exception {
// also doing BVA - make it 10s less than the timeout time
addLoginFailure(5, new Timestamp(System.currentTimeMillis() - (AuthDAO.LOGIN_TIMEOUT - 10000)));
assertEquals(5, authDAO.getLoginFailures(ipAddr));
}
public void testGetLoginFailures15MinutesAgo() throws Exception {
// for BVA here, make it 10s greater than the timeout time
addLoginFailure(5, new Timestamp(System.currentTimeMillis() - (AuthDAO.LOGIN_TIMEOUT) + 10000));
assertEquals(5, authDAO.getLoginFailures(ipAddr));
}
private void addLoginFailure(int count, Timestamp lastFailure) throws SQLException {
Connection conn = null;
PreparedStatement ps = null;
try {
conn = factory.getConnection();
ps = conn.prepareStatement(
"INSERT INTO loginfailures(IPAddress,failureCount, lastFailure) " + "VALUES(?,?,?)");
ps.setString(1, ipAddr);
ps.setInt(2, count);
ps.setTimestamp(3, lastFailure);
ps.executeUpdate();
} catch (SQLException ex) {
throw ex;
} finally {
DBUtil.closeConnection(conn, ps);
}
}
}
| 2,116
| 32.078125
| 98
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/auth/GetUserNameTest.java
|
package edu.ncsu.csc.itrust.unit.dao.auth;
import junit.framework.TestCase;
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 GetUserNameTest extends TestCase {
AuthDAO authDAO = TestDAOFactory.getTestInstance().getAuthDAO();
private TestDataGenerator gen = new TestDataGenerator();
@Override
protected void setUp() throws Exception {
gen.clearAllTables();
}
public void testHCP0() throws Exception {
gen.hcp0();
assertEquals("HCP 0", "Kelly Doctor", authDAO.getUserName(9000000000L));
}
public void testPatient1() throws Exception {
gen.patient1();
assertEquals("Patient 1", "Random Person", authDAO.getUserName(1L));
}
public void testAdmin1() throws Exception {
gen.admin1();
assertEquals("Admin 1", "Shape Shifter", authDAO.getUserName(9000000001L));
}
}
| 933
| 28.1875
| 77
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/auth/GetUserRoleTest.java
|
package edu.ncsu.csc.itrust.unit.dao.auth;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
import junit.framework.TestCase;
public class GetUserRoleTest extends TestCase {
private TestDataGenerator gen = new TestDataGenerator();
@Override
protected void setUp() throws Exception {
gen.clearAllTables();
}
public void testHCPMeganHunt() throws Exception {
gen.hcp0();
assertEquals("HCP 90..0", "hcp",
TestDAOFactory.getTestInstance().getAuthDAO().getUserRole(9000000000L).getUserRolesString());
}
}
| 595
| 26.090909
| 97
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/auth/RecordLoginFailureTest.java
|
package edu.ncsu.csc.itrust.unit.dao.auth;
import junit.framework.TestCase;
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 RecordLoginFailureTest extends TestCase {
private DAOFactory factory = TestDAOFactory.getTestInstance();
AuthDAO authDAO = factory.getAuthDAO();
private TestDataGenerator gen = new TestDataGenerator();
private String ipAddr = "192.168.1.1";
@Override
protected void setUp() throws Exception {
gen.clearLoginFailures();
}
public void testGetLoginFailuresNoEntry() throws Exception {
authDAO.recordLoginFailure(ipAddr);
assertEquals(1, authDAO.getLoginFailures(ipAddr));
}
public void testGetLoginFailuresWithEntry() throws Exception {
assertEquals(0, authDAO.getLoginFailures(ipAddr));
authDAO.recordLoginFailure(ipAddr);
assertEquals(1, authDAO.getLoginFailures(ipAddr));
authDAO.recordLoginFailure(ipAddr);
assertEquals(2, authDAO.getLoginFailures(ipAddr));
authDAO.recordLoginFailure(ipAddr);
assertEquals(3, authDAO.getLoginFailures(ipAddr));
}
}
| 1,208
| 33.542857
| 65
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/auth/ResetPasswordTest.java
|
package edu.ncsu.csc.itrust.unit.dao.auth;
import junit.framework.TestCase;
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.model.old.dao.mysql.AuthDAO;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
/**
* ResetPasswordTest
*/
public class ResetPasswordTest extends TestCase {
private DAOFactory factory = TestDAOFactory.getTestInstance();
AuthDAO authDAO = factory.getAuthDAO();
private TestDataGenerator gen = new TestDataGenerator();
@Override
protected void setUp() throws Exception {
gen.clearAllTables();
gen.patient2();
}
/**
* testResetPassword
*
* @throws Exception
*/
public void testResetPassword() throws Exception {
/**
* assertEquals(DigestUtils.sha256Hex("pw"), getPassword(2L));
* authDAO.resetPassword(2L, "password");
* assertEquals(DigestUtils.sha256Hex("password"), getPassword(2L));
*/
// sanity check of the current user password
assertTrue(authDAO.authenticatePassword(2L, "pw"));
// reset the password
authDAO.resetPassword(2L, "password");
// check that the password is truly reset
assertTrue(authDAO.authenticatePassword(2L, "password"));
}
/**
* testResetPasswordNonExistent
*
* @throws Exception
*/
public void testResetPasswordNonExistent() throws Exception {
// Still runs with no exception - that's the expected behavior
authDAO.resetPassword(500L, "password");
}
/**
* testResetSecurityQuestionAnswer
*
* @throws DBException
*/
public void testResetSecurityQuestionAnswer() throws DBException {
authDAO.setSecurityQuestionAnswer("how you doin?", "good", 2L);
}
/**
* testGetNoSecurityAnswer
*
* @throws Exception
*/
public void testGetNoSecurityAnswer() throws Exception {
long mid = factory.getPatientDAO().addEmptyPatient();
try {
authDAO.getSecurityAnswer(mid);
fail("exception should have been thrown");
} catch (ITrustException e) {
assertEquals("No security answer set for MID " + mid, e.getMessage());
}
}
/**
* testGetNoSecurityQuestion
*
* @throws Exception
*/
public void testGetNoSecurityQuestion() throws Exception {
long mid = factory.getPatientDAO().addEmptyPatient();
try {
authDAO.getSecurityQuestion(mid);
fail("exception should have been thrown");
} catch (ITrustException e) {
assertEquals("No security question set for MID: " + mid, e.getMessage());
}
}
}
| 2,567
| 26.612903
| 76
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/auth/UserExistsTest.java
|
package edu.ncsu.csc.itrust.unit.dao.auth;
import junit.framework.TestCase;
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 UserExistsTest extends TestCase {
private DAOFactory factory = TestDAOFactory.getTestInstance();
AuthDAO authDAO = factory.getAuthDAO();
private TestDataGenerator gen = new TestDataGenerator();
@Override
protected void setUp() throws Exception {
gen.clearAllTables();
gen.patient1();
}
public void testUserExists() throws Exception {
assertTrue(authDAO.checkUserExists(1L));
assertFalse(authDAO.checkUserExists(200L));
}
}
| 765
| 29.64
| 65
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/billing/BillingDAOTest.java
|
/**
*
*/
package edu.ncsu.csc.itrust.unit.dao.billing;
import static org.junit.Assert.*;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
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.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;
/**
*/
public class BillingDAOTest {
private DAOFactory factory = TestDAOFactory.getTestInstance();
private EvilDAOFactory evil;
private BillingDAO evil2;
private BillingDAO billingDAO = factory.getBillingDAO();
private BillingBean b1;
private BillingBean b2;
private BillingBean bean;
private static final long PATIENT_MID = 42L;
private static final int OV_ID = 3;
private static final long DOCTOR_MID = 9000000000L;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
evil = new EvilDAOFactory(0);
evil2 = evil.getBillingDAO();
DBBuilder tables = new DBBuilder();
tables.dropTables();
tables.createTables();
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
b1 = new BillingBean();
b1.setAmt(40);
b1.setApptID(OV_ID);
b1.setBillID(1);
b1.setBillingAddress("123 somewhere drive");
b1.setCcHolderName("dad");
b1.setCcNumber("123456789");
b1.setCcType("Visa");
b1.setCvv("123");
b1.setHcp(DOCTOR_MID);
b1.setInsAddress1("123 else drive");
b1.setInsAddress2(" ");
b1.setInsCity("Durham");
b1.setInsHolderName("dad");
b1.setInsID("1234");
b1.setInsPhone("333-333-3333");
b1.setInsProviderName("insurance");
b1.setInsState("NC");
b1.setInsZip("27607");
b1.setPatient(PATIENT_MID);
b1.setStatus("Unsubmitted");
b2 = new BillingBean();
b2.setAmt(40);
b2.setApptID(OV_ID);
b2.setBillID(1);
b2.setBillingAddress("123 somewhere drive");
b2.setCcHolderName("dad");
b2.setCcNumber("987654321");
b2.setCcType("Visa");
b2.setCvv("123");
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("insurance");
b2.setInsState("NC");
b2.setInsZip("27607");
b2.setPatient(PATIENT_MID);
b2.setStatus("Unsubmitted");
}
/**
* Test method for
* {@link edu.ncsu.csc.itrust.model.old.dao.mysql.BillingDAO#addBill(BillingBean)}.
*
* @throws DBException
*/
@Test
public void testAddBill() throws DBException {
List<BillingBean> billing = billingDAO.getBills(PATIENT_MID);
assertEquals(0, billing.size());
billingDAO.addBill(b1);
billing = billingDAO.getBills(PATIENT_MID);
assertEquals(1, billing.size());
}
/**
* Test method for
* {@link edu.ncsu.csc.itrust.model.old.dao.mysql.BillingDAO#getBillWithOVId(long)}.
*
* @throws DBException
*/
@Test
public void testGetBillWithOVId() throws DBException {
billingDAO.addBill(b1);
BillingBean billing = billingDAO.getBillWithOVId(OV_ID);
assertEquals(40, billing.getAmt());
assertEquals(OV_ID, billing.getApptID());
assertEquals(1, billing.getBillID());
assertEquals("123 somewhere drive", billing.getBillingAddress());
assertEquals("dad", billing.getCcHolderName());
assertEquals("123456789", billing.getCcNumber());
assertEquals("Visa", billing.getCcType());
assertEquals("123", billing.getCvv());
assertEquals(DOCTOR_MID, billing.getHcp());
assertEquals("123 else drive", billing.getInsAddress1());
assertEquals(" ", billing.getInsAddress2());
assertEquals("Durham", billing.getInsCity());
assertEquals("dad", billing.getInsHolderName());
assertEquals("1234", billing.getInsID());
assertEquals("333-333-3333", billing.getInsPhone());
assertEquals("insurance", billing.getInsProviderName());
assertEquals("NC", billing.getInsState());
assertEquals("27607", billing.getInsZip());
assertEquals(PATIENT_MID, billing.getPatient());
assertEquals("Unsubmitted", billing.getStatus());
}
/**
* Test method for
* {@link edu.ncsu.csc.itrust.model.old.dao.mysql.BillingDAO#getBills(long)}.
*
* @throws DBException
*/
@Test
public void testGetBills() throws DBException {
billingDAO.addBill(b1);
List<BillingBean> billing = billingDAO.getBills(PATIENT_MID);
assertEquals(40, billing.get(0).getAmt());
assertEquals(3, billing.get(0).getApptID());
assertEquals(1, billing.get(0).getBillID());
assertEquals("123 somewhere drive", billing.get(0).getBillingAddress());
assertEquals("dad", billing.get(0).getCcHolderName());
assertEquals("123456789", billing.get(0).getCcNumber());
assertEquals("Visa", billing.get(0).getCcType());
assertEquals("123", billing.get(0).getCvv());
assertEquals(DOCTOR_MID, billing.get(0).getHcp());
assertEquals("123 else drive", billing.get(0).getInsAddress1());
assertEquals(" ", billing.get(0).getInsAddress2());
assertEquals("Durham", billing.get(0).getInsCity());
assertEquals("dad", billing.get(0).getInsHolderName());
assertEquals("1234", billing.get(0).getInsID());
assertEquals("333-333-3333", billing.get(0).getInsPhone());
assertEquals("insurance", billing.get(0).getInsProviderName());
assertEquals("NC", billing.get(0).getInsState());
assertEquals("27607", billing.get(0).getInsZip());
assertEquals(PATIENT_MID, billing.get(0).getPatient());
assertEquals("Unsubmitted", billing.get(0).getStatus());
}
/**
* Tests that you get the correct number of unpaid bills.
*
* @throws DBException
*/
@Test
public void testGetUnpaidBills() throws DBException {
List<BillingBean> bill = billingDAO.getUnpaidBills(PATIENT_MID);
assertEquals(0, bill.size());
}
@Test
public void testGetBillID() throws DBException {
List<BillingBean> billing = billingDAO.getBills(PATIENT_MID);
assertEquals(0, billing.size());
billingDAO.addBill(b1);
billing = billingDAO.getBills(PATIENT_MID);
assertEquals(1, billing.size());
bean = billingDAO.getBillId(1);
assertEquals(40, bean.getAmt());
}
@Test
public void testGetInsuranceBills() throws DBException {
b1.setBillID((int) billingDAO.addBill(b1));
b1.setSubmissions(b1.getSubmissions() + 1);
b1.setInsurance(true);
billingDAO.editBill(b1);
b1.setInsID("2NDID");
b1.setBillID((int) billingDAO.addBill(b1));
b1.setSubmissions(b1.getSubmissions() + 1);
b1.setInsurance(true);
billingDAO.editBill(b1);
List<BillingBean> list = billingDAO.getInsuranceBills();
assertEquals(2, list.size());
assertEquals(1, list.get(0).getSubmissions());
assertEquals(2, list.get(1).getSubmissions());
}
/**
* Test method for
* {@link edu.ncsu.csc.itrust.model.old.dao.mysql.BillingDAO#editBill(BillingBean)}.
*
* @throws DBException
*/
@Test(expected = DBException.class)
public void testEditBill() throws DBException {
List<BillingBean> billing = billingDAO.getBills(PATIENT_MID);
assertEquals(0, billing.size());
billingDAO.addBill(b1);
billing = billingDAO.getBills(PATIENT_MID);
assertEquals(1, billing.size());
billingDAO.editBill(b2);
billing = billingDAO.getBills(PATIENT_MID);
assertEquals(1, billing.get(0).getBillID());
assertEquals(40, billing.get(0).getAmt());
assertEquals("987654321", billing.get(0).getCcNumber());
evil2.addBill(b1);
}
/**
* Test method for
* {@link edu.ncsu.csc.itrust.model.old.dao.mysql.BillingDAO#RemoveBill(BillingBean)}.
*
* @throws DBException
*/
@Test(expected = DBException.class)
public void testRemoveBill() throws DBException {
List<BillingBean> billing = billingDAO.getBills(PATIENT_MID);
assertEquals(0, billing.size());
billingDAO.addBill(b1);
billing = billingDAO.getBills(PATIENT_MID);
assertEquals(1, billing.size());
billingDAO.removeBill(b1);
billing = billingDAO.getBills(PATIENT_MID);
assertEquals(0, billing.size());
evil2.removeBill(b1);
}
/**
* Test method for
* {@link edu.ncsu.csc.itrust.model.old.dao.mysql.BillingDAO#getPendingNum()}.
*
* @throws DBException
*/
@Test
public void testGetPendingNum() {
b1.setStatus(BillingBean.PENDING);
try {
billingDAO.addBill(b1);
assertEquals(1, billingDAO.getPendingNum());
} catch (DBException e) {
fail();
}
}
/**
* Test method for
* {@link edu.ncsu.csc.itrust.model.old.dao.mysql.BillingDAO#getDeniedNum(long)}.
*
* @throws DBException
*/
@Test
public void testGetDeniedNum() {
b1.setStatus(BillingBean.DENIED);
try {
billingDAO.addBill(b1);
assertEquals(1, billingDAO.getDeniedNum(PATIENT_MID));
} catch (DBException e) {
fail();
}
}
/**
* Test method for
* {@link edu.ncsu.csc.itrust.model.old.dao.mysql.BillingDAO#getApprovedNum(long)}.
*
* @throws DBException
*/
@Test
public void testGetApprovedNum() {
b1.setStatus(BillingBean.APPROVED);
try {
billingDAO.addBill(b1);
assertEquals(1, billingDAO.getApprovedNum(PATIENT_MID));
} catch (DBException e) {
fail();
}
}
}
| 9,147
| 28.798046
| 87
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/druginteraction/DrugInteractionDAOTest.java
|
package edu.ncsu.csc.itrust.unit.dao.druginteraction;
import java.util.List;
import edu.ncsu.csc.itrust.model.old.beans.DrugInteractionBean;
import edu.ncsu.csc.itrust.model.old.dao.mysql.DrugInteractionDAO;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
import junit.framework.TestCase;
public class DrugInteractionDAOTest extends TestCase {
private DrugInteractionDAO interactionDAO = TestDAOFactory.getTestInstance().getDrugInteractionDAO();
private TestDataGenerator gen;
@Override
protected void setUp() throws Exception {
gen = new TestDataGenerator();
gen.clearAllTables();
gen.admin1();
}
public void testReportInteraction() throws Exception {
interactionDAO.reportInteraction("619580501", "081096",
"May increase the risk and severity of nephrotoxicity due to additive effects on the kidney.");
List<DrugInteractionBean> testList = interactionDAO.getInteractions("619580501");
DrugInteractionBean interaction = testList.get(0);
assertEquals("619580501", interaction.getFirstDrug());
assertEquals("081096", interaction.getSecondDrug());
}
public void testReportInteractionThatExists() throws Exception {
gen.drugInteractions();
try {
interactionDAO.reportInteraction("009042407", "548680955", "This is not allowed.");
fail("Drug interaction already exists for these drugs.");
} catch (Exception e) {
// Good job, it works
}
}
public void testReportInteractionThatExistsReverseOrder() throws Exception {
gen.drugInteractions();
try {
interactionDAO.reportInteraction("548680955", "009042407", "This is not allowed.");
fail("Drug interaction already exists for these drugs.");
} catch (Exception e) {
// Good job, it works
}
}
public void testDeleteInteraction() throws Exception {
gen.drugInteractions();
interactionDAO.deleteInteraction("009042407", "548680955");
List<DrugInteractionBean> testList = interactionDAO.getInteractions("548680955");
assertTrue(testList.isEmpty());
}
}
| 2,051
| 33.779661
| 102
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/fakeemail/EmailExceptionTest.java
|
package edu.ncsu.csc.itrust.unit.dao.fakeemail;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.old.beans.Email;
import edu.ncsu.csc.itrust.model.old.dao.DAOFactory;
import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory;
public class EmailExceptionTest extends TestCase {
private DAOFactory factory;
public void testGetAllException() throws Exception {
factory = EvilDAOFactory.getEvilInstance();
try {
factory.getFakeEmailDAO().getAllEmails();
fail("exception should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetPersonException() throws Exception {
factory = EvilDAOFactory.getEvilInstance();
try {
factory.getFakeEmailDAO().getEmailsByPerson("gstormcrow@iTrust.org");
fail("exception should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testSendException() throws Exception {
factory = EvilDAOFactory.getEvilInstance();
try {
factory.getFakeEmailDAO().sendEmailRecord(new Email());
fail("exception should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
}
| 1,351
| 29.727273
| 74
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/fakeemail/EmailTest.java
|
package edu.ncsu.csc.itrust.unit.dao.fakeemail;
import java.util.Arrays;
import java.util.List;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.EmailUtil;
import edu.ncsu.csc.itrust.model.old.beans.Email;
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 EmailTest extends TestCase {
DAOFactory factory = TestDAOFactory.getTestInstance();
@Override
protected void setUp() throws Exception {
TestDataGenerator gen = new TestDataGenerator();
gen.clearFakeEmail();
gen.fakeEmail();
}
public void testListAllEmails() throws Exception {
List<Email> emails = factory.getFakeEmailDAO().getAllEmails();
assertEquals(4, emails.size());
Email email = getTestEmail();
new EmailUtil(factory).sendEmail(email);
emails = factory.getFakeEmailDAO().getAllEmails();
assertEquals(5, emails.size());
assertEquals(getTestEmail(), emails.get(0));
}
public void testListEmailsByPerson() throws Exception {
String email = "gstormcrow@iTrust.org";
List<Email> emails = factory.getFakeEmailDAO().getEmailsByPerson(email);
assertEquals(2, emails.size());
assertEquals("this is an email", emails.get(0).getSubject());
assertEquals("this is another email", emails.get(1).getSubject());
}
public void testFindWithString() throws Exception {
factory.getFakeEmailDAO().sendEmailRecord(getTestEmail());
factory.getFakeEmailDAO().sendEmailRecord(getTestEmail());
Email other = getTestEmail();
other.setBody("");
factory.getFakeEmailDAO().sendEmailRecord(other);
List<Email> emails = factory.getFakeEmailDAO().getEmailWithBody("is the");
assertEquals(2, emails.size());
assertEquals(getTestEmail(), emails.get(0));
assertEquals(getTestEmail(), emails.get(1));
}
private Email getTestEmail() {
Email email = new Email();
email.setBody("this is the body");
email.setFrom("ncsucsc326@gmail.com");
email.setSubject("this is the subject");
email.setToList(Arrays.asList("ncsucsc326@gmail.com"));
return email;
}
}
| 2,108
| 32.47619
| 76
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/family/FamilyDAOExceptionTest.java
|
package edu.ncsu.csc.itrust.unit.dao.family;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.old.dao.mysql.FamilyDAO;
import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory;
public class FamilyDAOExceptionTest extends TestCase {
private FamilyDAO evilDAO = EvilDAOFactory.getEvilInstance().getFamilyDAO();
@Override
protected void setUp() throws Exception {
}
public void testFamilyMemberException() throws Exception {
try {
evilDAO.getParents(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
}
| 694
| 26.8
| 77
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/family/FamilyMembersTest.java
|
package edu.ncsu.csc.itrust.unit.dao.family;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.model.old.beans.FamilyMemberBean;
import edu.ncsu.csc.itrust.model.old.dao.DAOFactory;
import edu.ncsu.csc.itrust.model.old.dao.mysql.FamilyDAO;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
public class FamilyMembersTest extends TestCase implements Comparator<FamilyMemberBean> {
private DAOFactory factory = TestDAOFactory.getTestInstance();
private FamilyDAO familyDAO = factory.getFamilyDAO();
@Override
protected void setUp() throws Exception {
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
gen.hospitals();
gen.hcp0();
gen.family();
}
public void testGetNoParents() throws Exception {
assertEquals(0, familyDAO.getParents(5).size());
}
public void testGetBothParents() throws Exception {
List<FamilyMemberBean> parents = familyDAO.getParents(3);
assertEquals(2, parents.size());
Collections.sort(parents, this);
assertEquals("Dad", parents.get(0).getFirstName());
assertEquals("", parents.get(0).getLastName());
assertEquals("Dad ", parents.get(0).getFullName());
assertEquals("Mom", parents.get(1).getFirstName());
assertEquals("Parent", parents.get(0).getRelation());
}
public void testGetAllSiblings() throws Exception {
List<FamilyMemberBean> siblings = familyDAO.getSiblings(3);
assertEquals(3, siblings.size());
Collections.sort(siblings, this);
assertEquals("Sib1", siblings.get(0).getFirstName());
assertEquals("Sib2", siblings.get(1).getFirstName());
assertEquals("Sib3", siblings.get(2).getFirstName());
assertEquals("Sibling", siblings.get(0).getRelation());
}
public void testGetChildrenWithPerson() throws Exception {
List<FamilyMemberBean> children = familyDAO.getChildren(3);
assertEquals(2, children.size());
Collections.sort(children, this);
assertEquals("Kid1", children.get(0).getFirstName());
assertEquals("Kid2", children.get(1).getFirstName());
assertEquals("Child", children.get(0).getRelation());
}
public void testGetChildrenWithMom() throws Exception {
// Note that you don't get Patient 9
assertEquals(3, familyDAO.getChildren(4).size());
}
@Override
public int compare(FamilyMemberBean o1, FamilyMemberBean o2) {
return o1.getFirstName().compareTo(o2.getFirstName());
}
}
| 2,483
| 34.485714
| 89
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/hospital/AddEditHospitalDAOTest.java
|
package edu.ncsu.csc.itrust.unit.dao.hospital;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
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.model.old.dao.mysql.HospitalsDAO;
import edu.ncsu.csc.itrust.unit.DBBuilder;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
/**
* Test Hostipal DAO
*/
public class AddEditHospitalDAOTest extends TestCase {
private DAOFactory factory = TestDAOFactory.getTestInstance();
private HospitalsDAO hospitalDAO = factory.getHospitalsDAO();
TestDataGenerator gen = new TestDataGenerator();
@Override
protected void setUp() throws Exception {
gen.clearAllTables();
gen.hospitals();
}
private void clearHospitals() throws SQLException {
new DBBuilder(factory).executeSQL(Arrays.asList("DELETE FROM hospitals;"));
}
/**
* Test All hospital test Get HospitalFromEmptyTable test GetHospital test
* AddDupe testUpdateName
*
* @throws Exception
*/
public void testGetAllHospitals() throws Exception {
List<HospitalBean> hospitals = hospitalDAO.getAllHospitals();
assertEquals(9, hospitals.size());
// All hospitals in alphabetical order.
assertEquals("Facebook Rehab Center", hospitals.get(0).getHospitalName());
assertEquals("Health Institute Dr. E", hospitals.get(1).getHospitalName());
assertEquals("Health Institute Mr. Barry", hospitals.get(2).getHospitalName());
assertEquals("Health Institute Mr. Donghoon", hospitals.get(3).getHospitalName());
assertEquals("Le Awesome Hospital", hospitals.get(4).getHospitalName());
assertEquals("Mental Hospital 4 iTrust Devs", hospitals.get(5).getHospitalName());
assertEquals("Ninja Hospital", hospitals.get(6).getHospitalName());
}
public void testGetHospital() throws DBException {
HospitalBean hosp = hospitalDAO.getHospital("9191919191");
assertEquals("9191919191", hosp.getHospitalID());
assertEquals("Test Hospital 9191919191", hosp.getHospitalName());
}
public void testGetAllFromEmptyTable() throws SQLException, DBException {
clearHospitals();
assertEquals(0, hospitalDAO.getAllHospitals().size());
}
public void testGetHospitalFromEmptyTable() throws SQLException, DBException {
clearHospitals();
assertEquals(null, hospitalDAO.getHospital("9191919191"));
}
public void testAddHospital() throws DBException, ITrustException {
final String id = "9191919192";
final String name = "testAddHospital Hospital ";
genericAdd(id, name);
List<HospitalBean> allCodes = hospitalDAO.getAllHospitals();
assertEquals(id, allCodes.get(allCodes.size() - 1).getHospitalID());
assertEquals(name, allCodes.get(allCodes.size() - 1).getHospitalName());
}
public void testAddDupe() throws SQLException, DBException, ITrustException {
final String id = "0000000000";
final String name0 = "testAddDupe Hospital";
HospitalBean hosp = genericAdd(id, name0);
try {
hosp.setHospitalName("");
hospitalDAO.addHospital(hosp);
fail("CPTCodeTest.testAddDupe failed to catch dupe");
} catch (ITrustException e) {
assertEquals("Error: Hospital already exists.", e.getMessage());
hosp = hospitalDAO.getHospital(id);
assertEquals(name0, hosp.getHospitalName());
}
}
private HospitalBean genericAdd(String id, String name) throws DBException, ITrustException {
HospitalBean hosp = new HospitalBean(id, name);
assertTrue(hospitalDAO.addHospital(hosp));
assertEquals(name, hospitalDAO.getHospital(id).getHospitalName());
return hosp;
}
public void testUpdateName() throws DBException, ITrustException {
final String id = "7777777777";
final String name = "testUpdateName NEW Hospital";
HospitalBean hosp = genericAdd(id, "");
hosp.setHospitalName(name);
assertEquals(1, hospitalDAO.updateHospital(hosp));
hosp = hospitalDAO.getHospital(id);
assertEquals(name, hosp.getHospitalName());
}
public void testUpdateNonExistent() throws SQLException, DBException {
clearHospitals();
final String id = "0000000000";
HospitalBean hosp = new HospitalBean(id, "");
assertEquals(0, hospitalDAO.updateHospital(hosp));
assertEquals(0, hospitalDAO.getAllHospitals().size());
}
}
| 4,407
| 35.733333
| 94
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/hospital/AssignHospitalDAOTest.java
|
package edu.ncsu.csc.itrust.unit.dao.hospital;
import java.util.List;
import junit.framework.TestCase;
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.model.old.dao.mysql.HospitalsDAO;
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;
public class AssignHospitalDAOTest extends TestCase {
private DAOFactory factory = TestDAOFactory.getTestInstance();
private HospitalsDAO hosDAO = factory.getHospitalsDAO();
private PersonnelDAO personnelDAO = factory.getPersonnelDAO();
@Override
protected void setUp() throws Exception {
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
gen.hospitals();
gen.hcp0();
}
public void testPersonnelHospitals() throws Exception {
List<HospitalBean> hospitals = personnelDAO.getHospitals(9000000000L);
assertEquals(2, hospitals.size());
assertEquals("8181818181", hospitals.get(0).getHospitalID());
assertEquals("9191919191", hospitals.get(1).getHospitalID());
List<HospitalBean> hospList = hosDAO.getHospitalsAssignedToPhysician(9000000000L);
assertEquals(2, hospList.size());
}
public void testAssignNewHospital() throws Exception {
assertEquals(2, personnelDAO.getHospitals(9000000000L).size());
hosDAO.assignHospital(9000000000L, "1");
assertEquals(3, personnelDAO.getHospitals(9000000000L).size());
}
public void testDoItTwice() throws Exception {
hosDAO.assignHospital(9000000000L, "1");
try {
hosDAO.assignHospital(9000000000L, "1");
fail("Exception should have been thrown");
} catch (ITrustException e) {
assertEquals("HCP 9000000000 already assigned to hospital 1", e.getMessage());
}
}
}
| 1,891
| 34.698113
| 84
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/hospital/HospitalDAOExceptionTest.java
|
package edu.ncsu.csc.itrust.unit.dao.hospital;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.old.beans.HospitalBean;
import edu.ncsu.csc.itrust.model.old.dao.mysql.HospitalsDAO;
import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory;
public class HospitalDAOExceptionTest extends TestCase {
private HospitalsDAO evilDAO = EvilDAOFactory.getEvilInstance().getHospitalsDAO();
@Override
protected void setUp() throws Exception {
}
public void testAddHospitalException() throws Exception {
try {
evilDAO.addHospital(new HospitalBean());
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testAssignHospitalException() throws Exception {
try {
evilDAO.assignHospital(0L, "");
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetAllHospitalsException() throws Exception {
try {
evilDAO.getAllHospitals();
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetHospitalException() throws Exception {
try {
evilDAO.getHospital("");
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testRemoveAllHospitalAssignmentsException() throws Exception {
try {
evilDAO.removeAllHospitalAssignmentsFrom(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testRemoveHospitalAssignmentException() throws Exception {
try {
evilDAO.removeHospitalAssignment(0L, "");
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testUpdateHospitalException() throws Exception {
try {
evilDAO.updateHospital(new HospitalBean());
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
}
| 2,409
| 29.506329
| 83
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/patient/AddPatientTest.java
|
package edu.ncsu.csc.itrust.unit.dao.patient;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.ITrustException;
import edu.ncsu.csc.itrust.model.old.beans.PatientBean;
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;
public class AddPatientTest extends TestCase {
private TestDataGenerator gen = new TestDataGenerator();
private PatientDAO patientDAO = TestDAOFactory.getTestInstance().getPatientDAO();
@Override
protected void setUp() throws Exception {
gen.clearAllTables();
}
public void testAddEmptyPatient() throws Exception {
long pid = patientDAO.addEmptyPatient();
assertEquals(" ", patientDAO.getName(pid));
}
public void testGetEmptyPatient() throws Exception {
try {
patientDAO.getName(0L);
fail("exception should have been thrown");
} catch (ITrustException e) {
assertEquals("User does not exist", e.getMessage());
}
}
public void testInsertDeath() throws Exception {
gen.patient1();
PatientBean p = patientDAO.getPatient(1l);
assertEquals("Random", p.getFirstName());
assertEquals("", p.getCauseOfDeath());
assertEquals("", p.getDateOfDeathStr());
p.setDateOfDeathStr("09/12/2007");
p.setCauseOfDeath("79.3");
patientDAO.editPatient(p, 9000000003L);
PatientBean p2 = patientDAO.getPatient(1l);
assertEquals("79.3", p2.getCauseOfDeath());
assertEquals("09/12/2007", p2.getDateOfDeathStr());
}
public void testEmergencyContactInfo() throws Exception {
long pid = patientDAO.addEmptyPatient();
PatientBean p = patientDAO.getPatient(pid);
p.setFirstName("Lola");
p.setLastName("Schaefer");
p.setEmail("l@cox.net");
p.setCity("Raleigh");
p.setState("NC");
p.setZip("27602");
p.setPhone("222-222-3333");
p.setSecurityQuestion("What is the best team in the acc?");
p.setSecurityAnswer("NCSU");
p.setIcName("Blue Cross");
p.setIcAddress1("222 Blue Rd");
p.setIcCity("Raleigh");
p.setIcState("NC");
p.setIcZip("27607");
p.setIcPhone("222-333-4444");
p.setIcID("2343");
p.setEmergencyName("Joy Jones");
p.setEmergencyPhone("012-345-6789");
patientDAO.editPatient(p, 9000000003L);
assertEquals("Joy Jones", patientDAO.getPatient(pid).getEmergencyName());
assertEquals("012-345-6789", patientDAO.getPatient(pid).getEmergencyPhone());
}
}
| 2,405
| 31.513514
| 82
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/patient/DeclareHCPTest.java
|
package edu.ncsu.csc.itrust.unit.dao.patient;
import java.util.List;
import junit.framework.TestCase;
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.model.old.dao.mysql.PatientDAO;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
public class DeclareHCPTest extends TestCase {
private DAOFactory factory = TestDAOFactory.getTestInstance();
private PatientDAO patientDAO = factory.getPatientDAO();
private TestDataGenerator gen;
@Override
protected void setUp() throws Exception {
gen = new TestDataGenerator();
gen.clearAllTables();
gen.hcp3(); // 3 is declared, 0 is not
gen.patient2();
gen.hcp0();
}
public void testGetDeclaredHCPs() throws Exception {
List<PersonnelBean> hcps = patientDAO.getDeclaredHCPs(2L);
assertEquals(1, hcps.size());
assertEquals(9000000003L, hcps.get(0).getMID());
assertEquals("Gandalf Stormcrow", hcps.get(0).getFullName());
}
public void testDeclareHCP() throws Exception {
assertEquals(1, patientDAO.getDeclaredHCPs(2L).size());
patientDAO.declareHCP(2L, 9000000000L);
assertEquals(2, patientDAO.getDeclaredHCPs(2L).size());
}
public void testDeclareDuplicateHCP() throws Exception {
patientDAO.declareHCP(2L, 9000000000L);
try {
patientDAO.declareHCP(2L, 9000000000L);
fail("Exception should have been thrown");
} catch (ITrustException e) {
assertEquals("HCP 9000000000 has already been declared for patient 2", e.getMessage());
}
}
public void testUnDeclareHCP() throws Exception {
assertEquals(1, patientDAO.getDeclaredHCPs(2L).size());
patientDAO.undeclareHCP(2L, 9000000003L);
assertEquals(0, patientDAO.getDeclaredHCPs(2L).size());
}
public void testUnDeclareNotDeclaredHCP() throws Exception {
assertEquals(1, patientDAO.getDeclaredHCPs(2L).size());
boolean confirm = patientDAO.undeclareHCP(2L, 9000000000L);
assertFalse(confirm);
assertEquals(1, patientDAO.getDeclaredHCPs(2L).size());
}
public void testCheckDeclared() throws Exception {
assertTrue(patientDAO.checkDeclaredHCP(2L, 9000000003L));
assertFalse(patientDAO.checkDeclaredHCP(2L, 9000000000L));
}
}
| 2,309
| 32.970588
| 90
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/patient/EditPatientTest.java
|
package edu.ncsu.csc.itrust.unit.dao.patient;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.old.beans.PatientBean;
import edu.ncsu.csc.itrust.model.old.dao.mysql.PatientDAO;
import edu.ncsu.csc.itrust.model.old.enums.Ethnicity;
import edu.ncsu.csc.itrust.model.old.enums.Gender;
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 EditPatientTest extends TestCase {
PatientDAO patientDAO = TestDAOFactory.getTestInstance().getPatientDAO();
TestDataGenerator gen = new TestDataGenerator();
@Override
protected void setUp() throws Exception {
gen.clearAllTables();
gen.patient2();
}
public void testGetPatient2() throws Exception {
PatientBean p = patientDAO.getPatient(2);
assertNotNull(p);
assertIsPatient2(p);
}
public void testEditPatient2() throws Exception {
PatientBean p = patientDAO.getPatient(2);
p.setFirstName("Person1");
p.setEmail("another email");
p.setEmergencyName("another emergency person");
p.setTopicalNotes("some topical notes");
p.setDateOfBirthStr("05/20/1984");
p.setDateOfDeactivationStr("05/21/1984");
patientDAO.editPatient(p, 9000000003L);
p = patientDAO.getPatient(2);
assertEquals("Person1", p.getFirstName());
assertEquals("Programmer", p.getLastName());
assertEquals("another email", p.getEmail());
assertEquals("another emergency person", p.getEmergencyName());
assertEquals("some topical notes", p.getTopicalNotes());
assertEquals("05/20/1984", p.getDateOfBirthStr());
assertEquals("05/21/1984", p.getDateOfDeactivationStr());
assertEquals("250.10", p.getCauseOfDeath());
assertEquals("344 Bob Street", p.getStreetAddress1());
assertEquals("", p.getStreetAddress2());
assertEquals("Raleigh", p.getCity());
assertEquals("NC", p.getState());
assertEquals("27607", p.getZip());
assertEquals("555-555-5555", p.getPhone());
assertEquals("555-555-5551", p.getEmergencyPhone());
assertEquals("IC", p.getIcName());
assertEquals("Street1", p.getIcAddress1());
assertEquals("Street2", p.getIcAddress2());
assertEquals("City", p.getIcCity());
assertEquals("PA", p.getIcState());
assertEquals("19003-2715", p.getIcZip());
assertEquals("555-555-5555", p.getIcPhone());
assertEquals("1", p.getIcID());
assertEquals("1", p.getMotherMID());
assertEquals("0", p.getFatherMID());
assertEquals("O-", p.getBloodType().getName());
assertEquals(Ethnicity.Caucasian, p.getEthnicity());
assertEquals(Gender.Male, p.getGender());
}
public void testGetEmpty() throws Exception {
assertNull(patientDAO.getPatient(0L));
}
private void assertIsPatient2(PatientBean p) {
assertEquals(2L, p.getMID());
assertEquals("Andy", p.getFirstName());
assertEquals("Programmer", p.getLastName());
assertEquals("05/19/1984", p.getDateOfBirthStr());
assertEquals("250.10", p.getCauseOfDeath());
assertEquals("andy.programmer@gmail.com", p.getEmail());
assertEquals("344 Bob Street", p.getStreetAddress1());
assertEquals("", p.getStreetAddress2());
assertEquals("Raleigh", p.getCity());
assertEquals("NC", p.getState());
assertEquals("27607", p.getZip());
assertEquals("555-555-5555", p.getPhone());
assertEquals("Mr Emergency", p.getEmergencyName());
assertEquals("555-555-5551", p.getEmergencyPhone());
assertEquals("IC", p.getIcName());
assertEquals("Street1", p.getIcAddress1());
assertEquals("Street2", p.getIcAddress2());
assertEquals("City", p.getIcCity());
assertEquals("PA", p.getIcState());
assertEquals("19003-2715", p.getIcZip());
assertEquals("555-555-5555", p.getIcPhone());
assertEquals("1", p.getIcID());
assertEquals("1", p.getMotherMID());
assertEquals("0", p.getFatherMID());
assertEquals("O-", p.getBloodType().getName());
assertEquals(Ethnicity.Caucasian, p.getEthnicity());
assertEquals(Gender.Male, p.getGender());
assertEquals("This person is absolutely crazy. Do not touch them.", p.getTopicalNotes());
}
public void testRemoveAllRepresented() throws Exception {
// 2 represents 1, but not 4
gen.patient1();
gen.patient4();
// Add patient 4 to be represented by patient 2
patientDAO.addRepresentative(2L, 4L);
// Ensure the representatives were added correctly
assertEquals(2, patientDAO.getRepresented(2L).size());
// Remove all patient's from being represented by patient 2
patientDAO.removeAllRepresented(2L);
// Assert that no more patients are represented by patient 2
assertTrue(patientDAO.getRepresented(2L).isEmpty());
// Test with an evil factory
patientDAO = new PatientDAO(EvilDAOFactory.getEvilInstance());
try {
patientDAO.removeAllRepresented(2L);
fail("Exception should be caught");
} catch (DBException e) {
// Successful test
}
}
}
| 4,888
| 36.037879
| 91
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/patient/PatientDAOExceptionTest.java
|
package edu.ncsu.csc.itrust.unit.dao.patient;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.old.beans.PatientBean;
import edu.ncsu.csc.itrust.model.old.dao.mysql.PatientDAO;
import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory;
public class PatientDAOExceptionTest extends TestCase {
private PatientDAO evilDAO = EvilDAOFactory.getEvilInstance().getPatientDAO();
@Override
protected void setUp() throws Exception {
}
public void testAddEmptyPatientException() throws Exception {
try {
evilDAO.addEmptyPatient();
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testAddRepException() throws Exception {
try {
evilDAO.addRepresentative(0L, 0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testCheckDeclaredHCPException() throws Exception {
try {
evilDAO.checkDeclaredHCP(0L, 0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testCheckPatientExistsException() throws Exception {
try {
evilDAO.checkPatientExists(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testDeclareHCPException() throws Exception {
try {
evilDAO.declareHCP(0L, 0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testEditPatientException() throws Exception {
try {
evilDAO.editPatient(new PatientBean(), 9000000003L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetDeclaredHCPsException() throws Exception {
try {
evilDAO.getDeclaredHCPs(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals("pid cannot be 0", e.getSQLException().getMessage());
}
}
public void testGetNameException() throws Exception {
try {
evilDAO.getName(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetPatientException() throws Exception {
try {
evilDAO.getPatient(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetRepresentedException() throws Exception {
try {
evilDAO.getRepresented(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testRemoveRepresentativeException() throws Exception {
try {
evilDAO.removeRepresentative(0L, 0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testRepresentsException() throws Exception {
try {
evilDAO.represents(0L, 0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testUndeclareHCPException() throws Exception {
try {
evilDAO.undeclareHCP(0L, 0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
}
| 3,901
| 28.119403
| 79
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/patient/PatientExistsTest.java
|
package edu.ncsu.csc.itrust.unit.dao.patient;
import junit.framework.TestCase;
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;
public class PatientExistsTest extends TestCase {
PatientDAO patientDAO = TestDAOFactory.getTestInstance().getPatientDAO();
@Override
protected void setUp() throws Exception {
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
gen.patient1();
gen.patient2();
}
public void testGetPatient2() throws Exception {
assertTrue(patientDAO.checkPatientExists(2));
}
public void testNotPatient200() throws Exception {
assertFalse(patientDAO.checkPatientExists(200));
}
public void testGetAllPatients() throws Exception {
assertEquals(2, patientDAO.getAllPatients().size());
}
}
| 881
| 27.451613
| 74
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/patient/RepresentativeTest.java
|
package edu.ncsu.csc.itrust.unit.dao.patient;
import java.util.List;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.ITrustException;
import edu.ncsu.csc.itrust.model.old.beans.PatientBean;
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;
public class RepresentativeTest extends TestCase {
PatientDAO patientDAO = TestDAOFactory.getTestInstance().getPatientDAO();
private TestDataGenerator gen;
@Override
protected void setUp() throws Exception {
gen = new TestDataGenerator();
gen.clearAllTables();
gen.patient1();
gen.patient2();
}
public void testGetRepresented() throws Exception {
List<PatientBean> rep = patientDAO.getRepresented(2L);
assertEquals(1, rep.size());
assertEquals(1L, rep.get(0).getMID());
}
public void testGetNoneRepresented() throws Exception {
assertEquals(0, patientDAO.getRepresented(1L).size());
}
public void testGetNonExistentRepresented() throws Exception {
assertEquals(0, patientDAO.getRepresented(500L).size());
}
public void testRepresentsTrue() throws Exception {
assertTrue(patientDAO.represents(2L, 1L));
}
public void testRepresentsFalse() throws Exception {
assertFalse(patientDAO.represents(1L, 2L));
}
public void testAddRepresentative() throws Exception {
assertEquals(0, patientDAO.getRepresented(1L).size());
patientDAO.addRepresentative(1L, 2L);
assertEquals(1, patientDAO.getRepresented(1L).size());
}
public void testAddExistingRepresentative() throws Exception {
patientDAO.addRepresentative(1L, 2L);
try {
patientDAO.addRepresentative(1L, 2L);
fail("exception should have been thrown");
} catch (ITrustException e) {
assertEquals("Patient 1 already represents patient 2", e.getMessage());
}
}
public void testRemoveRepresentative() throws Exception {
assertEquals(1, patientDAO.getRepresented(2L).size());
boolean confirm = patientDAO.removeRepresentative(2L, 1L);
assertEquals(0, patientDAO.getRepresented(2L).size());
assertTrue(confirm);
}
public void testRemoveNonExistingRepresentative() throws Exception {
assertEquals(1, patientDAO.getRepresented(2L).size());
boolean confirm = patientDAO.removeRepresentative(2L, 3L);
assertEquals(1, patientDAO.getRepresented(2L).size());
assertFalse(confirm);
}
public void testGetDependents() throws Exception {
// 2 represents 1 but 1 is not a dependent
// so the size should be zero
assertEquals(0, patientDAO.getDependents(2L).size());
// We wanted to test getDependents when a users isDependent field is 1
// but the current test generator does not have any patients with this
// attribute.
}
}
| 2,759
| 31.470588
| 74
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/personnel/AddPersonnelTest.java
|
package edu.ncsu.csc.itrust.unit.dao.personnel;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.ITrustException;
import edu.ncsu.csc.itrust.model.old.dao.mysql.PersonnelDAO;
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 AddPersonnelTest extends TestCase {
PersonnelDAO personnelDAO = TestDAOFactory.getTestInstance().getPersonnelDAO();
@Override
protected void setUp() throws Exception {
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
}
public void testAddEmptyPersonnel() throws Exception {
long mid = personnelDAO.addEmptyPersonnel(Role.HCP);
assertEquals(" ", personnelDAO.getName(mid));
assertEquals(Role.HCP, personnelDAO.getPersonnel(mid).getRole());
assertTrue("hcp MID is greater or equal to 9 billion, actual:" + mid, mid >= 9000000000L);
}
public void testAddEmptyER() throws Exception {
long mid = personnelDAO.addEmptyPersonnel(Role.ER);
assertEquals(" ", personnelDAO.getName(mid));
assertEquals("er", personnelDAO.getPersonnel(mid).getRole().getUserRolesString());
}
public void testGetNextID() throws Exception {
assertEquals(1L, personnelDAO.getNextID(Role.ADMIN));
assertEquals(9000000000L, personnelDAO.getNextID(Role.ER));
assertEquals(9000000000L, personnelDAO.getNextID(Role.HCP));
assertEquals(5000000000L, personnelDAO.getNextID(Role.LT));
assertEquals(1L, personnelDAO.getNextID(Role.PATIENT));
assertEquals(7000000000L, personnelDAO.getNextID(Role.PHA));
assertEquals(1L, personnelDAO.getNextID(Role.TESTER));
assertEquals(8000000000L, personnelDAO.getNextID(Role.UAP));
}
public void testDoesNotExist() throws Exception {
try {
personnelDAO.getName(0L);
fail("exception should have been thrown");
} catch (ITrustException e) {
assertEquals("User does not exist", e.getMessage());
}
}
}
| 1,966
| 36.826923
| 92
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/personnel/EditPersonnelTest.java
|
package edu.ncsu.csc.itrust.unit.dao.personnel;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean;
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;
/**
*/
public class EditPersonnelTest extends TestCase {
PersonnelDAO personnelDAO = TestDAOFactory.getTestInstance().getPersonnelDAO();
@Override
protected void setUp() throws Exception {
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
gen.uap1();
gen.hcp0();
}
/**
* testGetPersonnel2
*
* @throws Exception
*/
public void testGetPersonnel2() throws Exception {
PersonnelBean p = personnelDAO.getPersonnel(8000000009L);
assertNotNull(p);
assertIsPersonnel2(p);
}
/**
* testEditPersonnel2
*
* @throws Exception
*/
public void testEditPersonnel2() throws Exception {
PersonnelBean p = personnelDAO.getPersonnel(8000000009L);
p.setFirstName("Person1");
p.setEmail("blah@blah.com");
personnelDAO.editPersonnel(p);
p = personnelDAO.getPersonnel(8000000009L);
assertEquals("Person1", p.getFirstName());
assertEquals("LastUAP", p.getLastName());
assertEquals("blah@blah.com", p.getEmail());
}
/**
* testGetNonExistentPersonnel
*
* @throws Exception
*/
public void testGetNonExistentPersonnel() throws Exception {
assertNull(personnelDAO.getPersonnel(0L));
}
private void assertIsPersonnel2(PersonnelBean p) {
assertEquals(8000000009L, p.getMID());
assertEquals("FirstUAP", p.getFirstName());
assertEquals("LastUAP", p.getLastName());
assertEquals("100 Ave", p.getStreetAddress1());
assertEquals("", p.getStreetAddress2());
assertEquals("Raleigh", p.getCity());
assertEquals("NC", p.getState());
assertEquals("27607", p.getZip());
assertEquals("111-111-1111", p.getPhone());
}
/**
* testEditPersonallZipCode
*
* @throws Exception
*/
public void testEditPersonnelZipCode() throws Exception {
PersonnelBean p = personnelDAO.getPersonnel(8000000009L);
p.setZip("55555-6666");
personnelDAO.editPersonnel(p);
assertEquals("55555-6666", p.getZip());
}
/**
* testEditPersonnelSpeciality
*
* @throws Exception
*/
public void testEditPersonnelSpecialty() throws Exception {
PersonnelBean p = personnelDAO.getPersonnel(8000000009L);
p.setSpecialty("chocolate");
personnelDAO.editPersonnel(p);
assertEquals("chocolate", p.getSpecialty());
}
/**
* testGetPersonnel
*
* @throws Exception
*/
public void testEditPersonnel() throws Exception {
PersonnelBean p = personnelDAO.getPersonnel(9000000000L);
assertNotNull(p);
assertIsPersonnel(p);
p.setFirstName("Kelly");
p.setLastName("Doctor");
p.setStreetAddress1("98765 Oak Hills Drive");
p.setCity("Capitol City");
p.setState("NC");
p.setZip("28700-0458");
p.setPhone("555-877-5100");
personnelDAO.editPersonnel(p);
assertEquals("Kelly", p.getFirstName());
assertEquals("Doctor", p.getLastName());
assertEquals("98765 Oak Hills Drive", p.getStreetAddress1());
assertEquals("Capitol City", p.getCity());
assertEquals("NC", p.getState());
assertEquals("28700-0458", p.getZip());
assertEquals("555-877-5100", p.getPhone());
}
private void assertIsPersonnel(PersonnelBean p) {
assertEquals(9000000000L, p.getMID());
assertEquals("Kelly", p.getFirstName());
assertEquals("Doctor", p.getLastName());
assertEquals("4321 My Road St", p.getStreetAddress1());
assertEquals("PO BOX 2", p.getStreetAddress2());
assertEquals("New York", p.getCity());
assertEquals("NY", p.getState());
assertEquals("10453", p.getZip());
assertEquals("999-888-7777", p.getPhone());
}
}
| 3,743
| 27.150376
| 80
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/personnel/PersonnelDAOExceptionTest.java
|
package edu.ncsu.csc.itrust.unit.dao.personnel;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean;
import edu.ncsu.csc.itrust.model.old.dao.mysql.PersonnelDAO;
import edu.ncsu.csc.itrust.model.old.enums.Role;
import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory;
public class PersonnelDAOExceptionTest extends TestCase {
private PersonnelDAO evilDAO = EvilDAOFactory.getEvilInstance().getPersonnelDAO();
@Override
protected void setUp() throws Exception {
}
public void testAddEmptyPersonnelException() throws Exception {
try {
evilDAO.addEmptyPersonnel(Role.HCP);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testCheckPersonnelExistsException() throws Exception {
try {
evilDAO.checkPersonnelExists(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testEditPersonnelException() throws Exception {
try {
evilDAO.editPersonnel(new PersonnelBean());
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetHospitalsException() throws Exception {
try {
evilDAO.getHospitals(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetUAPHospitalsException() throws Exception {
try {
evilDAO.getUAPHospitals(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetNameException() throws Exception {
try {
evilDAO.getName(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testPersonnelException() throws Exception {
try {
evilDAO.getPersonnel(0L);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
}
| 2,397
| 28.975
| 83
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/personnel/PersonnelExistsTest.java
|
package edu.ncsu.csc.itrust.unit.dao.personnel;
import java.util.List;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.model.old.beans.PersonnelBean;
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;
public class PersonnelExistsTest extends TestCase {
PersonnelDAO personnelDAO = TestDAOFactory.getTestInstance().getPersonnelDAO();
TestDataGenerator gen;
@Override
protected void setUp() throws Exception {
gen = new TestDataGenerator();
gen.clearAllTables();
}
public void testGetPersonnel2() throws Exception {
gen.uap1();
assertTrue(personnelDAO.checkPersonnelExists(8000000009l));
assertFalse(personnelDAO.checkPersonnelExists(8999999999l));
}
public void testFuzzySearch() throws Exception {
gen.standardData();
List<PersonnelBean> fetch = personnelDAO.fuzzySearchForExpertsWithName("Gan", "");
assertEquals(1, fetch.size());
}
}
| 1,013
| 29.727273
| 84
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/recordsrelease/RecordsReleaseDAOTest.java
|
package edu.ncsu.csc.itrust.unit.dao.recordsrelease;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.List;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.old.beans.RecordsReleaseBean;
import edu.ncsu.csc.itrust.model.old.dao.DAOFactory;
import edu.ncsu.csc.itrust.model.old.dao.mysql.RecordsReleaseDAO;
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;
/**
* RecordsReleaseDAOTest
*/
public class RecordsReleaseDAOTest extends TestCase {
private TestDataGenerator gen = new TestDataGenerator();
private DAOFactory factory = TestDAOFactory.getTestInstance();
private DAOFactory evilFactory = EvilDAOFactory.getEvilInstance();
private RecordsReleaseDAO testDAO;
private RecordsReleaseBean testBean;
@Override
protected void setUp() throws Exception {
gen.clearAllTables();
testDAO = new RecordsReleaseDAO(factory);
testBean = new RecordsReleaseBean();
testBean.setDateRequested(new Timestamp(Calendar.getInstance().getTimeInMillis()));
testBean.setReleaseHospitalID("1");
testBean.setPid(1L);
testBean.setRecHospitalName("Test Hospital");
testBean.setRecHospitalAddress("5 Test Drive");
testBean.setDocFirstName("Doctor");
testBean.setDocLastName("Test");
testBean.setDocPhone("555-555-5555");
testBean.setDocEmail("test@test.com");
testBean.setJustification("Justification");
testBean.setStatus(0);
}
/**
* testAddRecordsRelease
*
* @throws DBException
*/
public void testAddRecordsRelease() throws DBException {
assertTrue(testDAO.getAllRecordsReleasesByHospital("1").isEmpty());
assertTrue(testDAO.addRecordsRelease(testBean));
List<RecordsReleaseBean> list = testDAO.getAllRecordsReleasesByHospital("1");
assertEquals(1, list.size());
}
/**
* testUpdateRecordsRelease
*
* @throws DBException
*/
public void testUpdateRecordsRelease() throws DBException {
assertTrue(testDAO.getAllRecordsReleasesByHospital("1").isEmpty());
testDAO.addRecordsRelease(testBean);
testBean = testDAO.getAllRecordsReleasesByHospital("1").get(0);
assertEquals("Test Hospital", testBean.getRecHospitalName());
testBean.setRecHospitalAddress("Test");
assertTrue(testDAO.updateRecordsRelease(testBean));
List<RecordsReleaseBean> list = testDAO.getAllRecordsReleasesByHospital("1");
assertEquals(1, list.size());
assertEquals("Test", list.get(0).getRecHospitalAddress());
}
/**
* testGetRecordsReleaseByID
*
* @throws DBException
*/
public void testGetRecordsReleaseByID() throws DBException {
assertTrue(testDAO.getAllRecordsReleasesByHospital("1").isEmpty());
testDAO.addRecordsRelease(testBean);
testBean = testDAO.getAllRecordsReleasesByHospital("1").get(0);
RecordsReleaseBean idTestBean = testDAO.getRecordsReleaseByID(testBean.getReleaseID());
assertTrue(idTestBean != null);
assertEquals(testBean.getReleaseID(), idTestBean.getReleaseID());
assertEquals(testBean.getDateRequested(), idTestBean.getDateRequested());
assertEquals("1", idTestBean.getReleaseHospitalID());
assertEquals(1L, idTestBean.getPid());
assertEquals("Test Hospital", idTestBean.getRecHospitalName());
assertEquals("5 Test Drive", idTestBean.getRecHospitalAddress());
assertEquals("Doctor", idTestBean.getDocFirstName());
assertEquals("Test", idTestBean.getDocLastName());
assertEquals("555-555-5555", idTestBean.getDocPhone());
assertEquals("test@test.com", idTestBean.getDocEmail());
assertEquals("Justification", idTestBean.getJustification());
assertEquals(0, idTestBean.getStatus());
}
/**
* testGetAllHealthRecordsByHospital
*
* @throws DBException
*/
public void testGetAllHealthRecordsByHospital() throws DBException {
assertTrue(testDAO.getAllRecordsReleasesByHospital("1").isEmpty());
testDAO.addRecordsRelease(testBean);
List<RecordsReleaseBean> testList = testDAO.getAllRecordsReleasesByHospital("1");
assertEquals(1, testList.size());
testDAO.addRecordsRelease(testBean);
testList = testDAO.getAllRecordsReleasesByHospital("1");
assertEquals(2, testList.size());
testBean.setReleaseHospitalID("2");
testDAO.addRecordsRelease(testBean);
testList = testDAO.getAllRecordsReleasesByHospital("1");
assertEquals(2, testList.size());
}
/**
* testGetAllHealthRecordsByPid
*
* @throws DBException
*/
public void testGetAllHealthRecordsByPid() throws DBException {
assertTrue(testDAO.getAllRecordsReleasesByPid(1L).isEmpty());
testDAO.addRecordsRelease(testBean);
List<RecordsReleaseBean> testList = testDAO.getAllRecordsReleasesByPid(1L);
assertEquals(1, testList.size());
testDAO.addRecordsRelease(testBean);
testList = testDAO.getAllRecordsReleasesByPid(1L);
assertEquals(2, testList.size());
testBean.setPid(2L);
testDAO.addRecordsRelease(testBean);
testList = testDAO.getAllRecordsReleasesByPid(1L);
assertEquals(2, testList.size());
}
/**
* testDBException
*/
public void testDBException() {
testDAO = new RecordsReleaseDAO(evilFactory);
try {
testDAO.addRecordsRelease(testBean);
// Fail if exception isn't caught
fail();
} catch (DBException e) {
// TODO
}
try {
testDAO.updateRecordsRelease(testBean);
// Fail if exception isn't caught
fail();
} catch (DBException e) {
// TODO
}
try {
testDAO.getAllRecordsReleasesByHospital("1");
// Fail if exception isn't caught
} catch (DBException e) {
// TODO
}
try {
testDAO.getAllRecordsReleasesByPid(1L);
// Fail if exception isn't caught
fail();
} catch (DBException e) {
// TODO
}
try {
testDAO.getRecordsReleaseByID(0L);
// Fail if exception isn't caught
fail();
} catch (DBException e) {
// TODO
}
}
}
| 5,860
| 29.685864
| 89
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/remotemonitoring/PatientDataTest.java
|
package edu.ncsu.csc.itrust.unit.dao.remotemonitoring;
import java.util.List;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.ITrustException;
import edu.ncsu.csc.itrust.model.old.beans.RemoteMonitoringDataBean;
import edu.ncsu.csc.itrust.model.old.beans.TelemedicineBean;
import edu.ncsu.csc.itrust.model.old.dao.mysql.RemoteMonitoringDAO;
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 PatientDataTest extends TestCase {
private RemoteMonitoringDAO rmDAO = TestDAOFactory.getTestInstance().getRemoteMonitoringDAO();
private RemoteMonitoringDAO EvilrmDAO = EvilDAOFactory.getEvilInstance().getRemoteMonitoringDAO();
private TestDataGenerator gen;
@Override
protected void setUp() throws Exception {
gen = new TestDataGenerator();
gen.clearAllTables();
gen.patient2();
gen.hcp0();
gen.remoteMonitoring1();
}
/**
* testStoreRetrievePatientNormalData
*
* @throws Exception
*/
public void testStoreRetrievePatientNormalData() throws Exception {
RemoteMonitoringDataBean b = new RemoteMonitoringDataBean();
b.setSystolicBloodPressure(100);
b.setDiastolicBloodPressure(70);
b.setGlucoseLevel(80);
rmDAO.storePatientData(2, b, "self-reported", 2);
List<RemoteMonitoringDataBean> d = rmDAO.getPatientsData(9000000000L);
assertEquals(2, d.get(0).getPatientMID());
assertEquals(100, d.get(0).getSystolicBloodPressure());
assertEquals(70, d.get(0).getDiastolicBloodPressure());
assertEquals(80, d.get(0).getGlucoseLevel());
}
/**
* testGetMonitoringHCPs
*
* @throws Exception
*/
public void testGetMonitoringHCPs() throws Exception {
gen.remoteMonitoring5();
assertTrue(rmDAO.getMonitoringHCPs(1).size() == 1);
}
/**
* testBadStoreRetrievePatientNormalDataBad
*
* @throws Exception
*/
public void testBadStoreRetrievePatientNormalDataBad() throws Exception {
try {
RemoteMonitoringDataBean b = new RemoteMonitoringDataBean();
b.setSystolicBloodPressure(100);
b.setDiastolicBloodPressure(70);
b.setGlucoseLevel(80);
EvilrmDAO.storePatientData(2, b, "self-reported", 2);
fail();
} catch (DBException e) {
assertSame(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
/**
* testBadStoreRetrievePatientGlucoseOnlyDataBad
*
* @throws Exception
*/
public void testBadStoreRetrievePatientGlucoseOnlyDataBad() throws Exception {
try {
RemoteMonitoringDataBean b = new RemoteMonitoringDataBean();
b.setGlucoseLevel(80);
EvilrmDAO.storePatientData(2, b, "self-reported", 2);
fail();
} catch (DBException e) {
assertSame(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
/**
* testBadStoreRetrievePatientBPOnlyDataBad
*
* @throws Exception
*/
public void testBadStoreRetrievePatientBPOnlyDataBad() throws Exception {
try {
RemoteMonitoringDataBean b = new RemoteMonitoringDataBean();
b.setSystolicBloodPressure(80);
b.setDiastolicBloodPressure(100);
EvilrmDAO.storePatientData(2, b, "self-reported", 2);
fail();
} catch (DBException e) {
assertSame(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
/**
* testGetTelemadicineBean
*
* @throws Exception
*/
public void testGetTelemedicineBean() throws Exception {
try {
List<TelemedicineBean> tBeans = rmDAO.getTelemedicineBean(2L);
assertEquals(1, tBeans.size());
} catch (ITrustException e) {
fail();
}
}
/**
* testValidatePR
*
* @throws Exception
*/
public void testValidatePR() throws Exception {
try {
rmDAO.validatePR(2, 1);
assert (true);
} catch (ITrustException e) {
fail();
}
}
/**
* testValidatePRError
*
* @throws Exception
*/
public void testValidatePRError() throws Exception {
try {
rmDAO.validatePR(1, 2);
fail();
} catch (ITrustException e) {
assertEquals("Representer is not valid for patient 2", e.getMessage());
}
}
/**
* testRemovePatientFromListBad
*
* @throws Exception
*/
public void testRemovePatientFromListBad() throws Exception {
try {
EvilrmDAO.removePatientFromList(1, 2);
fail();
} catch (DBException e) {
assertSame(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
}
| 4,398
| 25.5
| 99
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/remotemonitoring/PatientListTest.java
|
package edu.ncsu.csc.itrust.unit.dao.remotemonitoring;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.model.old.beans.TelemedicineBean;
import edu.ncsu.csc.itrust.model.old.dao.mysql.RemoteMonitoringDAO;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
public class PatientListTest extends TestCase {
private RemoteMonitoringDAO rmDAO = TestDAOFactory.getTestInstance().getRemoteMonitoringDAO();
private TestDataGenerator gen;
@Override
protected void setUp() throws Exception {
gen = new TestDataGenerator();
gen.clearAllTables();
gen.patient2();
gen.hcp0();
}
public void testAddRemoveFromList() throws Exception {
TelemedicineBean tBean = new TelemedicineBean();
assertTrue(rmDAO.addPatientToList(2L, 9000000000L, tBean));
assertTrue(rmDAO.removePatientFromList(2L, 9000000000L));
}
}
| 901
| 32.407407
| 95
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/reportrequest/ReportRequestDAOTest.java
|
package edu.ncsu.csc.itrust.unit.dao.reportrequest;
import java.text.SimpleDateFormat;
import java.util.List;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.old.beans.ReportRequestBean;
import edu.ncsu.csc.itrust.model.old.dao.DAOFactory;
import edu.ncsu.csc.itrust.model.old.dao.mysql.ReportRequestDAO;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
/**
*
*
*/
public class ReportRequestDAOTest extends TestCase {
private DAOFactory factory = TestDAOFactory.getTestInstance();
private ReportRequestDAO dao = factory.getReportRequestDAO();
@Override
protected void setUp() throws Exception {
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
gen.reportRequests();
}
public void testGetReportsUnknownRequeter() throws Exception {
try {
dao.getAllReportRequestsForRequester(0);
fail("should have thrown an exception");
} catch (DBException ex) {
assertEquals("Invalid RequesterMID", ex.getSQLException().getMessage());
}
}
public void testGetReportsCheckListRequester() throws Exception {
List<ReportRequestBean> list = dao.getAllReportRequestsForRequester(9000000000L);
assertEquals(6, list.size());
assertEquals(ReportRequestBean.Requested, list.get(0).getStatus());
}
public void testGetReportsCheckListPatient() throws Exception {
List<ReportRequestBean> list = dao.getAllReportRequestsForPatient(2L);
assertEquals(4, list.size());
assertEquals(ReportRequestBean.Requested, list.get(0).getStatus());
}
public void testGetReportsNullReportID() throws Exception {
try {
dao.getReportRequest(0);
fail("Should have thrown an exception");
} catch (DBException ex) {
assertEquals("ID cannot be null", ex.getSQLException().getMessage());
}
}
public void testGetSpecificReport3CheckDetails() throws Exception {
ReportRequestBean b = dao.getReportRequest(3);
assertEquals(3, b.getID());
assertEquals(9000000000L, b.getRequesterMID());
assertEquals(2, b.getPatientMID());
assertEquals("01/03/2008 12:00", b.getRequestedDateString());
}
public void testGetSpecificReport4CheckDetails() throws Exception {
ReportRequestBean b = dao.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 testInsertReportFailureNullMIDs() throws Exception {
try {
dao.addReportRequest(0, 0, null);
fail("Should have throw exception");
} catch (DBException ex) {
assertEquals("RequesterMID cannot be null", ex.getSQLException().getMessage());
}
}
public void testAddThenRetrieveReport() throws Exception {
long id = dao.addReportRequest(9000000000L, 2,
new SimpleDateFormat(ReportRequestBean.dateFormat).parse("06/06/2008 13:00"));
ReportRequestBean b2 = dao.getReportRequest(id);
assertEquals(9000000000L, b2.getRequesterMID());
assertEquals(2, b2.getPatientMID());
assertEquals("06/06/2008 13:00", b2.getRequestedDateString());
assertEquals(ReportRequestBean.Requested, b2.getStatus());
}
public void testSetViewedFailure() throws Exception {
try {
dao.setViewed(0, null);
fail("Should have throw exception");
} catch (DBException ex) {
assertEquals("ID cannot be null", ex.getSQLException().getMessage());
}
}
public void testAddThenSetViewed() throws Exception {
long id = dao.addReportRequest(9000000000L, 2,
new SimpleDateFormat(ReportRequestBean.dateFormat).parse("06/06/2008 13:00"));
dao.setViewed(id, new SimpleDateFormat(ReportRequestBean.dateFormat).parse("08/08/2008 15:00"));
ReportRequestBean b2 = dao.getReportRequest(id);
assertEquals("08/08/2008 15:00", b2.getViewedDateString());
assertEquals(ReportRequestBean.Viewed, b2.getStatus());
}
}
| 4,042
| 33.853448
| 98
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/reviews/ReviewsDAOTest.java
|
package edu.ncsu.csc.itrust.unit.dao.reviews;
import static org.junit.Assert.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
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.exception.DBException;
import edu.ncsu.csc.itrust.model.old.beans.ReviewsBean;
import edu.ncsu.csc.itrust.model.old.dao.DAOFactory;
import edu.ncsu.csc.itrust.model.old.dao.mysql.ReviewsDAO;
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 ReviewsDAOTest {
/** ReviewsDAO instance for testing */
private ReviewsDAO rdao, evil2;
private EvilDAOFactory evil;
/** test instance of beans for testing */
private ReviewsBean beanValid, beanInvalid;
private static final long PID1 = 9000000000L, PID2 = 9000000003L, MID = 42L;
private static final Date REVDATE = new java.sql.Date(new Date().getTime());
/**
* Provide setup for the rest of the tests; initialize all globals.
*
* @throws Exception
*/
@Before
public void setUp() throws Exception {
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
gen.standardData();
gen.uc61reviews();
DAOFactory factory = TestDAOFactory.getTestInstance();
rdao = new ReviewsDAO(factory);
evil = new EvilDAOFactory(0);
evil2 = new ReviewsDAO(evil);
beanValid = new ReviewsBean();
beanValid.setMID(MID);
beanValid.setPID(PID1);
beanValid.setDescriptiveReview("oh well");
beanValid.setDateOfReview(REVDATE);
beanValid.setRating(2);
beanInvalid = new ReviewsBean();
beanInvalid.setMID(MID);
beanInvalid.setPID(PID2);
beanInvalid.setDateOfReview(REVDATE);
beanInvalid.setDescriptiveReview("oh well");
beanInvalid.setRating(2);
}
@After
public void tearDown() throws Exception {
}
/**
* Tests adding a review to the reviewsTable by comparing sizes of lists.
* Pre-condition: assuming the ReviewsDAO.getAllReviews() works AND setup is
* run between ea test.
*/
@Test
public final void testAddReviewValid() {
try {
// sanity check for the initial size of the entries in the reviews
// table
List<ReviewsBean> l = rdao.getAllReviews();
assertEquals(6, l.size());
// try adding a valid bean
assertTrue(rdao.addReview(beanValid));
// check the number of reviews table entries went up by 1
l = rdao.getAllReviews();
assertEquals(7, l.size());
assertEquals(false, rdao.addReview(null));
} catch (DBException e) {
fail();
}
}
/**
* Tests getting reviews from a current database for a given HCP.
*
* @throws DBException
*/
@Test(expected = DBException.class)
public final void testGetReviews() throws DBException {
List<ReviewsBean> l = rdao.getAllReviews(PID1);
// test getting reviews for Kelly Doctor
assertEquals(4, l.size());
// test getting reviews for Gandolf Stormcloud
l = rdao.getReviews(PID2);
assertEquals(2, l.size());
evil2.getAllReviews();
}
/**
* Tests that ALL in table reviews are retrieved when called.
*/
@Test
public final void testGetAllReviews() {
List<ReviewsBean> l;
try {
l = rdao.getAllReviews(PID1);
assertEquals(4, l.size());
l.clear();
assertEquals(0, l.size());
} catch (Exception e) {
fail();
}
}
/**
* Tests that overall rating averages are returned for ea HCP.
*/
@Test
public final void testGetTotalAverageRating() {
/** expected average rating for Kelly Doctor */
final double PID1AVG = 2.5;
/** expected average rating for Gandolf Stomcloud */
final double PID2AVG = 4.5;
try {
assertTrue(PID2AVG != rdao.getTotalAverageRating(PID1));
assertTrue(PID1AVG == rdao.getTotalAverageRating(PID1));
assertTrue(PID2AVG == rdao.getTotalAverageRating(PID2));
} catch (DBException e) {
fail();
}
}
/**
* Tests that a Patient can ONLY review a Physician they have previously
* seen.
*
* @throws IOException
* @throws SQLException
* @throws FileNotFoundException
*/
@Test
public final void testIsRateable() throws FileNotFoundException, SQLException, IOException {
try {
// Tests when it should not work,
// for Patient Tom Nook and HCP Gandolf Stormcloud
assertFalse(rdao.isRateable(MID, PID2));
// Tests when it should be added,
// for Patient Tom Nook and HCP Kelly Doctor
assertTrue(rdao.isRateable(MID, PID1));
} catch (DBException e) {
fail();
}
}
/**
* Tests adding an invalid review
*/
@Test
public void testAddInvalidReview() {
try {
beanInvalid.setMID(-1);
rdao.addReview(beanInvalid);
fail("Should have thrown an exception");
} catch (DBException e) {
assertEquals("A database exception has occurred. Please see the " + "log in the console for stacktrace",
e.getMessage());
}
}
/**
* Tests getting reviews with invalid dao
*/
@Test
public void testGetReviewsEvilDAO() {
try {
evil2.getReviews(1);
fail("Should have thrown an exception");
} catch (DBException e) {
assertEquals("A database exception has occurred. Please see the " + "log in the console for stacktrace",
e.getMessage());
}
}
/**
* Tests getting all of the reviews with invalid dao
*/
@Test
public void testGetAllReviewsEvilDAO() {
try {
evil2.getAllReviews(1);
fail("Should have thrown an exception");
} catch (DBException e) {
assertEquals("A database exception has occurred. Please see the " + "log in the console for stacktrace",
e.getMessage());
}
}
/**
* Tests getting the total average rating with invalid dao
*/
@Test
public void testAverageRatingEvilDAO() {
try {
evil2.getTotalAverageRating(1);
fail("Should have thrown an exception");
} catch (DBException e) {
assertEquals("A database exception has occurred. Please see the " + "log in the console for stacktrace",
e.getMessage());
}
}
}
| 5,997
| 24.965368
| 107
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/standards/NDCodeTest.java
|
package edu.ncsu.csc.itrust.unit.dao.standards;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.ITrustException;
import edu.ncsu.csc.itrust.model.old.beans.MedicationBean;
import edu.ncsu.csc.itrust.model.old.dao.DAOFactory;
import edu.ncsu.csc.itrust.model.old.dao.mysql.NDCodesDAO;
import edu.ncsu.csc.itrust.unit.DBBuilder;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
public class NDCodeTest extends TestCase {
private DAOFactory factory = TestDAOFactory.getTestInstance();
private NDCodesDAO ndDAO = factory.getNDCodesDAO();
@Override
protected void setUp() throws Exception {
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
gen.ndCodes();
}
// order by code asc but field isn't numerical, so codes will NOT be
// in NUMERICAL ascending order...
// (unless codes are switched to fixed width)
public void testGetAllNDCodes() throws Exception {
List<MedicationBean> codes = ndDAO.getAllNDCodes();
assertEquals(5, codes.size());
assertEquals("00060-431", codes.get(0).getNDCode());
assertEquals("Tetracycline", codes.get(1).getDescription());
}
public void testGetNDCode() throws DBException {
MedicationBean proc = ndDAO.getNDCode("08109-6");
assertEquals("08109-6", proc.getNDCode());
assertEquals("Aspirin", proc.getDescription());
}
public void testGetAllFromEmptyTable() throws SQLException, DBException {
clearNDCodes();
assertEquals(0, ndDAO.getAllNDCodes().size());
}
public void testGetNDCodeFromEmptyTable() throws SQLException, DBException {
clearNDCodes();
assertEquals(null, ndDAO.getNDCode("00904-2407"));
}
public void testAddNDCode() throws DBException, ITrustException {
final String code = "999999999";
final String desc = "testAddNDCode description";
genericAdd(code, desc);
List<MedicationBean> allCodes = ndDAO.getAllNDCodes();
assertEquals(code, allCodes.get(allCodes.size() - 1).getNDCode());
assertEquals(desc, allCodes.get(allCodes.size() - 1).getDescription());
}
public void testAddDupe() throws SQLException, DBException, ITrustException {
clearNDCodes();
final String code = "000000000";
final String descrip0 = "testAddDupe description";
MedicationBean proc = genericAdd(code, descrip0);
try {
proc.setDescription("");
ndDAO.addNDCode(proc);
fail("NDCodeTest.testAddDupe failed to catch dupe");
} catch (ITrustException e) {
assertEquals("Error: Code already exists.", e.getMessage());
proc = ndDAO.getNDCode(code);
assertEquals(descrip0, proc.getDescription());
}
}
private MedicationBean genericAdd(String code, String desc) throws DBException, ITrustException {
MedicationBean proc = new MedicationBean(code, desc);
assertTrue(ndDAO.addNDCode(proc));
assertEquals(desc, ndDAO.getNDCode(code).getDescription());
return proc;
}
public void testUpdateDescription() throws DBException, ITrustException {
final String code = "777777777";
final String desc = "testUpdateDescription NEW description";
MedicationBean proc = genericAdd(code, "");
proc.setDescription(desc);
assertEquals(1, ndDAO.updateCode(proc));
proc = ndDAO.getNDCode(code);
assertEquals(desc, proc.getDescription());
}
public void testUpdateNonExistent() throws SQLException, DBException {
clearNDCodes();
final String code = "0000F";
MedicationBean proc = new MedicationBean(code, "");
assertEquals(0, ndDAO.updateCode(proc));
assertEquals(0, ndDAO.getAllNDCodes().size());
}
private void clearNDCodes() throws SQLException {
new DBBuilder().executeSQL(Arrays.asList("DELETE FROM ndcodes;"));
}
}
| 3,795
| 34.148148
| 98
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/standards/NDDAOExceptionTest.java
|
package edu.ncsu.csc.itrust.unit.dao.standards;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.old.beans.MedicationBean;
import edu.ncsu.csc.itrust.model.old.dao.mysql.NDCodesDAO;
import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory;
public class NDDAOExceptionTest extends TestCase {
private NDCodesDAO evilDAO = EvilDAOFactory.getEvilInstance().getNDCodesDAO();
@Override
protected void setUp() throws Exception {
}
public void testAddCodeException() throws Exception {
try {
evilDAO.addNDCode(new MedicationBean());
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetAllCodesException() throws Exception {
try {
evilDAO.getAllNDCodes();
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testGetException() throws Exception {
try {
evilDAO.getNDCode("");
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testUpdateCodeException() throws Exception {
try {
evilDAO.updateCode(new MedicationBean());
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
}
| 1,534
| 28.519231
| 79
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/transaction/AccessRecordTest.java
|
package edu.ncsu.csc.itrust.unit.dao.transaction;
import java.text.SimpleDateFormat;
import java.util.List;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.model.old.beans.TransactionBean;
import edu.ncsu.csc.itrust.model.old.dao.mysql.TransactionDAO;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
public class AccessRecordTest extends TestCase {
private TransactionDAO tranDAO = TestDAOFactory.getTestInstance().getTransactionDAO();
private TestDataGenerator gen;
@Override
protected void setUp() throws Exception {
gen = new TestDataGenerator();
gen.clearAllTables();
gen.transactionLog();
}
// note - testing the actual loader is done elsewhere. Just check that we're
// getting the right
// ones here
public void testGetAllAccesses() throws Exception {
List<TransactionBean> transactions = tranDAO.getAllRecordAccesses(2L, -1, false);
assertEquals(5, transactions.size());
for (int i = 0; i < 5; i++) {
assertEquals(9000000000L, transactions.get(i).getLoggedInMID());
assertEquals(2L, transactions.get(i).getSecondaryMID());
}
}
public void testGetSomeAccesses() throws Exception {
List<TransactionBean> transactions = tranDAO.getRecordAccesses(2L, -1,
new SimpleDateFormat("MM/dd/yyyy").parse("06/23/2007"),
new SimpleDateFormat("MM/dd/yyyy").parse("06/24/2007"), false);
assertEquals(3, transactions.size());
transactions = tranDAO.getRecordAccesses(1L, -1, new SimpleDateFormat("MM/dd/yyyy").parse("06/23/2007"),
new SimpleDateFormat("MM/dd/yyyy").parse("06/24/2007"), false);
assertEquals(0, transactions.size());
}
}
| 1,674
| 36.222222
| 106
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/transaction/LogTransactionTest.java
|
package edu.ncsu.csc.itrust.unit.dao.transaction;
import java.util.List;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.model.old.beans.TransactionBean;
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;
public class LogTransactionTest extends TestCase {
private TransactionDAO tranDAO = TestDAOFactory.getTestInstance().getTransactionDAO();
private TestDataGenerator gen;
@Override
protected void setUp() throws Exception {
gen = new TestDataGenerator();
gen.clearAllTables();
gen.transactionLog();
}
public void testGetAllTransactions() throws Exception {
List<TransactionBean> list = tranDAO.getAllTransactions();
assertEquals(8, list.size());
// that last one inserted should be last because it was backdated
assertEquals(1L, list.get(3).getLoggedInMID());
assertEquals(TransactionType.DEMOGRAPHICS_EDIT, list.get(3).getTransactionType());
}
public void testLogFull() throws Exception {
tranDAO.logTransaction(TransactionType.OFFICE_VISIT_EDIT, 9000000000L, 1L, "added information");
List<TransactionBean> list = tranDAO.getAllTransactions();
assertEquals(9, list.size());
assertEquals(9000000000L, list.get(0).getLoggedInMID());
assertEquals(1L, list.get(0).getSecondaryMID());
assertEquals("added information", list.get(0).getAddedInfo());
assertEquals(TransactionType.OFFICE_VISIT_EDIT, list.get(0).getTransactionType());
}
/**
* Tests to see if the right MID number shows up in the secondaryMID column
* in the transactionLog.
*
* @throws Exception
*/
public void testSecondaryMIDHCP() throws Exception {
tranDAO.logTransaction(TransactionType.PATIENT_CREATE, 9000000000L, 98L, "added information");
List<TransactionBean> list = tranDAO.getAllTransactions();
assertEquals(9000000000L, list.get(0).getLoggedInMID());
assertEquals(98L, list.get(0).getSecondaryMID());
}
public void testSecondaryMIDPatient() throws Exception {
tranDAO.logTransaction(TransactionType.PATIENT_CREATE, 1L, 98L, "added information");
List<TransactionBean> list = tranDAO.getAllTransactions();
assertEquals(1L, list.get(0).getLoggedInMID());
assertEquals(98L, list.get(0).getSecondaryMID());
}
public void testSecondaryMIDUAP() throws Exception {
tranDAO.logTransaction(TransactionType.PATIENT_CREATE, 9000000001L, 98L, "added information");
List<TransactionBean> list = tranDAO.getAllTransactions();
assertEquals(9000000001L, list.get(0).getLoggedInMID());
assertEquals(98L, list.get(0).getSecondaryMID());
}
}
| 2,699
| 36.5
| 98
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/transaction/OperationalProfileTest.java
|
package edu.ncsu.csc.itrust.unit.dao.transaction;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.old.beans.OperationalProfile;
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.EvilDAOFactory;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
/**
* OperationalProfileTest
*/
public class OperationalProfileTest extends TestCase {
private TestDataGenerator gen;
private TransactionDAO transDAO = TestDAOFactory.getTestInstance().getTransactionDAO();
@Override
protected void setUp() throws Exception {
gen = new TestDataGenerator();
gen.clearAllTables();
gen.operationalProfile();
gen.tester();
}
/**
* testGetOperationalProfile
*
* @throws Exception
*/
public void testGetOperationalProfile() throws Exception {
OperationalProfile op = transDAO.getOperationalProfile();
Integer[] totalCounts = new Integer[43000];
Integer[] patientCounts = new Integer[43000];
Integer[] personnelCounts = new Integer[43000];
for (int i = 0; i < 43000; i++) {
totalCounts[i] = 0;
patientCounts[i] = 0;
personnelCounts[i] = 0;
}
totalCounts[1] = 1;
personnelCounts[1] = 1;
assertEquals(1, op.getNumTotalTransactions());
assertEquals(0, op.getNumPatientTransactions());
assertEquals(1, op.getNumPersonnelTransactions());
for (TransactionType type : TransactionType.values()) {
assertEquals("for type " + type.getDescription() + "(" + type.getCode() + ")", totalCounts[type.getCode()],
op.getTotalCount().get(type));
}
for (TransactionType type : TransactionType.values()) {
assertEquals("for type " + type.getDescription() + "(" + type.getCode() + ")",
patientCounts[type.getCode()], op.getPatientCount().get(type));
}
for (TransactionType type : TransactionType.values()) {
assertEquals("for type " + type.getDescription() + "(" + type.getCode() + ")",
personnelCounts[type.getCode()], op.getPersonnelCount().get(type));
}
}
/**
* testOperationProfileException
*
* @throws Exception
*/
public void testOperationProfileException() throws Exception {
TransactionDAO evilTranDAO = EvilDAOFactory.getEvilInstance().getTransactionDAO();
try {
evilTranDAO.getAllTransactions();
fail("exception should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
}
| 2,589
| 31.78481
| 110
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/dao/transaction/TransactionDAOExceptionTest.java
|
package edu.ncsu.csc.itrust.unit.dao.transaction;
import java.util.Date;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.old.dao.mysql.TransactionDAO;
import edu.ncsu.csc.itrust.unit.testutils.EvilDAOFactory;
public class TransactionDAOExceptionTest extends TestCase {
private TransactionDAO evilDAO = EvilDAOFactory.getEvilInstance().getTransactionDAO();
@Override
protected void setUp() throws Exception {
}
public void testGetAllAccessException() throws Exception {
try {
evilDAO.getAllRecordAccesses(0L, -1, false);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testAllTransactionsException() throws Exception {
try {
evilDAO.getAllTransactions();
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
public void testRecordAccessesException() throws Exception {
try {
evilDAO.getRecordAccesses(0L, -1, new Date(), new Date(), false);
fail("DBException should have been thrown");
} catch (DBException e) {
assertEquals(EvilDAOFactory.MESSAGE, e.getSQLException().getMessage());
}
}
}
| 1,323
| 29.790698
| 87
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/datagenerators/TestDataGenerator.java
|
package edu.ncsu.csc.itrust.unit.datagenerators;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import edu.ncsu.csc.itrust.model.old.dao.DAOFactory;
import edu.ncsu.csc.itrust.unit.DBBuilder;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
/**
* This TestDataGenerator class is in charge of centralizing all of the test
* data calls. Most of the SQL is in the sql/something.sql files. A few design
* conventions:
*
* <ul>
* <li>Any time you're using this class, be sure to run the "clearAllTables"
* first. This is not a very slow method (it's actually quite fast) but it
* clears all of the tables so that no data from a previous test can affect your
* current test.</li>
* <li>We do not recommend having one test method call another test method
* (except "standardData" or other intentionally "meta" methods). For example,
* loincs() should not call patient1() first. Instead, put BOTH patient1() and
* loincs() in your test case. If we keep this convention, then every time you
* call a method, you know that ONLY your sql file is called and nothing else.
* The alternative is a lot of unexpected, extraneous calls to some test methods
* like patient1().</li>
* </ul>
*
*
*
*/
public class TestDataGenerator {
public static void main(String[] args) throws IOException, SQLException {
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
gen.standardData();
}
private String DIR = "sql/data";
private DAOFactory factory;
public TestDataGenerator() {
this.factory = TestDAOFactory.getTestInstance();
}
public TestDataGenerator(String projectHome, DAOFactory factory) {
this.DIR = projectHome + "/sql/data";
this.factory = factory;
}
public void additionalOfficeVisits() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/ovAdditional.sql");
}
public void admin1() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/admin1.sql");
}
public void apptRequestConflicts() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/apptRequestConflicts.sql");
}
public void pha0() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/pha0.sql");
}
public void admin2() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/admin2.sql");
}
public void appointmentCase1() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/appointmentCase1.sql");
}
public void appointmentCase2() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/appointmentCase2.sql");
}
public void clearAllTables() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/deleteFromAllTables.sql");
}
public void clearAppointments() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/clearAppointments.sql");
}
public void clearFakeEmail() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/clearFakeemail.sql");
}
public void clearMessages() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/clearMessages.sql");
}
public void clearHospitalAssignments() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/hospitalAssignmentsReset.sql");
}
public void foreignKeyTest() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/foreignKeyTest.sql");
}
public void clearLoginFailures() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/loginFailures.sql");
}
public void clearTransactionLog() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/clearTransactionLog.sql");
}
public void setMode() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/setMode.sql");
}
public void drugInteractions() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/drugInteractions.sql");
}
public void drugInteractions2() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/drugInteractions2.sql");
}
public void drugInteractions3() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/drugInteractions3.sql");
}
public void drugInteractions4() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/drugInteractions4.sql");
}
public void fakeEmail() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/fakeemail.sql");
}
public void family() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/family.sql");
}
public void er4() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/er6.sql");
}
public void hcp0() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/hcp0.sql");
}
public void hcp1() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/hcp1.sql");
}
public void hcp2() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/hcp2.sql");
}
public void hcp3() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/hcp3.sql");
}
public void hcp4() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/hcp4.sql");
}
public void hcp5() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/hcp5.sql");
}
public void hcp7() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/hcp7.sql");
}
/**
* Adds HCP Curious George for testing purposes.
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
public void hcp8() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/hcp8.sql");
}
/**
* Adds HCP John Zoidberg for testing purposes.
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
public void hcp9() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/hcp9.sql");
} // NEW
public void hcp10() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/hcp10.sql");
}
/**
* Adds HCP Brooke Tran with Specialty Optometrist.
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
public void hcp11() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/hcp11.sql");
}
/**
* Adds HCP Lamar Bridges with Specialty Ophthalmologist.
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
public void hcp12() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/hcp12.sql");
}
public void hospitals() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/hospitals0.sql");
}
public void hospitals1() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/hospitals1.sql");
}
public void messages() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/message.sql");
}
public void messages6() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/messageCase6.sql");
}
public void ndCodes() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/ndCodes.sql");
}
public void ORCodes() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/ORCodes.sql");
}
public void ndCodes1() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/ndCodes1.sql");
}
public void ndCodes2() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/ndCodes2.sql");
}
public void ndCodes3() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/ndCodes3.sql");
}
public void ndCodes4() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/ndCodes4.sql");
}
/**
* Adds drugs Midichlominene and Midichlomaxene for UC10 and UC37 testing
* purposes.
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
public void ndCodes100() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/ndcodes100.sql");
} // NEW
public void ndCodes1000() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/ndcodes1000.sql");
} // NEW
/* Retained for setting up Allergy info */
public void officeVisit4() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/ov4.sql");
}
public void officeVisit8() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/ov8.sql");
}
public void operationalProfile() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/operationalProfile.sql");
}
public void patient1() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient1.sql");
}
public void clearProfilePhotos() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/clearphotos.sql");
}
public void patient2() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient2.sql");
}
public void patient3() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient3.sql");
}
public void patient4() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient4.sql");
}
public void patient5() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient5.sql");
}
public void patient6() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient6.sql");
}
public void patient7() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient7.sql");
}
public void patient8() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient8.sql");
}
public void patient9() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient9.sql");
}
public void patient10() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient10.sql");
}
public void patient11() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient11.sql");
}
public void patient12() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient12.sql");
}
public void patient13() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient13.sql");
}
public void patient14() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient14.sql");
}
public void patient15() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient15.sql");
}
public void UC32Acceptance() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/UC32Acceptance.sql");
}
public void patient20() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient20.sql");
}
public void patient21() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient21.sql");
}
public void patient22() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient22.sql");
}
/**
* Adds patient Dare Devil for testing purposes.
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
public void patient23() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient23.sql");
}
/**
* Adds patient Devils Advocate for testing purposes.
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
public void patient24() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient24.sql");
}
/**
* Adds patient Trend Setter for testing purposes.
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
public void patient25() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient25.sql");
}
/**
* Adds patient Philip Fry for testing purposes.
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
public void patient26() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient26.sql");
} // NEW
/**
* Adds patient Brody Franco, used in the testing of UC83.
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
public void patient27() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient27.sql");
}
/**
* Adds patient Freya Chandler, used in the testing of UC83.
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
public void patient28() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient28.sql");
}
/**
* Adds patient Brittany Franco, used in the testing of UC84.
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
public void patient29() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient29.sql");
}
/**
* Adds patient James Franco, used in the testing of UC84.
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
public void patient30() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient30.sql");
}
public void patient42() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient42.sql");
}
/**
* Adds patient Anakin Skywalker for UC10 and UC37 testing purposes.
*
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
public void patient100() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/patient100.sql");
} // NEW
public void pendingAppointmentAlert() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/pendingAppointmentAlert.sql");
}
public void pendingAppointmentConflict() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/pendingAppointmentConflict.sql");
}
public void reportRequests() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/reportRequests.sql");
}
public void surveyResults() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/surveyResults.sql");
}
public void tester() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/tester.sql");
}
public void timeout() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/timeout.sql");
}
public void transactionLog() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/transactionLog.sql");
}
public void transactionLog2() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/transactionLog2.sql");
}
public void transactionLog3() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/transactionLog3.sql");
}
public void transactionLog4() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/transactionLog4.sql");
}
public void transactionLog5() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/transactionLog5.sql");
}
public void transactionLog6() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/transactionLog6.sql");
}
public void uap1() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/uap1.sql");
}
public void remoteMonitoring1() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/remoteMonitoring1.sql");
}
public void remoteMonitoring2() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/remoteMonitoring2.sql");
}
public void remoteMonitoring3() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/remoteMonitoring3.sql");
}
public void remoteMonitoring4() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/remoteMonitoring4.sql");
}
public void remoteMonitoring5() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/remoteMonitoring5.sql");
}
public void remoteMonitoring6() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/remoteMonitoring6.sql");
}
public void remoteMonitoring7() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/remoteMonitoring7.sql");
}
public void remoteMonitoring8() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/remoteMonitoring8.sql");
}
public void remoteMonitoringUAP() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/remoteMonitoringUAP.sql");
}
public void remoteMonitoringAdditional() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/remoteMonitoringAdditional.sql");
}
public void remoteMonitoringPresentation() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/remoteMonitoringPresentation.sql");
}
public void pha1() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/pha1.sql");
}
public void appointment() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/appointment.sql");
}
public void appointmentCase3() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/appointmentCase3.sql");
}
public void appointmentType() throws FileNotFoundException, IOException, SQLException {
new DBBuilder(factory).executeSQLFile(DIR + "/appointmentType.sql");
}
public void admin3() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/admin3.sql");
}
public void labProcedure0() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/labProcedure0.sql");
}
public void labProcedure1() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/labProcedure1.sql");
}
public void labProcedure2() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/labProcedure2.sql");
}
public void labProcedure3() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/labProcedure3.sql");
}
public void labProcedure4() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/labProcedure4.sql");
}
public void labProcedure5() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/labProcedure5.sql");
}
public void loinc() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/loinc.sql");
}
public void ltData0() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/lt0.sql");
}
public void ltData1() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/lt1.sql");
}
public void ltData2() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/lt2.sql");
}
public void uc22() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/UC22.sql");
}
public void testExpertSearch() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/testExpertSearch.sql");
}
public void viewAccessLogTestData() throws SQLException, FileNotFoundException, IOException {
// previously contained sql for referral_sort_testdata
// create patients Dare Devil and Devils Advocate
// Devils Advocate is Dare Devil's Personal Representative
patient23();
patient24();
}
/**
* Adds additional DLHCPs to certain patients.
*
* MID DLHCPs --- ------ 1 9000000000, 9000000003
*
* @throws SQLException
* @throws FileNotFoundException
* @throws IOException
*/
public void messagingCcs() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/messagingCcs.sql");
}
public void insertwards() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/wardmanagementdata.sql");
}
/**
* generate test data for uc15 acceptance scenarios
*/
public void uc11() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc11.sql");
}
/**
* generate test data for uc15 acceptance scenarios
*/
public void uc15() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc15.sql");
}
/**
* generate test data for uc19 acceptance scenarios
*/
public void uc19() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc19.sql");
}
/**
* Generate test data for uc21 acceptance scenarios
* @throws FileNotFoundException
* @throws SQLException
* @throws IOException
*/
public void uc21() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc21.sql");
}
/**
* generate test data for uc26 acceptance scenarios
*/
public void uc26() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc26.sql");
}
/**
* Generate test data for uc51 acceptance scenarios
*/
public void uc51() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc51.sql");
}
public void uc52() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc52.sql");
}
public void uc47SetUp() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc47SetUp.sql");
}
public void zipCodes() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/zipCodes.sql");
}
public void uc47TearDown() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc47TearDown.sql");
}
public void uc53SetUp() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc53.sql");
}
public void uc55() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc55.sql");
}
/**
*
* Generate records release data for uc56 acceptance scenarios Includes
* recordsrelease table data and UAP-HCP relations
*/
public void uc56() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc56.sql");
}
/**
* Generate dependency data for uc58 acceptance. Create a dependent user, a
* representative user, and establish representative relationship between
* the two.
*/
public void uc58() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc58.sql");
}
/**
* Generate dependency data for uc59 acceptance. Create a dependent user and
* a representative user
*/
public void uc59() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc59.sql");
}
/**
* Generate dependency data for uc60 acceptance. Create a Patient and a HCP
* to bill the patient. Create a billed office visit the patient can view.
*/
public void uc60() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc60.sql");
}
/**
* Sets up patients 314159 (deactivated),
*/
public void basicPatients() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/basicPatients_users-patients.sql");
}
/**
* Generate dependency data for uc63 acceptance. Create two HCPs who are
* OB/GYNs Create seven new patients Give one patient a past pregnancy
*/
public void uc63() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc63.sql");
}
/**
*Based on previous data generator for UC68 that included data on Patient Derek Morgan, Patient Jennifer Jareau,
*Patient Aaron Hotchner, and HCP Spencer Reid that was also used for patient representatives
*and other tests*/
public void multiplePatients_old() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/multiplePatients_old.sql");
}
/**
* Inserts the user Emily Prentiss into the system and gives her one food
* diary entry.
*
* @throws SQLException
* @throws FileNotFoundException
* @throws IOException
*/
public void uc71() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc71.sql");
}
/**
* Inserts the user Emily Prentiss into the system and gives her one food
* diary entry.
*
* @throws SQLException
* @throws FileNotFoundException
* @throws IOException
*/
public void uc70() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/uc70.sql");
}
/**
* Generate dependency data for uc63 acceptance. NOTE: also executes the
* above method because the patients created above are also required for
* this use case. Give three patients initial obstetrics records.
*/
public void uc64() throws SQLException, FileNotFoundException, IOException {
uc63();
new DBBuilder(factory).executeSQLFile(DIR + "/uc64.sql");
}
/**
* Generate a list of reviews for 2 HCP's by 3 diff patients.
*/
public void uc61reviews() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/reviews.sql");
}
/**
* generate the dependency of Baby Programmer on Andy Programmer
*/
public void doBaby() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/programmerReps.sql");
}
/**
* generate the dependency of Baby Programmer on Andy Programmer
*/
public void reviews() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/reviews.sql");
}
/**
* Inserts a optometristVisit into the system
*
* @throws SQLException
* @throws FileNotFoundException
* @throws IOException
*/
public void uc85() throws SQLException, FileNotFoundException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/ophthalmologydiagnosis.sql");
}
public void cptCode() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/cptCodes.sql");
}
public void testIcdCode() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/testicdcode.sql");
}
public void icdCode() throws FileNotFoundException, SQLException, IOException {
new DBBuilder(factory).executeSQLFile(DIR + "/icdcode.sql");
}
public void standardData() throws FileNotFoundException, IOException, SQLException {
ndCodes();
ndCodes1();
ndCodes2();
ndCodes3();
ndCodes4();
ndCodes100(); // NEW
ndCodes1000(); // NEW
drugInteractions4();
ORCodes();
hospitals();
basicPatients();
hcp0();
ltData0();
ltData1();
ltData2();
hcp3();
hcp7();
er4();
pha1();
patient1();
patient2();
patient3();
patient4();
patient5();
patient6();
patient7();
patient8();
patient9();
patient10();
multiplePatients_old();
// Added so that the black box test plans for Use Case 32 can be run
// immediately after running TestDataGenerator
hcp1();
hcp2();
patient11();
patient12();
patient13();
patient14();
patient20();
patient21();
patient22();
patient25();
patient26(); // NEW
patient42();
patient100(); // NEW
admin1();
admin2();
admin3();
uap1();
messages();
tester();
fakeEmail();
reportRequests();
appointmentType();
appointment();
transactionLog();
transactionLog2();
transactionLog3();
transactionLog4();
hcp8();
hcp9(); // NEW
viewAccessLogTestData();
insertwards();
uc51();
uc52();
uc53SetUp();
uc21();
uc11();
uc15();
uc19();
uc26();
loinc();
cptCode();
icdCode();
uc63(); // NEW
uc55();
uc56();
if (!checkIfZipsExists()) {
zipCodes();
}
// Added for UC83
hcp11();
// Added for UC 86
hcp12();
patient27();
patient28();
patient29();
patient30();
setMode();
}
/**
* Do we have zipcodes?
*
* @return Whether or not we have zipcodes.
* @throws SQLException
*/
private boolean checkIfZipsExists() {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = factory.getConnection();
ps = conn.prepareStatement("SELECT * FROM zipcodes WHERE zip='27614'");
rs = ps.executeQuery();
if (rs.next()) {
return true;
}
} catch (SQLException e) {
return false;
} finally {
if (conn != null)
try {
conn.close();
} catch (SQLException e) {
return false;
}
}
return false;
}
}
| 32,789
| 31.178606
| 113
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/db/DBBuilderTest.java
|
package edu.ncsu.csc.itrust.unit.db;
import edu.ncsu.csc.itrust.unit.DBBuilder;
import junit.framework.TestCase;
public class DBBuilderTest extends TestCase {
// Make sure that the actual database can be rebuilt
// This is run twice so that we check the "drop tables" script
public void testRebuildNoException() throws Exception {
DBBuilder.rebuildAll();
DBBuilder.rebuildAll();
}
}
| 394
| 25.333333
| 63
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/db/DBUtilTest.java
|
package edu.ncsu.csc.itrust.unit.db;
import java.sql.Connection;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.DBUtil;
import edu.ncsu.csc.itrust.model.old.dao.DAOFactory;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
public class DBUtilTest extends TestCase {
public void testNoFailCloseConnection() throws Exception {
DAOFactory df = TestDAOFactory.getTestInstance();
Connection c = df.getConnection();
c.close();
DBUtil.closeConnection(c, null);
}
public void testCloseConnection() throws Exception {
DAOFactory df = TestDAOFactory.getTestInstance();
Connection c = df.getConnection();
DBUtil.closeConnection(c, null);
}
}
| 674
| 27.125
| 59
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/enums/BloodTypeTest.java
|
package edu.ncsu.csc.itrust.unit.enums;
import edu.ncsu.csc.itrust.model.old.enums.BloodType;
import junit.framework.TestCase;
public class BloodTypeTest extends TestCase {
public void testParse() throws Exception {
assertEquals(BloodType.ABNeg, BloodType.parse("AB-"));
assertEquals(BloodType.ONeg, BloodType.parse("O-"));
assertEquals(BloodType.NS, BloodType.parse("N/S"));
assertEquals(BloodType.NS, BloodType.parse("non-existent ethnicity"));
}
}
| 463
| 32.142857
| 72
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/enums/EthnicityTest.java
|
package edu.ncsu.csc.itrust.unit.enums;
import edu.ncsu.csc.itrust.model.old.enums.Ethnicity;
import junit.framework.TestCase;
public class EthnicityTest extends TestCase {
public void testParse() throws Exception {
assertEquals(Ethnicity.Caucasian, Ethnicity.parse("Caucasian"));
assertEquals(Ethnicity.AfricanAmerican, Ethnicity.parse("African American"));
assertEquals(Ethnicity.NotSpecified, Ethnicity.parse("Not Specified"));
assertEquals(Ethnicity.NotSpecified, Ethnicity.parse("non-existent ethnicity"));
}
}
| 528
| 36.785714
| 82
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/enums/StateTest.java
|
package edu.ncsu.csc.itrust.unit.enums;
import edu.ncsu.csc.itrust.model.old.enums.State;
import junit.framework.TestCase;
public class StateTest extends TestCase {
public void testParse() throws Exception {
assertEquals(State.NC, State.parse("NC"));
assertEquals(State.PA, State.parse("Pennsylvania"));
assertEquals(State.NC, State.parse("NOT A STATE!"));
}
}
| 371
| 27.615385
| 54
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/enums/TransactionTypeTest.java
|
package edu.ncsu.csc.itrust.unit.enums;
import edu.ncsu.csc.itrust.model.old.enums.TransactionType;
import junit.framework.TestCase;
public class TransactionTypeTest extends TestCase {
public void testParse() throws Exception {
for (TransactionType type : TransactionType.values()) {
assertEquals(type, TransactionType.parse(type.getCode()));
}
}
public void testBadParse() throws Exception {
try {
TransactionType.parse(37);
TransactionType.parse(99);
fail("exception should have been thrown");
} catch (IllegalArgumentException e) {
assertEquals("No transaction type exists for code 37", e.getMessage());
}
}
}
| 646
| 25.958333
| 74
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/exception/AddPatientFileExceptionTest.java
|
package edu.ncsu.csc.itrust.unit.exception;
import edu.ncsu.csc.itrust.exception.AddPatientFileException;
import junit.framework.TestCase;
public class AddPatientFileExceptionTest extends TestCase {
public void testMessage() throws Exception {
try {
throw new AddPatientFileException("Test");
} catch (AddPatientFileException e) {
assertTrue(e.getMessage().equals("Test"));
}
}
}
| 396
| 25.466667
| 61
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/exception/FormValidationExceptionTest.java
|
package edu.ncsu.csc.itrust.unit.exception;
import edu.ncsu.csc.itrust.exception.ErrorList;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import junit.framework.TestCase;
public class FormValidationExceptionTest extends TestCase {
public void testMessage() throws Exception {
ErrorList el = new ErrorList();
el.addIfNotNull("a");
FormValidationException e = new FormValidationException(el);
assertEquals(
"This form has not been validated correctly. " + "The following field are not properly filled in: [a]",
e.getMessage());
MockJSPWriter writer = new MockJSPWriter();
e.printHTML(writer);
assertEquals("<h2>Information not valid</h2><div class=\"errorList\">a<br /></div>", writer.input);
assertEquals("<h2>Information not valid</h2><div class=\"errorList\">a<br /></div>", e.printHTMLasString());
}
}
| 848
| 39.428571
| 110
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/exception/MockJSPWriter.java
|
package edu.ncsu.csc.itrust.unit.exception;
import java.io.IOException;
import org.apache.jasper.runtime.JspWriterImpl;
public class MockJSPWriter extends JspWriterImpl {
public String input = "";
@Override
public void print(String arg0) throws IOException {
this.input += arg0;
}
}
| 292
| 19.928571
| 52
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/cptcode/CPTCodeMySQLTest.java
|
package edu.ncsu.csc.itrust.unit.model.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.exception.DBException;
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 CPTCodeMySQLTest extends TestCase {
private DataSource ds;
TestDataGenerator gen;
private CPTCodeMySQL sql;
@Override
public void setUp() throws DBException, FileNotFoundException, SQLException, IOException{
ds = ConverterDAO.getDataSource();
sql = new CPTCodeMySQL(ds);
gen = new TestDataGenerator();
}
@Test
public void testCPTCodeMySQL() throws SQLException, FormValidationException, FileNotFoundException, IOException{
gen.clearAllTables();
// check that db is empty
List<CPTCode> codes = sql.getAll();
Assert.assertEquals(0, codes.size());
// add a code
CPTCode code1 = new CPTCode("11111", "test1");
Assert.assertTrue(sql.add(code1));
// make sure it was added right
codes = sql.getAll();
Assert.assertEquals(1, codes.size());
Assert.assertEquals("11111", codes.get(0).getCode());
Assert.assertEquals("test1", codes.get(0).getName());
// get it by id to make sure that works
CPTCode justAdded = sql.getByCode("11111");
Assert.assertNotNull(justAdded);
Assert.assertEquals("11111", codes.get(0).getCode());
Assert.assertEquals("test1", codes.get(0).getName());
// add another code
CPTCode code2 = new CPTCode("22222", "test2");
Assert.assertTrue(sql.add(code2));
// make sure it was added
codes = sql.getAll();
Assert.assertEquals(2, codes.size());
// update the first record
code1.setName("test3");
Assert.assertTrue(sql.update(code1));
// check that db is still correct
codes = sql.getAll();
Assert.assertEquals(2, codes.size());
CPTCode changed = sql.getByCode("11111");
Assert.assertNotNull(changed);
Assert.assertEquals("11111", changed.getCode());
Assert.assertEquals("test3", changed.getName());
CPTCode notChanged = sql.getByCode("22222");
Assert.assertNotNull(notChanged);
Assert.assertEquals("22222", notChanged.getCode());
Assert.assertEquals("test2", notChanged.getName());
// delete second record
Assert.assertTrue(sql.delete(code2));
// check that db is still correct
codes = sql.getAll();
Assert.assertEquals(1, codes.size());
CPTCode stillThere = sql.getByCode("11111");
Assert.assertNotNull(stillThere);
Assert.assertEquals("11111", stillThere.getCode());
Assert.assertEquals("test3", stillThere.getName());
// delete last record
Assert.assertTrue(sql.delete(code1));
// check db
Assert.assertEquals(0, sql.getAll().size());
}
@Test
public void testDiabolicals() throws FileNotFoundException, SQLException, IOException, FormValidationException{
gen.clearAllTables();
// check that db is empty
List<CPTCode> codes = sql.getAll();
Assert.assertEquals(0, codes.size());
// add invalid code
CPTCode bad = new CPTCode("a", "test1");
try {
sql.add(bad);
fail();
} catch (FormValidationException e) {
Assert.assertEquals("CPTCode: Up to four digit integer plus a letter or digit", e.getErrorList().get(0));
}
// add invalid name
bad = new CPTCode("22222", "%$#.<>?/'()");
try {
sql.add(bad);
fail();
} catch (FormValidationException e) {
Assert.assertEquals("Name: Up to 30 alphanumeric, space and ()<>,.\\-?/'", e.getErrorList().get(0));
}
// add a code
CPTCode good = new CPTCode("33333", "test3");
Assert.assertTrue(sql.add(good));
// try to add it again
Assert.assertFalse(sql.add(good));
// make sure db is still only size 1
Assert.assertEquals(1, sql.getAll().size());
// update nonexistent code
bad = new CPTCode("44444", "Hello World");
Assert.assertFalse(sql.update(bad));
// make sure db is still only size 1
Assert.assertEquals(1, sql.getAll().size());
// delete nonexistent code
Assert.assertFalse(sql.delete(bad));
// make sure db is still only size 1
Assert.assertEquals(1, sql.getAll().size());
// get invalid code
Assert.assertNull(sql.getByCode("44444"));
}
@Test
public void testNoDataSource(){
try {
new CPTCodeMySQL();
Assert.fail();
} catch (DBException e){
Assert.assertTrue(true);
}
}
}
| 5,407
| 33.012579
| 117
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/cptcode/CPTCodeTest.java
|
package edu.ncsu.csc.itrust.unit.model.cptcode;
import org.junit.Assert;
import org.junit.Test;
import edu.ncsu.csc.itrust.model.cptcode.CPTCode;
import junit.framework.TestCase;
public class CPTCodeTest extends TestCase {
CPTCode cptCode;
@Override
public void setUp(){
cptCode = new CPTCode("90650", "HPV, bivalent");
}
@Test
public void testCode(){
cptCode.setCode("90649");
Assert.assertEquals( "90649", cptCode.getCode() );
}
@Test
public void testName(){
cptCode.setName("HPV, quadrivalent");
Assert.assertEquals( "HPV, quadrivalent", cptCode.getName() );
}
}
| 662
| 21.1
| 67
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/cptcode/CPTCodeValidatorTest.java
|
package edu.ncsu.csc.itrust.unit.model.cptcode;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.model.old.validate.ValidationFormat;
import edu.ncsu.csc.itrust.unit.testutils.ValidatorProxy;
public class CPTCodeValidatorTest extends TestCase {
private ValidatorProxy validatorProxy = new ValidatorProxy();
private static final ValidationFormat VALIDATION_FORMAT = ValidationFormat.CPT;
private static final String PASSED = "";
private static final String FAILED = "Name: " + VALIDATION_FORMAT.getDescription();
public void testGood() throws Exception {
String value = "12345";
String errorMessage = PASSED;
assertEquals(errorMessage, validatorProxy.checkFormat("Name", value, VALIDATION_FORMAT, false));
}
public void testNotInt() throws Exception {
String value = "123a4";
String errorMessage = FAILED;
assertEquals(errorMessage, validatorProxy.checkFormat("Name", value, VALIDATION_FORMAT, false));
}
public void testTooLong() throws Exception {
String value = "123456";
String errorMessage = FAILED;
assertEquals(errorMessage, validatorProxy.checkFormat("Name", value, VALIDATION_FORMAT, false));
}
}
| 1,149
| 36.096774
| 98
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/diagnosis/DiagnosisControllerTest.java
|
package edu.ncsu.csc.itrust.unit.model.diagnosis;
import javax.sql.DataSource;
import org.junit.Assert;
import org.mockito.Mock;
import org.mockito.Mockito;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import java.sql.SQLException;
import java.util.List;
import edu.ncsu.csc.itrust.controller.diagnosis.DiagnosisController;
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.diagnosis.DiagnosisMySQL;
import edu.ncsu.csc.itrust.model.icdcode.ICDCode;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisitMySQL;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.webutils.SessionUtils;
import junit.framework.TestCase;
public class DiagnosisControllerTest extends TestCase {
DataSource ds;
DiagnosisController controller;
TestDataGenerator gen;
DiagnosisMySQL sql;
OfficeVisitMySQL ovSql;
@Mock
SessionUtils mockSessionUtils;
@Override
public void setUp() throws Exception {
ds = ConverterDAO.getDataSource();
gen = new TestDataGenerator();
gen.clearAllTables();
gen.uc11();
mockSessionUtils = Mockito.mock(SessionUtils.class);
Mockito.doReturn(1L).when(mockSessionUtils).getCurrentOfficeVisitId();
sql = spy(new DiagnosisMySQL(ds));
controller = new DiagnosisController(ds);
controller.setSql(sql);
ovSql = new OfficeVisitMySQL(ds);
}
public void testController() throws DBException{
Diagnosis d = new Diagnosis();
d.setIcdCode(new ICDCode("S108", "Skin injury neck", false));
long ovID = ovSql.getAll().get(0).getVisitID();
d.setVisitId(ovID);
controller.add(d);
List<Diagnosis> dList = controller.getDiagnosesByOfficeVisit(ovID);
Assert.assertEquals(1, dList.size());
d = dList.get(0);
d.setIcdCode(new ICDCode("S107", "Skin injury hand", false));
controller.edit(d);
dList = controller.getDiagnosesByOfficeVisit(ovID);
Assert.assertEquals(1, dList.size());
controller.remove(d.getId());
dList = controller.getDiagnosesByOfficeVisit(ovID);
Assert.assertEquals(0, dList.size());
d.setIcdCode(new ICDCode());
controller.add(d);
controller.edit(d);
controller.remove(0);
d.setIcdCode(new ICDCode("S107", "Skin injury hand", false));
when(sql.add(d)).thenReturn(false);
controller.add(d);
when(sql.update(d)).thenReturn(false);
controller.edit(d);
when(sql.remove(0)).thenThrow(new DBException(new SQLException()));
controller.remove(0);
when(sql.getAllDiagnosisByOfficeVisit(0)).thenThrow(new DBException(new SQLException()));
controller.getDiagnosesByOfficeVisit(0);
when(sql.getAllDiagnosisByOfficeVisit(1)).thenThrow(new NullPointerException());
controller.getDiagnosesByOfficeVisit(1);
}
}
| 3,163
| 33.391304
| 97
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/diagnosis/DiagnosisFormTest.java
|
package edu.ncsu.csc.itrust.unit.model.diagnosis;
import javax.sql.DataSource;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import java.sql.SQLException;
import edu.ncsu.csc.itrust.controller.diagnosis.DiagnosisController;
import edu.ncsu.csc.itrust.controller.diagnosis.DiagnosisForm;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.diagnosis.Diagnosis;
import edu.ncsu.csc.itrust.model.icdcode.ICDCodeMySQL;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.webutils.SessionUtils;
import junit.framework.TestCase;
public class DiagnosisFormTest extends TestCase {
DataSource ds;
DiagnosisForm form;
TestDataGenerator gen;
@Mock
SessionUtils mockSessionUtils;
@Override
public void setUp() throws Exception {
ds = ConverterDAO.getDataSource();
gen = new TestDataGenerator();
gen.clearAllTables();
gen.testIcdCode();
mockSessionUtils = Mockito.mock(SessionUtils.class);
Mockito.doReturn(1L).when(mockSessionUtils).getCurrentOfficeVisitId();
form = new DiagnosisForm(new DiagnosisController(ds), new ICDCodeMySQL(ds), mockSessionUtils, ds);
}
@Test
public void testDiagnosisForm() throws Exception {
form.add();
form.edit();
form.remove("0");
gen.uc21();
assertEquals(1, form.getDiagnosesByOfficeVisit().size());
try {
new DiagnosisForm();
} catch (Exception e) {
// Do nothing
}
Diagnosis d = new Diagnosis();
form.setDiagnosis(d);
Assert.assertEquals(d, form.getDiagnosis());
form.getICDCodes();
ICDCodeMySQL icdSql = spy(new ICDCodeMySQL(ds));
when(icdSql.getAll()).thenThrow(new SQLException());
form = new DiagnosisForm(new DiagnosisController(ds), icdSql, mockSessionUtils, ds);
form.getICDCodes();
}
}
| 1,911
| 25.555556
| 100
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/diagnosis/DiagnosisMySQLTest.java
|
package edu.ncsu.csc.itrust.unit.model.diagnosis;
import java.util.List;
import javax.sql.DataSource;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.Spy;
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.diagnosis.DiagnosisMySQL;
import edu.ncsu.csc.itrust.model.icdcode.ICDCode;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import junit.framework.TestCase;
public class DiagnosisMySQLTest extends TestCase {
DataSource ds;
DiagnosisMySQL sql;
@Spy
DiagnosisMySQL mockSql;
TestDataGenerator gen;
@Override
public void setUp() throws Exception {
ds = ConverterDAO.getDataSource();
sql = new DiagnosisMySQL(ds);
mockSql = Mockito.spy(new DiagnosisMySQL(ds));
gen = new TestDataGenerator();
gen.clearAllTables();
}
@Test
public void testGetAllEmergencyDiagnosis() throws Exception {
gen.uc21();
List<Diagnosis> dList = sql.getAllEmergencyDiagnosis(201);
assertEquals(2, dList.size());
assertEquals("J00", dList.get(0).getCode());
assertEquals("J45", dList.get(1).getCode());
}
@Test
public void testGetAll() throws Exception {
gen.uc21();
List<Diagnosis> list = sql.getAll();
assertNotNull(list);
assertEquals(4, list.size());
}
// TODO actually do this, this is just for coverage
@Test
public void testGetByID() throws Exception {
assertNull(sql.getByID(-1));
}
@Test
public void testAdd() throws Exception {
try {
sql.add(new Diagnosis(0, 0, null));
fail("Cannot add null ICDCode");
} catch (DBException e) {
// do nothing
}
gen.testIcdCode();
Diagnosis expected1 = new Diagnosis(0, 0, new ICDCode("T000", null, true));
Diagnosis expected2 = new Diagnosis(1, 0, new ICDCode("T001", "", true));
assertTrue(sql.add(expected1));
assertTrue(sql.add(expected2));
List<Diagnosis> list = sql.getAllDiagnosisByOfficeVisit(0);
assertEquals(2, list.size());
assertEquals("T000", list.get(0).getCode());
assertEquals("Test code 1", list.get(1).getName());
}
// TODO actually do this, this is just for coverage
@Test
public void testUpdate() throws Exception {
try {
sql.update(new Diagnosis(0, 0, null));
fail("Cannot update null ICDCode");
} catch (DBException e) {
// do nothing
}
gen.testIcdCode();
Diagnosis expected = new Diagnosis(0, 0, new ICDCode("T000", null, true));
assertTrue(sql.add(expected));
assertEquals(1, sql.getAllDiagnosisByOfficeVisit(0).size());
assertEquals(0, sql.getAllDiagnosisByOfficeVisit(1).size());
expected = sql.getAllDiagnosisByOfficeVisit(0).get(0);
assertEquals(0, expected.getVisitId());
expected.setVisitId(1);
assertTrue(sql.update(expected));
assertEquals(0, sql.getAllDiagnosisByOfficeVisit(0).size());
assertEquals(1, sql.getAllDiagnosisByOfficeVisit(1).size());
}
@Test
public void testProdConstructor() {
try {
new DiagnosisMySQL();
Assert.fail();
} catch (DBException e) {
// yay, we passed
}
}
public class TestDiagnosisMySQL extends DiagnosisMySQL {
public TestDiagnosisMySQL() throws DBException {
super();
}
public TestDiagnosisMySQL(DataSource ds) {
super(ds);
}
@Override
public DataSource getDataSource() {
return ds;
}
}
@Test
public void testMockDataSource() throws Exception {
DiagnosisMySQL mysql = new TestDiagnosisMySQL();
assertNotNull(mysql);
}
@Test
public void testRemove() throws Exception {
gen.testIcdCode();
sql.add(new Diagnosis(0, 0, new ICDCode("T000", null, true)));
assertEquals(1, sql.getAllDiagnosisByOfficeVisit(0).size());
Diagnosis expected = sql.getAllDiagnosisByOfficeVisit(0).get(0);
assertNotNull(expected);
sql.remove(expected.getId());
assertEquals(0, sql.getAllDiagnosisByOfficeVisit(0).size());
}
}
| 3,903
| 26.300699
| 77
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/diagnosis/DiagnosisTest.java
|
package edu.ncsu.csc.itrust.unit.model.diagnosis;
import org.junit.Assert;
import org.junit.Test;
import edu.ncsu.csc.itrust.model.diagnosis.Diagnosis;
import edu.ncsu.csc.itrust.model.icdcode.ICDCode;
import junit.framework.TestCase;
public class DiagnosisTest extends TestCase {
@Test
public void testGettersAndSetters(){
Diagnosis d = new Diagnosis(0, 0, null);
Assert.assertEquals(0, d.getId());
Assert.assertEquals(0, d.getVisitId());
Assert.assertEquals(null, d.getIcdCode());
Assert.assertEquals("", d.getCode());
Assert.assertEquals("", d.getName());
d.setVisitId(2);
Assert.assertEquals(2, d.getVisitId());
ICDCode code = new ICDCode("code", "name", true);
d.setIcdCode(code);
Assert.assertEquals(code, d.getIcdCode());
Assert.assertEquals("code", d.getCode());
Assert.assertEquals("name", d.getName());
}
}
| 959
| 29.967742
| 57
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/emergencyRecord/EmergencyRecordMySQLTest.java
|
package edu.ncsu.csc.itrust.unit.model.emergencyRecord;
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 org.mockito.Spy;
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.emergencyRecord.EmergencyRecordMySQL;
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.prescription.Prescription;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
import junit.framework.TestCase;
//@RunWith(PowerMockRunner.class)
//@PrepareForTest(EmergencyRecordMySQL.class)
public class EmergencyRecordMySQLTest extends TestCase {
private DataSource ds;
private EmergencyRecordMySQL sql;
@Spy
private EmergencyRecordMySQL mockSql;
@Override
public void setUp() throws DBException, FileNotFoundException, SQLException, IOException {
ds = ConverterDAO.getDataSource();
AllergyDAO allergyData = TestDAOFactory.getTestInstance().getAllergyDAO();
sql = new EmergencyRecordMySQL(ds, allergyData);
mockSql = Mockito.spy(new EmergencyRecordMySQL(ds, allergyData));
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
gen.ndCodes();
gen.ndCodes1();
gen.ndCodes100();
gen.ndCodes2();
gen.ndCodes3();
gen.ndCodes4();
gen.uc21();
}
@Test
public void testLoadRecord() throws DBException {
// loads the record for Sandy Sky
EmergencyRecord r = sql.getEmergencyRecordForPatient(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).getDrugCode().getNDCode());
Assert.assertEquals("48301-3420", pList.get(1).getDrugCode().getNDCode());
// 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 EmergencyRecordMySQL();
Assert.fail();
} catch (DBException e) {
// yay, we passed
}
}
class TestEmergencyRecordMySQL extends EmergencyRecordMySQL {
public TestEmergencyRecordMySQL() throws DBException {
super();
}
@Override
public DataSource getDataSource() {
return ds;
}
}
@Test
public void testMockDataSource() throws Exception {
EmergencyRecordMySQL mysql = new TestEmergencyRecordMySQL();
Assert.assertNotNull(mysql);
}
@Test
public void testMockGetEmergencyRecordForPatient() throws Exception {
Mockito.doThrow(SQLException.class).when(mockSql).loadRecord(Mockito.any());
try {
mockSql.getEmergencyRecordForPatient(1L);
fail();
} catch (DBException e) {
// Do nothing
}
}
@Test
public void testInvalidPatient() throws DBException {
Assert.assertNull(sql.getEmergencyRecordForPatient(-1));
}
}
| 4,454
| 27.557692
| 91
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/emergencyRecord/EmergencyRecordTest.java
|
package edu.ncsu.csc.itrust.unit.model.emergencyRecord;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import edu.ncsu.csc.itrust.model.diagnosis.Diagnosis;
import edu.ncsu.csc.itrust.model.emergencyRecord.EmergencyRecord;
import edu.ncsu.csc.itrust.model.icdcode.ICDCode;
import edu.ncsu.csc.itrust.model.old.beans.AllergyBean;
import junit.framework.TestCase;
public class EmergencyRecordTest extends TestCase {
EmergencyRecord r;
@Override
public void setUp(){
r = new EmergencyRecord();
}
@Test
public void testName(){
r.setName("testName");
Assert.assertEquals("testName", r.getName());
}
@Test
public void testAge(){
r.setAge(50);
Assert.assertEquals(50, r.getAge());
}
@Test
public void testGender(){
r.setGender("Female");
Assert.assertEquals("Female", r.getGender());
}
@Test
public void testContactName(){
r.setContactName("cName");
Assert.assertEquals("cName", r.getContactName());
}
@Test
public void testContactPhone(){
r.setContactPhone("999-555-1111");
Assert.assertEquals("999-555-1111", r.getContactPhone());
}
@Test
public void testAllergies(){
List<AllergyBean> allergies = new ArrayList<AllergyBean>();
AllergyBean a0 = new AllergyBean();
a0.setId(0L);
a0.setFirstFound(new Date(0L));
a0.setDescription("Test description");
a0.setNDCode("Test NDC");
a0.setPatientID(101L);
allergies.add(a0);
r.setAllergies(allergies);
Assert.assertEquals(1, r.getAllergies().size());
AllergyBean a1 = r.getAllergies().get(0);
Assert.assertEquals(0L, a1.getId());
Assert.assertEquals(new Date(0L), a1.getFirstFound());
Assert.assertEquals("Test description", a1.getDescription());
Assert.assertEquals("Test NDC", a1.getNDCode());
Assert.assertEquals(101L, a1.getPatientID());
}
@Test
public void testBloodType(){
r.setBloodType("A-");
Assert.assertEquals("A-", r.getBloodType());
}
@Test
public void testDiagnoses(){
List<Diagnosis> diagnoses = new ArrayList<Diagnosis>();
diagnoses.add(new Diagnosis(0L, 1L, new ICDCode("TESTICD", "Test name", true)));
r.setDiagnoses(diagnoses);
Assert.assertEquals(1, r.getDiagnoses().size());
Diagnosis d = r.getDiagnoses().get(0);
Assert.assertEquals(0, d.getId());
Assert.assertEquals(1, d.getVisitId());
Assert.assertEquals("TESTICD", d.getIcdCode().getCode());
Assert.assertEquals("Test name", d.getIcdCode().getName());
Assert.assertTrue(d.getIcdCode().isChronic());
}
//TODO: fix this when prescription functionality is added
@Test
public void testPrescriptions(){
r.setPrescriptions(null);
Assert.assertNull(r.getPrescriptions());
}
//TODO: fix this when immunization functionality is added
@Test
public void testImmunizations(){
r.setImmunizations(null);
Assert.assertNull(r.getImmunizations());
}
}
| 3,276
| 28
| 85
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/icdcode/ICDCodeMySQLTest.java
|
package edu.ncsu.csc.itrust.unit.model.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 edu.ncsu.csc.itrust.exception.DBException;
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 ICDCodeMySQLTest extends TestCase {
private ICDCodeMySQL mysql;
private DataSource ds;
@Override
public void setUp() {
ds = ConverterDAO.getDataSource();
mysql = new ICDCodeMySQL(ds);
}
@Test
public void testICDCodeMySQL() throws Exception {
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
// ensure db is empty
List<ICDCode> icdList = mysql.getAll();
Assert.assertEquals(0, icdList.size());
// add a code
ICDCode code1 = new ICDCode("A11", "test1", true);
Assert.assertTrue(mysql.add(code1));
// make sure it was added right
icdList = mysql.getAll();
Assert.assertEquals(1, icdList.size());
Assert.assertEquals("A11", icdList.get(0).getCode());
Assert.assertEquals("test1", icdList.get(0).getName());
Assert.assertTrue(icdList.get(0).isChronic());
// get it with getByID() and check again
ICDCode toCheck = mysql.getByCode("A11");
Assert.assertNotNull(toCheck);
Assert.assertEquals("A11", toCheck.getCode());
Assert.assertEquals("test1", toCheck.getName());
Assert.assertTrue(toCheck.isChronic());
// add another code
ICDCode code2 = new ICDCode("B22", "test2", false);
Assert.assertTrue(mysql.add(code2));
// check that it was added
icdList = mysql.getAll();
Assert.assertEquals(2, icdList.size());
// update the first record
code1.setName("test3");
code1.setChronic(false);
Assert.assertTrue(mysql.update(code1));
// check that db is still the same size
icdList = mysql.getAll();
Assert.assertEquals(2, icdList.size());
// delete the second record
Assert.assertTrue(mysql.delete(code2));
// check db size
icdList = mysql.getAll();
Assert.assertEquals(1, icdList.size());
// check that code1 is still in there
Assert.assertEquals("A11", icdList.get(0).getCode());
Assert.assertEquals("test3", icdList.get(0).getName());
Assert.assertFalse(icdList.get(0).isChronic());
// delete last record
Assert.assertTrue(mysql.delete(code1));
// check db size
icdList = mysql.getAll();
Assert.assertEquals(0, icdList.size());
}
@Test
public void testDiabolicals() throws FileNotFoundException, SQLException, IOException, DBException, FormValidationException{
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
// ensure db is empty
List<ICDCode> icdList = mysql.getAll();
Assert.assertEquals(0, icdList.size());
// add a bad code
ICDCode code1 = new ICDCode("A", "test1", true);
try {
mysql.add(code1);
fail();
} catch (FormValidationException e){
Assert.assertEquals("ICDCode: A capital letter, followed by a number, followed by a capital letter or number, optionally followed by 1-4 capital letters or numbers", e.getErrorList().get(0));
}
// ensure db is empty
icdList = mysql.getAll();
Assert.assertEquals(0, icdList.size());
// add a good record
code1.setCode("A11");
Assert.assertTrue(mysql.add(code1));
// check db
icdList = mysql.getAll();
Assert.assertEquals(1, icdList.size());
// try to add it again
Assert.assertFalse(mysql.add(code1));
// make sure that failed
Assert.assertEquals(1, icdList.size());
// update with bad name
code1.setName("*&?><:;");
try {
mysql.update(code1);
fail();
} catch (FormValidationException e){
Assert.assertEquals("Name: Up to 30 alphanumeric, space, and ()<>,.\\-?/'", e.getErrorList().get(0));
}
// put name back, object is valid now
code1.setName("test1");
// change code
code1.setCode("B22");
// try to delete nonexistent code
Assert.assertFalse(mysql.delete(code1));
// try to edit nonexistent code
Assert.assertFalse(mysql.update(code1));
}
@Test
public void testProdConstructor(){
try {
new ICDCodeMySQL();
fail();
} catch (DBException e) {
// yay we passed
}
}
}
| 5,196
| 30.883436
| 203
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/icdcode/ICDCodeTest.java
|
package edu.ncsu.csc.itrust.unit.model.icdcode;
import org.junit.Test;
import edu.ncsu.csc.itrust.model.icdcode.ICDCode;
import junit.framework.TestCase;
public class ICDCodeTest extends TestCase {
@Test
public void testICDCode() {
ICDCode icdCode = new ICDCode("initId", "initName", false);
icdCode.setChronic(true);
icdCode.setCode("testCode");
icdCode.setName("testName");
assertEquals("testCode", icdCode.getCode());
assertEquals("testName", icdCode.getName());
assertTrue(icdCode.isChronic());
}
}
| 523
| 25.2
| 61
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/immunization/ImmunizationMySQLTest.java
|
package edu.ncsu.csc.itrust.unit.model.immunization;
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.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import com.mysql.jdbc.Connection;
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.cptcode.CPTCodeMySQL;
import edu.ncsu.csc.itrust.model.immunization.Immunization;
import edu.ncsu.csc.itrust.model.immunization.ImmunizationMySQL;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import junit.framework.TestCase;
public class ImmunizationMySQLTest extends TestCase {
private DataSource ds;
@Mock
DataSource mockDS;
TestDataGenerator gen;
private ImmunizationMySQL sql;
@Override
public void setUp() throws DBException, FileNotFoundException, SQLException, IOException{
ds = ConverterDAO.getDataSource();
mockDS = Mockito.mock(DataSource.class);
sql = new ImmunizationMySQL(ds);
gen = new TestDataGenerator();
gen.clearAllTables();
gen.uc21();
}
@Test
public void testGetAll() throws SQLException {
List<Immunization> immunizations = null;
try {
immunizations = sql.getAll();
} catch (DBException e) {
Assert.fail();
}
Assert.assertEquals(1, immunizations.size());
// Now invoke the SQLException catch block via mocking
sql = new ImmunizationMySQL(mockDS);
Connection mockConnection = Mockito.mock(Connection.class);
when(mockDS.getConnection()).thenReturn(mockConnection);
when(mockConnection.prepareStatement(Mockito.anyString())).thenThrow(new SQLException());
try {
sql.getAll();
fail("Exception should be thrown");
} catch (DBException e) {
// Exception should throw
}
}
@Test
public void testAdd() throws DBException, SQLException {
{
CPTCode code = new CPTCode("90636", "Hep A-Hep B" );
Immunization immunization = new Immunization(500 , 1, code);
Assert.assertTrue(sql.add(immunization));
// Now invoke the SQLException catch block via mocking
sql = new ImmunizationMySQL(mockDS);
Mockito.doThrow(SQLException.class).when(mockDS).getConnection();
try {
sql.add(immunization);
fail("Exception should be thrown");
} catch (DBException e) {
// Exception should throw
}
}
{
CPTCode code = new CPTCode("", "Hep A-Hep B" );
Immunization immunization = new Immunization(501 , 1, code);
try {
sql.add(immunization);
fail();
} catch (DBException e) {
// Do nothing
}
}
}
@Test
public void testGetByID() throws DBException, SQLException {
Immunization immunization = sql.getByID(-1L);
Assert.assertNull(immunization);
Immunization expected = sql.getAllImmunizations(201L).get(0);
Immunization actual = sql.getByID(expected.getId());
assertEquals(expected.getCptCode().getCode(), actual.getCptCode().getCode());
// Now invoke the SQLException catch block via mocking
sql = new ImmunizationMySQL(mockDS);
Connection mockConnection = Mockito.mock(Connection.class);
when(mockDS.getConnection()).thenReturn(mockConnection);
when(mockConnection.prepareStatement(Mockito.anyString())).thenThrow(new SQLException());
try {
sql.getByID(1L);
fail("Exception should be thrown");
} catch (DBException e) {
// Exception should throw
}
}
@Test
public void testGetAllImmunizations() throws DBException, SQLException {
List<Immunization> list = sql.getAllImmunizations(201L);
Assert.assertNotNull(list);
Assert.assertEquals(1, list.size());
// Now invoke the SQLException catch block via mocking
sql = new ImmunizationMySQL(mockDS);
Connection mockConnection = Mockito.mock(Connection.class);
when(mockDS.getConnection()).thenReturn(mockConnection);
when(mockConnection.prepareStatement(Mockito.anyString())).thenThrow(new SQLException());
try {
sql.getAllImmunizations(1L);
fail("Exception should be thrown");
} catch (DBException e) {
// Exception should throw
}
}
@Test
public void testUpdate() throws DBException, SQLException{
CPTCode code = new CPTCode("90636", "Hep A-Hep B" );
Immunization immunization = new Immunization(1 , 1, code);
Assert.assertTrue(sql.update(immunization));
immunization.setId(-1L);
Assert.assertFalse(sql.update(immunization));
immunization.getCptCode().setCode("");
try {
sql.update(immunization);
fail("Exception should be thrown");
} catch (DBException e) {
// Do nothing
}
// Now invoke the SQLException catch block via mocking
sql = new ImmunizationMySQL(mockDS);
Mockito.doThrow(SQLException.class).when(mockDS).getConnection();
try {
sql.update(immunization);
fail("Exception should be thrown");
} catch (DBException e) {
// Exception should throw
}
}
@Test
public void testNoDataSource(){
try {
new CPTCodeMySQL();
Assert.fail();
} catch (DBException e){
Assert.assertTrue(true);
}
}
}
| 5,416
| 29.778409
| 93
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/immunization/ImmunizationTest.java
|
package edu.ncsu.csc.itrust.unit.model.immunization;
import org.junit.Assert;
import org.junit.Test;
import edu.ncsu.csc.itrust.model.cptcode.CPTCode;
import edu.ncsu.csc.itrust.model.immunization.Immunization;
import junit.framework.TestCase;
public class ImmunizationTest extends TestCase {
Immunization imm;
@Override
public void setUp(){
CPTCode cptCode = new CPTCode("90650", "HPV, bivalent");
imm = new Immunization(1, 1, cptCode);
}
@Test
public void testCPTCode(){
CPTCode cptCode = new CPTCode("90649", "HPV, quadrivalent");
imm.setCptCode(cptCode);
Assert.assertEquals( "90649", imm.getCode() );
Assert.assertEquals( "HPV, quadrivalent", imm.getName() );
}
@Test
public void testId(){
imm.setId(0);
Assert.assertEquals( 0, imm.getId() );
}
@Test
public void testVisitId(){
imm.setVisitId(0);
Assert.assertEquals( 0, imm.getVisitId() );
}
}
| 989
| 23.146341
| 65
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/immunization/ImmunizationValidatorTest.java
|
package edu.ncsu.csc.itrust.unit.model.immunization;
import javax.sql.DataSource;
import org.junit.Assert;
import org.junit.Test;
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.immunization.Immunization;
import edu.ncsu.csc.itrust.model.immunization.ImmunizationValidator;
import junit.framework.TestCase;
public class ImmunizationValidatorTest extends TestCase {
private Immunization imm;
private ImmunizationValidator iv;
private DataSource ds;
@Override
public void setUp(){
ds = ConverterDAO.getDataSource();
CPTCode cptCode = new CPTCode("90650", "HPV, bivalent");
imm = new Immunization(1, 1, cptCode);
iv = new ImmunizationValidator(ds);
}
@Test
public void testCorrectValidation(){
try{
iv.validate(imm);
} catch( FormValidationException e){
Assert.fail();
}
Assert.assertTrue(true);
}
@Test
public void testValidationBadCodeLength(){
imm.getCptCode().setCode("123456");
try{
iv.validate(imm);
} catch( FormValidationException e){
Assert.assertTrue(true);
return;
}
Assert.fail();
}
@Test
public void testValidationBadCodeZeroLength(){
imm.getCptCode().setCode("");
try{
iv.validate(imm);
} catch( FormValidationException e){
Assert.assertTrue(true);
return;
}
Assert.fail();
}
}
| 1,580
| 22.954545
| 68
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/labProcedure/LabProcedureFormTest.java
|
package edu.ncsu.csc.itrust.unit.model.labProcedure;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.faces.context.ExternalContext;
import javax.sql.DataSource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import com.sun.faces.context.RequestParameterMap;
import edu.ncsu.csc.itrust.controller.labProcedure.LabProcedureController;
import edu.ncsu.csc.itrust.controller.labProcedure.LabProcedureForm;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.labProcedure.LabProcedure;
import edu.ncsu.csc.itrust.model.labProcedure.LabProcedure.LabProcedureStatus;
import edu.ncsu.csc.itrust.model.labProcedure.LabProcedureData;
import edu.ncsu.csc.itrust.model.loinccode.LOINCCode;
import edu.ncsu.csc.itrust.model.loinccode.LOINCCodeData;
import edu.ncsu.csc.itrust.model.loinccode.LOINCCodeMySQL;
import edu.ncsu.csc.itrust.model.old.enums.TransactionType;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import edu.ncsu.csc.itrust.webutils.SessionUtils;
public class LabProcedureFormTest {
@Mock
private LabProcedureController mockController;
@Mock
private SessionUtils mockSessionUtils;
@Mock
private LabProcedureData mockData;
@Mock
private ExternalContext mockExternalContext;
@Mock
private RequestParameterMap mockReqParamMap;
@Mock
private LOINCCodeData mockCodeData;
private LabProcedureForm form;
private LabProcedure procedure;
private LOINCCodeData codeData;
private DataSource ds;
private TestDataGenerator gen;
@Before
public void setUp() throws Exception {
form = new LabProcedureForm();
procedure = new LabProcedure();
codeData = new LOINCCodeMySQL(ds);
ds = ConverterDAO.getDataSource();
gen = new TestDataGenerator();
gen.clearAllTables();
mockData = mock(LabProcedureData.class);
mockCodeData = mock(LOINCCodeData.class);
mockController = mock(LabProcedureController.class);
mockController.setLabProcedureData(mockData);
mockSessionUtils = mock(SessionUtils.class);
// mockFacesContext = mock(FacesContext.class);
mockExternalContext = mock(ExternalContext.class);
mockReqParamMap = mock(RequestParameterMap.class);
procedure.setCommentary("commentary");
procedure.setConfidenceIntervalLower(10);
procedure.setConfidenceIntervalUpper(30);
procedure.setLabProcedureCode("12345-6");
procedure.setIsRestricted(true);
procedure.setLabProcedureID(8L);
procedure.setLabTechnicianID(9L);
procedure.setOfficeVisitID(10L);
procedure.setPriority(3);
procedure.setResults("results");
procedure.setStatus(1L);
procedure.setUpdatedDate(new Timestamp(100L));
procedure.setHcpMID(9000000001L);
}
/** TODO: test this better */
@Test
public void testLabProcedureForm() {
form = new LabProcedureForm();
Assert.assertNotNull(form);
}
@Test
public void testLabProcedureFormLabProcedureController() {
when(mockSessionUtils.getRequestParameter("id")).thenReturn(procedure.getLabProcedureID().toString());
when(mockController.getLabProcedureByID(procedure.getLabProcedureID().toString())).thenReturn(procedure);
form = new LabProcedureForm(mockController, codeData, mockSessionUtils, ds);
Assert.assertNotNull(form);
verify(mockSessionUtils, times(0)).printFacesMessage(any(), any(), any(), any());
Assert.assertEquals(new Long(8L), form.getSelectedLabProcedure().getLabProcedureID());
}
@Test
public void testLabProcedureFormLabProcedureControllerNullLabProcedure() {
when(mockSessionUtils.getCurrentOfficeVisitId()).thenReturn(420L);
form = new LabProcedureForm(mockController, codeData, mockSessionUtils, ds);
Assert.assertNotNull(form);
verify(mockSessionUtils, times(0)).printFacesMessage(any(), any(), any(), any());
Assert.assertEquals(new Long(420), form.getLabProcedure().getOfficeVisitID());
Assert.assertEquals(LabProcedureStatus.IN_TRANSIT, form.getLabProcedure().getStatus());
}
@Test
public void testGetSelectedLabProcedure() {
when(mockSessionUtils.getRequestParameter("id")).thenReturn("3");
when(mockController.getLabProcedureByID("3")).thenReturn(procedure);
form = new LabProcedureForm(mockController, codeData, mockSessionUtils, ds);
LabProcedure returnedProcedure = form.getSelectedLabProcedure();
Assert.assertNotNull(returnedProcedure);
Assert.assertEquals("commentary", returnedProcedure.getCommentary());
Assert.assertEquals(new Integer(10), returnedProcedure.getConfidenceIntervalLower());
Assert.assertEquals(new Integer(30), returnedProcedure.getConfidenceIntervalUpper());
Assert.assertEquals("12345-6", returnedProcedure.getLabProcedureCode());
Assert.assertTrue(returnedProcedure.isRestricted());
Assert.assertEquals(new Long(9L), returnedProcedure.getLabTechnicianID());
Assert.assertEquals(new Long(10L), returnedProcedure.getOfficeVisitID());
Assert.assertEquals(new Integer(3), returnedProcedure.getPriority());
Assert.assertEquals("results", returnedProcedure.getResults());
Assert.assertEquals(1L, returnedProcedure.getStatus().getID());
Timestamp now = new Timestamp(System.currentTimeMillis());
// Assert updatedDate is within 5 seconds
Assert.assertTrue(now.compareTo(returnedProcedure.getUpdatedDate()) < 5000);
Assert.assertEquals(new Long(9000000001L), returnedProcedure.getHcpMID());
}
@Test
public void testAddCommentary() {
form = new LabProcedureForm(mockController, codeData, mockSessionUtils, ds);
when(mockController.getLabProcedureByID("8")).thenReturn(procedure);
when(mockSessionUtils.getCurrentFacesContext()).thenReturn(null);
form.addCommentary("8");
verify(mockController, times(1)).edit(procedure);
verify(mockController, times(1)).logTransaction(TransactionType.LAB_RESULTS_ADD_COMMENTARY, procedure.getLabProcedureCode());
Assert.assertEquals(LabProcedureStatus.COMPLETED, procedure.getStatus());
Assert.assertEquals("Reviewed by HCP", procedure.getCommentary());
}
@Test
public void testIsReassignable() {
when(mockController.getLabProcedureByID("4")).thenReturn(procedure);
form = new LabProcedureForm(mockController, codeData, mockSessionUtils, ds);
procedure.setStatus(LabProcedureStatus.IN_TRANSIT.getID());
Assert.assertTrue(form.isReassignable("4"));
procedure.setStatus(LabProcedureStatus.RECEIVED.getID());
Assert.assertTrue(form.isReassignable("4"));
procedure.setStatus(LabProcedureStatus.COMPLETED.getID());
Assert.assertFalse(form.isReassignable("4"));
procedure.setStatus(LabProcedureStatus.PENDING.getID());
Assert.assertFalse(form.isReassignable("4"));
procedure.setStatus(LabProcedureStatus.TESTING.getID());
Assert.assertFalse(form.isReassignable("4"));
}
@Test
public void testIsReassignableBadLong() {
boolean isReassignable = form.isReassignable("uh oh");
Assert.assertFalse(isReassignable);
}
@Test
public void testIsRemovable() {
when(mockController.getLabProcedureByID("4")).thenReturn(procedure);
form = new LabProcedureForm(mockController, codeData, mockSessionUtils, ds);
procedure.setStatus(LabProcedureStatus.IN_TRANSIT.getID());
Assert.assertTrue(form.isRemovable("4"));
procedure.setStatus(LabProcedureStatus.RECEIVED.getID());
Assert.assertTrue(form.isRemovable("4"));
procedure.setStatus(LabProcedureStatus.COMPLETED.getID());
Assert.assertFalse(form.isRemovable("4"));
procedure.setStatus(LabProcedureStatus.PENDING.getID());
Assert.assertFalse(form.isRemovable("4"));
procedure.setStatus(LabProcedureStatus.TESTING.getID());
Assert.assertFalse(form.isRemovable("4"));
}
@Test
public void testIsRemovableBadLong() {
boolean isRemovable = form.isRemovable("uh oh");
Assert.assertFalse(isRemovable);
}
@Test
public void testRemoveLabProcedure() {
String procID = procedure.getLabProcedureID().toString();
Mockito.doNothing().when(mockController).remove(procID);
when(mockSessionUtils.getRequestParameter("id")).thenReturn(procID);
when(mockController.getLabProcedureByID(procID)).thenReturn(procedure);
form = new LabProcedureForm(mockController, codeData, mockSessionUtils, ds);
form.removeLabProcedure(procedure.getLabProcedureID());
verify(mockController).remove(procID);
verify(mockController, times(1)).logTransaction(TransactionType.LAB_RESULTS_REMOVE, procedure.getLabProcedureCode());
verify(mockController, times(0)).printFacesMessage(any(), any(), any(), any());
}
@Test
public void testIsCommentable() {
when(mockController.getLabProcedureByID("4")).thenReturn(procedure);
form = new LabProcedureForm(mockController, codeData, mockSessionUtils, ds);
procedure.setStatus(LabProcedureStatus.PENDING.getID());
Assert.assertTrue(form.isCommentable("4"));
procedure.setStatus(LabProcedureStatus.IN_TRANSIT.getID());
Assert.assertFalse(form.isCommentable("4"));
procedure.setStatus(LabProcedureStatus.RECEIVED.getID());
Assert.assertFalse(form.isCommentable("4"));
procedure.setStatus(LabProcedureStatus.COMPLETED.getID());
Assert.assertFalse(form.isCommentable("4"));
procedure.setStatus(LabProcedureStatus.TESTING.getID());
Assert.assertFalse(form.isCommentable("4"));
}
@Test
public void testIsCommentableBadLong() {
boolean isCommentable = form.isCommentable("uh oh");
Assert.assertFalse(isCommentable);
}
// @Test
// public void testSubmitNewLabProcedure() {
// form = new LabProcedureForm(mockController, codeData, mockSessionUtils);
// form.submitNewLabProcedure();
// verify(mockController, times(1)).add(any());
//
// }
@Test
public void testSubmitReassignment() {
Mockito.doNothing().when(mockController).edit(procedure);
when(mockSessionUtils.getRequestParameter("id")).thenReturn("someID");
when(mockController.getLabProcedureByID("someID")).thenReturn(procedure);
form = new LabProcedureForm(mockController, codeData, mockSessionUtils, ds);
form.submitReassignment();
verify(mockController).edit(procedure);
verify(mockController).logTransaction(TransactionType.LAB_RESULTS_REASSIGN, procedure.getLabProcedureCode());
}
@Test
public void testIsLabProcedureCreated() {
when(mockSessionUtils.getRequestParameter("id")).thenReturn("8");
when(mockController.getLabProcedureByID(procedure.getLabProcedureID().toString())).thenReturn(procedure);
form = new LabProcedureForm(mockController, codeData, mockSessionUtils, ds);
Assert.assertTrue(form.isLabProcedureCreated());
}
@Test
public void testRecordResults() throws DBException {
String procID = procedure.getLabProcedureID().toString();
Mockito.doNothing().when(mockController).recordResults(procedure);
when(mockSessionUtils.getRequestParameter("id")).thenReturn(procID);
when(mockController.getLabProcedureByID(procID)).thenReturn(procedure);
form = new LabProcedureForm(mockController, codeData, mockSessionUtils, ds);
form.recordResults();
verify(mockController, times(1)).recordResults(any());
verify(mockSessionUtils, times(0)).printFacesMessage(any(), any(), any(), any());
verify(mockController, times(1)).logTransaction(TransactionType.LAB_RESULTS_RECORD, procedure.getLabProcedureCode());
}
@Test
public void testRecordResultsDBException() throws DBException, FormValidationException {
when(mockData.update(procedure)).thenThrow(new DBException(null));
form = new LabProcedureForm(mockController, codeData, mockSessionUtils, ds);
form.recordResults();
verify(mockController, times(1)).recordResults(any());
// TODO: verify sessionUtils.printFacesMessage() was called (limited by current mocking capabilities)
}
@Test
public void testGetLoincCodes() throws DBException {
List<LOINCCode> testCodes = new ArrayList<LOINCCode>(1);
when(mockCodeData.getAll()).thenReturn(testCodes);
form = new LabProcedureForm(mockController, mockCodeData, mockSessionUtils, ds);
testCodes.add(new LOINCCode("12345-6", "component", "kind of property"));
List<LOINCCode> returnedCodes = form.getLOINCCodes();
Assert.assertNotNull(returnedCodes);
Assert.assertEquals(1, returnedCodes.size());
}
@Test
public void testGetLoincCodesEmpty() throws DBException {
when(mockCodeData.getAll()).thenReturn(Collections.emptyList());
form = new LabProcedureForm(mockController, mockCodeData, mockSessionUtils, ds);
List<LOINCCode> codes = form.getLOINCCodes();
Assert.assertNotNull(codes);
Assert.assertEquals(0, codes.size());
}
@Test
public void testGetLoincCodesDBException() throws DBException {
when(mockCodeData.getAll()).thenThrow(new DBException(null));
form = new LabProcedureForm(mockController, mockCodeData, mockSessionUtils, ds);
List<LOINCCode> codes = form.getLOINCCodes();
Assert.assertNotNull(codes);
Assert.assertEquals(0, codes.size());
}
}
| 13,053
| 40.44127
| 127
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/labProcedure/LabProcedureMySQLTest.java
|
package edu.ncsu.csc.itrust.unit.model.labProcedure;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;
import javax.sql.DataSource;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import com.mysql.jdbc.Connection;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.labProcedure.LabProcedure;
import edu.ncsu.csc.itrust.model.labProcedure.LabProcedureMySQL;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
/**
* Tests the LabProcedureMySQL class.
*
* @author mwreesjo
*
*/
public class LabProcedureMySQLTest {
DataSource ds;
@Mock
DataSource mockDS;
LabProcedureMySQL data;
LabProcedure procedure;
TestDataGenerator gen;
@Before
public void setUp() throws Exception {
ds = ConverterDAO.getDataSource();
mockDS = Mockito.mock(DataSource.class);
data = new LabProcedureMySQL(ds);
gen = new TestDataGenerator();
gen.clearAllTables();
procedure = new LabProcedure();
procedure.setCommentary("commentary");
procedure.setConfidenceIntervalLower(10);
procedure.setConfidenceIntervalUpper(30);
procedure.setLabProcedureCode("12345-6");
procedure.setIsRestricted(true);
procedure.setLabProcedureID(8L);
procedure.setLabTechnicianID(9L);
procedure.setOfficeVisitID(10L);
procedure.setPriority(3);
procedure.setResults("results");
procedure.setStatus(1L);
procedure.setUpdatedDate(new Timestamp(100L));
procedure.setHcpMID(9000000001L);
}
@After
public void tearDown() throws FileNotFoundException, SQLException, IOException {
gen.clearAllTables();
}
@Test
public void testGetByID() throws FileNotFoundException, SQLException, IOException {
try {
gen.labProcedure0();
gen.labProcedure0();
} catch (SQLException | IOException e1) {
fail("Couldn't set up test data");
e1.printStackTrace();
}
try {
LabProcedure proc = data.getByID(1L);
Assert.assertNotNull(proc);
Assert.assertTrue(proc.getLabProcedureID() == 1L);
Assert.assertTrue(proc.getStatus().getID() == 1L);
Assert.assertEquals("This is a lo pri lab procedure", proc.getCommentary());
Assert.assertEquals("Foobar", proc.getResults());
} catch (DBException e) {
fail("Getting an existing lab procedure by ID shouldn't throw exception");
e.printStackTrace();
}
// Now invoke the SQLException catch block via mocking
data = new LabProcedureMySQL(mockDS);
Connection mockConnection = Mockito.mock(Connection.class);
when(mockDS.getConnection()).thenReturn(mockConnection);
when(mockConnection.prepareStatement(Mockito.anyString())).thenThrow(new SQLException());
try {
data.getByID(1L);
fail("Exception should be thrown");
} catch (DBException e) {
// Exception should throw
}
}
@Test
public void testGetLabProceduresByOfficeVisitSQLException() throws SQLException {
// Now invoke the SQLException catch block via mocking
data = new LabProcedureMySQL(mockDS);
Connection mockConnection = Mockito.mock(Connection.class);
when(mockDS.getConnection()).thenReturn(mockConnection);
when(mockConnection.prepareStatement(Mockito.anyString())).thenThrow(new SQLException());
try {
data.getLabProceduresByOfficeVisit(1L);
fail("Exception should be thrown");
} catch (DBException e) {
// Exception should throw
}
}
/**
* Tests the getAll() method. At the time of writing of this test, the lab
* procedures returned are in insertion order. We use this assumption to
* validate the output.
*
* @throws SQLException
*/
@Test
public void testGetAll() throws SQLException {
try {
gen.labProcedure0();
gen.labProcedure1();
gen.labProcedure2();
gen.labProcedure3();
gen.labProcedure4();
gen.labProcedure5();
} catch (SQLException | IOException e1) {
fail("Couldn't set up test data");
e1.printStackTrace();
}
try {
// Returned in insertion order
List<LabProcedure> all = data.getAll();
Assert.assertNotNull(all);
Assert.assertTrue(all.size() == 6);
Assert.assertEquals("This is a lo pri lab procedure", all.get(0).getCommentary());
Assert.assertEquals("Foobar", all.get(0).getResults());
Assert.assertEquals("This is for lab tech 5000000002", all.get(5).getCommentary());
} catch (DBException e) {
fail("Getting all lab procedures shouldn't throw exception");
e.printStackTrace();
}
// Now invoke the SQLException catch block via mocking
data = new LabProcedureMySQL(mockDS);
Connection mockConnection = Mockito.mock(Connection.class);
when(mockDS.getConnection()).thenReturn(mockConnection);
when(mockConnection.prepareStatement(Mockito.anyString())).thenThrow(new SQLException());
try {
data.getAll();
fail("Exception should be thrown");
} catch (DBException e) {
// Exception should throw
}
}
@Test
public void testAdd() {
try {
data.add(procedure);
} catch (DBException e) {
fail("Adding lab procedure should not throw error: " + e.getMessage());
e.printStackTrace();
}
try {
List<LabProcedure> all = data.getAll();
Assert.assertEquals(1, all.size());
LabProcedure proc = all.get(0);
Assert.assertNotNull(proc);
Assert.assertEquals("commentary", proc.getCommentary());
Assert.assertEquals(new Integer(10), proc.getConfidenceIntervalLower());
Assert.assertEquals(new Integer(30), proc.getConfidenceIntervalUpper());
Assert.assertEquals("12345-6", proc.getLabProcedureCode());
Assert.assertTrue(proc.isRestricted());
Assert.assertEquals(new Long(9L), proc.getLabTechnicianID());
Assert.assertEquals(new Long(10L), proc.getOfficeVisitID());
Assert.assertEquals(new Integer(3), proc.getPriority());
Assert.assertEquals("results", proc.getResults());
Assert.assertEquals(1L, proc.getStatus().getID());
Timestamp now = new Timestamp(System.currentTimeMillis());
// Assert updatedDate is within 5 seconds
Assert.assertTrue(now.compareTo(proc.getUpdatedDate()) < 5000);
Assert.assertEquals(new Long(9000000001L), proc.getHcpMID());
} catch (DBException e) {
fail("Couldn't get all lab procedures");
e.printStackTrace();
}
}
@Test
public void testAddInvalid() throws SQLException {
mockDS = Mockito.mock(DataSource.class);
data = new LabProcedureMySQL(mockDS);
procedure.setConfidenceIntervalLower(-1);
try {
data.add(procedure);
fail("Adding invalid lab procedure should throw DBException");
} catch (DBException e) {
// Exception should be thrown
}
verify(mockDS, times(0)).getConnection();
}
@Test
public void testUpdate() {
try {
gen.labProcedure0();
} catch (Exception e) {
fail("Couldn't set up test data");
}
procedure.setCommentary("updated comment");
procedure.setLabProcedureID(1L);
boolean success = false;
try {
success = data.update(procedure);
} catch (DBException e) {
fail("Shouldn't throw exception when updating lab procedure: " + e.getMessage());
}
if (!success) {
fail("Update method should return true when updating is successful");
}
List<LabProcedure> all;
try {
all = data.getAll();
if (all.size() != 1) {
fail("Update method should not increase the number of lab procedures");
}
LabProcedure updatedProc = all.get(0);
Assert.assertEquals(procedure.getCommentary(), updatedProc.getCommentary());
} catch (DBException e) {
fail("DBException should not be thrown");
}
}
@Test
public void testUpdateInvalid() {
procedure.setLabProcedureCode("oopsie doopsie");
boolean success = false;
try {
success = data.update(procedure);
fail("Should throw exception when updating invalid lab procedure");
} catch (DBException e) {
// Exception should be thrown
}
if (success) {
fail("Update method should return false when updating is unsuccessful");
}
}
@Test
public void testRemoveLabProcedure() {
try {
gen.labProcedure0();
} catch (SQLException | IOException e1) {
fail("Couldn't set up test data");
}
boolean success = false;
try {
success = data.removeLabProcedure(1L);
} catch (DBException e) {
fail("Shouldn't throw exception when removing existing lab procedure");
}
if (!success) {
fail("removeLabProcedure should return true for successful removal");
}
try {
List<LabProcedure> all = data.getAll();
Assert.assertTrue(all.size() == 0);
} catch (DBException e) {
fail("Couldn't get all lab procedures");
}
}
@Test
public void testGetLabProcedure() throws Exception {
gen.labProcedure0();
LabProcedure proc = data.getByID(1L);
Assert.assertNotNull(proc);
Assert.assertEquals(5000000001L, proc.getLabTechnicianID().longValue());
proc = data.getByID(0L);
Assert.assertNull(proc);
}
}
| 9,039
| 29.540541
| 91
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/labProcedure/LabProcedureTest.java
|
package edu.ncsu.csc.itrust.unit.model.labProcedure;
import java.sql.Timestamp;
import java.util.Date;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import edu.ncsu.csc.itrust.model.labProcedure.LabProcedure;
public class LabProcedureTest {
LabProcedure proc;
@Before
public void setUp() throws Exception {
proc = new LabProcedure();
}
@Test
public void testGetLabProcedureID() {
proc.setLabProcedureID(4L);
Assert.assertTrue(proc.getLabProcedureID() == 4L);
}
@Test
public void testSetLabProcedureID() {
proc.setLabProcedureID(4L);
Assert.assertTrue(proc.getLabProcedureID() == 4L);
}
@Test
public void testGetLabTechnicianID() {
proc.setLabTechnicianID(4L);
Assert.assertTrue(proc.getLabTechnicianID() == 4L);
}
@Test
public void testSetLabTechnicianID() {
proc.setLabTechnicianID(4L);
Assert.assertTrue(proc.getLabTechnicianID() == 4L);
}
@Test
public void testGetOfficeVisitID() {
proc.setOfficeVisitID(3L);
Assert.assertTrue(proc.getOfficeVisitID() == 3L);
}
@Test
public void testSetOfficeVisitID() {
proc.setOfficeVisitID(3L);
Assert.assertTrue(proc.getOfficeVisitID() == 3L);
}
@Test
public void testGetLabProcedureCode() {
proc.setLabProcedureCode("23232-4");
Assert.assertEquals("23232-4", proc.getLabProcedureCode());
}
@Test
public void testSetLabProcedureCode() {
proc.setLabProcedureCode("23232-4");
Assert.assertEquals("23232-4", proc.getLabProcedureCode());
}
@Test
public void testGetPriority() {
proc.setPriority(3);
Assert.assertTrue(proc.getPriority() == 3);
}
@Test
public void testSetPriority() {
proc.setPriority(3);
Assert.assertTrue(proc.getPriority() == 3);
}
@Test
public void testIsRestricted() {
proc.setIsRestricted(true);
Assert.assertTrue(proc.isRestricted());
}
@Test
public void testSetIsRestricted() {
proc.setIsRestricted(true);
Assert.assertTrue(proc.isRestricted());
}
@Test
public void testGetStatus() {
proc.setStatus(3);
Assert.assertTrue(proc.getStatus().getID() == 3);
}
@Test
public void testSetStatusLong() {
proc.setStatus(3);
Assert.assertTrue(proc.getStatus().getID() == 3);
}
@Test
public void testSetStatusString() {
proc.setStatus("Completed");
Assert.assertEquals("Completed", proc.getStatus().getName());
}
@Test
public void testGetCommentary() {
proc.setCommentary("foobar");
Assert.assertEquals("foobar", proc.getCommentary());
}
@Test
public void testSetCommentary() {
proc.setCommentary("foobar");
Assert.assertEquals("foobar", proc.getCommentary());
}
@Test
public void testGetResults() {
proc.setResults("foobar");
Assert.assertEquals("foobar", proc.getResults());
}
@Test
public void testSetResults() {
proc.setResults("foobar");
Assert.assertEquals("foobar", proc.getResults());
}
@Test
public void testGetUpdatedDate() {
Timestamp t = new Timestamp(new Date().getTime());
proc.setUpdatedDate(t);
Assert.assertEquals(t, proc.getUpdatedDate());
}
@Test
public void testSetUpdatedDate() {
Timestamp t = new Timestamp(new Date().getTime());
proc.setUpdatedDate(t);
Assert.assertEquals(t, proc.getUpdatedDate());
}
@Test
public void testGetConfidenceIntervalLower() {
proc.setConfidenceIntervalLower(30);
Assert.assertTrue(proc.getConfidenceIntervalLower() == 30);
}
@Test
public void testSetConfidenceIntervalLower() {
proc.setConfidenceIntervalLower(30);
Assert.assertTrue(proc.getConfidenceIntervalLower() == 30);
}
@Test
public void testGetConfidenceIntervalUpper() {
proc.setConfidenceIntervalUpper(30);
Assert.assertTrue(proc.getConfidenceIntervalUpper() == 30);
}
@Test
public void testSetConfidenceIntervalUpper() {
proc.setConfidenceIntervalUpper(30);
Assert.assertTrue(proc.getConfidenceIntervalUpper() == 30);
}
}
| 3,828
| 20.88
| 63
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/labProcedure/LabProcedureValidatorTest.java
|
package edu.ncsu.csc.itrust.unit.model.labProcedure;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
import java.sql.Timestamp;
import java.util.Date;
import org.junit.Before;
import org.junit.Test;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.model.labProcedure.LabProcedure;
import edu.ncsu.csc.itrust.model.labProcedure.LabProcedureValidator;
/**
* Tests the LabProcedureValidator class.
*
* @author mwreesjo
*
*/
public class LabProcedureValidatorTest {
/**
* Used to validate fields with 500-char limit. 'o' is the 501th character.
*/
private static final String stringWith501Chars = "ffffffffffffffffffffffffffffffffffffffffffffffffff"
+ "ffffffffffffffffffffffffffffffffffffffffffffffffff"
+ "ffffffffffffffffffffffffffffffffffffffffffffffffff"
+ "ffffffffffffffffffffffffffffffffffffffffffffffffff"
+ "ffffffffffffffffffffffffffffffffffffffffffffffffff"
+ "ffffffffffffffffffffffffffffffffffffffffffffffffff"
+ "ffffffffffffffffffffffffffffffffffffffffffffffffff"
+ "ffffffffffffffffffffffffffffffffffffffffffffffffff"
+ "ffffffffffffffffffffffffffffffffffffffffffffffffff"
+ "ffffffffffffffffffffffffffffffffffffffffffffffffff" + "o";
LabProcedureValidator validator;
LabProcedure proc;
@Before
public void setUp() throws Exception {
validator = new LabProcedureValidator();
proc = new LabProcedure();
proc.setCommentary("commentary");
proc.setIsRestricted(true);
proc.setLabProcedureID(8L);
proc.setLabTechnicianID(9L);
proc.setOfficeVisitID(10L);
proc.setPriority(3);
proc.setResults("results");
proc.setLabProcedureCode("00000-0");
proc.setConfidenceIntervalLower(50);
proc.setConfidenceIntervalUpper(60);
proc.setStatus(1L);
proc.setUpdatedDate(new Timestamp(100L));
proc.setHcpMID(9000000001L);
}
@Test
public void testValidLabProcedure() {
try {
validator.validate(proc);
} catch (FormValidationException f) {
fail("Valid lab procedure wasn't validated. Error: " + f.getMessage());
}
}
@Test
public void testInvalidCommentary() {
proc.setCommentary(stringWith501Chars);
tryValidateWithInvalidField(proc, "commentary");
}
@Test
public void testInvalidConfidenceIntervalLower() {
proc.setConfidenceIntervalLower(-1);
tryValidateWithInvalidField(proc, "confidence interval lower");
proc.setConfidenceIntervalLower(101);
tryValidateWithInvalidField(proc, "confidence interval lower");
}
@Test
public void testInvalidConfidenceIntervalUpper() {
proc.setConfidenceIntervalUpper(-1);
tryValidateWithInvalidField(proc, "confidence interval upper");
proc.setConfidenceIntervalUpper(101);
tryValidateWithInvalidField(proc, "confidence interval upper");
}
@Test
public void testInvalidLabProcedureCode() {
proc.setLabProcedureCode("0");
tryValidateWithInvalidField(proc, "lab procedure code");
proc.setLabProcedureCode("00000");
tryValidateWithInvalidField(proc, "lab procedure code");
proc.setLabProcedureCode("-0");
tryValidateWithInvalidField(proc, "lab procedure code");
}
@Test
public void testInvalidLabProcedureID() {
proc.setLabProcedureID(-1L);
tryValidateWithInvalidField(proc, "lab procedure ID");
// Lab procedure can be null but cannot be negative
proc.setLabProcedureID(null);
try {
validator.validate(proc);
} catch (FormValidationException f) {
fail("Valid lab procedure wasn't validated. Error: " + f.getMessage());
}
}
@Test
public void testInvalidOfficeVisitID() {
proc.setOfficeVisitID(-1L);
tryValidateWithInvalidField(proc, "office visit ID");
proc.setOfficeVisitID(null);
tryValidateWithInvalidField(proc, "office visit ID");
}
@Test
public void testInvalidLabTechnicianID() {
proc.setLabTechnicianID(-1L);
tryValidateWithInvalidField(proc, "lab technician ID");
proc.setLabTechnicianID(null);
tryValidateWithInvalidField(proc, "lab technician ID");
}
@Test
public void testInvalidPriority() {
proc.setPriority(0);
tryValidateWithInvalidField(proc, "priority");
proc.setPriority(4);
tryValidateWithInvalidField(proc, "priority");
}
@Test
public void testInvalidResults() {
proc.setResults(stringWith501Chars);
tryValidateWithInvalidField(proc, "results");
}
@Test
public void testInvalidStatus() {
// Create new LP since proc.setStatus(null) isn't possible
LabProcedure statusNotInitialized = new LabProcedure();
statusNotInitialized.setCommentary("f");
statusNotInitialized.setConfidenceIntervalLower(30);
statusNotInitialized.setConfidenceIntervalUpper(40);
statusNotInitialized.setIsRestricted(true);
statusNotInitialized.setLabProcedureCode("12345-6");
statusNotInitialized.setLabProcedureID(4L);
statusNotInitialized.setLabTechnicianID(5L);
statusNotInitialized.setOfficeVisitID(1L);
statusNotInitialized.setPriority(2);
statusNotInitialized.setResults("results yeah");
statusNotInitialized.setUpdatedDate(new Timestamp(new Date().getTime()));
try {
validator.validate(statusNotInitialized);
fail("Validator should catch invalid status");
} catch (FormValidationException e) {
// Exception should be thrown
}
}
@Test
public void testInvalidUpdatedDate() {
proc.setUpdatedDate(null);
tryValidateWithInvalidField(proc, "updated date");
}
@Test
public void testInvalidHcpMID() {
proc.setHcpMID(null);
tryValidateWithInvalidField(proc, "HCP MID");
proc.setHcpMID(1L);
tryValidateWithInvalidField(proc, "HCP MID");
proc.setHcpMID(-1L);
tryValidateWithInvalidField(proc, "HCP MID");
proc.setHcpMID(12345678901L);
tryValidateWithInvalidField(proc, "HCP MID");
proc.setHcpMID(92345678901L);
tryValidateWithInvalidField(proc, "HCP MID");
}
/**
* Invokes the validator.validate() method on the given lab procedure,
* Assert.fail()ing if the validator does not throw an exception.
*
* @param proc
* The procedure with one invalid field
* @param nameOfInvalidField
* Name of the field which is invalid
*/
private void tryValidateWithInvalidField(LabProcedure proc, String nameOfInvalidField) {
try {
validator.validate(proc);
fail("Validator should catch invalid field " + nameOfInvalidField);
} catch (FormValidationException e) {
// Exception should be thrown
assertThat(e.getMessage().toLowerCase(), containsString(nameOfInvalidField.toLowerCase()));
}
}
}
| 6,468
| 29.804762
| 102
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/loinccode/LOINCCodeMySQLTest.java
|
package edu.ncsu.csc.itrust.unit.model.loinccode;
import java.sql.SQLException;
import java.util.List;
import javax.sql.DataSource;
import static org.junit.Assert.*;
import org.junit.Test;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.loinccode.LOINCCode;
import edu.ncsu.csc.itrust.model.loinccode.LOINCCodeData;
import edu.ncsu.csc.itrust.model.loinccode.LOINCCodeMySQL;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import junit.framework.TestCase;
public class LOINCCodeMySQLTest extends TestCase {
LOINCCodeMySQL data;
TestDataGenerator gen;
DataSource ds;
@Override
public void setUp() throws Exception {
ds = ConverterDAO.getDataSource();
data = new LOINCCodeMySQL(ds);
gen = new TestDataGenerator();
gen.clearAllTables();
gen.uc26();
}
@Test
public void testGetAll() throws Exception {
List<LOINCCode> loincList = data.getAll();
assertEquals("00000-1", loincList.get(0).getCode());
assertEquals("00000-2", loincList.get(1).getCode());
}
@Test
public void testGetByID() throws Exception {
assertNull(data.getByID(0L));
}
@Test
public void testGetByCode() throws Exception {
LOINCCode c = data.getByCode("00000-1");
assertNotNull(c);
assertEquals("fluid", c.getKindOfProperty());
}
@Test
public void testAdd() throws Exception {
final String code = "99999-9";
assertNull(data.getByCode(code));
LOINCCode loincToAdd = new LOINCCode(code, "comp", "prop");
data.add(loincToAdd);
LOINCCode loinc = data.getByCode(code);
assertNotNull(loinc);
assertEquals("comp", loinc.getComponent());
}
@Test
public void testEdit() throws Exception {
final String code = "99999-9";
assertNull(data.getByCode(code));
LOINCCode loincToAdd = new LOINCCode(code, "comp", "prop");
data.add(loincToAdd);
LOINCCode loinc = data.getByCode(code);
assertNotNull(loinc);
assertEquals("comp", loinc.getComponent());
loincToAdd.setComponent("newComp");
data.update(loincToAdd);
LOINCCode newLoinc = data.getByCode(code);
assertNotNull(newLoinc);
assertEquals("newComp", newLoinc.getComponent());
}
@Test
public void testAddInvalid() throws Exception {
final String code = "99999-99999";
assertNull(data.getByCode(code));
LOINCCode loincToAdd = new LOINCCode(code, "comp", "prop");
try {
data.add(loincToAdd);
fail("LOINC with invalid code should not have been added");
} catch (Exception e) {
// Do nothing
}
}
@Test
public void testDelete() throws DBException, FormValidationException, SQLException{
data.add(new LOINCCode("12345-6", "a", "b"));
data.delete(new LOINCCode("12345-6", "a", "b"));
}
}
| 2,783
| 26.84
| 84
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/loinccode/LOINCCodeTest.java
|
package edu.ncsu.csc.itrust.unit.model.loinccode;
import org.junit.Test;
import edu.ncsu.csc.itrust.model.loinccode.LOINCCode;
import junit.framework.TestCase;
public class LOINCCodeTest extends TestCase {
private LOINCCode loinc;
@Override
public void setUp() {
loinc = new LOINCCode("code", "comp", "prop", "time", "system", "scale", "method");
}
@Test
public void testConstructors() {
assertEquals("code", loinc.getCode());
assertEquals("comp", loinc.getComponent());
assertEquals("prop", loinc.getKindOfProperty());
assertEquals("time", loinc.getTimeAspect());
assertEquals("system", loinc.getSystem());
assertEquals("scale", loinc.getScaleType());
assertEquals("method", loinc.getMethodType());
}
@Test
public void testGettersAndSetters() {
loinc.setComponent("newComponent");
loinc.setKindOfProperty("newProp");
loinc.setTimeAspect("newTime");
loinc.setSystem("newSystem");
loinc.setScaleType("newScale");
loinc.setMethodType("newMethod");
assertEquals("newComponent", loinc.getComponent());
assertEquals("newProp", loinc.getKindOfProperty());
assertEquals("newTime", loinc.getTimeAspect());
assertEquals("newSystem", loinc.getSystem());
assertEquals("newScale", loinc.getScaleType());
assertEquals("newMethod", loinc.getMethodType());
}
}
| 1,302
| 29.302326
| 85
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/medicalProcedure/MedicalProcedureMySQLTest.java
|
package edu.ncsu.csc.itrust.unit.model.medicalProcedure;
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.exception.DBException;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.cptcode.CPTCode;
import edu.ncsu.csc.itrust.model.medicalProcedure.MedicalProcedure;
import edu.ncsu.csc.itrust.model.medicalProcedure.MedicalProcedureMySQL;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisitMySQL;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import junit.framework.TestCase;
public class MedicalProcedureMySQLTest extends TestCase {
private DataSource ds;
private TestDataGenerator gen;
private MedicalProcedureMySQL sql;
private OfficeVisitMySQL ovSql;
@Override
public void setUp() throws FileNotFoundException, SQLException, IOException {
ds = ConverterDAO.getDataSource();
sql = new MedicalProcedureMySQL(ds);
ovSql = new OfficeVisitMySQL(ds);
gen = new TestDataGenerator();
gen.clearAllTables();
gen.uc11();
}
@Test
public void testValids() throws SQLException, DBException {
long ovID = ovSql.getAll().get(0).getVisitID();
MedicalProcedure p = new MedicalProcedure();
p.setOfficeVisitId(ovID);
p.setCptCode(new CPTCode("90717", "Typhoid Vaccine"));
Assert.assertTrue(sql.add(p));
List<MedicalProcedure> pList = sql.getMedicalProceduresForOfficeVisit(ovID);
Assert.assertEquals(1, pList.size());
Assert.assertEquals("90717", pList.get(0).getCode());
long mpID = pList.get(0).getId();
Assert.assertEquals("90717", sql.get(mpID).getCode());
Assert.assertEquals("Typhoid Vaccine", sql.getCodeName("90717"));
p.setCptCode(new CPTCode("99214", ""));
p.setId(mpID);
Assert.assertTrue(sql.update(p));
pList = sql.getMedicalProceduresForOfficeVisit(ovID);
Assert.assertEquals(1, pList.size());
Assert.assertEquals("99214", pList.get(0).getCode());
Assert.assertTrue(sql.remove(mpID));
pList = sql.getMedicalProceduresForOfficeVisit(ovID);
Assert.assertEquals(0, pList.size());
}
}
| 2,414
| 35.044776
| 84
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/medicalProcedure/MedicalProcedureTest.java
|
package edu.ncsu.csc.itrust.unit.model.medicalProcedure;
import org.junit.Assert;
import edu.ncsu.csc.itrust.model.cptcode.CPTCode;
import edu.ncsu.csc.itrust.model.medicalProcedure.MedicalProcedure;
import junit.framework.TestCase;
public class MedicalProcedureTest extends TestCase{
public void testFields(){
MedicalProcedure p = new MedicalProcedure();
p.setId(90);
Assert.assertEquals(90, p.getId());
p.setOfficeVisitId(80);
Assert.assertEquals(80, p.getOfficeVisitId());
p.setCptCode(new CPTCode("blah", "other"));
Assert.assertEquals("blah", p.getCode());
Assert.assertEquals("other", p.getName());
}
}
| 711
| 28.666667
| 67
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/ndcode/NDCCodeMySQLTest.java
|
package edu.ncsu.csc.itrust.unit.model.ndcode;
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 edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.ndcode.NDCCode;
import edu.ncsu.csc.itrust.model.ndcode.NDCCodeMySQL;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import junit.framework.TestCase;
public class NDCCodeMySQLTest extends TestCase {
private DataSource ds;
@Override
public void setUp() throws FileNotFoundException, SQLException, IOException{
ds = ConverterDAO.getDataSource();
}
public void testNDCodeMySQL() throws FileNotFoundException, SQLException, IOException, FormValidationException{
TestDataGenerator gen = new TestDataGenerator();
gen.clearAllTables();
NDCCodeMySQL sql = new NDCCodeMySQL(ds);
// ensure there are no records to start
Assert.assertEquals(0, sql.getAll().size());
// test adding a valid record
NDCCode newCode = new NDCCode();
newCode.setCode("123");
newCode.setDescription("test");
Assert.assertTrue(sql.add(newCode));
List<NDCCode> ndList = sql.getAll();
Assert.assertEquals(1, ndList.size());
Assert.assertEquals("123", ndList.get(0).getCode());
Assert.assertEquals("test", ndList.get(0).getDescription());
// make sure we can get it with getByID()
NDCCode toCheck = sql.getByCode("123");
Assert.assertNotNull(toCheck);
Assert.assertEquals("123", ndList.get(0).getCode());
Assert.assertEquals("test", ndList.get(0).getDescription());
// make sure we can't get nonexistent codes
toCheck = sql.getByCode("a");
Assert.assertNull(toCheck);
// make sure we can't add it again
Assert.assertFalse(sql.add(newCode));
ndList = sql.getAll();
Assert.assertEquals(1, ndList.size());
Assert.assertEquals("123", ndList.get(0).getCode());
Assert.assertEquals("test", ndList.get(0).getDescription());
// test adding a record with bad code
newCode.setCode("a");
newCode.setDescription("test2");
try {
sql.add(newCode);
fail("Record should not have been added");
} catch (FormValidationException e){
List<String> errors = e.getErrorList();
Assert.assertEquals(1, errors.size());
Assert.assertEquals("NDCCode: Up to five digits, followed by an optional dash with 1-4 more digits", errors.get(0));
}
Assert.assertEquals(1, sql.getAll().size());
// test adding a record with too long description
newCode.setCode("321");
newCode.setDescription("test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3");
try {
sql.add(newCode);
fail("Record should not have been added");
} catch (FormValidationException e){
List<String> errors = e.getErrorList();
Assert.assertEquals(1, errors.size());
Assert.assertEquals("Description: Up to 100 alphanumeric characters plus space and ()<>,.-?/'", errors.get(0));
}
Assert.assertEquals(1, sql.getAll().size());
// test deleting a record that doesn't exist
newCode.setCode("4");
newCode.setDescription("test4");
Assert.assertFalse(sql.delete(newCode));
Assert.assertEquals(1, sql.getAll().size());
// test updating 123
newCode.setCode("123");
newCode.setDescription("blah");
Assert.assertTrue(sql.update(newCode));
toCheck = sql.getByCode("123");
Assert.assertNotNull(toCheck);
Assert.assertEquals("blah", toCheck.getDescription());
// make sure we can't update with a bad record
newCode.setDescription("fdsa$@$@$<>,.?/");
try {
sql.update(newCode);
fail();
} catch (FormValidationException e){
// yay we passed
}
toCheck = sql.getByCode("123");
Assert.assertNotNull(toCheck);
Assert.assertEquals("blah", toCheck.getDescription());
// test updating nonexistent record
newCode.setDescription("blah2");
newCode.setCode("54643");
Assert.assertFalse(sql.update(newCode));
// test deleting a record that does exist
newCode.setCode("123");
newCode.setDescription("test1");
Assert.assertTrue(sql.delete(newCode));
Assert.assertEquals(0, sql.getAll().size());
}
public void testProdConstructor(){
try {
new NDCCodeMySQL();
fail();
} catch (DBException e) {
// yay, we passed
}
}
}
| 5,117
| 36.357664
| 140
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/ndcode/NDCCodeTest.java
|
package edu.ncsu.csc.itrust.unit.model.ndcode;
import org.junit.Assert;
import edu.ncsu.csc.itrust.model.ndcode.NDCCode;
import junit.framework.TestCase;
public class NDCCodeTest extends TestCase {
public void testEverything(){
NDCCode nd = new NDCCode();
nd.setCode("test");
Assert.assertEquals("test", nd.getCode());
nd.setDescription("test2");
Assert.assertEquals("test2", nd.getDescription());
}
}
| 467
| 23.631579
| 58
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/officeVisit/OfficeVisitMySQLTest.java
|
package edu.ncsu.csc.itrust.unit.model.officeVisit;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.List;
import javax.sql.DataSource;
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisit;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisitMySQL;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import junit.framework.TestCase;
public class OfficeVisitMySQLTest extends TestCase {
private DataSource ds;
private OfficeVisitMySQL ovsql;
private TestDataGenerator gen;
@Mock
private DataSource mockDataSource;
@Mock
private Connection mockConnection;
@Mock
private PreparedStatement mockPreparedStatement;
@Mock
private ResultSet mockResultSet;
private OfficeVisitMySQL mockOvsql;
@Override
public void setUp() throws Exception {
ds = ConverterDAO.getDataSource();
ovsql = new OfficeVisitMySQL(ds);
gen = new TestDataGenerator();
gen.clearAllTables();
gen.uc51();
mockDataSource = Mockito.mock(DataSource.class);
mockOvsql = new OfficeVisitMySQL(mockDataSource);
mockConnection = Mockito.mock(Connection.class);
mockResultSet = Mockito.mock(ResultSet.class);
mockPreparedStatement = Mockito.mock(PreparedStatement.class);
}
@Test
public void testGetVisitsForPatient() throws Exception {
List<OfficeVisit> list101 = ovsql.getVisitsForPatient(101L);
assertEquals(0, list101.size());
}
@Test
public void testGetPatientDOB() throws Exception {
LocalDate patient101DOB = ovsql.getPatientDOB(101L);
// patient with MID 101 is initialized with birthday as '2013-05-01'
LocalDate expectedPatientDOB = LocalDate.of(2013, 5, 1);
assertEquals(expectedPatientDOB, patient101DOB);
LocalDate invalidPatient106DOB = ovsql.getPatientDOB(106L);
assertNull(invalidPatient106DOB);
LocalDate invalidPatient107DOB = ovsql.getPatientDOB(107L);
assertNull(invalidPatient107DOB);
}
@Test
public void testGetPatientDOBWithInvalidDataSource() throws Exception {
Mockito.doThrow(new SQLException("mock exception")).when(mockDataSource).getConnection();
LocalDate patient101DOB = mockOvsql.getPatientDOB(101L);
assertNull(patient101DOB);
Mockito.reset(mockDataSource);
Mockito.when(mockDataSource.getConnection()).thenReturn(mockConnection);
Mockito.when(mockConnection.prepareStatement(Matchers.any(String.class))).thenReturn(mockPreparedStatement);
Mockito.when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet);
Mockito.doThrow(new SQLException("mock exception")).when(mockResultSet).next();
Mockito.doThrow(new SQLException("mock exception")).when(mockResultSet).close();
LocalDate patient102DOB = mockOvsql.getPatientDOB(102L);
assertNull(patient102DOB);
}
}
| 2,975
| 31
| 110
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/officeVisit/OfficeVisitSQLLoaderTest.java
|
package edu.ncsu.csc.itrust.unit.model.officeVisit;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisitSQLLoader;
import junit.framework.TestCase;
public class OfficeVisitSQLLoaderTest extends TestCase {
private static String MOCK_COLUMN_NAME = "mock_column";
private static Integer MOCK_COLUMN_INDEX = 0;
private static Integer MOCK_INT_VALUE = 1031;
private static Float MOCK_FLOAT_VALUE = 1031.1f;
private OfficeVisitSQLLoader ovloader;
@Mock
private ResultSet mockIntValResultSet;
@Mock
private ResultSet mockIntNullResultSet;
@Mock
private ResultSet mockFloatValResultSet;
@Mock
private ResultSet mockFloatNullResultSet;
@Mock
private PreparedStatement mockPreparedStatement;
@SuppressWarnings("null")
@Override
public void setUp() throws Exception {
ovloader = new OfficeVisitSQLLoader();
// Mock a ResultSet containing int value
mockIntValResultSet = Mockito.mock(ResultSet.class);
Mockito.when(mockIntValResultSet.getInt(MOCK_COLUMN_NAME)).thenReturn(MOCK_INT_VALUE);
Mockito.when(mockIntValResultSet.wasNull()).thenReturn(false);
// Mock a ResultSet containing null int value
mockIntNullResultSet = Mockito.mock(ResultSet.class);
Mockito.when(mockIntNullResultSet.getInt(MOCK_COLUMN_NAME)).thenReturn(0);
Mockito.when(mockIntNullResultSet.wasNull()).thenReturn(true);
// Mock a ResultSet containing int value
mockFloatValResultSet = Mockito.mock(ResultSet.class);
Mockito.when(mockFloatValResultSet.getFloat(MOCK_COLUMN_NAME)).thenReturn(MOCK_FLOAT_VALUE);
Mockito.when(mockFloatValResultSet.wasNull()).thenReturn(false);
// Mock a ResultSet containing null int value
mockFloatNullResultSet = Mockito.mock(ResultSet.class);
Mockito.when(mockFloatNullResultSet.getFloat(MOCK_COLUMN_NAME)).thenReturn(0.0f);
Mockito.when(mockFloatNullResultSet.wasNull()).thenReturn(true);
// Mock a PreparedStatement with a placeholder
mockPreparedStatement = Mockito.mock(PreparedStatement.class);
}
@Test
public void testGetIntOrNull() throws Exception {
Assert.assertEquals(MOCK_INT_VALUE, ovloader.getIntOrNull(mockIntValResultSet, MOCK_COLUMN_NAME));
Assert.assertEquals(null, ovloader.getIntOrNull(mockIntNullResultSet, MOCK_COLUMN_NAME));
}
@Test
public void testGetFloatOrNull() throws Exception {
Assert.assertEquals(MOCK_FLOAT_VALUE, ovloader.getFloatOrNull(mockFloatValResultSet, MOCK_COLUMN_NAME));
Assert.assertEquals(null, ovloader.getFloatOrNull(mockFloatNullResultSet, MOCK_COLUMN_NAME));
}
@Test
public void testSetIntOrNull() throws Exception {
try {
ovloader.setIntOrNull(mockPreparedStatement, MOCK_COLUMN_INDEX, MOCK_INT_VALUE);
} catch (NullPointerException e) {
fail();
}
try {
ovloader.setIntOrNull(mockPreparedStatement, MOCK_COLUMN_INDEX, null);
} catch (NullPointerException e) {
fail();
}
}
@Test
public void testSetFloatOrNull() throws Exception {
try {
ovloader.setFloatOrNull(mockPreparedStatement, MOCK_COLUMN_INDEX, MOCK_FLOAT_VALUE);
} catch (NullPointerException e) {
fail();
}
try {
ovloader.setFloatOrNull(mockPreparedStatement, MOCK_COLUMN_INDEX, null);
} catch (NullPointerException e) {
fail();
}
}
}
| 3,364
| 31.355769
| 106
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/officeVisit/OfficeVisitTest.java
|
package edu.ncsu.csc.itrust.unit.model.officeVisit;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import javax.sql.DataSource;
import org.junit.Assert;
import org.junit.Test;
import junit.framework.TestCase;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.apptType.ApptType;
import edu.ncsu.csc.itrust.model.apptType.ApptTypeData;
import edu.ncsu.csc.itrust.model.apptType.ApptTypeMySQLConverter;
import edu.ncsu.csc.itrust.model.hospital.Hospital;
import edu.ncsu.csc.itrust.model.hospital.HospitalData;
import edu.ncsu.csc.itrust.model.hospital.HospitalMySQLConverter;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisit;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
public class OfficeVisitTest extends TestCase {
private OfficeVisit test;
private ApptTypeData apptData;
private TestDataGenerator gen;
private DataSource ds;
@Override
protected void setUp() throws Exception {
ds = ConverterDAO.getDataSource();
test = new OfficeVisit();
apptData = new ApptTypeMySQLConverter(ds);
gen = new TestDataGenerator();
}
@Test
public void testApptTypeID() throws DBException, FileNotFoundException, IOException, SQLException {
gen.appointmentType();
List<ApptType> types = apptData.getAll();
long apptTypeID = types.get((types.size()-1)).getID();
test.setApptTypeID(apptTypeID);
long testID = test.getApptTypeID();
Assert.assertEquals(apptTypeID, testID);
}
@Test
public void testDate() {
LocalDateTime testTime = LocalDateTime.now();
test.setDate(testTime);
Assert.assertTrue(ChronoUnit.MINUTES.between(testTime, test.getDate())<1);
}
@Test
public void testLocationID() throws FileNotFoundException, SQLException, IOException, DBException {
gen.hospitals();
HospitalData hData = new HospitalMySQLConverter(ds);
List<Hospital> all = hData.getAll();
String id = all.get(0).getHospitalID();
test.setLocationID(id);
Assert.assertEquals(id, test.getLocationID());
}
@Test
public void testNotes() {
String note = "ABCDEF123><$%> ";
test.setNotes(note);
Assert.assertEquals(note, test.getNotes());
}
@Test
public void testBill() {
test.setSendBill(true);
Assert.assertTrue(test.getSendBill());
test.setSendBill(false);
Assert.assertFalse(test.getSendBill());
}
@Test
public void testPatient() throws FileNotFoundException, IOException, SQLException {
gen.patient1();
test.setPatientMID(1L);
Assert.assertEquals(new Long(1),test.getPatientMID());
}
@Test
public void testID() {
test.setVisitID(1L);
long check = test.getVisitID();
Assert.assertEquals(1L, check);
}
/** Tests height methods. */
@Test
public void testHeight() {
test.setHeight(1F);
float check = test.getHeight();
Assert.assertEquals(1F, check, .01);
}
/** Tests length methods. */
@Test
public void testLength() {
test.setLength(1F);
float check = test.getLength();
Assert.assertEquals(1F, check, .01);
}
/** Tests weight methods. */
@Test
public void testWeight() {
test.setWeight(1F);
float check = test.getWeight();
Assert.assertEquals(1F, check, .01);
}
/** Tests headCircunference methods. */
@Test
public void testHeadCircumference() {
test.setHeadCircumference(1F);
float check = test.getHeadCircumference();
Assert.assertEquals(1F, check, .01);
}
/** Tests bloodPressure methods. */
@Test
public void testBloodPressure() {
String bp = "140/90";
test.setBloodPressure(bp);
Assert.assertEquals(bp, test.getBloodPressure());
}
/** Tests HDL Cholesterol methods. */
@Test
public void testHDL() {
test.setHDL(1);
long check = test.getHDL();
Assert.assertEquals(1, check);
}
/** Tests Triglyceride Cholesterol methods. */
@Test
public void testTriglyceride() {
test.setTriglyceride(1);
long check = test.getTriglyceride();
Assert.assertEquals(1, check);
}
/** Tests LDL Cholesterol methods. */
@Test
public void testLDL() {
test.setLDL(1);
long check = test.getLDL();
Assert.assertEquals(1, check);
}
/** Tests Household Smoking Status methods. */
@Test
public void testHouseholdSmokingStatus() {
test.setHouseholdSmokingStatus(1);
long check = test.getHouseholdSmokingStatus();
Assert.assertEquals(1, check);
}
@Test
public void testHouseholdSmokingStatusDescription() {
final int HSS_ID = 1;
test.setHouseholdSmokingStatus(HSS_ID);
Assert.assertEquals(OfficeVisit.HouseholdSmokingStatus.NON_SMOKING_HOUSEHOLD, OfficeVisit.HouseholdSmokingStatus.valueOf("NON_SMOKING_HOUSEHOLD"));
Assert.assertEquals(HSS_ID + " - Non-Smoking Household", test.getHouseholdSmokingStatusDescription());
}
@Test
public void testHouseholdSmokingStatusDescriptionInvalidID() {
test.setHouseholdSmokingStatus(-1);
Assert.assertEquals("", test.getHouseholdSmokingStatusDescription());
}
@Test
public void testPatientSmokingStatusDescription() {
final int PSS_ID = 1;
test.setPatientSmokingStatus(PSS_ID);
Assert.assertEquals(OfficeVisit.PatientSmokingStatus.CURRENT_EVERY_DAY_SMOKER, OfficeVisit.PatientSmokingStatus.valueOf("CURRENT_EVERY_DAY_SMOKER"));
Assert.assertEquals(PSS_ID + " - Current Every Day Smoker", test.getPatientSmokingStatusDescription());
}
@Test
public void testPatientSmokingStatusDescriptionInvalidID() {
test.setPatientSmokingStatus(-1);
Assert.assertEquals("", test.getPatientSmokingStatusDescription());
}
/** Tests Patient Smoking Status methods. */
@Test
public void testPatientSmokingStatus() {
test.setPatientSmokingStatus(1);
long check = test.getPatientSmokingStatus();
Assert.assertEquals(1, check);
}
}
| 5,783
| 27.92
| 151
|
java
|
iTrust
|
iTrust-master/iTrust/src/test/java/edu/ncsu/csc/itrust/unit/model/officeVisit/OfficeVisitValidatorTest.java
|
package edu.ncsu.csc.itrust.unit.model.officeVisit;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.List;
import javax.sql.DataSource;
import org.junit.Assert;
import org.junit.Test;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.model.ConverterDAO;
import edu.ncsu.csc.itrust.model.apptType.ApptType;
import edu.ncsu.csc.itrust.model.apptType.ApptTypeData;
import edu.ncsu.csc.itrust.model.apptType.ApptTypeMySQLConverter;
import edu.ncsu.csc.itrust.model.hospital.Hospital;
import edu.ncsu.csc.itrust.model.hospital.HospitalData;
import edu.ncsu.csc.itrust.model.hospital.HospitalMySQLConverter;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisit;
import edu.ncsu.csc.itrust.model.officeVisit.OfficeVisitValidator;
import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
import junit.framework.TestCase;
public class OfficeVisitValidatorTest extends TestCase {
private ApptTypeData apptData;
private TestDataGenerator gen;
private DataSource ds;
private HospitalData hData;
private OfficeVisitValidator validator;
@Override
protected void setUp() throws Exception {
ds = ConverterDAO.getDataSource();
apptData = new ApptTypeMySQLConverter(ds);
hData = new HospitalMySQLConverter(ds);
gen = new TestDataGenerator();
validator = new OfficeVisitValidator(ds);
gen.clearAllTables();
}
@Test
public void testValidOfficeVisit() throws FileNotFoundException, IOException, SQLException, DBException{
gen.patient1();
gen.appointmentType();
OfficeVisit ov = new OfficeVisit();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ov.setApptTypeID(apptList.get(0).getID());
}
ov.setDate(LocalDateTime.now());
gen.hospitals();
List<Hospital> hList = hData.getAll();
ov.setLocationID(hList.get(hList.size()-1).getHospitalID());
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(1L);
try{
validator.validate(ov);
Assert.assertTrue(true);
}
catch(FormValidationException f){
Assert.fail("Should be no error!");
}
}
@Test
public void testInvalidMID() throws FileNotFoundException, IOException, SQLException, DBException{
gen.patient1();
gen.appointmentType();
OfficeVisit ov = new OfficeVisit();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ov.setApptTypeID(apptList.get(0).getID());
}
ov.setDate(LocalDateTime.now());
gen.hospitals();
List<Hospital> hList = hData.getAll();
ov.setLocationID(hList.get(hList.size()-1).getHospitalID());
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(9000000000L);
try{
validator.validate(ov);
Assert.fail("No error thrown");
}
catch(FormValidationException f){
Assert.assertTrue(true); //error thrown
}
}
public void testInvalidApptID() throws FileNotFoundException, IOException, SQLException, DBException{
OfficeVisit ov = new OfficeVisit();
ov.setApptTypeID(10L);
ov.setDate(LocalDateTime.now());
gen.patient1();
gen.hospitals();
List<Hospital> hList = hData.getAll();
ov.setLocationID(hList.get(hList.size()-1).getHospitalID());
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(1L);
try{
validator.validate(ov);
Assert.fail("No error thrown");
}
catch(FormValidationException f){
Assert.assertTrue(true); //error thrown
}
}
@Test
public void testSetInvalidHospital() throws FileNotFoundException, IOException, SQLException, DBException {
gen.clearAllTables();
gen.hospitals();
String hID = "-1";
gen.patient1();
gen.appointmentType();
OfficeVisit ov = new OfficeVisit();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ov.setApptTypeID(apptList.get(0).getID());
}
ov.setDate(LocalDateTime.now());
ov.setLocationID(hID);
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(1L);
try{
validator.validate(ov);
Assert.fail("No error thrown");
}
catch(FormValidationException f){
Assert.assertTrue(true); //error thrown
}
}
@Test
public void testSetNullMID() throws FileNotFoundException, IOException, SQLException, DBException{
gen.hospitals();
List<Hospital> hList = hData.getAll();
String hID = hList.get(hList.size()-1).getHospitalID();
gen.patient1();
gen.appointmentType();
OfficeVisit ov = new OfficeVisit();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ov.setApptTypeID(apptList.get(0).getID());
}
ov.setDate(LocalDateTime.now());
ov.setLocationID(hID);
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(null);
try{
validator.validate(ov);
Assert.fail("No error thrown");
}
catch(FormValidationException f){
Assert.assertTrue(true); //error thrown
}
}
public void testInvalidWeight() throws FileNotFoundException, IOException, SQLException, DBException{
OfficeVisit ov = new OfficeVisit();
ov.setDate(LocalDateTime.now());
gen.patient1();
gen.hospitals();
List<Hospital> hList = hData.getAll();
ov.setLocationID(hList.get(hList.size()-1).getHospitalID());
ov.setVisitID(1L);
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(1L);
gen.appointmentType();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ov.setApptTypeID(apptList.get(0).getID());
}
ov.setWeight(132.51F);
ov.setHouseholdSmokingStatus(1);
ov.setHeight(12.3F);
ov.setBloodPressure("140/90");
ov.setPatientSmokingStatus(1);
ov.setHDL(45);
ov.setTriglyceride(250);
ov.setLDL(300);
try{
validator.validate(ov);
Assert.fail("No error thrown");
}
catch(FormValidationException f){
Assert.assertTrue(true); //error thrown
}
}
public void testInvalidHeight() throws FileNotFoundException, IOException, SQLException, DBException{
OfficeVisit ov = new OfficeVisit();
ov.setDate(LocalDateTime.now());
gen.patient1();
gen.hospitals();
List<Hospital> hList = hData.getAll();
ov.setLocationID(hList.get(hList.size()-1).getHospitalID());
ov.setVisitID(1L);
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(1L);
gen.appointmentType();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ov.setApptTypeID(apptList.get(0).getID());
}
ov.setWeight(132.1F);
ov.setHouseholdSmokingStatus(1);
ov.setHeight(12.34F);
ov.setBloodPressure("140/90");
ov.setPatientSmokingStatus(1);
ov.setHDL(45);
ov.setTriglyceride(250);
ov.setLDL(300);
try{
validator.validate(ov);
Assert.fail("No error thrown");
}
catch(FormValidationException f){
Assert.assertTrue(true); //error thrown
}
}
public void testInvalidHSS() throws FileNotFoundException, IOException, SQLException, DBException{
OfficeVisit ov = new OfficeVisit();
ov.setDate(LocalDateTime.now());
gen.patient1();
gen.hospitals();
List<Hospital> hList = hData.getAll();
ov.setLocationID(hList.get(hList.size()-1).getHospitalID());
ov.setVisitID(1L);
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(1L);
gen.appointmentType();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ov.setApptTypeID(apptList.get(0).getID());
}
ov.setWeight(132.1F);
ov.setHouseholdSmokingStatus(-1);
ov.setHeight(12.3F);
ov.setBloodPressure("140/90");
ov.setPatientSmokingStatus(1);
ov.setHDL(45);
ov.setTriglyceride(250);
ov.setLDL(300);
try{
validator.validate(ov);
Assert.fail("No error thrown");
}
catch(FormValidationException f){
Assert.assertTrue(true); //error thrown
}
}
public void testInvalidPSS() throws FileNotFoundException, IOException, SQLException, DBException{
OfficeVisit ov = new OfficeVisit();
ov.setDate(LocalDateTime.now());
gen.patient1();
gen.hospitals();
List<Hospital> hList = hData.getAll();
ov.setLocationID(hList.get(hList.size()-1).getHospitalID());
ov.setVisitID(1L);
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(1L);
gen.appointmentType();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ov.setApptTypeID(apptList.get(0).getID());
}
ov.setWeight(132.1F);
ov.setHouseholdSmokingStatus(1);
ov.setHeight(12.3F);
ov.setBloodPressure("140/90");
ov.setPatientSmokingStatus(-1);
ov.setHDL(45);
ov.setTriglyceride(250);
ov.setLDL(300);
try{
validator.validate(ov);
Assert.fail("No error thrown");
}
catch(FormValidationException f){
Assert.assertTrue(true); //error thrown
}
}
public void testInvalidBloodPressure() throws FileNotFoundException, IOException, SQLException, DBException{
OfficeVisit ov = new OfficeVisit();
ov.setDate(LocalDateTime.now());
gen.patient1();
gen.hospitals();
List<Hospital> hList = hData.getAll();
ov.setLocationID(hList.get(hList.size()-1).getHospitalID());
ov.setVisitID(1L);
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(1L);
gen.appointmentType();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ov.setApptTypeID(apptList.get(0).getID());
}
ov.setWeight(132.1F);
ov.setHouseholdSmokingStatus(1);
ov.setHeight(12.3F);
ov.setBloodPressure("1400/90");
ov.setPatientSmokingStatus(1);
ov.setHDL(45);
ov.setTriglyceride(250);
ov.setLDL(300);
try{
validator.validate(ov);
Assert.fail("No error thrown");
}
catch(FormValidationException f){
Assert.assertTrue(true); //error thrown
}
}
public void testInvalidHDL() throws FileNotFoundException, IOException, SQLException, DBException{
OfficeVisit ov = new OfficeVisit();
ov.setDate(LocalDateTime.now());
gen.patient1();
gen.hospitals();
List<Hospital> hList = hData.getAll();
ov.setLocationID(hList.get(hList.size()-1).getHospitalID());
ov.setVisitID(1L);
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(1L);
gen.appointmentType();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ov.setApptTypeID(apptList.get(0).getID());
}
ov.setWeight(132.1F);
ov.setHouseholdSmokingStatus(1);
ov.setHeight(12.3F);
ov.setBloodPressure("140/90");
ov.setPatientSmokingStatus(1);
ov.setHDL(100);
ov.setTriglyceride(250);
ov.setLDL(300);
try{
validator.validate(ov);
Assert.fail("No error thrown");
}
catch(FormValidationException f){
Assert.assertTrue(true); //error thrown
}
}
public void testInvalidTriglyceride() throws FileNotFoundException, IOException, SQLException, DBException{
OfficeVisit ov = new OfficeVisit();
ov.setDate(LocalDateTime.now());
gen.patient1();
gen.hospitals();
List<Hospital> hList = hData.getAll();
ov.setLocationID(hList.get(hList.size()-1).getHospitalID());
ov.setVisitID(1L);
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(1L);
gen.appointmentType();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ov.setApptTypeID(apptList.get(0).getID());
}
ov.setWeight(132.1F);
ov.setHouseholdSmokingStatus(1);
ov.setHeight(12.3F);
ov.setBloodPressure("140/90");
ov.setPatientSmokingStatus(1);
ov.setHDL(45);
ov.setTriglyceride(90);
ov.setLDL(300);
try{
validator.validate(ov);
Assert.fail("No error thrown");
}
catch(FormValidationException f){
Assert.assertTrue(true); //error thrown
}
}
public void testInvalidLDL() throws FileNotFoundException, IOException, SQLException, DBException{
OfficeVisit ov = new OfficeVisit();
ov.setDate(LocalDateTime.now());
gen.patient1();
gen.hospitals();
List<Hospital> hList = hData.getAll();
ov.setLocationID(hList.get(hList.size()-1).getHospitalID());
ov.setVisitID(1L);
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(1L);
gen.appointmentType();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ov.setApptTypeID(apptList.get(0).getID());
}
ov.setWeight(132.1F);
ov.setHouseholdSmokingStatus(1);
ov.setHeight(12.3F);
ov.setBloodPressure("140/90");
ov.setPatientSmokingStatus(1);
ov.setHDL(45);
ov.setTriglyceride(250);
ov.setLDL(700);
try{
validator.validate(ov);
Assert.fail("No error thrown");
}
catch(FormValidationException f){
Assert.assertTrue(true); //error thrown
}
}
public void testValidChild() throws FileNotFoundException, IOException, SQLException, DBException{
OfficeVisit ov = new OfficeVisit();
ov.setDate(LocalDateTime.of(1956, Month.MAY, 10, 0, 0));
gen.patient1(); // b-day 1950
gen.hospitals();
List<Hospital> hList = hData.getAll();
ov.setLocationID(hList.get(hList.size()-1).getHospitalID());
ov.setVisitID(1L);
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(1L);
gen.appointmentType();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ov.setApptTypeID(apptList.get(0).getID());
}
ov.setWeight(132.1F);
ov.setHouseholdSmokingStatus(1);
ov.setHeight(12.3F);
ov.setBloodPressure("140/90");
ov.setPatientSmokingStatus(1);
ov.setHDL(45);
ov.setTriglyceride(250);
ov.setLDL(300);
try{
validator.validate(ov);
Assert.assertTrue(true);
}
catch(FormValidationException f){
Assert.fail("Should be no error!");
}
}
public void testInvalidLength() throws FileNotFoundException, IOException, SQLException, DBException{
OfficeVisit ov = new OfficeVisit();
ov.setDate(LocalDateTime.of(1952, Month.MAY, 10, 0, 0));
gen.patient1(); // b-day 1950
gen.hospitals();
List<Hospital> hList = hData.getAll();
ov.setLocationID(hList.get(hList.size()-1).getHospitalID());
ov.setVisitID(1L);
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(1L);
gen.appointmentType();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ov.setApptTypeID(apptList.get(0).getID());
}
ov.setWeight(132.1F);
ov.setHouseholdSmokingStatus(1);
ov.setLength(12.33F);
ov.setHeadCircumference(12.3F);
try{
validator.validate(ov);
Assert.fail("No error thrown");
}
catch(FormValidationException f){
Assert.assertTrue(true); //error thrown
}
}
public void testInvalidHeadCircumference() throws FileNotFoundException, IOException, SQLException, DBException{
OfficeVisit ov = new OfficeVisit();
ov.setDate(LocalDateTime.of(1952, Month.MAY, 10, 0, 0));
gen.patient1(); // b-day 1950
gen.hospitals();
List<Hospital> hList = hData.getAll();
ov.setLocationID(hList.get(hList.size()-1).getHospitalID());
ov.setVisitID(1L);
ov.setNotes("Hello World!");
ov.setSendBill(false);
ov.setPatientMID(1L);
gen.appointmentType();
List<ApptType> apptList = apptData.getAll();
if(apptList.size()>0){
ov.setApptTypeID(apptList.get(0).getID());
}
ov.setWeight(132.1F);
ov.setHouseholdSmokingStatus(1);
ov.setLength(12.3F);
ov.setHeadCircumference(12.33F);
try{
validator.validate(ov);
Assert.fail("No error thrown");
}
catch(FormValidationException f){
Assert.assertTrue(true); //error thrown
}
}
}
| 15,790
| 27.198214
| 114
|
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.