use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class DeleteTest method testDeleteIndicator.
@Test
public void testDeleteIndicator() throws CommandException {
SchemaDTO schema = execute(new GetSchema());
execute(new Delete(schema.getIndicatorById(1)));
schema = execute(new GetSchema());
Assert.assertNull(schema.getIndicatorById(1));
PagingResult<SiteDTO> sites = execute(GetSites.byId(1));
Assert.assertNull(sites.getData().get(0).getIndicatorValue(1));
}
use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class SiteRendererTest method multipleGroupsRender.
@Test
public void multipleGroupsRender() {
IndicatorDTO indicator1 = new IndicatorDTO();
indicator1.setId(1);
indicator1.setAggregation(IndicatorDTO.AGGREGATE_SUM);
indicator1.setName("First indicator");
indicator1.setCategory("First group");
IndicatorDTO indicator2 = new IndicatorDTO();
indicator2.setAggregation(IndicatorDTO.AGGREGATE_SUM);
indicator2.setId(2);
indicator2.setName("Second indicator");
indicator2.setCategory("Second group");
ActivityDTO activity = new ActivityDTO();
activity.setId(1);
activity.getIndicators().add(indicator1);
activity.getIndicators().add(indicator2);
SiteDTO site = new SiteDTO();
site.setIndicatorValue(1, 1000d);
site.setIndicatorValue(2, 2000d);
String html = siteRenderer.renderSite(site, activity, false, true);
assertTrue(html.contains(indicator1.getName()));
assertTrue(html.contains(indicator2.getName()));
}
use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class CreateSiteTest method test.
@Test
public void test() throws CommandException {
LocationDTO location = LocationDTOs.newLocation();
execute(new CreateLocation(location));
SiteDTO newSite = SiteDTOs.newSite();
newSite.setLocation(location);
CreateSite cmd = new CreateSite(newSite);
setUser(1);
CreateResult result = execute(cmd);
newSite.setId(result.getNewId());
assertThat(result.getNewId(), not(equalTo(0)));
PagingLoadResult<SiteDTO> loadResult = execute(GetSites.byId(newSite.getId()));
Assert.assertEquals(1, loadResult.getData().size());
SiteDTO secondRead = loadResult.getData().get(0);
SiteDTOs.validateNewSite(secondRead);
}
use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class CreateSiteTest method testAllAttribsFalse.
@Test
public void testAllAttribsFalse() 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.setAttributeValue(1, false);
newSite.setAttributeValue(2, false);
newSite.setProject(new ProjectDTO(1, "SomeProject"));
// create command
CreateSite cmd = new CreateSite(newSite);
assertThat((Integer) cmd.getProperties().get("locationId"), equalTo(1));
// execute the command
setUser(1);
CreateResult result = execute(cmd);
// let the client know the command has succeeded
newSite.setId(result.getNewId());
// cmd.onCompleted(result);
// try to retrieve what we've created
PagingLoadResult<SiteDTO> loadResult = execute(GetSites.byId(newSite.getId()));
Assert.assertEquals(1, loadResult.getData().size());
SiteDTO secondRead = loadResult.getData().get(0);
// confirm that the changes are there
Assert.assertEquals("site.attribute[2]", false, secondRead.getAttributeValue(1));
Assert.assertEquals("site.attribute[2]", false, secondRead.getAttributeValue(2));
}
use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class SyncIntegrationTest method run.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void run() throws SQLException, InterruptedException {
synchronizeFirstTime();
Collector<Date> lastUpdate = Collector.newCollector();
syncHistoryTable.get(lastUpdate);
assertThat(lastUpdate.getResult(), is(not(nullValue())));
assertThat(queryString("select Name from Indicator where IndicatorId=103"), equalTo("Nb. of distributions"));
assertThat(queryString("select Name from AdminLevel where AdminLevelId=1"), equalTo("Province"));
assertThat(queryString("select Name from AdminEntity where AdminEntityId=21"), equalTo("Irumu"));
assertThat(queryString("select Name from Location where LocationId=7"), equalTo("Shabunda"));
assertThat(queryInt("select value from IndicatorValue where ReportingPeriodId=601 and IndicatorId=6"), equalTo(35));
assertThat(queryInt("select PartnerId from partnerInDatabase where databaseid=2"), equalTo(1));
assertThat(queryInt("select AttributeGroupId from AttributeGroupInActivity where ActivityId=2"), equalTo(1));
assertThat(queryInt("select count(*) from LockedPeriod"), equalTo(4));
assertThat(queryInt("select count(*) from LockedPeriod where ProjectId is not null"), equalTo(1));
assertThat(queryInt("select count(*) from LockedPeriod where ActivityId is not null"), equalTo(1));
assertThat(queryInt("select count(*) from LockedPeriod where UserDatabaseId is not null"), equalTo(2));
// / now try updating a site remotely (from another client)
// and veryify that we get the update after we synchronized
Thread.sleep(1000);
SiteDTO s1 = executeLocally(GetSites.byId(1)).getData().get(0);
assertThat(s1.getIndicatorValue(1), equalTo(1500d));
Map<String, Object> changes = Maps.newHashMap();
changes.put(AttributeDTO.getPropertyName(1), true);
changes.put("comments", "newComments");
executeRemotely(new UpdateSite(1, changes));
synchronize();
s1 = executeLocally(GetSites.byId(1)).getData().get(0);
assertThat(s1.getAttributeValue(1), equalTo(true));
assertThat(s1.getAttributeValue(2), equalTo(false));
assertThat(s1.getComments(), equalTo("newComments"));
// old values are preserved...
assertThat(s1.getIndicatorValue(1), equalTo(1500d));
// Try deleting a site
executeRemotely(new Delete("Site", 1));
synchronize();
SiteResult siteResult = executeLocally(GetSites.byId(1));
assertThat(siteResult.getData().size(), equalTo(0));
// Verify that we haven't toasted the other data
SiteDTO site = executeLocally(GetSites.byId(3)).getData().get(0);
assertThat(site.getIndicatorValue(1), equalTo(10000d));
}
Aggregations