use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.
the class SyncIntegrationTest method locationsAreChunked.
@Test
@OnDataSet("/dbunit/locations.db.xml")
public void locationsAreChunked() throws SQLException, InterruptedException {
addLocationsToServerDatabase(220);
synchronize();
assertThat(Integer.valueOf(queryString("select count(*) from Location")), equalTo(221));
// update a location on the server
serverEm.getTransaction().begin();
Location location = (Location) serverEm.createQuery("select l from Location l where l.name = 'Penekusu 26'").getSingleResult();
location.setAxe("Motown");
location.setVersion(location.getLocationType().incrementVersion());
serverEm.getTransaction().commit();
newRequest();
synchronize();
assertThat(queryInt("select count(*) from Location where Name='Penekusu 26'"), equalTo(1));
assertThat(queryString("select axe from Location where Name='Penekusu 26'"), equalTo("Motown"));
// now create a new location
Location newLocation = new Location();
int locationId = keyGenerator.generateInt();
newLocation.setName("Bukavu");
newLocation.setId(123456789);
newLocation.setLocationType(serverEm.find(LocationType.class, 1));
newLocation.setVersion(newLocation.getLocationType().incrementVersion());
newLocation.setId(locationId);
serverEm.getTransaction().begin();
serverEm.persist(newLocation);
serverEm.getTransaction().commit();
newRequest();
synchronize();
assertThat(queryString("select name from Location where LocationId = " + locationId), equalTo("Bukavu"));
}
use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.
the class UpdateUserPermissionsHandlerTest method testOwnerUpdate.
/**
* Verifies that the owner of a database can update an existing users permission
*/
@Test
@OnDataSet("/dbunit/schema1.db.xml")
public void testOwnerUpdate() throws CommandException {
setUser(1);
UserPermissionDTO user = new UserPermissionDTO();
user.setEmail("bavon@nrcdrc.org");
user.setPartner(new PartnerDTO(1, "NRC"));
user.setAllowView(true);
user.setAllowViewAll(false);
user.setAllowEdit(true);
user.setAllowEdit(false);
user.setAllowDesign(true);
execute(new UpdateUserPermissions(1, user));
UserResult result = execute(new GetUsers(1));
UserPermissionDTO reUser = result.getData().get(0);
assertThat(reUser.getEmail(), equalTo("bavon@nrcdrc.org"));
assertThat(reUser.getAllowDesign(), equalTo(true));
}
use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.
the class LocationBuilderTest method cutting.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void cutting() throws Exception {
EntityManager em = emf.createEntityManager();
int chunkSize = 2;
LocationUpdateBuilder builder = new LocationUpdateBuilder(em, chunkSize);
GetSyncRegionUpdates request = new GetSyncRegionUpdates("location/" + 1, null);
SyncRegionUpdate update = builder.build(new User(), request);
assertThat(update.isComplete(), equalTo(false));
// first chunk
assertThat(update.getVersion(), equalTo("2"));
assertThat(update.getSql(), containsString("Ngshwe"));
request.setLocalVersion(update.getVersion());
update = builder.build(new User(), request);
assertThat(update.isComplete(), equalTo(true));
// second chunk
assertThat(update.getVersion(), equalTo("3"));
assertThat(update.getSql(), containsString("Boga"));
}
use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.
the class GetSitesTest method duplicated.
@Test
@OnDataSet("/dbunit/sites-linked.db.xml")
public void duplicated() {
// A given site can be appear multiple times in the list if it is the
// source
// of one or more indicators
setUser(1);
GetSites cmd = new GetSites();
SiteResult result = execute(cmd);
assertThat(result.getData().size(), equalTo(3));
}
use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.
the class GetSitesTest method testAdminEntitySort.
@Test
@OnDataSet("/dbunit/sites-public.db.xml")
public void testAdminEntitySort() throws CommandException {
setUser(DATABASE_OWNER);
// level 1 - DESC
GetSites cmd = new GetSites();
cmd.filter().onActivity(1);
cmd.setSortInfo(new SortInfo("E1", SortDir.DESC));
PagingLoadResult<SiteDTO> result = execute(cmd);
assertThat("sorted", adminName(result, 0, "E1"), equalTo("Sud Kivu"));
assertThat("sorted", adminName(result, 1, "E1"), equalTo("Sud Kivu"));
assertThat("sorted", adminName(result, 2, "E1"), equalTo("Ituri"));
// level 1 - ASC
cmd = new GetSites();
cmd.filter().onActivity(1);
cmd.setSortInfo(new SortInfo("E1", SortDir.ASC));
result = execute(cmd);
assertThat("sorted", adminName(result, 0, "E1"), equalTo("Ituri"));
assertThat("sorted", adminName(result, 1, "E1"), equalTo("Sud Kivu"));
assertThat("sorted", adminName(result, 2, "E1"), equalTo("Sud Kivu"));
// level 2 - DESC
cmd = new GetSites();
cmd.filter().onActivity(1);
cmd.setSortInfo(new SortInfo("E2", SortDir.DESC));
result = execute(cmd);
assertThat("sorted", adminName(result, 0, "E2"), equalTo("Walungu"));
assertThat("sorted", adminName(result, 1, "E2"), equalTo("Shabunda"));
assertThat("sorted", adminName(result, 2, "E2"), equalTo("Irumu"));
// level 2 - ASC
cmd = new GetSites();
cmd.filter().onActivity(1);
cmd.setSortInfo(new SortInfo("E2", SortDir.ASC));
result = execute(cmd);
assertThat("sorted", adminName(result, 0, "E2"), equalTo("Irumu"));
assertThat("sorted", adminName(result, 1, "E2"), equalTo("Shabunda"));
assertThat("sorted", adminName(result, 2, "E2"), equalTo("Walungu"));
}
Aggregations