use of org.activityinfo.legacy.shared.command.result.CreateResult 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.result.CreateResult 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();
List<TargetDTO> targets = execute(new GetTargets(db.getId())).getData();
TargetDTO dto = getTargetById(targets, newId);
assertEquals("name", "Target0071", dto.getName());
execute(new Delete(dto));
targets = execute(new GetTargets()).getData();
TargetDTO deleted = getTargetById(targets, newId);
assertNull(deleted);
}
use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class TargetTest method testTarget.
@Test
public void testTarget() throws CommandException {
TargetDTO target = createTarget();
CreateResult cresult = execute(new AddTarget(db.getId(), target));
int newId = cresult.getNewId();
List<TargetDTO> targets = execute(new GetTargets(db.getId())).getData();
TargetDTO dto = getTargetById(targets, newId);
assertNotNull(dto);
assertEquals("name", "Target0071", dto.getName());
}
use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class LocalSchemaChangeTest method updatePartners.
@Test
public void updatePartners() throws Exception {
int databaseId = 1;
CreateResult createResult = assertChangeIsSynchronized(new UpdatePartner(databaseId, new PartnerDTO("Judean People's Front")));
assertChangeIsSynchronized(new RemovePartner(1, createResult.getNewId()));
}
use of org.activityinfo.legacy.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class LocalSiteCreateTest method siteRemovePartnerConflict.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void siteRemovePartnerConflict() {
// FIRST U1 adds a new partner
int databaseId = 1;
PartnerDTO iom = new PartnerDTO();
iom.setName("IOM");
CreateResult result = executeRemotely(new UpdatePartner(databaseId, iom));
iom.setId(result.getNewId());
// Now U2 synchronizes, and adds a new site with this partner
synchronize();
SiteDTO site = new SiteDTO();
site.setId(3343234);
site.setActivityId(1);
site.setPartner(iom);
site.setDate1(new Date());
site.setDate2(new Date());
site.setLocationId(1);
executeLocally(new CreateSite(site));
// At T+3, U2 thinks better, removes IOM
executeRemotely(new RemovePartner(databaseId, iom.getId()));
// At T+4, U1 synchronizes, and IOM is removed, but site remains
synchronize();
// Verify that there is still a label for this partner
SiteResult sites = executeLocally(GetSites.byId(site.getId()));
assertThat(sites.getTotalLength(), equalTo(1));
assertThat(sites.getData().get(0).getName(), equalTo(site.getName()));
}
Aggregations