use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.
the class GetPartnersDimensionHandlerTest method testIndicatorLinked1.
@Test
@OnDataSet("/dbunit/sites-linked.db.xml")
public void testIndicatorLinked1() throws CommandException {
// NRC, NRC2
PartnerResult result = execute(DimensionType.Indicator, 1);
assertThat(result.getData().size(), equalTo(2));
assertThat(result.getData().get(0).getName(), equalTo("NRC"));
assertThat(result.getData().get(1).getName(), equalTo("NRC2"));
}
use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.
the class GetPartnersDimensionHandlerTest method testIndicatorLinked100.
@Test
@OnDataSet("/dbunit/sites-linked.db.xml")
public void testIndicatorLinked100() throws CommandException {
// empty
PartnerResult result = execute(DimensionType.Indicator, 100);
assertThat(result.getData().size(), equalTo(0));
}
use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.
the class GetPartnersDimensionHandlerTest method testEmptyFilter.
// empty
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void testEmptyFilter() throws CommandException {
PartnerResult result = this.execute();
assertThat(result.getData().size(), equalTo(0));
}
use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.
the class SyncIntegrationTest method failResume.
// AI-864 : we know that
// 1) on customer side location is present but locationadminlink entry is absent.
// 2) location and locationadminlink are updated with single SyncRegion
// Conclusion: the only possible bug is that location was updated but locationadminlink failed to update
// due to some weird problem (network connection failure)
// Test: in this test we will try to emulate connection failure
@Test
@OnDataSet("/dbunit/sites-simple-with-unicode.db.xml")
public void failResume() throws SQLException, InterruptedException {
String databaseName = TestOutput.getFile(getClass(), ".sqlite").getAbsolutePath();
final AtomicBoolean forceFail = new AtomicBoolean(true);
final TestSqliteDatabase localDatabase = new TestSqliteDatabase(databaseName) {
@Override
public String adjustExecuteUpdates(String json) {
JsonParser parser = new JsonParser();
JsonArray list = parser.parse(json).getAsJsonArray();
// ugly : better way to identify when to fail ?
if (list.size() == 2 && json.contains("location") && json.contains("locationadminlink") && forceFail.get()) {
forceFail.set(false);
throw new RuntimeException("Forced to fail locationadminlink update");
}
return json;
}
};
Dispatcher remoteDispatcher = new RemoteDispatcherStub(servlet);
Injector clientSideInjector = Guice.createInjector(new LocalModuleStub(AuthenticationModuleStub.getCurrentUser(), localDatabase, remoteDispatcher));
final InstallPipeline installer = clientSideInjector.getInstance(InstallPipeline.class);
// sync with failure
newRequest();
installer.start();
localDatabase.processEventQueue();
// try again (now without failure)
JdbcScheduler.get().forceCleanup();
newRequest();
installer.start();
localDatabase.processEventQueue();
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"));
}
use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.
the class SyncIntegrationTest method run.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void run() throws SQLException, InterruptedException {
synchronize();
Collector<Date> lastUpdate = Collector.newCollector();
syncHistoryTable.get(lastUpdate);
assertThat(lastUpdate.getResult(), is(not(nullValue())));
assertThat(queryString("select Name from Indicator where IndicatorId=103"), equalTo("Nb. of distributions"));
assertThat(queryString("select Name from AdminLevel where AdminLevelId=1"), equalTo("Province"));
assertThat(queryString("select Name from AdminEntity where AdminEntityId=21"), equalTo("Irumu"));
assertThat(queryString("select Name from Location where LocationId=7"), equalTo("Shabunda"));
assertThat(queryInt("select value from IndicatorValue where ReportingPeriodId=601 and IndicatorId=6"), equalTo(35));
assertThat(queryInt("select PartnerId from partnerInDatabase where databaseid=2"), equalTo(1));
assertThat(queryInt("select AttributeGroupId from AttributeGroupInActivity where ActivityId=2"), equalTo(1));
assertThat(queryInt("select count(*) from LockedPeriod"), equalTo(4));
assertThat(queryInt("select count(*) from LockedPeriod where ProjectId is not null"), equalTo(1));
assertThat(queryInt("select count(*) from LockedPeriod where ActivityId is not null"), equalTo(1));
assertThat(queryInt("select count(*) from LockedPeriod where ProjectId is null and ActivityId is null"), equalTo(2));
// / now try updating a site remotely (from another client)
// and veryify that we get the update after we synchronized
Thread.sleep(1000);
SiteDTO s1 = executeLocally(GetSites.byId(1)).getData().get(0);
assertThat((Double) s1.getIndicatorValue(1), equalTo(1500d));
Map<String, Object> changes = Maps.newHashMap();
changes.put(AttributeDTO.getPropertyName(1), true);
changes.put("comments", "newComments");
executeRemotely(new UpdateSite(1, changes));
synchronize();
s1 = executeLocally(GetSites.byId(1)).getData().get(0);
assertThat(s1.getAttributeValue(1), equalTo(true));
assertThat(s1.getAttributeValue(2), equalTo(false));
assertThat(s1.getComments(), equalTo("newComments"));
// old values are preserved...
assertThat(s1.getIndicatorDoubleValue(1), equalTo(1500d));
// Try deleting a site
executeRemotely(new Delete("Site", 1));
synchronize();
SiteResult siteResult = executeLocally(GetSites.byId(1));
assertThat(siteResult.getData().size(), equalTo(0));
// Verify that we haven't toasted the other data
SiteDTO site = executeLocally(GetSites.byId(3)).getData().get(0);
assertThat(site.getIndicatorDoubleValue(1), equalTo(10000d));
}
Aggregations