use of de.symeda.sormas.app.rest.ServerCommunicationException in project SORMAS-Project by hzi-braunschweig.
the class RegionBackendTest method testHandlePulledList.
@Test
public void testHandlePulledList() {
long startRegionCount = DatabaseHelper.getRegionDao().countOf();
List<RegionDto> regions = new ArrayList<>();
RegionDto region1 = RegionDto.build();
region1.setCreationDate(new Date());
region1.setChangeDate(new Date());
region1.setName("TestA");
regions.add(region1);
RegionDto region2 = RegionDto.build();
region2.setCreationDate(new Date());
region2.setChangeDate(new Date());
region2.setName("TestB");
regions.add(region2);
// this should cause a roll-back
region2.setUuid(null);
boolean hadException = false;
try {
new RegionDtoHelper().handlePulledList(DatabaseHelper.getRegionDao(), regions);
} catch (DaoException | NoConnectionException | ServerConnectionException | ServerCommunicationException e) {
hadException = true;
}
assertTrue(hadException);
long regionCount = DatabaseHelper.getRegionDao().countOf();
assertEquals(startRegionCount, regionCount);
// now it should work
region2.setUuid(DataHelper.createUuid());
hadException = false;
try {
new RegionDtoHelper().handlePulledList(DatabaseHelper.getRegionDao(), regions);
} catch (DaoException | NoConnectionException | ServerConnectionException | ServerCommunicationException e) {
hadException = true;
}
assertFalse(hadException);
regionCount = DatabaseHelper.getRegionDao().countOf();
assertEquals(startRegionCount + 2, regionCount);
}
Aggregations