use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordUpdaterTest method testCardinalityValidatedOnRecordInitialization.
@Test
public void testCardinalityValidatedOnRecordInitialization() {
record(rootEntityDef(entityDef("time_study", attributeDef("start_time")).multiple().required()));
Entity rootEntity = record.getRootEntity();
assertEquals(ValidationResultFlag.ERROR, rootEntity.getMinCountValidationResult("time_study"));
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordUpdaterTest method testMinCountValidationResultOnEntityWhenRequiredAttributeIsEmpty.
@Test
public void testMinCountValidationResultOnEntityWhenRequiredAttributeIsEmpty() {
record(rootEntityDef(entityDef("time_study", attributeDef("start_time").required())), entity("time_study"));
Entity timeStudy = entityByPath("/root/time_study");
assertEquals(ValidationResultFlag.ERROR, timeStudy.getMinCountValidationResult("start_time"));
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordUpdaterTest method testCardinalityRevalidatedWhenBecomesRelevant.
@Test
public void testCardinalityRevalidatedWhenBecomesRelevant() {
record(rootEntityDef(attributeDef("source"), attributeDef("dependent").multiple().relevant("source = '1'").minCount("1")), attribute("source", "2"), attribute("dependent", null));
Entity rootEntity = record.getRootEntity();
assertEquals(ValidationResultFlag.OK, rootEntity.getMinCountValidationResult("dependent"));
Attribute<?, ?> source = record.findNodeByPath("/root/source");
NodeChangeSet nodeChangeSet = update(source, "1");
EntityChange rootEntityChange = (EntityChange) nodeChangeSet.getChange(rootEntity);
assertNotNull(rootEntityChange);
ValidationResultFlag dependentValidationResult = rootEntityChange.getChildrenMinCountValidation().get("dependent");
assertEquals(ValidationResultFlag.ERROR, dependentValidationResult);
assertEquals(ValidationResultFlag.ERROR, rootEntity.getMinCountValidationResult("dependent"));
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordUpdaterTest method testRemoveEntityUpdatesCalculatedPosition.
@Test
public void testRemoveEntityUpdatesCalculatedPosition() {
record(rootEntityDef(entityDef("tree", attributeDef("tree_num").calculated("idm:position()")).multiple()), entity("tree"), entity("tree"), entity("tree"));
Entity tree1 = entityByPath("/root/tree[1]");
Entity tree2 = entityByPath("/root/tree[2]");
Entity tree3 = entityByPath("/root/tree[3]");
updater.deleteNode(tree2);
Attribute<?, ?> treeNum1 = (Attribute<?, ?>) tree1.getChild("tree_num");
assertEquals(new TextValue("1"), treeNum1.getValue());
Attribute<?, ?> treeNum3 = (Attribute<?, ?>) tree3.getChild("tree_num");
assertEquals(new TextValue("2"), treeNum3.getValue());
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordUpdaterTest method testRecordInitializationPreservesEntities.
@Test
public void testRecordInitializationPreservesEntities() {
record(rootEntityDef(entityDef("time_study", attributeDef("start_time")).multiple().required()), entity("time_study", attribute("start_time", "start first")), entity("time_study", attribute("start_time", "start second")));
Entity rootEntity = record.getRootEntity();
assertEquals(2, rootEntity.getCount("time_study"));
}
Aggregations