Search in sources :

Example 1 with ExpressionNode

use of com.sldeditor.filter.v2.expression.ExpressionNode 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.Test)

Example 2 with ExpressionNode

use of com.sldeditor.filter.v2.expression.ExpressionNode 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.Test)

Example 3 with ExpressionNode

use of com.sldeditor.filter.v2.expression.ExpressionNode in project sldeditor by robward-scisys.

the class ExpressionNodeTest method testSetName.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.expression.ExpressionNode#setName(java.lang.String)}.
 */
@Test
public void testSetName() {
    String expectedName = "test";
    ExpressionNode node = new ExpressionNode();
    assertTrue(node.toString().compareTo(Localisation.getString(ExpressionPanelv2.class, "ExpressionPanelv2.expressionNotSet")) == 0);
    node.setName(expectedName);
    assertTrue(node.toString().compareTo(expectedName + " : " + Localisation.getString(ExpressionPanelv2.class, "ExpressionPanelv2.expressionNotSet")) == 0);
}
Also used : ExpressionPanelv2(com.sldeditor.filter.v2.expression.ExpressionPanelv2) ExpressionNode(com.sldeditor.filter.v2.expression.ExpressionNode) Test(org.junit.Test)

Example 4 with ExpressionNode

use of com.sldeditor.filter.v2.expression.ExpressionNode in project sldeditor by robward-scisys.

the class ExpressionNodeTest method testSetExpressionType.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.expression.ExpressionNode#setExpressionType(com.sldeditor.filter.v2.expression.ExpressionTypeEnum)}.
 * Test method for
 * {@link com.sldeditor.filter.v2.expression.ExpressionNode#getExpressionType()}.
 */
@Test
public void testSetExpressionType() {
    ExpressionNode node = new ExpressionNode();
    assertTrue(node.toString().compareTo(Localisation.getString(ExpressionPanelv2.class, "ExpressionPanelv2.expressionNotSet")) == 0);
    node.setExpressionType(ExpressionTypeEnum.LITERAL);
    assertEquals(ExpressionTypeEnum.LITERAL, node.getExpressionType());
    assertTrue(node.toString().compareTo(Localisation.getString(ExpressionPanelv2.class, "ExpressionPanelv2.literalNotSet")) == 0);
    node.setExpressionType(ExpressionTypeEnum.PROPERTY);
    assertEquals(ExpressionTypeEnum.PROPERTY, node.getExpressionType());
    assertTrue(node.toString().compareTo(Localisation.getString(ExpressionPanelv2.class, "ExpressionPanelv2.propertyNotSet")) == 0);
    assertNull(node.getExpression());
}
Also used : ExpressionPanelv2(com.sldeditor.filter.v2.expression.ExpressionPanelv2) ExpressionNode(com.sldeditor.filter.v2.expression.ExpressionNode) Test(org.junit.Test)

Aggregations

ExpressionNode (com.sldeditor.filter.v2.expression.ExpressionNode)4 Test (org.junit.Test)4 ExpressionPanelv2 (com.sldeditor.filter.v2.expression.ExpressionPanelv2)3 ArrayList (java.util.ArrayList)1 FunctionImpl (org.geotools.filter.FunctionImpl)1 DefaultFunctionFactory (org.geotools.filter.function.DefaultFunctionFactory)1 EnvFunction (org.geotools.filter.function.EnvFunction)1 ConcatenateFunction (org.geotools.filter.function.string.ConcatenateFunction)1 FilterFactory (org.opengis.filter.FilterFactory)1 Expression (org.opengis.filter.expression.Expression)1 Function (org.opengis.filter.expression.Function)1