Search in sources :

Example 6 with LessThanNode

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

LessThanNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode)6 Test (org.junit.Test)6 ModelMappingCondition (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition)5 EqualToNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode)3 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 ModelAlignment (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment)1 ModelAttributeMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell)1 ModelClassMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelClassMappingCell)1 ModelStaticAssignmentCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell)1 OrNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.OrNode)1 URL (java.net.URL)1