Search in sources :

Example 16 with OnDataSet

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"));
}
Also used : LocationType(org.activityinfo.server.database.hibernate.entity.LocationType) Location(org.activityinfo.server.database.hibernate.entity.Location) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 17 with OnDataSet

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));
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) UpdateUserPermissions(org.activityinfo.legacy.shared.command.UpdateUserPermissions) UserResult(org.activityinfo.legacy.shared.command.result.UserResult) GetUsers(org.activityinfo.legacy.shared.command.GetUsers) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 18 with OnDataSet

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"));
}
Also used : GetSyncRegionUpdates(org.activityinfo.legacy.shared.command.GetSyncRegionUpdates) EntityManager(javax.persistence.EntityManager) User(org.activityinfo.server.database.hibernate.entity.User) SyncRegionUpdate(org.activityinfo.legacy.shared.command.result.SyncRegionUpdate) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 19 with OnDataSet

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));
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) GetSites(org.activityinfo.legacy.shared.command.GetSites) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 20 with OnDataSet

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"));
}
Also used : GetSites(org.activityinfo.legacy.shared.command.GetSites) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Aggregations

OnDataSet (org.activityinfo.server.database.OnDataSet)48 Test (org.junit.Test)46 PartnerResult (org.activityinfo.legacy.shared.command.result.PartnerResult)9 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)8 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)6 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)6 EntityManager (javax.persistence.EntityManager)5 GetSites (org.activityinfo.legacy.shared.command.GetSites)5 FormInstance (org.activityinfo.model.form.FormInstance)5 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)4 Date (java.util.Date)4 Response (javax.ws.rs.core.Response)4 GetSyncRegionUpdates (org.activityinfo.legacy.shared.command.GetSyncRegionUpdates)4 SyncRegionUpdate (org.activityinfo.legacy.shared.command.result.SyncRegionUpdate)4 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)4 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)4 ResourceId (org.activityinfo.model.resource.ResourceId)4 LocalDate (org.activityinfo.model.type.time.LocalDate)4 GetUsers (org.activityinfo.legacy.shared.command.GetUsers)3 UpdateUserPermissions (org.activityinfo.legacy.shared.command.UpdateUserPermissions)3