Search in sources :

Example 21 with OnDataSet

use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.

the class LocalSiteCreateTest method siteRemovePartnerConflict.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void siteRemovePartnerConflict() {
    // FIRST U1 adds a new partner
    int databaseId = 1;
    PartnerDTO iom = new PartnerDTO();
    iom.setName("IOM");
    CreateResult result = executeRemotely(new UpdatePartner(databaseId, iom));
    iom.setId(result.getNewId());
    // Now U2 synchronizes, and adds a new site with this partner
    synchronize();
    SiteDTO site = new SiteDTO();
    site.setId(3343234);
    site.setActivityId(1);
    site.setPartner(iom);
    site.setDate1(new Date());
    site.setDate2(new Date());
    site.setLocationId(1);
    executeLocally(new CreateSite(site));
    // At T+3, U2 thinks better, removes IOM
    executeRemotely(new RemovePartner(databaseId, iom.getId()));
    // At T+4, U1 synchronizes, and IOM is removed, but site remains
    synchronize();
    // Verify that there is still a label for this partner
    SiteResult sites = executeLocally(GetSites.byId(site.getId()));
    assertThat(sites.getTotalLength(), equalTo(1));
    assertThat(sites.getData().get(0).getName(), equalTo(site.getName()));
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) Date(java.util.Date) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 22 with OnDataSet

use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.

the class XFormResourceTest method parse.

@Test
@OnDataSet("/dbunit/chad-form.db.xml")
public void parse() throws IOException {
    byte[] bytes = asByteSource(getResource(XFormResourceTest.class, "form.mime")).read();
    Response response = formSubmissionResource.submit(bytes);
    assertEquals(CREATED, fromStatusCode(response.getStatus()));
// Map<String, Object> map = store.getLastUpdated().getProperties();
// assertEquals(7, map.size());
// assertEquals(CLASS_ID.asString(), map.get("classId"));
// assertEquals(new ReferenceValue(partnerInstanceId(507, 562)).asRecord(), map.get(fieldName(PARTNER_FIELD)));
// assertEquals(new LocalDate(2005, 8, 31).asRecord(), map.get(fieldName(END_DATE_FIELD)));
// assertEquals("09/06/06", map.get(CODE_FIELD));
// assertEquals(new ReferenceValue(entity(141796)).asRecord(), map.get("a1081f11"));
// assertNull(map.get("i5346"));
// assertEquals(new NarrativeValue("Awesome.").asRecord(), map.get("a1081f14"));
// assertNotNull(map.get("backupBlobId"));
}
Also used : Response(javax.ws.rs.core.Response) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 23 with OnDataSet

use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.

the class XFormResourceTest method invalidExpr.

@Test
@OnDataSet("/dbunit/invalid-relevance.db.xml")
public void invalidExpr() throws Exception {
    setUser(USER_ID);
    FormClass formClass = resourceLocator.getFormClass(CuidAdapter.activityFormClass(ACTIVITY_ID));
    FormField field = new FormField(ResourceId.generateFieldId(QuantityType.TYPE_CLASS));
    field.setLabel("Question");
    field.setType(new QuantityType());
    field.setRelevanceConditionExpression("DELETED_FIELD=1");
    formClass.addElement(field);
    resourceLocator.persist(formClass);
    Response form = this.formResource.form(ACTIVITY_ID);
    validate(form);
}
Also used : Response(javax.ws.rs.core.Response) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) FormField(org.activityinfo.model.form.FormField) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 24 with OnDataSet

use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.

the class XFormResourceTest method getBlankForm.

@Test
@OnDataSet("/dbunit/chad-form.db.xml")
public void getBlankForm() throws Exception {
    setUser(USER_ID);
    Response form = this.formResource.form(ACTIVITY_ID);
    validate(form);
}
Also used : Response(javax.ws.rs.core.Response) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 25 with OnDataSet

use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.

the class InstanceScoreTest method adminEntityScoring.

@OnDataSet("/dbunit/nfi-import.db.xml")
@Test
public void adminEntityScoring() throws IOException {
    setUser(3);
    FormTree formTree = assertResolves(locator.getFormTree(ImportWithMultiClassRangeTest.SCHOOL_FORM_CLASS));
    FormTreePrettyPrinter.print(formTree);
    importModel = new ImportModel(formTree);
    importer = new Importer(locator, formTree, FieldImportStrategies.get(JvmConverterFactory.get()));
    // Step 1: User pastes in data to import
    PastedTable source = new PastedTable(Resources.toString(getResource(getClass(), "school-import.csv"), Charsets.UTF_8));
    importModel.setSource(source);
    dumpList("COLUMNS", source.getColumns());
    importModel.setColumnAction(columnIndex("School"), target("Name"));
    // Province is at the root of both hierarchies
    importModel.setColumnAction(columnIndex("Province"), target("Province Name"));
    // Admin hierarchy
    importModel.setColumnAction(columnIndex("District"), target("District Name"));
    importModel.setColumnAction(columnIndex("Territoire"), target("Territoire Name"));
    importModel.setColumnAction(columnIndex("Secteur"), target("Secteur Name"));
    importModel.setColumnAction(columnIndex("Groupement"), target("Secteur Name"));
    // health ministry hierarchy
    importModel.setColumnAction(columnIndex("Zone de Santé"), target("Zone de Santé Name"));
    FormTree.Node rootField = formTree.getRootField(ADMINISTRATIVE_UNIT_FIELD);
    TargetCollector targetCollector = new TargetCollector(rootField);
    Map<TargetSiteId, ColumnAccessor> mappedColumns = importModel.getMappedColumns(rootField.getFieldId());
    List<ColumnAccessor> sourceColumns = Lists.newArrayList();
    Map<FieldPath, Integer> referenceFields = targetCollector.getPathMap(mappedColumns, sourceColumns);
    // Province level
    ColumnSet columnSet = assertResolves(query(referenceFields, ImportWithMultiClassRangeTest.PROVINCE_LEVEL));
    InstanceScoreSource scoreSource = new InstanceScoreSourceBuilder(CuidAdapter.adminLevelFormClass(ImportWithMultiClassRangeTest.PROVINCE_LEVEL), referenceFields, sourceColumns).build(columnSet);
    InstanceScorer.Score score = score(source.getRows().get(0), scoreSource);
    assertScore(score, "Katanga");
    // District level
    columnSet = assertResolves(query(referenceFields, ImportWithMultiClassRangeTest.DISTRICT_LEVEL));
    scoreSource = new InstanceScoreSourceBuilder(CuidAdapter.adminLevelFormClass(ImportWithMultiClassRangeTest.DISTRICT_LEVEL), referenceFields, sourceColumns).build(columnSet);
    score = score(source.getRows().get(1), scoreSource);
    assertScore(score, "Katanga");
    assertScore(score, "Tanganika");
    // Territoire level
    columnSet = assertResolves(query(referenceFields, ImportWithMultiClassRangeTest.TERRITOIRE_LEVEL));
    scoreSource = new InstanceScoreSourceBuilder(CuidAdapter.adminLevelFormClass(ImportWithMultiClassRangeTest.TERRITOIRE_LEVEL), referenceFields, sourceColumns).build(columnSet);
    score = score(source.getRows().get(2), scoreSource);
    assertScore(score, "Katanga");
    assertScore(score, "Tanganika");
    assertScore(score, "Kalemie");
    assertThat(scoreSource.getReferenceInstanceIds().get(score.getBestMatchIndex()), equalTo(ImportWithMultiClassRangeTest.TERRITOIRE_KALEMIE));
}
Also used : PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) FieldPath(org.activityinfo.model.formTree.FieldPath) ColumnSet(org.activityinfo.model.query.ColumnSet) FormTree(org.activityinfo.model.formTree.FormTree) ImportModel(org.activityinfo.ui.client.component.importDialog.model.ImportModel) 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