use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.
the class CreateDatabaseTest method createWithSpecificCountry.
@Test
@OnDataSet("/dbunit/multicountry.db.xml")
public void createWithSpecificCountry() throws CommandException {
UserDatabaseDTO db = new UserDatabaseDTO();
db.setName("Warchild Haiti");
db.setFullName("Warchild Haiti");
setUser(1);
CreateEntity cmd = new CreateEntity(db);
cmd.getProperties().put("countryId", 2);
CreateResult cr = execute(cmd);
SchemaDTO schema = execute(new GetSchema());
UserDatabaseDTO newdb = schema.getDatabaseById(cr.getNewId());
assertNotNull(newdb);
assertThat(newdb.getCountry(), is(notNullValue()));
assertThat(newdb.getCountry().getName(), is(equalTo("Haiti")));
}
use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.
the class GetSchemaTest method createFolder.
@Test
@OnDataSet("/dbunit/schema3.db.xml")
public void createFolder() {
setUser(1);
CreateResult result = execute(new CreateEntity(new FolderDTO(1, "NFI")));
SchemaDTO schema = execute(new GetSchema());
FolderDTO folder = schema.getDatabaseById(1).getFolderById(result.getNewId());
assertThat(folder.getName(), equalTo("NFI"));
}
use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.
the class ResourceLocatorAdaptorTest method persistSiteWithCalculatedIndicators.
@Test
@OnDataSet("/dbunit/sites-calculated-indicators.db.xml")
public void persistSiteWithCalculatedIndicators() {
int siteId = new KeyGenerator().generateInt();
FormInstance instance = new FormInstance(CuidAdapter.cuid(SITE_DOMAIN, siteId), NFI_DIST_FORM_CLASS);
instance.set(indicatorField(1), 1);
instance.set(indicatorField(2), 2);
instance.set(locationField(NFI_DIST_ID), locationRef(VILLAGE_CLASS, 1));
instance.set(partnerField(NFI_DIST_ID), partnerRef(PEAR_DATABASE_ID, 1));
instance.set(projectField(NFI_DIST_ID), projectRef(PEAR_DATABASE_ID, 1));
instance.set(field(NFI_DIST_FORM_CLASS, START_DATE_FIELD), new LocalDate(2014, 1, 1));
instance.set(field(NFI_DIST_FORM_CLASS, END_DATE_FIELD), new LocalDate(2014, 1, 1));
instance.set(field(NFI_DIST_FORM_CLASS, COMMENT_FIELD), NarrativeValue.valueOf("My comment"));
assertResolves(locator.persist(instance));
FormInstance firstRead = assertResolves(locator.getFormInstance(NFI_DIST_FORM_CLASS, instance.getId()));
assertThat(firstRead.get(indicatorField(1)), equalTo((FieldValue) new Quantity(1)));
assertThat(firstRead.get(indicatorField(2)), equalTo((FieldValue) new Quantity(2)));
// set indicators to null
instance.set(indicatorField(1).asString(), null);
instance.set(indicatorField(2).asString(), null);
// persist it
assertResolves(locator.persist(instance));
// read from server
FormInstance secondRead = assertResolves(locator.getFormInstance(NFI_DIST_FORM_CLASS, instance.getId()));
// BENE
assertThat(secondRead.get(indicatorField(1)), nullValue());
// BACHE
assertThat(secondRead.get(indicatorField(2)), nullValue());
// // Both BENE+BACHE and BENE/BACHE should be missing, because both
// // BENE and BACHE are missing
// assertEquals(null, secondRead.getValue(path(indicatorField(11))));
// assertEquals(null, secondRead.getValue(path(indicatorField(12))));
}
use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.
the class ResourceLocatorAdaptorTest method getLocation.
@Test
@OnDataSet("/dbunit/jordan-locations.db.xml")
public void getLocation() {
ResourceId classId = locationFormClass(50512);
FormInstance instance = assertResolves(locator.getFormInstance(classId, locationInstanceId(1590565828)));
ReferenceValue adminUnits = (ReferenceValue) instance.get(field(classId, ADMIN_FIELD));
System.out.println(adminUnits);
}
use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.
the class GetPartnersDimensionHandlerTest method testSiteCountIndicators.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void testSiteCountIndicators() throws CommandException {
/*
Activity #1
Indicator #103 (site count)
Indicator #675 (site count)
Site #1: Partner #1
Site #2: Partner #1
Site #3: partner #2
*/
// empty
PartnerResult result = execute(DimensionType.Indicator, 103, 675);
// indicators 103 and 675 are site count indicators, so all sites of activity #1
// should have a non empty value and be considered present
assertThat(result.getData().size(), equalTo(2));
}
Aggregations