Search in sources :

Example 16 with CreateResult

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));
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) GregorianCalendar(java.util.GregorianCalendar) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) UpdateSite(org.activityinfo.legacy.shared.command.UpdateSite) CreateSite(org.activityinfo.legacy.shared.command.CreateSite) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 17 with CreateResult

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);
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) TargetDTO(org.activityinfo.legacy.shared.model.TargetDTO) Test(org.junit.Test)

Example 18 with CreateResult

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());
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) TargetDTO(org.activityinfo.legacy.shared.model.TargetDTO) Test(org.junit.Test)

Example 19 with CreateResult

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

Example 20 with CreateResult

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()));
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) 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

CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)46 Test (org.junit.Test)26 Date (java.util.Date)9 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)7 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)7 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)7 OnDataSet (org.activityinfo.server.database.OnDataSet)6 CreateSite (org.activityinfo.legacy.shared.command.CreateSite)5 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)5 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)4 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)4 TargetDTO (org.activityinfo.legacy.shared.model.TargetDTO)4 CuidAdapter.activityFormClass (org.activityinfo.model.legacy.CuidAdapter.activityFormClass)4 ResourceId (org.activityinfo.model.resource.ResourceId)4 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)3 GregorianCalendar (java.util.GregorianCalendar)3 CloneDatabase (org.activityinfo.legacy.shared.command.CloneDatabase)3 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)3 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)3 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)3