use of org.openforis.idm.model.Entity in project collect by openforis.
the class ExpressionTest method testConstant.
@Test
public void testConstant() throws InvalidExpressionException {
Entity plot = EntityBuilder.addEntity(cluster, "plot");
Entity tree = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree, "dbh", 54.2);
String expr = "543534";
Object object = evaluateExpression(expr);
Assert.assertEquals(Double.valueOf(expr), object);
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class ExpressionTest method testMissingValueExpressionWithOperation.
@Test
public void testMissingValueExpressionWithOperation() throws InvalidExpressionException {
Entity plot = EntityBuilder.addEntity(cluster, "plot");
Entity tree = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree, "dbh", 54.2);
String expr = "plot[25]/tree[3]/dbh/parent()/dbh + 4";
Object object = evaluateExpression(expr);
Assert.assertEquals(4d, object);
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class ExpressionTest method testAddWithParentFuncExpression.
@Test
public void testAddWithParentFuncExpression() throws InvalidExpressionException {
Entity plot = EntityBuilder.addEntity(cluster, "plot");
Entity tree = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree, "dbh", 54.2);
String expr = "plot[1]/tree[1]/dbh/parent()/dbh + 1";
Object object = evaluateExpression(expr);
Assert.assertEquals(55.2, object);
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class IDMFunctionsTest method testDistinctValuesFunctionWithDuplicates.
@Test
public void testDistinctValuesFunctionWithDuplicates() throws InvalidExpressionException {
Entity plot1 = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot1, "no", new Code("1"));
Entity plot2 = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot2, "no", new Code("2"));
Entity plot3 = EntityBuilder.addEntity(cluster, "plot");
// duplicate value
EntityBuilder.addValue(plot3, "no", new Code("1"));
String expr = ExpressionFactory.IDM_PREFIX + ":" + "distinct-values(plot/no)";
Object result = evaluateExpression(expr);
Assert.assertEquals(Arrays.asList("1", "2"), result);
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class IDMFunctionsTest method testIndexAndPosition.
@Test
public void testIndexAndPosition() throws InvalidExpressionException {
Entity plot1 = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot1, "no", new Code("1"));
Entity plot2 = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot2, "no", new Code("2"));
Assert.assertEquals(Integer.valueOf(0), evaluateExpression(cluster, "idm:index(plot[1])"));
Assert.assertEquals(Integer.valueOf(0), evaluateExpression(cluster, "idm:index(plot[no='1'])"));
Assert.assertEquals(Integer.valueOf(1), evaluateExpression(cluster, "idm:index(plot[2])"));
Assert.assertEquals(Integer.valueOf(1), evaluateExpression(cluster, "idm:index(plot[no='2'])"));
Assert.assertEquals(Integer.valueOf(1), evaluateExpression(cluster, "idm:position(plot[1])"));
Assert.assertEquals(Integer.valueOf(2), evaluateExpression(cluster, "idm:position(plot[2])"));
Assert.assertEquals(Integer.valueOf(1), evaluateExpression(plot2, "idm:index()"));
}
Aggregations