use of com.sldeditor.filter.v2.expression.ExpressionPanelv2 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 com.sldeditor.filter.v2.expression.ExpressionPanelv2 in project sldeditor by robward-scisys.
the class ExpressionNodeTest method testExpressionNode.
/**
* Test method for {@link com.sldeditor.filter.v2.expression.ExpressionNode#ExpressionNode()}.
* Test method for {@link com.sldeditor.filter.v2.expression.ExpressionNode#toString()}. Test
* method for {@link com.sldeditor.filter.v2.expression.ExpressionNode#isValueOnly()}. Test
* method for {@link com.sldeditor.filter.v2.expression.ExpressionNode#setValueOnly(boolean)}.
*/
@Test
public void testExpressionNode() {
ExpressionNode node = new ExpressionNode();
assertTrue(node.toString().compareTo(Localisation.getString(ExpressionPanelv2.class, "ExpressionPanelv2.expressionNotSet")) == 0);
Class<?> type = String.class;
node.setType(type);
assertEquals(type, node.getType());
boolean isValueOnly = true;
node.setValueOnly(isValueOnly);
assertEquals(isValueOnly, node.isValueOnly());
}
use of com.sldeditor.filter.v2.expression.ExpressionPanelv2 in project sldeditor by robward-scisys.
the class FilterNodeTest method testSetFilter.
/**
* Test method for {@link
* com.sldeditor.filter.v2.expression.FilterNode#setFilter(org.opengis.filter.Filter,
* com.sldeditor.filter.v2.function.FilterConfigInterface)}.
*/
@Test
public void testSetFilter() {
String category = "Test category";
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
FilterNode node = new FilterNode();
// BinaryComparisonAbstract
Filter filter = ff.greaterOrEqual(ff.literal(45), ff.literal(23));
node.setFilter(filter, null);
node.addFilter();
String actual = node.toString();
String expected = "Filter : " + Localisation.getString(ExpressionPanelv2.class, "FilterNode.filterNotSet");
assertTrue(actual.compareTo(expected) == 0);
assertEquals(filter, node.getFilter());
FilterConfigInterface filterConfig = new IsGreaterThan(category);
node.setFilter(filter, filterConfig);
assertEquals(filterConfig, node.getFilterConfig());
expected = "Filter : PropertyIsGreaterThan";
actual = node.toString();
assertTrue(actual.compareTo(expected) == 0);
assertTrue(filterConfig.category().compareTo(category) == 0);
// PropertyIsLike
filter = ff.like(ff.literal("abc def ghi"), "abc");
filterConfig = new IsLike(category);
node.setFilter(filter, filterConfig);
expected = "Filter : Like";
actual = node.toString();
assertTrue(actual.compareTo(expected) == 0);
assertTrue(filterConfig.category().compareTo(category) == 0);
// BinarySpatialOperator
Hints hints = new Hints(Hints.CRS, DefaultGeographicCRS.WGS84);
PositionFactory positionFactory = GeometryFactoryFinder.getPositionFactory(hints);
GeometryFactory geometryFactory = GeometryFactoryFinder.getGeometryFactory(hints);
PrimitiveFactory primitiveFactory = GeometryFactoryFinder.getPrimitiveFactory(hints);
AggregateFactory aggregateFactory = GeometryFactoryFinder.getAggregateFactory(hints);
WKTParser wktParser = new WKTParser(geometryFactory, primitiveFactory, positionFactory, aggregateFactory);
Geometry geometry = null;
try {
geometry = wktParser.parse("POINT( 48.44 -123.37)");
} catch (ParseException e) {
fail(e.getStackTrace().toString());
}
filter = ff.overlaps("property", geometry);
filterConfig = new Overlaps(category);
node.setFilter(filter, filterConfig);
expected = "Filter : Overlaps";
actual = node.toString();
assertTrue(actual.compareTo(expected) == 0);
assertTrue(filterConfig.category().compareTo(category) == 0);
// Is Between
filter = ff.between(ff.literal(25), ff.literal(5), ff.literal(50));
filterConfig = new IsBetween(category);
node.setFilter(filter, filterConfig);
expected = "Filter : PropertyIsBetween";
actual = node.toString();
assertTrue(actual.compareTo(expected) == 0);
assertTrue(filterConfig.category().compareTo(category) == 0);
// Is Null
filter = ff.isNull(ff.literal(12));
filterConfig = new IsNull(category);
node.setFilter(filter, filterConfig);
expected = "Filter : IsNull";
actual = node.toString();
assertTrue(actual.compareTo(expected) == 0);
assertTrue(filterConfig.category().compareTo(category) == 0);
// BinaryTemporalOperator
filter = ff.after(ff.literal(12), ff.literal(312));
filterConfig = new After(category);
node.setFilter(filter, filterConfig);
expected = "Filter : After";
actual = node.toString();
assertTrue(actual.compareTo(expected) == 0);
assertTrue(filterConfig.category().compareTo(category) == 0);
// Logic filter
filter = ff.and(ff.after(ff.literal(12), ff.literal(312)), ff.between(ff.literal(25), ff.literal(5), ff.literal(50)));
filterConfig = new And(category);
node.setFilter(filter, filterConfig);
expected = "Filter : And";
actual = node.toString();
assertTrue(actual.compareTo(expected) == 0);
assertTrue(filterConfig.category().compareTo(category) == 0);
node.addFilter();
}
use of com.sldeditor.filter.v2.expression.ExpressionPanelv2 in project sldeditor by robward-scisys.
the class FilterNodeTest method testFilterNode.
/**
* Test method for {@link com.sldeditor.filter.v2.expression.FilterNode#FilterNode()}. Test
* method for {@link com.sldeditor.filter.v2.expression.FilterNode#toString()}. Test method for
* {@link com.sldeditor.filter.v2.expression.FilterNode#getFilter()}. Test method for {@link
* com.sldeditor.filter.v2.expression.FilterNode#getType()}. Test method for {@link
* com.sldeditor.filter.v2.expression.FilterNode#setType(java.lang.Class)}.
*/
@Test
public void testFilterNode() {
FilterNode node = new FilterNode();
assertNull(node.getFilter());
assertTrue(node.toString().compareTo(Localisation.getString(ExpressionPanelv2.class, "FilterNode.filterNotSet")) == 0);
Class<?> type = Double.class;
node.setType(type);
assertEquals(type, node.getType());
}
use of com.sldeditor.filter.v2.expression.ExpressionPanelv2 in project sldeditor by robward-scisys.
the class PanelFieldTest method testGetField.
/**
* Test method for {@link
* com.sldeditor.filter.v2.expression.PanelField#getField(java.lang.Class, java.lang.String,
* java.lang.Class, java.util.List)}.
*/
@Test
public void testGetField() {
Class<?> classType = ExpressionPanelv2.class;
String valueTextLocalisation = "ExpressionSubPanel.value";
Map<Class<?>, Class<?>> expectedValueMap = new HashMap<Class<?>, Class<?>>();
expectedValueMap.put(Float.class, FieldConfigDouble.class);
expectedValueMap.put(Geometry.class, FieldConfigGeometry.class);
expectedValueMap.put(Date.class, FieldConfigDate.class);
expectedValueMap.put(ReferencedEnvelope.class, FieldConfigBoundingBox.class);
expectedValueMap.put(String.class, FieldConfigString.class);
expectedValueMap.put(Object.class, FieldConfigString.class);
expectedValueMap.put(Boolean.class, FieldConfigBoolean.class);
expectedValueMap.put(Integer.class, FieldConfigInteger.class);
expectedValueMap.put(Double.class, FieldConfigDouble.class);
expectedValueMap.put(Unit.class, FieldConfigMapUnits.class);
for (Class<?> nodeType : expectedValueMap.keySet()) {
FieldConfigPopulate fieldConfig = PanelField.getField(classType, valueTextLocalisation, nodeType, null, ExpressionNode.UNLIMITED_STRING_SIZE, false, true);
Class<?> expected = expectedValueMap.get(nodeType);
Class<?> actual = (fieldConfig == null) ? null : fieldConfig.getClass();
assertEquals(expected, actual, nodeType.getName());
}
// Special case
// Number.class
FieldConfigPopulate fieldConfig = PanelField.getField(classType, valueTextLocalisation, Number.class, null, ExpressionNode.UNLIMITED_STRING_SIZE, false, true);
Class<?> expected = FieldConfigInteger.class;
Class<?> actual = fieldConfig.getClass();
assertEquals(expected, actual, Number.class.getName());
TypeManager.getInstance().reset();
TypeManager.getInstance().setDataType(Float.class);
fieldConfig = PanelField.getField(classType, valueTextLocalisation, Number.class, null, ExpressionNode.UNLIMITED_STRING_SIZE, false, true);
expected = FieldConfigDouble.class;
actual = fieldConfig.getClass();
assertEquals(expected, actual, Number.class.getName() + "/" + Float.class.getName());
TypeManager.getInstance().reset();
TypeManager.getInstance().setDataType(Double.class);
fieldConfig = PanelField.getField(classType, valueTextLocalisation, Number.class, null, ExpressionNode.UNLIMITED_STRING_SIZE, false, true);
expected = FieldConfigDouble.class;
actual = fieldConfig.getClass();
assertEquals(expected, actual, Number.class.getName() + "/" + Double.class.getName());
TypeManager.getInstance().reset();
TypeManager.getInstance().setDataType(String.class);
fieldConfig = PanelField.getField(classType, valueTextLocalisation, Number.class, null, ExpressionNode.UNLIMITED_STRING_SIZE, false, true);
expected = FieldConfigInteger.class;
actual = fieldConfig.getClass();
assertEquals(expected, actual, Number.class.getName());
// Try single character string
TypeManager.getInstance().reset();
TypeManager.getInstance().setDataType(String.class);
fieldConfig = PanelField.getField(classType, valueTextLocalisation, String.class, null, 1, true, true);
expected = FieldConfigString.class;
actual = fieldConfig.getClass();
assertEquals(expected, actual, String.class.getName());
TypeManager.getInstance().reset();
}
Aggregations