/**
* Test evaluating complex feature
*/
// test evaluating simple property
AttributeExpressionImpl ex = new AttributeExpressionImpl("eg:simpleAttribute", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
assertEquals(simpleAttribute, ex.evaluate(feature));
// test evaluating complex property
ex = new AttributeExpressionImpl("eg:complexAttribute", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
assertEquals(complexAttribute, ex.evaluate(feature));
// test multi-valued nested properties
ex = new AttributeExpressionImpl("eg:complexAttribute/eg:rootAttribute", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
// no index would return array of all features
Object o = ex.evaluate(feature);
assertTrue( o instanceof List );
assertEquals(3, ((List) o).size());
assertEquals(rootOne, ((List) o).get(0));
assertEquals(rootTwo, ((List) o).get(1));
assertEquals(rootThree, ((List) o).get(2));
//test nested on multi-valued attributes
ex = new AttributeExpressionImpl("eg:complexAttribute/eg:rootAttribute/eg:singleLeafAttribute", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
// no index would return array of all features
o = ex.evaluate(feature);
assertTrue( o instanceof List );
assertEquals(3, ((List) o).size());
assertEquals(singleLeaf, ((List) o).get(0));
assertEquals(singleLeaf, ((List) o).get(1));
assertEquals(singleLeaf, ((List) o).get(2));
// index specified
ex = new AttributeExpressionImpl("eg:complexAttribute/eg:rootAttribute[1]", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
assertEquals(rootOne, ex.evaluate(feature));
ex = new AttributeExpressionImpl("eg:complexAttribute/eg:rootAttribute[2]", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
assertEquals(rootTwo, ex.evaluate(feature));
// single valued nested property
ex = new AttributeExpressionImpl(
"eg:complexAttribute/eg:rootAttribute[3]/eg:singleLeafAttribute", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
assertEquals(singleLeaf, ex.evaluate(feature));
// null values
ex = new AttributeExpressionImpl(
"eg:complexAttribute/eg:rootAttribute[3]/eg:multiLeafAttribute", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
assertEquals(null, ex.evaluate(feature));
// deeper nesting
ex = new AttributeExpressionImpl(
"eg:complexAttribute/eg:rootAttribute[2]/eg:multiLeafAttribute", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
assertEquals(leafOne, ex.evaluate(feature));
// property index doesn't exist
ex = new AttributeExpressionImpl(
"eg:complexAttribute/eg:rootAttribute[2]/eg:multiLeafAttribute[2]", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
assertEquals(null, ex.evaluate(feature));
// expect an exception when object supplied is not a complex attribute
boolean exceptionThrown = false;
try {
ex.setLenient(false); //NC -added, only exception if lenient off
assertEquals(null, ex.evaluate(singleLeaf));
} catch (Exception e) {
exceptionThrown = true;
}
if (!exceptionThrown) {
fail("Expecting Exception since object passed in is not a complex attribute.");
}
// invalid property
ex = new AttributeExpressionImpl("randomAttribute", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
assertEquals(null, ex.evaluate(feature));
assertEquals(null, ex.evaluate(fType));
// NC - test xml attribute
ex = new AttributeExpressionImpl(
"eg:complexAttribute/eg:rootAttribute[3]/eg:singleLeafAttribute/@eg:att", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
assertEquals("test attribute", ex.evaluate(feature));
// NC - test descriptor functionality
ex = new AttributeExpressionImpl("eg:simpleAttribute", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
assertEquals( simpleAttributeDesc, ex.evaluate(fType));
ex = new AttributeExpressionImpl("eg:complexAttribute", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
assertEquals( complexDesc, ex.evaluate(fType));
// test nested properties
ex = new AttributeExpressionImpl("eg:complexAttribute/eg:rootAttribute", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
assertEquals( rootDesc, ex.evaluate(fType));
ex = new AttributeExpressionImpl(
"eg:complexAttribute/eg:rootAttribute/eg:singleLeafAttribute", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
assertEquals(singleLeafDesc, ex.evaluate(fType));
ex = new AttributeExpressionImpl(
"eg:complexAttribute/eg:rootAttribute/eg:multiLeafAttribute", new Hints(
FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
assertEquals(multiLeafDesc, ex.evaluate(fType));
}