use of org.whole.lang.models.codebase.XmlModel in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testHelperResultAs.
@Test
public void testHelperResultAs() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Model m = new XmlModel().create();
PathExpression query = (PathExpression) tm.create("helperResultAs");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
bm.wDefValue("ftype", "firstName");
IEntityIterator<?> iterator = BehaviorUtils.<FieldDeclaration>compileAndLazyEvaluate(query, m, bm);
Assert.assertTrue(iterator.hasNext());
IEntity result = iterator.next();
IEntity as = bm.wGet("jtype");
Assert.assertEquals("FirstName", result.wStringValue());
Assert.assertEquals("FirstName", as.wStringValue());
Assert.assertFalse(iterator.hasNext());
iterator.reset(m);
bm.wDefValue("ftype", "secondName");
Assert.assertTrue(iterator.hasNext());
IEntity result2 = iterator.next();
IEntity as2 = bm.wGet("jtype");
Assert.assertEquals("SecondName", result2.wStringValue());
Assert.assertEquals("SecondName", as2.wStringValue());
}
use of org.whole.lang.models.codebase.XmlModel 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.models.codebase.XmlModel in project whole by wholeplatform.
the class SelectQueriesTest method testSelectTemplateWithJavaHelpers.
@Test
public void testSelectTemplateWithJavaHelpers() {
ITemplateManager tm = SelectQueriesTemplateManager.instance();
Model m = new XmlModel().create();
PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithJavaHelpers");
for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m)) {
assertEquals(JavaEntityDescriptorEnum.ClassDeclaration, t.wGetEntityDescriptor());
String cname = t.getName().wStringValue();
assertTrue(Character.isUpperCase(cname.charAt(0)) && cname.endsWith("Impl"));
for (int i = 0; i < t.getBodyDeclarations().wSize(); i++) {
FieldDeclaration fd = (FieldDeclaration) t.getBodyDeclarations().wGet(i);
assertTrue(Character.isUpperCase(fd.getType().wStringValue().charAt(0)));
}
}
}
use of org.whole.lang.models.codebase.XmlModel in project whole by wholeplatform.
the class SelectQueriesTest method testTemplateFromWhere.
@Test
public void testTemplateFromWhere() {
Model m = new XmlModel().create();
SimpleEntity simpleEntity = (SimpleEntity) m.getDeclarations().wGet(0);
ITemplateManager tm = SelectQueriesTemplateManager.instance();
PathExpression pe1 = (PathExpression) tm.create("selectTemplateFromWhere");
for (ClassDeclaration classDecl : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, simpleEntity)) {
assertEquals(StringUtils.toUpperCap(simpleEntity.getName().getValue()), classDecl.getName().wStringValue());
int featuresSize = simpleEntity.getFeatures().wSize();
assertEquals(featuresSize * 2, classDecl.getBodyDeclarations().wSize());
}
}
use of org.whole.lang.models.codebase.XmlModel in project whole by wholeplatform.
the class SelectQueriesTest method testBindingScopes3.
@Test
public void testBindingScopes3() {
Model model = new XmlModel().create();
ITemplateManager tm = SelectQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("selectBindingScopes3");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
Document d = (Document) tuple.wGet(0);
IEntity nameData = tuple.wGet(1);
String name = nameData.wStringValue();
String entityName = bm.wStringValue("entityName");
assertEquals(name, d.wGet(0).wGet(1).wStringValue());
assertEquals(name, entityName);
assertFalse(bm.wIsSet("fromName"));
}
}
Aggregations