use of de.symeda.sormas.app.backend.sample.Sample in project SORMAS-Project by hzi-braunschweig.
the class AbstractAdoDaoTest method testQueryForNew.
@Test
public void testQueryForNew() throws DaoException {
CaseDao caseDao = DatabaseHelper.getCaseDao();
// Case with change date 0 should be included
Case caseChangeDate0 = TestEntityCreator.createCase();
List<Case> newCases = caseDao.queryForNew();
assertEquals(1, newCases.size());
// Case with newer change date should not be included
Case caseNewChangeDate = TestEntityCreator.createCase();
caseNewChangeDate.setChangeDate(new Date());
caseDao.saveAndSnapshot(caseNewChangeDate);
newCases = caseDao.queryForNew();
assertEquals(1, newCases.size());
// Additional tests for other entities
Contact contact = TestEntityCreator.createContact(caseChangeDate0);
Visit visit = TestEntityCreator.createVisit(contact);
Sample sample = TestEntityCreator.createSample(caseChangeDate0);
Event event = TestEntityCreator.createEvent();
EventParticipant eventParticipant = TestEntityCreator.createEventParticipant(event);
assertEquals(1, DatabaseHelper.getContactDao().queryForNew().size());
assertEquals(1, DatabaseHelper.getVisitDao().queryForNew().size());
assertEquals(1, DatabaseHelper.getSampleDao().queryForNew().size());
assertEquals(1, DatabaseHelper.getEventDao().queryForNew().size());
assertEquals(1, DatabaseHelper.getEventParticipantDao().queryForNew().size());
}
use of de.symeda.sormas.app.backend.sample.Sample in project SORMAS-Project by hzi-braunschweig.
the class TestEntityCreator method createSample.
public static Sample createSample(Case caze) {
if (caze == null) {
caze = createCase();
}
Date sampleDateTime = DateHelper.subtractDays(new Date(), 1);
Facility lab = DatabaseHelper.getFacilityDao().queryForAll().get(0);
SampleMaterial material = SampleMaterial.BLOOD;
Sample sample = DatabaseHelper.getSampleDao().build(caze);
sample.setSampleDateTime(sampleDateTime);
sample.setLab(lab);
sample.setSampleMaterial(material);
try {
DatabaseHelper.getSampleDao().saveAndSnapshot(sample);
DatabaseHelper.getSampleDao().accept(sample);
} catch (DaoException e) {
throw new RuntimeException(e);
}
return DatabaseHelper.getSampleDao().queryForIdWithEmbedded(sample.getId());
}
use of de.symeda.sormas.app.backend.sample.Sample in project SORMAS-Project by hzi-braunschweig.
the class SampleBackendTest method shouldMergeSamplesAsExpected.
@Test
public void shouldMergeSamplesAsExpected() throws DaoException {
Sample sample = TestEntityCreator.createSample(null);
PathogenTest pathogenTest = TestEntityCreator.createSampleTest(sample);
sample.setComment("AppSampleComment");
pathogenTest.setTestResult(PathogenTestResultType.NEGATIVE);
DatabaseHelper.getSampleDao().saveAndSnapshot(sample);
DatabaseHelper.getSampleDao().accept(sample);
DatabaseHelper.getSampleTestDao().saveAndSnapshot(pathogenTest);
DatabaseHelper.getSampleTestDao().accept(pathogenTest);
Sample mergeSample = (Sample) sample.clone();
mergeSample.setAssociatedCase((Case) sample.getAssociatedCase().clone());
mergeSample.setId(null);
mergeSample.setComment("ServerSampleComment");
PathogenTest mergePathogenTest = (PathogenTest) pathogenTest.clone();
mergePathogenTest.setId(null);
mergePathogenTest.setTestResult(PathogenTestResultType.POSITIVE);
DatabaseHelper.getSampleDao().mergeOrCreate(mergeSample);
DatabaseHelper.getSampleTestDao().mergeOrCreate(mergePathogenTest);
Sample updatedSample = DatabaseHelper.getSampleDao().queryUuid(sample.getUuid());
assertThat(updatedSample.getComment(), is("ServerSampleComment"));
PathogenTest updatedPathogenTest = DatabaseHelper.getSampleTestDao().queryUuid(pathogenTest.getUuid());
assertThat(updatedPathogenTest.getTestResult(), is(PathogenTestResultType.POSITIVE));
}
use of de.symeda.sormas.app.backend.sample.Sample in project SORMAS-Project by hzi-braunschweig.
the class SampleBackendTest method shouldCreateSampleTest.
@Test
public void shouldCreateSampleTest() {
assertThat(DatabaseHelper.getSampleTestDao().queryForAll().size(), is(0));
Sample sample = TestEntityCreator.createSample(null);
TestEntityCreator.createSampleTest(sample);
assertThat(DatabaseHelper.getSampleTestDao().queryForAll().size(), is(1));
}
use of de.symeda.sormas.app.backend.sample.Sample in project SORMAS-Project by hzi-braunschweig.
the class CaseBackendTest method shouldDeleteWithDependingEntities.
@Test
public void shouldDeleteWithDependingEntities() throws DaoException, SQLException {
// Assure that there are no cases or depending entities in the app to start with
assertThat(DatabaseHelper.getCaseDao().queryForAll().size(), is(0));
assertThat(DatabaseHelper.getContactDao().queryForAll().size(), is(0));
assertThat(DatabaseHelper.getVisitDao().queryForAll().size(), is(0));
assertThat(DatabaseHelper.getSampleDao().queryForAll().size(), is(0));
assertThat(DatabaseHelper.getSampleTestDao().queryForAll().size(), is(0));
assertThat(DatabaseHelper.getTaskDao().queryForAll().size(), is(0));
Case caze = TestEntityCreator.createCase();
Contact contact = TestEntityCreator.createContact(caze);
TestEntityCreator.createVisit(contact);
Sample sample = TestEntityCreator.createSample(caze);
TestEntityCreator.createSampleTest(sample);
TestEntityCreator.createCaseTask(caze, TaskStatus.PENDING, caze.getReportingUser());
// Assure that the case and depending entities have been successfully created
assertThat(DatabaseHelper.getCaseDao().queryForAll().size(), is(1));
assertThat(DatabaseHelper.getContactDao().queryForAll().size(), is(1));
assertThat(DatabaseHelper.getVisitDao().queryForAll().size(), is(1));
assertThat(DatabaseHelper.getSampleDao().queryForAll().size(), is(1));
assertThat(DatabaseHelper.getSampleTestDao().queryForAll().size(), is(1));
assertThat(DatabaseHelper.getTaskDao().queryForAll().size(), is(1));
DatabaseHelper.getCaseDao().deleteCaseAndAllDependingEntities(caze.getUuid());
// Assure that there are no cases or depending entities in the app after the deletion
assertThat(DatabaseHelper.getCaseDao().queryForAll().size(), is(0));
assertThat(DatabaseHelper.getContactDao().queryForAll().size(), is(0));
assertThat(DatabaseHelper.getVisitDao().queryForAll().size(), is(0));
assertThat(DatabaseHelper.getSampleDao().queryForAll().size(), is(0));
assertThat(DatabaseHelper.getSampleTestDao().queryForAll().size(), is(0));
assertThat(DatabaseHelper.getTaskDao().queryForAll().size(), is(0));
}
Aggregations