use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode in project hale by halestudio.
the class TestAlignmentToModelAlignmentDigester method testExample3CPWithFilter.
/**
* Tests translation based on the example 3 CP data set including a simple
* predicate filter on the mapping of source classes to the target logical
* schema.
*
* @throws TranslationException
* if any errors occurred during the translation
*/
@Test
public void testExample3CPWithFilter() throws TranslationException {
URL url = getClass().getClassLoader().getResource(// $NON-NLS-1$
"com/onespatial/jrc/tnstg/proto/oml_to_rif/alignments/example3_cp_filter.goml");
ModelAlignment result = translator.translate(url);
assertNotNull(result);
assertNotNull(result.getClassMappings());
assertNotNull(result.getAttributeMappings());
assertNotNull(result.getStaticAssignments());
assertThat(result.getClassMappings().size(), is(1));
ModelClassMappingCell modelClassMappingCell = result.getClassMappings().get(0);
assertNotNull(modelClassMappingCell);
assertNotNull(modelClassMappingCell.getSourceClass());
assertNotNull(modelClassMappingCell.getTargetClass());
assertNotNull(modelClassMappingCell.getMappingConditions());
assertThat(modelClassMappingCell.getMappingConditions().size(), is(1));
assertNotNull(modelClassMappingCell.getMappingConditions().get(0).getRoot());
FilterNode root = modelClassMappingCell.getMappingConditions().get(0).getRoot();
assertThat(root, is(instanceOf(LessThanNode.class)));
LessThanNode lessNode = (LessThanNode) root;
assertNotNull(lessNode.getLeft());
// $NON-NLS-1$
assertThat(lessNode.getLeft().getPropertyName(), is(equalTo("MI_PRINX")));
// $NON-NLS-1$
assertThat(lessNode.getRight().getLiteralValue().toString(), is(equalTo("3.5")));
assertNotNull(lessNode.getRight());
// $NON-NLS-1$
assertThat(modelClassMappingCell.getSourceClass().getElementName().getLocalPart(), is("ParcelArea"));
// $NON-NLS-1$
assertThat(modelClassMappingCell.getTargetClass().getElementName().getLocalPart(), is("CadastralParcel"));
// CHECKSTYLE:OFF
assertThat(result.getAttributeMappings().size(), is(7));
// CHECKSTYLE:ON
ModelAttributeMappingCell attributeMapping0 = result.getAttributeMappings().get(0);
assertThat(attributeMapping0.getSourceAttribute().get(0).getDefinition().getName(), // $NON-NLS-1$
is("PCVL_PRCL_"));
assertThat(attributeMapping0.getTargetAttribute().get(0).getDefinition().getName(), // $NON-NLS-1$
is("inspireId"));
assertThat(result.getStaticAssignments().size(), is(1));
ModelStaticAssignmentCell assignment0 = result.getStaticAssignments().get(0);
// $NON-NLS-1$
assertThat(assignment0.getTarget().get(0).getDefinition().getName(), is("inspireId"));
// $NON-NLS-1$
assertThat(assignment0.getContent(), is("DP.CAD.CP"));
}
use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode in project hale by halestudio.
the class TestCqlToMappingConditionTranslator method testTranslateMoreComplexLogical.
/**
* Test that takes a slightly more complex logical expression comprising a
* nested tree of predicates each comprising a comparison operation. Also it
* tests the greater than and equals operations, and contains a mix of
* string, floating-point and integer literals.
*
* @throws CQLException
* if any errors occurred parsing the CQL string
* @throws TranslationException
* if any errors occurred during the translation
*/
@Test
public void testTranslateMoreComplexLogical() 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(OrNode.class)));
assertNotNull(result.getRoot().getChildren());
assertThat(result.getRoot().getChildren().size(), is(equalTo(2)));
assertThat(result.getRoot().getChild(0), is(instanceOf(AndNode.class)));
AndNode andNode = (AndNode) result.getRoot().getChild(0);
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(EqualToNode.class)));
EqualToNode equalNode = (EqualToNode) andNode.getChild(1);
// $NON-NLS-1$ //$NON-NLS-2$
checkComparisonRightLiteral(equalNode, "ATTR2", "chocolate");
assertThat(result.getRoot().getChild(1), is(instanceOf(GreaterThanNode.class)));
GreaterThanNode greaterNode = (GreaterThanNode) result.getRoot().getChild(1);
// $NON-NLS-1$ //$NON-NLS-2$
checkComparisonRightLiteral(greaterNode, "ATTR3", "10");
}
use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode in project hale by halestudio.
the class TestCqlToMappingConditionTranslator method testTranslateAndWithThreeChildren.
/**
* Tests translating a CQL expression where an 'AND' filter has three child
* comparison operators.
*
* @throws CQLException
* if any errors occurred parsing the CQL string
* @throws TranslationException
* if any errors occurred during the translation
*/
@Test
public void testTranslateAndWithThreeChildren() throws CQLException, TranslationException {
// $NON-NLS-1$
String cqlPredicate = "ATTR1 < 10.5 AND ATTR2 = 'chocolate' AND ATTR3 > 10";
ModelMappingCondition result = digester.translate(CQL.toFilter(cqlPredicate));
assertNotNull(result);
assertNotNull(result.getRoot());
assertThat(result.getRoot(), instanceOf(AndNode.class));
AndNode andNode = (AndNode) result.getRoot();
assertThat(andNode.getChildren().size(), is(equalTo(2)));
assertThat(andNode.getChild(0), is(instanceOf(AndNode.class)));
AndNode nestedAndNode = (AndNode) andNode.getChild(0);
assertThat(nestedAndNode.getChild(0), is(instanceOf(LessThanNode.class)));
LessThanNode lessNode = (LessThanNode) nestedAndNode.getChild(0);
// $NON-NLS-1$ //$NON-NLS-2$
checkComparisonRightLiteral(lessNode, "ATTR1", "10.5");
assertThat(nestedAndNode.getChild(1), is(instanceOf(EqualToNode.class)));
EqualToNode equalNode = (EqualToNode) nestedAndNode.getChild(1);
// $NON-NLS-1$ //$NON-NLS-2$
checkComparisonRightLiteral(equalNode, "ATTR2", "chocolate");
assertThat(andNode.getChild(1), is(instanceOf(GreaterThanNode.class)));
GreaterThanNode greaterNode = (GreaterThanNode) andNode.getChild(1);
// $NON-NLS-1$ //$NON-NLS-2$
checkComparisonRightLiteral(greaterNode, "ATTR3", "10");
}
use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode 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.rif.filter.nonterminal.comparison.LessThanNode 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");
}
Aggregations