use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class RewriteQueriesTest method testUpdate4.
@Test
public void testUpdate4() {
Model model = new ModelsModel().create();
ModelDeclarations declarations = model.getDeclarations();
ITemplateManager tm = RewriteQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("update4");
List<String> dataEntityNames = new ArrayList<String>();
for (int i = 0; i < declarations.wSize(); i++) {
IEntity decl = declarations.wGet(i);
if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl))
dataEntityNames.add(((DataEntity) decl).getName().getValue());
}
for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.SimpleName, entity));
Iterator<String> dataEntityNamesIterator = dataEntityNames.iterator();
for (int i = 0; i < declarations.wSize() && dataEntityNamesIterator.hasNext(); i++) {
IEntity decl = declarations.wGet(i);
if (Matcher.match(ModelsEntityDescriptorEnum.SimpleEntity, decl))
assertEquals(dataEntityNamesIterator.next(), ((SimpleEntity) decl).getName().getValue());
}
for (int i = 0; i < declarations.wSize(); i++) {
IEntity decl = declarations.wGet(i);
if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl))
assertTrue(EntityUtils.isResolver(((DataEntity) decl).getName()));
}
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class RewriteQueriesTest method testUpdate9.
@Test
public void testUpdate9() {
Model model = new ModelsModel().create();
ModelDeclarations declarations = model.getDeclarations();
ITemplateManager tm = RewriteQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("update9");
for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.DataEntity, entity));
for (int i = 0; i < declarations.wSize(); i++) {
IEntity decl = declarations.wGet(i);
if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl)) {
assertEquals("Object", ((DataEntity) decl).getDataType().getValue());
assertTrue(((DataEntity) decl).getName().getValue().startsWith("My"));
}
}
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class RewriteQueriesTest method testUpdate8.
@Test
public void testUpdate8() {
Model model = new ModelsModel().create();
ModelDeclarations declarations = model.getDeclarations();
ITemplateManager tm = RewriteQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("update8");
for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.DataEntity, entity));
for (int i = 0; i < declarations.wSize(); i++) {
IEntity decl = declarations.wGet(i);
if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl)) {
assertEquals("Object", ((DataEntity) decl).getDataType().getValue());
assertTrue(((DataEntity) decl).getName().getValue().startsWith("My"));
}
}
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class SelectQueriesTest method testVariableScopes.
@Test
public void testVariableScopes() {
Model model = new XmlModel().create();
ITemplateManager tm = SelectQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("selectVariableScopes");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
Document d = (Document) tuple.wGet(0);
SimpleEntity se = (SimpleEntity) tuple.wGet(1);
assertFalse(bm.wIsSet("fromName"));
assertFalse(bm.wIsSet("oneTime"));
assertFalse(bm.wIsSet("featuresTimes"));
assertFalse(bm.wIsSet("featuresTimesInLine"));
assertFalse(bm.wIsSet("fTimes"));
assertFalse(bm.wIsSet("siblingTimes"));
// changed semantics: from variables are substituted multiple times
assertTrue(1 < d.wGet(0).wSize() - 1);
assertEquals(1, d.wGet(1).wSize() - 1);
assertEquals(se.getFeatures().wSize(), d.wGet(2).wSize() - 1);
assertEquals(se.getFeatures().wSize(), d.wGet(3).wSize() - 1);
assertEquals(model.getDeclarations().wSize() - 1 - model.getDeclarations().wIndexOf(se), d.wGet(4).wSize() - 1);
}
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class SelectQueriesTest method testSelectTemplateWithTwoNestedSimpleQueries.
@Test
public void testSelectTemplateWithTwoNestedSimpleQueries() {
ITemplateManager tm = SelectQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithTwoNestedSimpleQueries");
for (Feature f : BehaviorUtils.<Feature>compileAndLazyEvaluate(pe1, g)) {
assertEquals(ModelsEntityDescriptorEnum.Feature, f.wGetEntityDescriptor());
}
}
Aggregations