Search in sources :

Example 26 with OnDataSet

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")));
}
Also used : CreateEntity(org.activityinfo.legacy.shared.command.CreateEntity) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 27 with OnDataSet

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

Example 28 with OnDataSet

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))));
}
Also used : Quantity(org.activityinfo.model.type.number.Quantity) FieldValue(org.activityinfo.model.type.FieldValue) FormInstance(org.activityinfo.model.form.FormInstance) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) LocalDate(org.activityinfo.model.type.time.LocalDate) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 29 with OnDataSet

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);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) FormInstance(org.activityinfo.model.form.FormInstance) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 30 with OnDataSet

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

Aggregations

OnDataSet (org.activityinfo.server.database.OnDataSet)48 Test (org.junit.Test)46 PartnerResult (org.activityinfo.legacy.shared.command.result.PartnerResult)9 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)8 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)6 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)6 EntityManager (javax.persistence.EntityManager)5 GetSites (org.activityinfo.legacy.shared.command.GetSites)5 FormInstance (org.activityinfo.model.form.FormInstance)5 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)4 Date (java.util.Date)4 Response (javax.ws.rs.core.Response)4 GetSyncRegionUpdates (org.activityinfo.legacy.shared.command.GetSyncRegionUpdates)4 SyncRegionUpdate (org.activityinfo.legacy.shared.command.result.SyncRegionUpdate)4 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)4 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)4 ResourceId (org.activityinfo.model.resource.ResourceId)4 LocalDate (org.activityinfo.model.type.time.LocalDate)4 GetUsers (org.activityinfo.legacy.shared.command.GetUsers)3 UpdateUserPermissions (org.activityinfo.legacy.shared.command.UpdateUserPermissions)3