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()));
}
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"));
}
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);
}
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);
}
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));
}
Aggregations