use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class CreateSiteTest method unauthorized.
@Test(expected = NotAuthorizedException.class)
public void unauthorized() throws CommandException {
// create a new detached, client model
SiteDTO newSite = SiteDTOs.newSite();
newSite.setPartner(new PartnerDTO(2, "Not NRC"));
// create command
CreateSite cmd = new CreateSite(newSite);
// execute the command
// bavon (only has access to his own partners in database 1)
setUser(2);
execute(cmd);
}
use of org.activityinfo.shared.dto.SiteDTO 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));
}
use of org.activityinfo.shared.dto.SiteDTO 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));
}
use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class GetSitesTest method testDatabasePaged.
@Test
public void testDatabasePaged() throws CommandException {
setUser(DATABASE_OWNER);
GetSites cmd = new GetSites();
cmd.getFilter().addRestriction(DimensionType.Database, 1);
cmd.setLimit(2);
PagingLoadResult<SiteDTO> result = execute(cmd);
Assert.assertEquals("rows", 2, result.getData().size());
}
use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class GetSitesTest method testGetPublicSites.
@Test
@OnDataSet("/dbunit/sites-public.db.xml")
public void testGetPublicSites() throws CommandException {
int anonnoymsUserID = 0;
setUser(anonnoymsUserID);
GetSites cmd = new GetSites();
cmd.filter().onActivity(1);
cmd.setSortInfo(new SortInfo("date2", SortDir.DESC));
PagingLoadResult<SiteDTO> result = execute(cmd);
Assert.assertEquals("totalLength", 3, result.getData().size());
Assert.assertEquals("totalLength", 3, result.getTotalLength());
Assert.assertEquals("offset", 0, result.getOffset());
// Assert.assertNull("row(0).activity",
// result.getData().get(0).getActivity());
// assure sorted
Assert.assertEquals("sorted", 2, result.getData().get(0).getId());
Assert.assertEquals("sorted", 1, result.getData().get(1).getId());
Assert.assertEquals("sorted", 3, result.getData().get(2).getId());
// assure indicators are present (site id=3)
SiteDTO s = result.getData().get(2);
Assert.assertEquals("entityName", "Ituri", s.getAdminEntity(1).getName());
Assert.assertNotNull("admin bounds", s.getAdminEntity(1).getBounds());
Assert.assertEquals("indicator", 10000.0, s.getIndicatorValue(1));
Assert.assertNull("site x", s.getX());
// assure project is present
SiteDTO s1 = result.getData().get(1);
assertThat(s1.getId(), equalTo(1));
assertThat(s1.getProject().getId(), equalTo(1));
}
Aggregations