use of org.geotools.filter.function.DefaultFunctionFactory in project sldeditor by robward-scisys.
the class FieldConfigBaseTest method testFunctionUpdated.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigBase#functionUpdated(org.opengis.filter.expression.Expression)}.
*/
@Test
public void testFunctionUpdated() {
FieldIdEnum expectedFieldId = FieldIdEnum.NAME;
String expectedLabel = "test label";
TestFieldConfigBase field = new TestFieldConfigBase(new FieldConfigCommonData(String.class, expectedFieldId, expectedLabel, false));
TestUpdateSymbolInterface listener = new TestUpdateSymbolInterface();
field.addDataChangedListener(listener);
assertFalse(listener.hasBeenCalled());
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
FunctionName functionName = null;
for (FunctionName func : functionFactory.getFunctionNames()) {
if (func.getName() == "greaterThan") {
functionName = func;
break;
}
}
assertNotNull(functionName);
Expression testExpression = ff.function(functionName.getFunctionName(), ff.literal(1), ff.literal(2));
field.functionUpdated(testExpression);
assertTrue(listener.hasBeenCalled());
assertEquals(ExpressionTypeEnum.E_FUNCTION, field.getExpressionType());
Expression expression = field.getExpression();
assertTrue(expression.toString().startsWith(functionName.getName()));
}
use of org.geotools.filter.function.DefaultFunctionFactory in project sldeditor by robward-scisys.
the class ExpressionNodeTest method testSetExpression.
/**
* Test method for
* {@link com.sldeditor.filter.v2.expression.ExpressionNode#setExpression(org.opengis.filter.expression.Expression)}.
*/
@Test
public void testSetExpression() {
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
ExpressionNode node = new ExpressionNode();
// Test literal expression
String expressionString = "Literalexpression";
Expression literal = ff.literal(expressionString);
node.setExpression(literal);
String expected = Localisation.getField(ExpressionPanelv2.class, "ExpressionPanelv2.literal") + " " + expressionString;
String actual = node.toString();
assertTrue(actual.compareTo(expected) == 0);
// Test attribute expression
String propertyName = "testproperty";
Expression attribute = ff.property(propertyName);
node.setExpression(attribute);
expected = Localisation.getField(ExpressionPanelv2.class, "ExpressionPanelv2.attribute") + " [" + attribute + "]";
actual = node.toString();
assertTrue(actual.compareTo(expected) == 0);
// Test attribute expression
literal = ff.literal(ff.property(propertyName));
node.setExpression(literal);
expected = Localisation.getField(ExpressionPanelv2.class, "ExpressionPanelv2.attribute") + " [" + attribute + "]";
actual = node.toString();
assertTrue(actual.compareTo(expected) == 0);
// Test math expression
Expression maths = ff.multiply(ff.literal(6), ff.literal(7));
node.setExpression(maths);
expected = "*";
actual = node.toString();
assertTrue(actual.compareTo(expected) == 0);
// Test function
FunctionImpl function = new ConcatenateFunction();
List<Expression> params = new ArrayList<Expression>();
params.add(ff.literal("world"));
params.add(ff.literal("dog"));
function.setParameters(params);
node.setExpression(function);
expected = "Concatenate([world], [dog])";
actual = node.toString();
assertTrue(actual.compareTo(expected) == 0);
// Test function expression
DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
String name = "strConcat";
List<Expression> parameters = new ArrayList<Expression>();
parameters.add(ff.literal("cat"));
parameters.add(ff.literal("dog"));
Function functionExpression = functionFactory.function(name, parameters, null);
node.setExpression(functionExpression);
expected = "strConcat([cat], [dog])";
actual = node.toString();
assertTrue(actual.compareTo(expected) == 0);
// Test environment function
EnvFunction envExpression = (EnvFunction) ff.function("env", ff.literal("foo"), ff.literal(0));
node.setExpression(envExpression);
expected = "env([foo], [0])";
actual = node.toString();
assertTrue(actual.compareTo(expected) == 0);
}
use of org.geotools.filter.function.DefaultFunctionFactory in project sldeditor by robward-scisys.
the class FieldConfigBaseTest method testPopulateExpressionExpression.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigBase#populate(org.opengis.filter.expression.Expression)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigBase#populate(org.opengis.filter.expression.Expression, org.opengis.filter.expression.Expression)}.
*/
@Test
public void testPopulateExpressionExpression() {
FieldIdEnum expectedFieldId = FieldIdEnum.NAME;
String expectedLabel = "test label";
TestFieldConfigBase field = new TestFieldConfigBase(new FieldConfigCommonData(String.class, expectedFieldId, expectedLabel, false));
AttributeSelection attributeSelectionPanel = AttributeSelection.createAttributes(String.class, field, false);
field.testAttributeSelectionPanel(attributeSelectionPanel);
TestUpdateSymbolInterface listener = new TestUpdateSymbolInterface();
field.addDataChangedListener(listener);
assertFalse(listener.hasBeenCalled());
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
// Test function
DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
FunctionName functionName = null;
for (FunctionName func : functionFactory.getFunctionNames()) {
if (func.getName() == "greaterThan") {
functionName = func;
break;
}
}
assertNotNull(functionName);
Expression testExpression = ff.function(functionName.getFunctionName(), ff.literal(1), ff.literal(2));
field.populate(testExpression);
// Updated because the attribute pulldown changed
assertTrue(listener.hasBeenCalled());
assertEquals(ExpressionTypeEnum.E_EXPRESSION, field.getExpressionType());
Expression expression = field.getExpression();
assertTrue(expression.toString().startsWith(functionName.getName()));
// Attribute expression wrapped in a literal expression
String testAttributeName = "test attribute";
NameImpl name = new NameImpl(testAttributeName);
AttributeExpressionImpl attributeExpression = new AttributeExpressionImpl(name);
Expression literalExpression = ff.literal(attributeExpression);
field.populate(literalExpression);
assertEquals(ExpressionTypeEnum.E_ATTRIBUTE, field.getExpressionType());
// Process Function
// ProcessFunctionFactory factory = new ProcessFunctionFactory();
// FunctionTableModel functionParameterTableModel = new FunctionTableModel();
// ProcessFunction processFunction = functionParameterTableModel.getExpression(factory);
// field.populate(processFunction);
// assertEquals(ExpressionTypeEnum.E_VALUE, field.getExpressionType());
}
use of org.geotools.filter.function.DefaultFunctionFactory in project sldeditor by robward-scisys.
the class FilterManagerTest method testConvertParameters.
/**
* Test method for
* {@link com.sldeditor.filter.v2.function.FilterManager#convertParameters(java.lang.Class, com.sldeditor.ui.detail.config.FieldId, org.opengis.filter.capability.FunctionName)}.
*/
@Test
public void testConvertParameters() {
DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
List<FunctionName> functionNameList = functionFactory.getFunctionNames();
// Try with empty parameters
Class<?> panelId = null;
List<GroupConfigInterface> list = FilterManager.getInstance().convertParameters(panelId, null);
assertTrue(list.isEmpty());
// Find a known function
for (FunctionName functionName : functionNameList) {
list = FilterManager.getInstance().convertParameters(panelId, functionName);
System.out.println(functionName.getName());
assertEquals(1, list.size());
GroupConfig groupConfig = (GroupConfig) list.get(0);
List<FieldConfigBase> fieldList = groupConfig.getFieldConfigList();
assertEquals(functionName.getName(), fieldList.size(), Math.abs(functionName.getArgumentCount()));
List<String> argList = new ArrayList<String>();
for (int fieldIndex = 0; fieldIndex < fieldList.size(); fieldIndex++) {
checkFieldType(fieldIndex, fieldList, functionName, argList);
}
StringBuilder sb = new StringBuilder();
sb.append(functionName.getName());
sb.append("(");
for (int index = 0; index < argList.size(); index++) {
if (index > 0) {
sb.append(", ");
}
sb.append(argList.get(index));
}
sb.append(")");
String prototype = groupConfig.getLabel();
assertNotNull(functionName.getName(), prototype);
assertNotNull(functionName.getName(), sb.toString());
assertTrue(prototype.compareTo(sb.toString()) == 0);
}
}
use of org.geotools.filter.function.DefaultFunctionFactory in project sldeditor by robward-scisys.
the class FilterManagerTest method testCreateExpression.
/**
* Test method for
* {@link com.sldeditor.filter.v2.function.FilterManager#createExpression(org.opengis.filter.capability.FunctionName)}.
*/
@Test
public void testCreateExpression() {
DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
List<FunctionName> functionNameList = functionFactory.getFunctionNames();
FunctionName functionName = null;
Expression expression = FilterManager.getInstance().createExpression(functionName);
assertNull(expression);
functionName = functionNameList.get(0);
expression = FilterManager.getInstance().createExpression(functionName);
assertNotNull(expression);
FunctionExpression funcExpression = (FunctionExpression) expression;
assertTrue(functionName.getName().compareTo(funcExpression.getName()) == 0);
}
Aggregations