Search in sources :

Example 1 with Delete

use of org.activityinfo.shared.command.Delete in project activityinfo by bedatadriven.

the class DesignTest method testDelete.

@Test
public void testDelete() {
    // Dummy Data
    SchemaDTO schema = DTOs.pear();
    // Collaborator
    DispatcherStub service = new DispatcherStub();
    service.setResult(GetSchema.class, schema);
    service.setResult(Delete.class, new VoidResult());
    // Collaborator
    DesignPresenter.View view = createNiceMock(DesignPresenter.View.class);
    expect(view.getSelection()).andReturn(schema.getActivityById(91));
    view.confirmDeleteSelected(isA(ConfirmCallback.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            ((ConfirmCallback) getCurrentArguments()[0]).confirmed();
            return null;
        }
    });
    replay(view);
    // Collaborator
    UIConstants constants = createNiceMock(UIConstants.class);
    replay(constants);
    DesignPresenter designer = new DesignPresenter(new MockEventBus(), service, new StateManagerStub(), view, constants);
    designer.go(schema.getDatabaseById(1));
    // Verify that the proper delete command executes
    designer.onUIAction(UIActions.DELETE);
    Delete cmd = service.getLastExecuted(Delete.class);
    Assert.assertEquals("Activity", cmd.getEntityName());
    Assert.assertEquals(91, cmd.getId());
}
Also used : Delete(org.activityinfo.shared.command.Delete) ConfirmCallback(org.activityinfo.client.page.common.grid.ConfirmCallback) VoidResult(org.activityinfo.shared.command.result.VoidResult) DispatcherStub(org.activityinfo.client.dispatch.DispatcherStub) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) MockEventBus(org.activityinfo.client.MockEventBus) UIConstants(org.activityinfo.client.i18n.UIConstants) StateManagerStub(org.activityinfo.client.mock.StateManagerStub) Test(org.junit.Test)

Example 2 with Delete

use of org.activityinfo.shared.command.Delete in project activityinfo by bedatadriven.

the class DeleteTest method testDeleteIndicator.

@Test
public void testDeleteIndicator() throws CommandException {
    SchemaDTO schema = execute(new GetSchema());
    execute(new Delete(schema.getIndicatorById(1)));
    schema = execute(new GetSchema());
    Assert.assertNull(schema.getIndicatorById(1));
    PagingResult<SiteDTO> sites = execute(GetSites.byId(1));
    Assert.assertNull(sites.getData().get(0).getIndicatorValue(1));
}
Also used : Delete(org.activityinfo.shared.command.Delete) SiteDTO(org.activityinfo.shared.dto.SiteDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 3 with Delete

use of org.activityinfo.shared.command.Delete in project activityinfo by bedatadriven.

the class SyncIntegrationTest method run.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void run() throws SQLException, InterruptedException {
    synchronizeFirstTime();
    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 UserDatabaseId is not 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(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.getIndicatorValue(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.getIndicatorValue(1), equalTo(10000d));
}
Also used : Delete(org.activityinfo.shared.command.Delete) SiteResult(org.activityinfo.shared.command.result.SiteResult) SiteDTO(org.activityinfo.shared.dto.SiteDTO) UpdateSite(org.activityinfo.shared.command.UpdateSite) Date(java.util.Date) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 4 with Delete

use of org.activityinfo.shared.command.Delete in project activityinfo by bedatadriven.

the class TargetTest method deleteTargetTest.

@Test
public void deleteTargetTest() {
    TargetDTO target = createTarget();
    CreateResult cresult = execute(new AddTarget(db.getId(), target));
    int newId = cresult.getNewId();
    /*
         * Load Targets to verify the changes have stuck
         */
    List<TargetDTO> targets = execute(new GetTargets(db.getId())).getData();
    TargetDTO dto = getTargetById(targets, newId);
    Assert.assertEquals("name", "Target0071", dto.getName());
    /*
         * Delete new target now
         */
    execute(new Delete(dto));
    /*
         * Verify if target is deleted.
         */
    targets = execute(new GetTargets()).getData();
    TargetDTO deleted = getTargetById(targets, newId);
    Assert.assertNull(deleted);
}
Also used : Delete(org.activityinfo.shared.command.Delete) GetTargets(org.activityinfo.shared.command.GetTargets) CreateResult(org.activityinfo.shared.command.result.CreateResult) AddTarget(org.activityinfo.shared.command.AddTarget) TargetDTO(org.activityinfo.shared.dto.TargetDTO) Test(org.junit.Test)

Example 5 with Delete

use of org.activityinfo.shared.command.Delete in project activityinfo by bedatadriven.

the class LockedPeriodsPresenter method onConfirmDelete.

@Override
public void onConfirmDelete(ConfirmDeleteEvent deleteEvent) {
    final LockedPeriodDTO lockedPeriod = view.getValue();
    service.execute(new Delete(lockedPeriod), new AsyncCallback<VoidResult>() {

        @Override
        public void onFailure(Throwable caught) {
            MessageBox.alert(I18N.CONSTANTS.error(), I18N.CONSTANTS.errorOnServer() + "\n\n" + caught.getMessage(), null);
        }

        @Override
        public void onSuccess(VoidResult result) {
            view.delete(lockedPeriod);
            parentModel.getLockedPeriods().remove(lockedPeriod);
        }
    });
}
Also used : Delete(org.activityinfo.shared.command.Delete) VoidResult(org.activityinfo.shared.command.result.VoidResult) LockedPeriodDTO(org.activityinfo.shared.dto.LockedPeriodDTO)

Aggregations

Delete (org.activityinfo.shared.command.Delete)9 Test (org.junit.Test)8 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)5 GetSchema (org.activityinfo.shared.command.GetSchema)4 SiteDTO (org.activityinfo.shared.dto.SiteDTO)3 VoidResult (org.activityinfo.shared.command.result.VoidResult)2 Date (java.util.Date)1 MockEventBus (org.activityinfo.client.MockEventBus)1 DispatcherStub (org.activityinfo.client.dispatch.DispatcherStub)1 UIConstants (org.activityinfo.client.i18n.UIConstants)1 StateManagerStub (org.activityinfo.client.mock.StateManagerStub)1 ConfirmCallback (org.activityinfo.client.page.common.grid.ConfirmCallback)1 OnDataSet (org.activityinfo.server.database.OnDataSet)1 AddTarget (org.activityinfo.shared.command.AddTarget)1 GetSites (org.activityinfo.shared.command.GetSites)1 GetTargets (org.activityinfo.shared.command.GetTargets)1 UpdateSite (org.activityinfo.shared.command.UpdateSite)1 CreateResult (org.activityinfo.shared.command.result.CreateResult)1 SiteResult (org.activityinfo.shared.command.result.SiteResult)1 LockedPeriodDTO (org.activityinfo.shared.dto.LockedPeriodDTO)1