Search in sources :

Example 6 with ModelMappingCondition

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)));
}
Also used : WithinNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.geometric.WithinNode) ModelMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition)

Example 7 with ModelMappingCondition

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
}
Also used : ModelMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition) Test(org.junit.Test)

Example 8 with ModelMappingCondition

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");
}
Also used : LessThanNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode) ModelMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition) Test(org.junit.Test)

Example 9 with ModelMappingCondition

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");
}
Also used : EqualToNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode) AndNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.AndNode) GreaterThanNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.GreaterThanNode) LessThanNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode) ModelMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition) OrNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.OrNode) Test(org.junit.Test)

Example 10 with ModelMappingCondition

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")));
}
Also used : FilterNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode) LessThanNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode) ModelMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition) Test(org.junit.Test)

Aggregations

ModelMappingCondition (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition)12 Test (org.junit.Test)8 EqualToNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode)5 LessThanNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode)5 GreaterThanNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.GreaterThanNode)3 AndNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.AndNode)3 FilterNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode)2 ModelAttributeMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell)1 ModelStaticAssignmentCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell)1 ModelSentence (com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelSentence)1 AbstractFilterNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.AbstractFilterNode)1 AbstractComparisonNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.AbstractComparisonNode)1 AbstractGeometricNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.geometric.AbstractGeometricNode)1 WithinNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.geometric.WithinNode)1 NotNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.NotNode)1 OrNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.OrNode)1 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)1 CompareFilterImpl (org.geotools.filter.CompareFilterImpl)1 GeometryFilterImpl (org.geotools.filter.GeometryFilterImpl)1 LogicFilterImpl (org.geotools.filter.LogicFilterImpl)1