use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition in project hale by halestudio.
the class TestCqlToMappingConditionTranslator method testTranslateGeometricWithin.
/**
* Tests translating a CQL expression which includes a geometric 'within'
* predicate.
*
* @throws CQLException
* if any errors occurred parsing the CQL string
* @throws TranslationException
* if any errors occurred during the translation
*/
// @Test
public void testTranslateGeometricWithin() throws CQLException, TranslationException {
// $NON-NLS-1$
String cqlPredicate = "DWITHIN(ATTR1, POINT(1 2), 10, kilometers)";
ModelMappingCondition result = digester.translate(CQL.toFilter(cqlPredicate));
assertNotNull(result);
assertNotNull(result.getRoot());
assertThat(result.getRoot(), is(instanceOf(WithinNode.class)));
WithinNode withinNode = (WithinNode) result.getRoot();
assertThat(withinNode.getLeaves().size(), is(equalTo(2)));
assertNotNull(withinNode.getLeft());
// $NON-NLS-1$
assertThat(withinNode.getLeft().getPropertyName(), is(equalTo("ATTR1")));
assertNotNull(withinNode.getRight());
// CHECKSTYLE:OFF
assertThat(withinNode.getDistance(), is(equalTo(10.0)));
// CHECKSTYLE:ON
assertThat(withinNode.getDistanceUnits(), is(equalTo(UnitOfMeasureType.kilometers)));
}
use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition in project hale by halestudio.
the class TestCqlToMappingConditionTranslator method testTranslateNegation.
/**
* Tests the negation filter.
*
* @throws CQLException
* if any errors occurred parsing the CQL string
* @throws TranslationException
* if any errors occurred during the translation
*/
@Test
public void testTranslateNegation() throws CQLException, TranslationException {
// $NON-NLS-1$
String cqlPredicate = "TEMA<>'RL_TUNNEL' OR TEMA<>'CL_RAIL' OR TEMA<>'UNSHOWN_RL'";
ModelMappingCondition result = digester.translate(CQL.toFilter(cqlPredicate));
assertNotNull(result);
assertNotNull(result.getRoot());
// TODO finish test assertions
}
use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition in project hale by halestudio.
the class TestCqlToMappingConditionTranslator method testTranslateEqualityTwoProperties.
/**
* Tests translating a CQL expression that creates a simple equality filter
* where both sides of the expression are property names.
*
* @throws CQLException
* if any errors occurred parsing the CQL string
* @throws TranslationException
* if any errors occurred during the translation
*/
@Test
public void testTranslateEqualityTwoProperties() throws CQLException, TranslationException {
// $NON-NLS-1$
String cqlPredicate = "ATTR1 < ATTR2";
ModelMappingCondition result = digester.translate(CQL.toFilter(cqlPredicate));
assertNotNull(result);
assertNotNull(result.getRoot());
assertThat(result.getRoot(), is(instanceOf(LessThanNode.class)));
LessThanNode lessNode = (LessThanNode) result.getRoot();
// $NON-NLS-1$ //$NON-NLS-2$
checkComparisonRightProperty(lessNode, "ATTR1", "ATTR2");
}
use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition in project hale by halestudio.
the class TestCqlToMappingConditionTranslator method testTranslateLogicalPrecedenceOverridden.
/**
* Same as testTranslateSlightlyMoreComplexLogical but brackets around the
* 'OR' express overrides the natural precedence of the 'AND' filter.
*
* @throws CQLException
* if any errors occurred parsing the CQL string
* @throws TranslationException
* if any errors occurred during the translation
*/
@Test
public void testTranslateLogicalPrecedenceOverridden() throws CQLException, TranslationException {
// $NON-NLS-1$
String cqlPredicate = "ATTR1 < 10.5 AND (ATTR2 = 'chocolate' OR ATTR3 > 10)";
ModelMappingCondition result = digester.translate(CQL.toFilter(cqlPredicate));
assertNotNull(result);
assertNotNull(result.getRoot());
assertThat(result.getRoot(), is(instanceOf(AndNode.class)));
AndNode andNode = (AndNode) result.getRoot();
assertNotNull(andNode.getChildren());
assertThat(andNode.getChildren().size(), is(equalTo(2)));
assertThat(andNode.getChild(0), is(instanceOf(LessThanNode.class)));
LessThanNode lessNode = (LessThanNode) andNode.getChild(0);
// $NON-NLS-1$ //$NON-NLS-2$
checkComparisonRightLiteral(lessNode, "ATTR1", "10.5");
assertThat(andNode.getChild(1), is(instanceOf(OrNode.class)));
OrNode orNode = (OrNode) andNode.getChild(1);
assertThat(orNode.getChildren().size(), is(equalTo(2)));
assertThat(orNode.getChild(0), is(instanceOf(EqualToNode.class)));
EqualToNode equalNode = (EqualToNode) orNode.getChild(0);
// $NON-NLS-1$ //$NON-NLS-2$
checkComparisonRightLiteral(equalNode, "ATTR2", "chocolate");
assertThat(orNode.getChild(1), is(instanceOf(GreaterThanNode.class)));
GreaterThanNode greaterNode = (GreaterThanNode) orNode.getChild(1);
// $NON-NLS-1$ //$NON-NLS-2$
checkComparisonRightLiteral(greaterNode, "ATTR3", "10");
}
use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition in project hale by halestudio.
the class TestCqlToMappingConditionTranslator method testTranslateSimpleLogical.
/**
* Test that takes a simple logical expression comprising a parent logical
* filter and for each child filter, an equality test.
*
* @throws CQLException
* if any errors occurred parsing the CQL string
* @throws TranslationException
* if any errors occurred during the translation
*/
@Test
public void testTranslateSimpleLogical() throws CQLException, TranslationException {
// $NON-NLS-1$
String cqlPredicate = "ATTR1 < 10 AND ATTR2 < 2";
ModelMappingCondition result = digester.translate(CQL.toFilter(cqlPredicate));
assertNotNull(result);
assertNotNull(result.getRoot());
assertThat(result.getRoot(), is(instanceOf(AndNode.class)));
assertNotNull(result.getRoot().getChildren());
assertThat(result.getRoot().getChildren().size(), is(equalTo(2)));
FilterNode firstNode = result.getRoot().getChildren().get(0);
assertThat(firstNode, is(instanceOf(LessThanNode.class)));
LessThanNode less1 = (LessThanNode) firstNode;
assertNotNull(less1.getLeft());
assertNotNull(less1.getLeft().getPropertyName());
// $NON-NLS-1$
assertThat(less1.getLeft().getPropertyName(), is(equalTo("ATTR1")));
assertNotNull(less1.getRight());
assertNotNull(less1.getRight().getLiteralValue());
// $NON-NLS-1$
assertThat(less1.getRight().getLiteralValue().toString(), is(equalTo("10")));
FilterNode secondNode = result.getRoot().getChildren().get(1);
assertThat(secondNode, is(instanceOf(LessThanNode.class)));
LessThanNode less2 = (LessThanNode) secondNode;
assertNotNull(less2.getLeft());
assertNotNull(less2.getLeft().getPropertyName());
// $NON-NLS-1$
assertThat(less2.getLeft().getPropertyName(), is(equalTo("ATTR2")));
assertNotNull(less2.getRight());
assertNotNull(less2.getRight().getLiteralValue());
// $NON-NLS-1$
assertThat(less2.getRight().getLiteralValue().toString(), is(equalTo("2")));
}
Aggregations