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));
}
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));
}
}
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));
}
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));
}
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"));
}
Aggregations