use of org.activityinfo.legacy.shared.command.UpdateSite in project activityinfo by bedatadriven.
the class CreateSiteTest method testSiteWithCalculatedIndicators.
@OnDataSet("/dbunit/sites-calculated-indicators.db.xml")
@Test
public void testSiteWithCalculatedIndicators() throws CommandException {
// create a new detached, client model
SiteDTO newSite = new SiteDTO();
newSite.setId(new KeyGenerator().generateInt());
newSite.setActivityId(1);
newSite.setLocationId(1);
newSite.setPartner(new PartnerDTO(1, "Foobar"));
newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
newSite.setLocationName("Virunga");
newSite.setProject(new ProjectDTO(1, "SomeProject"));
newSite.setReportingPeriodId(11);
newSite.setIndicatorValue(1, 1);
newSite.setIndicatorValue(2, 2);
// create command
CreateSite cmd = new CreateSite(newSite);
assertThat((Integer) cmd.getProperties().get("locationId"), equalTo(1));
// execute the command
setUser(1);
CreateResult result = execute(cmd);
newSite.setId(result.getNewId());
// try to retrieve what we've created
SiteDTO firstRead = readSite(newSite.getId());
Assert.assertEquals(1d, firstRead.<Object>getIndicatorValue(1));
Assert.assertEquals(2d, firstRead.<Object>getIndicatorValue(2));
Assert.assertEquals(3d, firstRead.<Object>getIndicatorValue(11));
Assert.assertEquals(0.5d, firstRead.<Object>getIndicatorValue(12));
SiteDTO updateSite = new SiteDTO(newSite);
updateSite.setIndicatorValue(1, null);
updateSite.setIndicatorValue(2, null);
// update site
execute(new UpdateSite(newSite, updateSite));
SiteDTO secondRead = readSite(newSite.getId());
// BACHE
Assert.assertEquals(null, secondRead.getIndicatorValue(1));
// BENE
Assert.assertEquals(null, secondRead.getIndicatorValue(2));
Assert.assertEquals(null, secondRead.getIndicatorValue(11));
Assert.assertEquals(null, secondRead.getIndicatorValue(12));
}
use of org.activityinfo.legacy.shared.command.UpdateSite in project activityinfo by bedatadriven.
the class CommandQueueTest method testUpdateSite.
@Test
public void testUpdateSite() {
Map<String, Object> changes = new HashMap<String, Object>();
changes.put("anInt", 34);
changes.put("aString", "testing");
final UpdateSite cmd = new UpdateSite(99, changes);
db.transaction(new SqlTransactionCallback() {
@Override
public void begin(SqlTransaction tx) {
queue.queue(tx, cmd);
}
});
Collector<CommandQueue.QueueEntry> reread = Collector.newCollector();
queue.peek(reread);
assertThat(reread.getResult(), not(nullValue()));
assertThat(cmd, equalTo(reread.getResult().getCommand()));
}
use of org.activityinfo.legacy.shared.command.UpdateSite in project activityinfo by bedatadriven.
the class UpdateSiteTest method charsets.
@Test
public void charsets() throws CommandException {
// retrieve from the server
ListResult<SiteDTO> result = execute(GetSites.byId(1));
SiteDTO original = result.getData().get(0);
SiteDTO modified = original.copy();
assertThat(modified.getId(), equalTo(original.getId()));
// modify and generate command
// note that the character sequence below is two characters:
// the first a simple unicode character and the second a code point
// requiring 4-bytes.
// http://www.charbase.com/20731-unicode-cjk-unified-ideograph
// NOTE: for the moment, i'm rolling back utf8mb4 support becuase it
// requires
// Mysql-5.5 which is **PITA*** to get running on earlier versions of
// ubuntu.
// To be reapplied when suppport
// modified.setComments("≥\ud841\udf31");
modified.setComments("≥");
System.out.println(modified.getComments());
assertThat(modified.getComments().codePointCount(0, modified.getComments().length()), equalTo(1));
UpdateSite cmd = new UpdateSite(original, modified);
assertThat((String) cmd.getChanges().get("comments"), equalTo(modified.getComments()));
execute(cmd);
// retrieve the old one
result = execute(GetSites.byId(1));
SiteDTO secondRead = result.getData().get(0);
// confirm that the changes are there
assertThat(secondRead.getComments(), equalTo(modified.getComments()));
}
use of org.activityinfo.legacy.shared.command.UpdateSite in project activityinfo by bedatadriven.
the class UpdateSiteTest method testUpdatePartner.
@Test
public void testUpdatePartner() throws CommandException {
// define changes for site id=2
Map<String, Object> changes = new HashMap<String, Object>();
changes.put("partnerId", 2);
execute(new UpdateSite(2, changes));
// assure that the change has been effected
Site site = em.find(Site.class, 2);
Assert.assertEquals("partnerId", 2, site.getPartner().getId());
}
use of org.activityinfo.legacy.shared.command.UpdateSite in project activityinfo by bedatadriven.
the class CreateSiteHandlerAsync method updateExistingSite.
private void updateExistingSite(final CreateSite cmd, ExecutionContext context, final AsyncCallback<CreateResult> callback) {
UpdateSite updateSite = new UpdateSite(cmd.getSiteId(), cmd.getProperties());
context.execute(updateSite, new AsyncCallback<VoidResult>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onSuccess(VoidResult result) {
callback.onSuccess(new CreateResult(cmd.getSiteId()));
}
});
}
Aggregations