Search in sources :

Example 6 with ServerCommunicationException

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);
}
Also used : ServerCommunicationException(de.symeda.sormas.app.rest.ServerCommunicationException) RegionDtoHelper(de.symeda.sormas.app.backend.region.RegionDtoHelper) NoConnectionException(de.symeda.sormas.app.rest.NoConnectionException) ServerConnectionException(de.symeda.sormas.app.rest.ServerConnectionException) ArrayList(java.util.ArrayList) RegionDto(de.symeda.sormas.api.infrastructure.region.RegionDto) DaoException(de.symeda.sormas.app.backend.common.DaoException) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ServerCommunicationException (de.symeda.sormas.app.rest.ServerCommunicationException)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Date (java.util.Date)3 NoConnectionException (de.symeda.sormas.app.rest.NoConnectionException)2 ServerConnectionException (de.symeda.sormas.app.rest.ServerConnectionException)2 PushResult (de.symeda.sormas.api.PushResult)1 FacilityDto (de.symeda.sormas.api.infrastructure.facility.FacilityDto)1 RegionDto (de.symeda.sormas.api.infrastructure.region.RegionDto)1 DaoException (de.symeda.sormas.app.backend.common.DaoException)1 Region (de.symeda.sormas.app.backend.region.Region)1 RegionDtoHelper (de.symeda.sormas.app.backend.region.RegionDtoHelper)1 SQLException (java.sql.SQLException)1 Test (org.junit.Test)1 Call (retrofit2.Call)1