Java Code Examples for org.opengis.filter.FilterFactory#literal()

The following examples show how to use org.opengis.filter.FilterFactory#literal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FieldConfigBaseTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigBase#expressionUpdated(org.opengis.filter.expression.Expression)}.
 */
@Test
public void testExpressionUpdated() {
    FieldIdEnum expectedFieldId = FieldIdEnum.NAME;
    String expectedLabel = "test label";
    TestFieldConfigBase field =
            new TestFieldConfigBase(
                    new FieldConfigCommonData(
                            String.class, expectedFieldId, expectedLabel, false, false));

    TestUpdateSymbolInterface listener = new TestUpdateSymbolInterface();
    field.addDataChangedListener(listener);

    String expressionName = "test expression";
    assertFalse(listener.hasBeenCalled());
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Expression testExpression = ff.literal(expressionName);
    field.expressionUpdated(testExpression);
    assertTrue(listener.hasBeenCalled());

    assertEquals(ExpressionTypeEnum.E_EXPRESSION, field.getExpressionType());
    Expression expression = field.getExpression();
    assertTrue(expressionName.compareTo(expression.toString()) == 0);
}
 
Example 2
Source File: ArrowUtilsTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.marker.arrow.ArrowUtils#decodeArrowThickness(java.lang.String)}.
 */
@Test
public void testDecodeArrowThickness() {
    FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);

    Expression hr = ff.literal(1.2);
    Expression t = ff.literal(0.34);
    Expression ab = ff.literal(0.56);
    String expectedString = ArrowUtils.encode(hr, t, ab);

    Expression actual = ArrowUtils.decodeArrowThickness(expectedString);
    assertEquals(t.toString(), actual.toString());

    actual = ArrowUtils.decodeArrowThickness("abcdefg");
    assertEquals("0.2", actual.toString());

    actual = ArrowUtils.decodeHeightOverWidth(expectedString);
    assertEquals(hr.toString(), actual.toString());

    actual = ArrowUtils.decodeHeightOverWidth("abcdefg");
    assertEquals("2.0", actual.toString());

    actual = ArrowUtils.decodeHeadBaseRatio(expectedString);
    assertEquals(ab.toString(), actual.toString());

    actual = ArrowUtils.decodeHeadBaseRatio("abcdefg");
    assertEquals("0.5", actual.toString());
}
 
Example 3
Source File: ColourUtilsTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.common.utils.ColourUtils#getIntColour(org.opengis.filter.expression.Expression)}.
 */
@Test
public void testGetIntColour() {

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Expression colourExpression = ff.literal("#FF00FF");
    int colourValue = ColourUtils.getIntColour(colourExpression);
    assertEquals(0xff00ff, colourValue);

    colourValue = ColourUtils.getIntColour(null);
}
 
Example 4
Source File: EnvironmentVariableManagerTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.filter.v2.envvar.EnvironmentVariableManager#getDataType(org.opengis.filter.expression.Expression)}.
 */
@Test
public void testGetDataType() {
    Class<?> dataType = EnvironmentVariableManager.getInstance().getDataType(null);
    assertEquals(Object.class, dataType);

    dataType = EnvironmentVariableManager.getInstance().getDataType(ConstantExpression.TWO);
    assertEquals(Object.class, dataType);

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Expression literal = ff.literal("wms_width");
    dataType = EnvironmentVariableManager.getInstance().getDataType(literal);
    assertEquals(Integer.class, dataType);
}
 
Example 5
Source File: ColourRampTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/** Test method for {@link com.sldeditor.colourramp.ColourRamp#ColourRamp()}. */
@Test
public void testColourRamp() {
    ColourRamp ramp = new ColourRamp();

    assertEquals(Color.BLACK, ramp.getStartColour());
    assertEquals(Color.WHITE, ramp.getEndColour());

    Color expectedStart = Color.red;
    Color expectedEnd = Color.pink;

    ramp.setColourRamp(expectedStart, expectedEnd);
    assertEquals(expectedStart, ramp.getStartColour());
    assertEquals(expectedEnd, ramp.getEndColour());

    Color expectedEnd2 = Color.cyan;
    ramp.addColour(expectedEnd2);
    assertEquals(expectedStart, ramp.getStartColour());
    assertEquals(expectedEnd2, ramp.getEndColour());
    assertEquals(3, ramp.getColourList().size());

    ImageIcon icon1 = ramp.getImageIcon(false);
    assertNotNull(icon1);
    ImageIcon icon2 = ramp.getImageIcon(true);
    assertNotNull(icon2);

    FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
    ColourRampData data = new ColourRampData();
    Expression expectedMinValue = ff.literal(1);
    Expression expectedMaxValue = ff.literal(10);
    data.setColourRamp(ramp);
    data.setMinValue(1);
    data.setMaxValue(10);

    Expression actualStart = ramp.getColour(data, expectedMinValue, false);
    @SuppressWarnings("unused")
    Expression actualEnd = ramp.getColour(data, expectedMaxValue, false);

    assertEquals(ColourUtils.toColour(actualStart.toString()), expectedStart);

    // Can't test end value
    // assertEquals(ColourUtils.toColour(actualEnd.toString()), expectedEnd2);

    // Reverse colours
    actualStart = ramp.getColour(data, expectedMinValue, true);
    actualEnd = ramp.getColour(data, expectedMaxValue, true);

    assertEquals(ColourUtils.toColour(actualStart.toString()), expectedEnd2);
    // Can't test end value
    //        assertEquals(ColourUtils.toColour(actualEnd.toString()), expectedStart);
}
 
Example 6
Source File: FieldConfigBaseTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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, 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());
}
 
Example 7
Source File: FieldConfigGeometryFieldTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigGeometryField#generateExpression()}. Test method
 * for {@link
 * com.sldeditor.ui.detail.config.FieldConfigGeometryField#populateExpression(java.lang.Object)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigGeometryField#populateField(java.lang.String)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigGeometryField#setTestValue(com.sldeditor.ui.detail.config.FieldId,
 * java.lang.String)}. Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigGeometryField#getStringValue()}.
 */
@Test
public void testGenerateExpression() {
    class TestFieldConfigGeometryField extends FieldConfigGeometryField {

        public TestFieldConfigGeometryField(FieldConfigCommonData commonData) {
            super(commonData);
        }

        public Expression callGenerateExpression() {
            return generateExpression();
        }
    }

    TestFieldConfigGeometryField field =
            new TestFieldConfigGeometryField(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", false, false));
    Expression actualExpression = field.callGenerateExpression();
    assertNull(actualExpression);

    field.createUI();
    TestDataSource testDataSource = new TestDataSource();
    @SuppressWarnings("unused")
    DataSourceInterface dataSource = DataSourceFactory.createDataSource(testDataSource);

    field.dataSourceLoaded(GeometryTypeEnum.POLYGON, false);

    String expectedValue = "";
    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue);
    actualExpression = field.callGenerateExpression();
    assertTrue(expectedValue.compareTo(actualExpression.toString()) == 0);

    // Attribute expression
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Expression expectedExpression = ff.property(testDataSource.getDefaultGeometryField());
    field.populateExpression(expectedExpression);
    actualExpression = field.callGenerateExpression();
    assertTrue(expectedExpression.toString().compareTo(actualExpression.toString()) == 0);

    // Literal expression
    expectedExpression = ff.literal(testDataSource.getDefaultGeometryField());
    field.populateExpression(expectedExpression);
    actualExpression = field.callGenerateExpression();
    assertTrue(expectedExpression.toString().compareTo(actualExpression.toString()) == 0);

    // Property exists
    DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();

    List<Expression> expList = new ArrayList<Expression>();
    expList.add(ff.literal(TestDataSource.GEOMETRY_FIELD));
    Function func = functionFactory.function("PropertyExists", expList, null);
    expectedExpression = func;
    field.populateExpression(func);
    actualExpression = field.callGenerateExpression();
    assertTrue(TestDataSource.GEOMETRY_FIELD.compareTo(actualExpression.toString()) == 0);

    // Set null values
    field.populateField((String) null);
    String stringValue = field.getStringValue();
    assertNull(stringValue);

    field.populateExpression((String) null);
    stringValue = field.getStringValue();
    assertNull(stringValue);
}
 
Example 8
Source File: VOGeoServerTextSymbolizer2Test.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.text.VOGeoServerTextSymbolizer2#VOGeoServerTextSymbolizer2(java.lang.Class,
 * com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testVOGeoServerTextSymbolizer2() {
    TextSymbolizerDetails panel = new TextSymbolizerDetails();

    TextSymbolizer2 textSymbolizer = null;
    VOGeoServerTextSymbolizer2 testObj = new VOGeoServerTextSymbolizer2(panel.getClass());
    testObj.setParentPanel(panel);
    testObj.populate(textSymbolizer);
    testObj.updateSymbol(textSymbolizer);

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    textSymbolizer = (TextSymbolizer2) styleFactory.createTextSymbolizer();

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Literal featureDescription = ff.literal("feature description");
    textSymbolizer.setFeatureDescription(featureDescription);

    OtherText otherText = new OtherTextImpl();
    otherText.setTarget("target");
    Literal otherTextExpression = ff.literal("other text");
    otherText.setText(otherTextExpression);
    textSymbolizer.setOtherText(otherText);
    Literal snippet = ff.literal("snippet");
    textSymbolizer.setSnippet(snippet);

    // Try with marker symbol
    Graphic graphic = styleFactory.createDefaultGraphic();
    graphic.graphicalSymbols().add(styleFactory.createMark());
    textSymbolizer.setGraphic(graphic);
    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);

    // Try with external graphic
    graphic = styleFactory.createDefaultGraphic();
    try {
        graphic.graphicalSymbols()
                .add(
                        styleFactory.createExternalGraphic(
                                new File("test.png").toURI().toURL(), "png"));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    textSymbolizer.setGraphic(graphic);
    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);

    // Find minimum version with textSymbolizer2 values set
    List<VendorOptionPresent> vendorOptionsPresentList = new ArrayList<VendorOptionPresent>();
    testObj.getMinimumVersion(null, textSymbolizer, vendorOptionsPresentList);
    assertEquals(1, vendorOptionsPresentList.size());

    // Find minimum version with no textSymbolizer2 values set
    vendorOptionsPresentList.clear();
    testObj.getMinimumVersion(
            null, styleFactory.createTextSymbolizer(), vendorOptionsPresentList);
    assertEquals(0, vendorOptionsPresentList.size());

    // Get the code coverage values up
    testObj.populate(SelectedSymbol.getInstance());

    PolygonSymbolizer polygon = null;
    testObj.populate(polygon);
    testObj.updateSymbol(polygon);

    RasterSymbolizer raster = null;
    testObj.populate(raster);
    testObj.updateSymbol(raster);
    testObj.preLoadSymbol();
    assertTrue(testObj.isDataPresent());
}
 
Example 9
Source File: VOGeoServerTextSpacingTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.text.VOGeoServerTextSpacingTest#VOGeoServerTextSpacingTest(java.lang.Class,
 * com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testVOGeoServerTextSpacingTest() {
    TextSymbolizerDetails panel = new TextSymbolizerDetails();

    TextSymbolizer2 textSymbolizer = null;
    VOGeoServerTextSpacing testObj = new VOGeoServerTextSpacing(panel.getClass());
    testObj.setParentPanel(panel);
    testObj.populate(textSymbolizer);
    testObj.updateSymbol(textSymbolizer);

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    textSymbolizer = (TextSymbolizer2) styleFactory.createTextSymbolizer();

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Literal featureDescription = ff.literal("feature description");
    textSymbolizer.setFeatureDescription(featureDescription);

    OtherText otherText = new OtherTextImpl();
    otherText.setTarget("target");
    Literal otherTextExpression = ff.literal("other text");
    otherText.setText(otherTextExpression);
    textSymbolizer.setOtherText(otherText);
    Literal snippet = ff.literal("snippet");
    textSymbolizer.setSnippet(snippet);

    // Try with marker symbol
    Graphic graphic = styleFactory.createDefaultGraphic();
    graphic.graphicalSymbols().add(styleFactory.createMark());
    textSymbolizer.setGraphic(graphic);
    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);

    // Try with external graphic
    graphic = styleFactory.createDefaultGraphic();
    try {
        graphic.graphicalSymbols()
                .add(
                        styleFactory.createExternalGraphic(
                                new File("test.png").toURI().toURL(), "png"));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    textSymbolizer.setGraphic(graphic);

    textSymbolizer.getOptions().put("wordSpacing", String.valueOf(42));
    textSymbolizer.getOptions().put("charSpacing", String.valueOf(21));

    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);

    // Find minimum version with textSymbolizer2 values set
    List<VendorOptionPresent> vendorOptionsPresentList = new ArrayList<VendorOptionPresent>();
    testObj.getMinimumVersion(null, textSymbolizer, vendorOptionsPresentList);
    assertEquals(2, vendorOptionsPresentList.size());

    // Find minimum version with no textSymbolizer2 values set
    vendorOptionsPresentList.clear();
    testObj.getMinimumVersion(
            null, styleFactory.createTextSymbolizer(), vendorOptionsPresentList);
    assertEquals(0, vendorOptionsPresentList.size());

    // Get the code coverage values up
    testObj.populate(SelectedSymbol.getInstance());

    PolygonSymbolizer polygon = null;
    testObj.populate(polygon);
    testObj.updateSymbol(polygon);

    FeatureTypeStyle fts = null;
    testObj.populate(fts);
    testObj.updateSymbol(fts);

    RasterSymbolizer raster = null;
    testObj.populate(raster);
    testObj.updateSymbol(raster);
    testObj.preLoadSymbol();
    assertTrue(testObj.isDataPresent());
}
 
Example 10
Source File: ExpressionNodeTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 11
Source File: FunctionTableModelTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/** Test all the methods using a ProcessFunction */
@SuppressWarnings({"unchecked", "rawtypes"})
@Test
void testProcessFunction() {
    FunctionTableModel model = new FunctionTableModel();

    assertEquals(0, model.getRowCount());

    model.addNewValue(0);
    ProcessFunction processFunction = createProcessFunction();

    FunctionName name =
            new FunctionNameImpl(
                    new NameImpl("vec", "PointStacker"),
                    parameter("cellSize", Double.class),
                    new Parameter(
                            "outputBBOX", Number.class, null, null, false, 0, 100, null, null),
                    parameter("outputWidth", Number.class),
                    parameter("outputHeight", Number.class));

    assertFalse(name.getArguments().get(0).isRequired());
    assertTrue(name.getArguments().get(1).isRequired());

    model.populate(name, processFunction);

    assertEquals(3, model.getRowCount());
    assertEquals(4, model.getColumnCount());

    // Get value
    assertEquals("outputBBOX", model.getValueAt(0, 0));
    assertEquals(Number.class.getSimpleName(), model.getValueAt(0, 1));
    assertEquals(true, model.getValueAt(0, 2));
    assertEquals("env([wms_bbox])", model.getValueAt(0, 3));
    assertNull(model.getValueAt(0, 4));

    // Is editable
    assertFalse(model.isCellEditable(0, 0));
    assertFalse(model.isCellEditable(0, 1));
    assertTrue(model.isCellEditable(0, FunctionTableModel.getOptionalColumn()));
    assertFalse(model.isCellEditable(0, 3));
    assertFalse(model.isCellEditable(0, 4));

    // Set value
    model.setValueAt(true, 0, 2);
    assertTrue((Boolean) model.getValueAt(0, FunctionTableModel.getOptionalColumn()));
    model.setValueAt(false, 0, 2);
    assertFalse((Boolean) model.getValueAt(0, FunctionTableModel.getOptionalColumn()));

    // Get row
    assertNull(model.getValue(-1));
    assertNull(model.getValue(10));

    // Add a new value
    assertEquals(0, model.getNoOfOccurences(null));
    ProcessFunctionParameterValue value = model.getValue(0);
    assertEquals(1, model.getNoOfOccurences(value));
    model.addNewValue(0);
    assertEquals(4, model.getRowCount());

    assertEquals(2, model.getNoOfOccurences(value));

    // Remove value
    model.removeValue(3);
    assertEquals(3, model.getRowCount());

    // Get expression
    ProcessFunction actualFunction = model.getExpression(null);
    assertNull(actualFunction);

    model.setValueAt(true, 0, FunctionTableModel.getOptionalColumn());

    ProcessFunctionFactory factory = new ProcessFunctionFactory();
    actualFunction = model.getExpression(factory);
    assertNotNull(actualFunction);

    // Update expression
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Expression expression = ff.literal(4.2);
    model.update(expression, 0);
    model.update(null, 1);
}
 
Example 12
Source File: FunctionTableModelTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test all the methods using a ProcessBriefType.
 *
 * <p>Not tested because it needs to interact with GeoServer to create a receive a remote custom
 * WPS function.
 */
@SuppressWarnings({"unchecked", "rawtypes"})
@Disabled
@Test
void testProcessBriefType() {
    FunctionTableModel model = new FunctionTableModel();

    assertEquals(0, model.getRowCount());

    model.addNewValue(0);
    ProcessBriefType customFunction = createCustomFunction();

    FunctionName name =
            new FunctionNameImpl(
                    new NameImpl("vec", "PointStacker"),
                    parameter("cellSize", Double.class),
                    new Parameter(
                            "outputBBOX", Number.class, null, null, false, 0, 100, null, null),
                    parameter("outputWidth", Number.class),
                    parameter("outputHeight", Number.class));

    assertFalse(name.getArguments().get(0).isRequired());
    assertTrue(name.getArguments().get(1).isRequired());

    model.populate(customFunction);

    assertEquals(3, model.getRowCount());
    assertEquals(4, model.getColumnCount());

    // Get value
    assertEquals("outputBBOX", model.getValueAt(0, 0));
    assertEquals(Number.class.getSimpleName(), model.getValueAt(0, 1));
    assertEquals(true, model.getValueAt(0, 2));
    assertEquals("env([wms_bbox])", model.getValueAt(0, 3));
    assertNull(model.getValueAt(0, 4));

    // Is editable
    assertFalse(model.isCellEditable(0, 0));
    assertFalse(model.isCellEditable(0, 1));
    assertTrue(model.isCellEditable(0, FunctionTableModel.getOptionalColumn()));
    assertFalse(model.isCellEditable(0, 3));
    assertFalse(model.isCellEditable(0, 4));

    // Set value
    model.setValueAt(true, 0, 2);
    assertTrue((Boolean) model.getValueAt(0, FunctionTableModel.getOptionalColumn()));
    model.setValueAt(false, 0, 2);
    assertFalse((Boolean) model.getValueAt(0, FunctionTableModel.getOptionalColumn()));

    // Get row
    assertNull(model.getValue(-1));
    assertNull(model.getValue(10));

    // Add a new value
    assertEquals(0, model.getNoOfOccurences(null));
    ProcessFunctionParameterValue value = model.getValue(0);
    assertEquals(1, model.getNoOfOccurences(value));
    model.addNewValue(0);
    assertEquals(4, model.getRowCount());

    assertEquals(2, model.getNoOfOccurences(value));

    // Remove value
    model.removeValue(3);
    assertEquals(3, model.getRowCount());

    // Get expression
    ProcessFunction actualFunction = model.getExpression(null);
    assertNull(actualFunction);

    model.setValueAt(true, 0, FunctionTableModel.getOptionalColumn());

    ProcessFunctionFactory factory = new ProcessFunctionFactory();
    actualFunction = model.getExpression(factory);
    assertNotNull(actualFunction);

    // Update expression
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Expression expression = ff.literal(4.2);
    model.update(expression, 0);
    model.update(null, 1);
}