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