use of org.opengis.filter.capability.FunctionName in project sldeditor by robward-scisys.
the class BuiltInProcessFunctionTest method testExtractParametersProcessFunction.
/**
* Test method for
* {@link com.sldeditor.rendertransformation.BuiltInProcessFunction#extractParameters(org.opengis.filter.capability.FunctionName, org.geotools.process.function.ProcessFunction)}.
*/
@Test
public void testExtractParametersProcessFunction() {
BuiltInProcessFunction obj = new BuiltInProcessFunction();
String testData = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<StyledLayerDescriptor version=\"1.0.0\" xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" xmlns=\"http://www.opengis.net/sld\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<ogc:Function name=\"vec:PointStacker\">" + "<ogc:Function name=\"parameter\">" + " <ogc:Literal>data</ogc:Literal>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + " <ogc:Literal>cellSize</ogc:Literal>" + " <ogc:Literal>30</ogc:Literal>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + " <ogc:Literal>outputBBOX</ogc:Literal>" + " <ogc:Function name=\"env\">" + " <ogc:Literal>wms_bbox</ogc:Literal>" + " </ogc:Function>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + " <ogc:Literal>outputWidth</ogc:Literal>" + " <ogc:Function name=\"env\">" + " <ogc:Literal>wms_width</ogc:Literal>" + " </ogc:Function>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + " <ogc:Literal>outputHeight</ogc:Literal>" + " <ogc:Function name=\"env\">" + " <ogc:Literal>wms_height</ogc:Literal>" + " </ogc:Function>" + " </ogc:Function>" + "</ogc:Function>" + "</StyledLayerDescriptor>";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
ProcessFunction tx = null;
try {
builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(testData));
Document doc = builder.parse(is);
ExpressionDOMParser parser = new ExpressionDOMParser(CommonFactoryFinder.getFilterFactory2(null));
tx = (ProcessFunction) parser.expression(doc.getDocumentElement().getFirstChild());
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
List<ProcessFunctionParameterValue> valueList = obj.extractParameters(null, tx);
assertTrue(valueList.isEmpty());
ProcessFunctionFactory processFunctionFactory = new ProcessFunctionFactory();
for (FunctionName functionName : processFunctionFactory.getFunctionNames()) {
if (functionName.getName().compareTo("PointStacker") == 0) {
valueList = obj.extractParameters(functionName, tx);
assertEquals(functionName.getArguments().size(), valueList.size());
}
}
}
use of org.opengis.filter.capability.FunctionName 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.opengis.filter.capability.FunctionName 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);
}
use of org.opengis.filter.capability.FunctionName in project sldeditor by robward-scisys.
the class FunctionManagerTest method testGetFunctionNameList2.
/**
* Test method for
* {@link com.sldeditor.filter.v2.function.FunctionManager#getFunctionNameList(java.lang.Class)}.
* Testing FunctionNameFilterRaster
*/
@Test
public void testGetFunctionNameList2() {
Class<?> returnType = FunctionManager.getInstance().getFunctionType(null);
assertNull(returnType);
List<FunctionName> functionNameList = FunctionManager.getInstance().getFunctionNameList(Object.class, null);
FunctionName propertyFunction = null;
FunctionName idFunction = null;
FunctionName areaFunction = null;
FunctionName ceilFunction = null;
for (FunctionName functionName : functionNameList) {
if (functionName.getName().compareTo("property") == 0) {
propertyFunction = functionName;
} else if (functionName.getName().compareTo("id") == 0) {
idFunction = functionName;
} else if (functionName.getName().compareTo("Area") == 0) {
areaFunction = functionName;
} else if (functionName.getName().compareTo("ceil") == 0) {
ceilFunction = functionName;
}
}
assertNotNull(propertyFunction);
assertNotNull(areaFunction);
assertNotNull(ceilFunction);
assertNotNull(idFunction);
List<FunctionNameFilterInterface> functionNameFilterList = new ArrayList<FunctionNameFilterInterface>();
FunctionNameFilterRaster rasterFilter = new FunctionNameFilterRaster();
rasterFilter.accept(null);
functionNameFilterList.add(rasterFilter);
List<FunctionName> rasterFunctionNameList = FunctionManager.getInstance().getFunctionNameList(Object.class, functionNameFilterList);
assertFalse(rasterFunctionNameList.contains(propertyFunction));
assertFalse(rasterFunctionNameList.contains(areaFunction));
assertFalse(rasterFunctionNameList.contains(idFunction));
assertTrue(rasterFunctionNameList.contains(ceilFunction));
}
use of org.opengis.filter.capability.FunctionName in project sldeditor by robward-scisys.
the class FunctionManagerTest method testGetFunctionNameList.
/**
* Test method for
* {@link com.sldeditor.filter.v2.function.FunctionManager#getFunctionNameList(java.lang.Class)}.
*/
@Test
public void testGetFunctionNameList() {
DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
List<FunctionName> functionNameList = functionFactory.getFunctionNames();
// CHECKSTYLE:OFF
Class<?>[] allowedNumberTypes = { Number.class, Double.class, Float.class, Integer.class, Long.class, Object.class };
// CHECKSTYLE:ON
List<Class<?>> allowedNumberTypesList = Arrays.asList(allowedNumberTypes);
int count = 0;
for (FunctionName functionName : functionNameList) {
Class<?> type = functionName.getReturn().getType();
if (allowedNumberTypesList.contains(type)) {
count++;
}
}
List<FunctionNameFilterInterface> functionNameFilterList = new ArrayList<FunctionNameFilterInterface>();
functionNameFilterList.add(new FunctionNameFilterAll());
List<FunctionName> actualList = FunctionManager.getInstance().getFunctionNameList(Number.class, functionNameFilterList);
assertEquals(count, actualList.size());
// Try with null
actualList = FunctionManager.getInstance().getFunctionNameList(null, null);
assertEquals(functionNameList.size(), actualList.size());
// Try with non-matching class
actualList = FunctionManager.getInstance().getFunctionNameList(FunctionManagerTest.class, functionNameFilterList);
assertTrue(actualList.isEmpty());
}
Aggregations