Search in sources :

Example 11 with OnDataSet

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

Example 12 with OnDataSet

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

Example 13 with OnDataSet

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

Example 14 with OnDataSet

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"));
}
Also used : JsonArray(com.google.gson.JsonArray) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestSqliteDatabase(org.activityinfo.server.database.TestSqliteDatabase) InstallPipeline(org.activityinfo.ui.client.local.sync.pipeline.InstallPipeline) Injector(com.google.inject.Injector) Dispatcher(org.activityinfo.ui.client.dispatch.Dispatcher) LocalModuleStub(org.activityinfo.ui.client.local.LocalModuleStub) JsonParser(com.google.gson.JsonParser) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 15 with OnDataSet

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));
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) Date(java.util.Date) 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