Search in sources :

Example 36 with OnDataSet

use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.

the class SyncIntegrationTest method updateMonthlyReports.

@Test
@OnDataSet("/dbunit/monthly-calc-indicators.db.xml")
public void updateMonthlyReports() throws SQLException, InterruptedException {
    synchronize();
    int siteId = 1;
    MonthlyReportResult result = executeLocally(new GetMonthlyReports(siteId, new Month(2009, 1), 5));
    IndicatorRowDTO women = result.getData().get(0);
    IndicatorRowDTO men = result.getData().get(1);
    assertThat(women.getIndicatorName(), equalTo("women"));
    assertThat(women.getIndicatorId(), equalTo(7002));
    assertThat(men.getIndicatorName(), equalTo("men"));
    assertThat(men.getActivityName(), equalTo("NFI"));
    assertThat(men.getActivityId(), equalTo(901));
    assertThat(men.getIndicatorId(), equalTo(7001));
    assertThat(men.getValue(2009, 1), CoreMatchers.equalTo(200d));
    assertThat(women.getValue(2009, 1), equalTo(300d));
    assertThat(men.getValue(2009, 2), equalTo(150d));
    assertThat(women.getValue(2009, 2), equalTo(330d));
    // Update locally
    executeLocally(new UpdateMonthlyReports(siteId, Lists.newArrayList(new Change(men.getIndicatorId(), new Month(2009, 1), 221d), new Change(men.getIndicatorId(), new Month(2009, 3), 444d), new Change(women.getIndicatorId(), new Month(2009, 5), 200d), new Change(men.getIndicatorId(), new Month(2009, 5), 522d))));
    result = executeLocally(new GetMonthlyReports(siteId, new Month(2009, 1), 12));
    women = result.getData().get(0);
    men = result.getData().get(1);
    assertThat(men.getValue(2009, 1), equalTo(221d));
    assertThat(women.getValue(2009, 1), equalTo(300d));
    // same - no change
    assertThat(men.getValue(2009, 2), equalTo(150d));
    assertThat(women.getValue(2009, 2), equalTo(330d));
    // new periods
    assertThat(men.getValue(2009, 3), equalTo(444d));
    assertThat(women.getValue(2009, 5), equalTo(200d));
    assertThat(men.getValue(2009, 5), equalTo(522d));
    // Synchronize
    synchronize();
    newRequest();
    MonthlyReportResult remoteResult = executeRemotely(new GetMonthlyReports(siteId, new Month(2009, 1), 12));
    women = remoteResult.getData().get(0);
    men = remoteResult.getData().get(1);
    assertThat(men.getValue(2009, 1), equalTo(221d));
    assertThat(women.getValue(2009, 1), equalTo(300d));
    // same - no change
    assertThat(men.getValue(2009, 2), equalTo(150d));
    assertThat(women.getValue(2009, 2), equalTo(330d));
    // new periods
    assertThat(men.getValue(2009, 3), equalTo(444d));
    assertThat(women.getValue(2009, 5), equalTo(200d));
    assertThat(men.getValue(2009, 5), equalTo(522d));
    newRequest();
    // REmote update
    executeRemotely(new UpdateMonthlyReports(siteId, Lists.newArrayList(new Change(men.getIndicatorId(), new Month(2009, 1), 40d), new Change(women.getIndicatorId(), new Month(2009, 3), 6000d))));
    newRequest();
    synchronize();
    result = executeLocally(new GetMonthlyReports(siteId, new Month(2009, 1), 5));
    women = result.getData().get(0);
    men = result.getData().get(1);
    assertThat(men.getValue(2009, 1), CoreMatchers.equalTo(40d));
    // unchanged
    assertThat(women.getValue(2009, 1), CoreMatchers.equalTo(300d));
    assertThat(women.getValue(2009, 3), equalTo(6000d));
}
Also used : Month(org.activityinfo.model.type.time.Month) Change(org.activityinfo.legacy.shared.command.UpdateMonthlyReports.Change) MonthlyReportResult(org.activityinfo.legacy.shared.command.result.MonthlyReportResult) IndicatorRowDTO(org.activityinfo.legacy.shared.model.IndicatorRowDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 37 with OnDataSet

use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.

the class SyncIntegrationTest method syncWithHugeLocationsCount.

// AI-864, create 50k locations and try to sync them
// Check response time (must be less than 5seconds)
@Test
// we don't want to kill our build time, please run it manually
@Ignore
@OnDataSet("/dbunit/sites-simple-with-unicode.db.xml")
public void syncWithHugeLocationsCount() throws SQLException, InterruptedException {
    final TestSqliteDatabase localDatabase = new TestSqliteDatabase("target/localdbtest" + new java.util.Date().getTime());
    // before sync, fill in db with locations
    int generatedLocationCount = 50000;
    final List<Integer> locationIds = addLocationsToServerDatabase(generatedLocationCount);
    Dispatcher remoteDispatcher = new RemoteDispatcherStub(servlet);
    Injector clientSideInjector = Guice.createInjector(new LocalModuleStub(AuthenticationModuleStub.getCurrentUser(), localDatabase, remoteDispatcher));
    final InstallPipeline installer = clientSideInjector.getInstance(InstallPipeline.class);
    // sync
    newRequest();
    installer.start();
    localDatabase.processEventQueue();
    int locationCountInDataSet = 7;
    assertThat(localDatabase.selectInt("select count(*) from Location"), equalTo(generatedLocationCount + locationCountInDataSet));
    assertThat(localDatabase.selectString("select Name from Location where LocationId=7"), equalTo("Shabunda"));
    assertThat(localDatabase.selectString(adminEntityBy(7, 1)), equalTo("3"));
    assertThat(localDatabase.selectString(adminEntityBy(7, 2)), equalTo("12"));
    // assert all locations are persisted
    for (Integer id : locationIds) {
        assertThat(localDatabase.selectInt("select LocationId from Location where LocationId=" + id), equalTo(id));
    }
}
Also used : TestSqliteDatabase(org.activityinfo.server.database.TestSqliteDatabase) InstallPipeline(org.activityinfo.ui.client.local.sync.pipeline.InstallPipeline) Date(java.util.Date) Injector(com.google.inject.Injector) Dispatcher(org.activityinfo.ui.client.dispatch.Dispatcher) LocalModuleStub(org.activityinfo.ui.client.local.LocalModuleStub) Ignore(org.junit.Ignore) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 38 with OnDataSet

use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.

the class UpdateUserPermissionsHandlerTest method testAuthorizedCreate.

/**
 * Verifies that a user with the manageUsers permission can add another user to the UserDatabase
 */
@Test
@OnDataSet("/dbunit/schema1.db.xml")
public void testAuthorizedCreate() throws CommandException {
    setUser(2);
    UserPermissionDTO user = new UserPermissionDTO();
    user.setEmail("ralph@lauren.com");
    user.setName("Ralph");
    user.setPartner(new PartnerDTO(1, "NRC"));
    user.setAllowView(true);
    user.setAllowEdit(true);
    UpdateUserPermissions cmd = new UpdateUserPermissions(1, user);
    execute(cmd);
    UserResult result = execute(new GetUsers(1));
    assertThat(result.getTotalLength(), equalTo(1));
    UserPermissionDTO ralph = result.getData().get(0);
    assertThat(ralph.getEmail(), equalTo("ralph@lauren.com"));
    assertThat(ralph.getAllowEdit(), equalTo(true));
    assertThat(ralph.hasFolderLimitation(), equalTo(false));
}
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 39 with OnDataSet

use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.

the class UpdateUserPermissionsHandlerTest method testFolderLevelUpdate.

@Test
@OnDataSet("/dbunit/schema3.db.xml")
public void testFolderLevelUpdate() {
    setUser(1);
    UserPermissionDTO newUser = new UserPermissionDTO();
    newUser.setName("Bavon");
    newUser.setEmail("bavon@nrcdrc.org");
    newUser.setPartner(new PartnerDTO(1, "NRC"));
    newUser.setAllowView(true);
    newUser.setAllowViewAll(false);
    newUser.setAllowEdit(true);
    newUser.setAllowEdit(false);
    newUser.setAllowDesign(true);
    FolderDTO health = new FolderDTO();
    health.setId(3);
    newUser.setFolders(Arrays.asList(health));
    newUser.setFolderLimitation(true);
    execute(new UpdateUserPermissions(1, newUser));
    UserResult users = execute(new GetUsers(1));
    UserPermissionDTO bavon = users.getData().get(0);
    assertThat(bavon.hasFolderLimitation(), equalTo(true));
}
Also used : FolderDTO(org.activityinfo.legacy.shared.model.FolderDTO) 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 40 with OnDataSet

use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.

the class LocationBuilderTest method sqlBuilding.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void sqlBuilding() throws Exception {
    EntityManager em = emf.createEntityManager();
    int locationType = 3;
    GetSyncRegionUpdates request = new GetSyncRegionUpdates("location/" + locationType, null);
    LocationUpdateBuilder builder = new LocationUpdateBuilder(em);
    SyncRegionUpdate update = builder.build(new User(), request);
    System.out.println("sql: " + update.getSql());
    System.out.println("size: " + update.getSql().length());
    assertThat(update.getSql(), containsString("location"));
    assertThat(update.getSql(), containsString("locationadminlink"));
    assertThat(update.getSql(), containsString("Shabunda"));
    // admin level for Shabunda
    assertThat(update.getSql(), containsString("12,7"));
}
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)

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