Search in sources :

Example 1 with OrNode

use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.OrNode 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)

Aggregations

ModelMappingCondition (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition)1 EqualToNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode)1 GreaterThanNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.GreaterThanNode)1 LessThanNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode)1 AndNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.AndNode)1 OrNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.OrNode)1 Test (org.junit.Test)1