Search in sources :

Example 1 with ExpressionPanelv2

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);
}
Also used : EnvFunction(org.geotools.filter.function.EnvFunction) ConcatenateFunction(org.geotools.filter.function.string.ConcatenateFunction) Function(org.opengis.filter.expression.Function) EnvFunction(org.geotools.filter.function.EnvFunction) Expression(org.opengis.filter.expression.Expression) DefaultFunctionFactory(org.geotools.filter.function.DefaultFunctionFactory) ExpressionNode(com.sldeditor.filter.v2.expression.ExpressionNode) FunctionImpl(org.geotools.filter.FunctionImpl) ArrayList(java.util.ArrayList) ConcatenateFunction(org.geotools.filter.function.string.ConcatenateFunction) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.jupiter.api.Test)

Example 2 with ExpressionPanelv2

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());
}
Also used : ExpressionPanelv2(com.sldeditor.filter.v2.expression.ExpressionPanelv2) ExpressionNode(com.sldeditor.filter.v2.expression.ExpressionNode) Test(org.junit.jupiter.api.Test)

Example 3 with ExpressionPanelv2

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();
}
Also used : ExpressionPanelv2(com.sldeditor.filter.v2.expression.ExpressionPanelv2) Overlaps(com.sldeditor.filter.v2.function.geometry.Overlaps) GeometryFactory(org.opengis.geometry.coordinate.GeometryFactory) Hints(org.geotools.factory.Hints) PositionFactory(org.opengis.geometry.PositionFactory) FilterNode(com.sldeditor.filter.v2.expression.FilterNode) IsBetween(com.sldeditor.filter.v2.function.property.IsBetween) FilterConfigInterface(com.sldeditor.filter.v2.function.FilterConfigInterface) IsGreaterThan(com.sldeditor.filter.v2.function.property.IsGreaterThan) WKTParser(org.geotools.geometry.text.WKTParser) IsLike(com.sldeditor.filter.v2.function.misc.IsLike) PrimitiveFactory(org.opengis.geometry.primitive.PrimitiveFactory) FilterFactory(org.opengis.filter.FilterFactory) Geometry(org.opengis.geometry.Geometry) Filter(org.opengis.filter.Filter) And(com.sldeditor.filter.v2.function.logic.And) After(com.sldeditor.filter.v2.function.temporal.After) IsNull(com.sldeditor.filter.v2.function.misc.IsNull) AggregateFactory(org.opengis.geometry.aggregate.AggregateFactory) ParseException(java.text.ParseException) Test(org.junit.jupiter.api.Test)

Example 4 with ExpressionPanelv2

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());
}
Also used : ExpressionPanelv2(com.sldeditor.filter.v2.expression.ExpressionPanelv2) FilterNode(com.sldeditor.filter.v2.expression.FilterNode) Test(org.junit.jupiter.api.Test)

Example 5 with ExpressionPanelv2

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();
}
Also used : ExpressionPanelv2(com.sldeditor.filter.v2.expression.ExpressionPanelv2) FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) HashMap(java.util.HashMap) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) FieldConfigPopulate(com.sldeditor.ui.detail.config.FieldConfigPopulate) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)8 ExpressionPanelv2 (com.sldeditor.filter.v2.expression.ExpressionPanelv2)7 ExpressionNode (com.sldeditor.filter.v2.expression.ExpressionNode)4 FilterNode (com.sldeditor.filter.v2.expression.FilterNode)3 SubPanelUpdatedInterface (com.sldeditor.ui.attribute.SubPanelUpdatedInterface)2 FieldConfigInteger (com.sldeditor.ui.detail.config.FieldConfigInteger)2 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)2 ArrayList (java.util.ArrayList)2 JPanel (javax.swing.JPanel)2 FilterFactory (org.opengis.filter.FilterFactory)2 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)1 FilterConfigInterface (com.sldeditor.filter.v2.function.FilterConfigInterface)1 FilterField (com.sldeditor.filter.v2.function.FilterField)1 FunctionField (com.sldeditor.filter.v2.function.FunctionField)1 Disjoint (com.sldeditor.filter.v2.function.geometry.Disjoint)1 Overlaps (com.sldeditor.filter.v2.function.geometry.Overlaps)1 And (com.sldeditor.filter.v2.function.logic.And)1 IsLike (com.sldeditor.filter.v2.function.misc.IsLike)1 IsNull (com.sldeditor.filter.v2.function.misc.IsNull)1 IsBetween (com.sldeditor.filter.v2.function.property.IsBetween)1