Search in sources :

Example 6 with UpdateSite

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

the class UpdateSiteTest method testUpdatePreservesAdminMemberships.

@Test
public void testUpdatePreservesAdminMemberships() throws CommandException {
    Map<String, Object> changes = Maps.newHashMap();
    changes.put("comments", "new comments");
    execute(new UpdateSite(1, changes));
    // retrieve the old one
    SiteResult result = execute(GetSites.byId(1));
    SiteDTO secondRead = result.getData().get(0);
    assertThat(secondRead.getAdminEntity(1).getId(), equalTo(2));
    assertThat(secondRead.getAdminEntity(2).getId(), equalTo(12));
}
Also used : SiteResult(org.activityinfo.shared.command.result.SiteResult) SiteDTO(org.activityinfo.shared.dto.SiteDTO) UpdateSite(org.activityinfo.shared.command.UpdateSite) Test(org.junit.Test)

Example 7 with UpdateSite

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

the class UpdateSiteTest method testUpdate.

@Test
public void testUpdate() 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
    modified.setComments("NEW <b>Commentaire</b>");
    modified.setAttributeValue(1, true);
    modified.setAttributeValue(2, null);
    modified.setAttributeValue(3, true);
    modified.setAttributeValue(4, false);
    modified.setIndicatorValue(2, 995.0);
    modified.setAdminEntity(2, null);
    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
    Assert.assertEquals("site.comments", modified.getComments(), secondRead.getComments());
    Assert.assertEquals("site.reportingPeriod[0].indicatorValue[0]", 995, secondRead.getIndicatorValue(2).intValue());
    Assert.assertEquals("site.attribute[1]", true, modified.getAttributeValue(1));
    Assert.assertEquals("site.attribute[3]", true, modified.getAttributeValue(3));
    Assert.assertEquals("site.attribute[4]", false, modified.getAttributeValue(4));
}
Also used : SiteDTO(org.activityinfo.shared.dto.SiteDTO) UpdateSite(org.activityinfo.shared.command.UpdateSite) Test(org.junit.Test)

Aggregations

UpdateSite (org.activityinfo.shared.command.UpdateSite)7 Test (org.junit.Test)6 SiteDTO (org.activityinfo.shared.dto.SiteDTO)5 HashMap (java.util.HashMap)2 SiteResult (org.activityinfo.shared.command.result.SiteResult)2 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 SqlTransactionCallback (com.bedatadriven.rebar.sql.client.SqlTransactionCallback)1 Date (java.util.Date)1 OnDataSet (org.activityinfo.server.database.OnDataSet)1 Site (org.activityinfo.server.database.hibernate.entity.Site)1 Delete (org.activityinfo.shared.command.Delete)1 VoidResult (org.activityinfo.shared.command.result.VoidResult)1