use of org.whole.lang.models.model.SimpleEntity in project whole by wholeplatform.
the class SelectQueriesTest method testSelectTemplateFromPatternWithWhere.
@Test
public void testSelectTemplateFromPatternWithWhere() {
Model m = new XmlModel().create();
Feature feature = (Feature) ((SimpleEntity) m.getDeclarations().wGet(0)).getFeatures().wGet(0);
ITemplateManager tm = SelectQueriesTemplateManager.instance();
PathExpression pe1 = (PathExpression) tm.create("selectTemplateFromPatternWithWhere");
for (FieldDeclaration field : BehaviorUtils.<FieldDeclaration>compileAndLazyEvaluate(pe1, feature)) {
assertEquals(feature.getName().wStringValue(), field.getFragments().wGet(0).wGet(0).wStringValue());
assertEquals(StringUtils.toUpperCap(feature.getType().wStringValue()), field.getType().wStringValue());
}
}
use of org.whole.lang.models.model.SimpleEntity in project whole by wholeplatform.
the class SelectQueriesTest method testSelectHelperResultAs.
@Test
public void testSelectHelperResultAs() {
ITemplateManager tm = SelectQueriesTemplateManager.instance();
Model model = new XmlModel().create();
PathExpression query = (PathExpression) tm.create("selectHelperResultAs");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
IEntity stringData = tuple.wGet(0);
SimpleEntity e = (SimpleEntity) tuple.wGet(1);
String entityName = e.getName().getValue();
String className = bm.wStringValue("className");
assertEquals(StringUtils.toUpperCap(entityName), className);
assertEquals(className, stringData.wStringValue());
}
}
use of org.whole.lang.models.model.SimpleEntity in project whole by wholeplatform.
the class SelectQueriesTest method testBindingScopes.
@Test
public void testBindingScopes() {
Model m = new XmlModel().create();
ITemplateManager tm = SelectQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("selectBindingScopes");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
BindingsTester bt = new BindingsTester(bm);
bm.wDefValue("bindingsTester", bt);
for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, m, bm)) {
Document d = (Document) tuple.wGet(0);
SimpleEntity e = (SimpleEntity) tuple.wGet(1);
String eName = e.getName().getValue();
assertEquals(eName, d.wGet(0).wGet(1).wStringValue());
assertEquals(eName + eName, d.wGet(1).wGet(1).wStringValue());
assertEquals(eName + eName + eName + eName, d.wGet(2).wGet(1).wStringValue());
for (int f = 0; f < e.getFeatures().wSize(); f++) {
assertEquals(eName + eName + eName + eName + eName + eName + eName + eName, d.wGet(3).wGet(1 + f).wStringValue());
assertEquals("true", d.wGet(4).wGet(1 + f).wStringValue());
assertEquals("true", d.wGet(5).wGet(1 + f).wStringValue());
}
assertEquals(3, d.wGet(6).wSize());
assertTrue(EntityUtils.isVariable(d.wGet(6).wGet(1)));
assertTrue(EntityUtils.isVariable(d.wGet(6).wGet(2)));
}
}
use of org.whole.lang.models.model.SimpleEntity in project whole by wholeplatform.
the class ControlQueriesTest method testChoose1.
@Test
public void testChoose1() {
Model model = new ModelsModel().create();
ModelDeclarations decls = model.getDeclarations();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("choose1");
assertFalse(BehaviorUtils.compileAndLazyEvaluate(query, model).hasNext());
int i = 0;
while (!Matcher.match(ModelsEntityDescriptorEnum.SimpleEntity, decls.wGet(i))) i++;
SimpleEntity simpleEntity = (SimpleEntity) decls.wGet(i);
int j = 0;
for (IEntity name : BehaviorUtils.compileAndLazyEvaluate(query, simpleEntity)) {
assertEquals(((Feature) simpleEntity.getFeatures().wGet(j++)).getName().wStringValue(), name.wStringValue());
}
assertEquals(simpleEntity.getFeatures().wSize(), j);
while (!Matcher.match(ModelsEntityDescriptorEnum.CompositeEntity, decls.wGet(i))) i++;
CompositeEntity compositeEntity = (CompositeEntity) decls.wGet(i);
IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, compositeEntity);
assertTrue(iterator.hasNext());
assertEquals(compositeEntity.getComponentType().wStringValue(), iterator.next().wStringValue());
assertFalse(iterator.hasNext());
while (!Matcher.match(ModelsEntityDescriptorEnum.EnumEntity, decls.wGet(i))) i++;
EnumEntity enumEntity = (EnumEntity) decls.wGet(i);
iterator = BehaviorUtils.compileAndLazyEvaluate(query, enumEntity);
assertTrue(iterator.hasNext());
assertTrue(iterator.next() instanceof EnumValues);
assertFalse(iterator.hasNext());
}
use of org.whole.lang.models.model.SimpleEntity in project whole by wholeplatform.
the class ModelInvariantsTest method testSetOrphanByIndexInComposite.
@Test
public void testSetOrphanByIndexInComposite() {
IEntity parent = model.getDeclarations();
int index = 0;
IEntity oldChild = parent.wGet(index);
SimpleEntity newChild = ModelsEntityFactory.instance.createSimpleEntity();
Assert.assertTrue(parent.wContains(oldChild));
Assert.assertSame(parent, oldChild.wGetParent());
Assert.assertTrue(EntityUtils.hasParent(oldChild));
Assert.assertSame(NullEntity.instance, newChild.wGetParent());
Assert.assertTrue(!EntityUtils.hasParent(newChild));
parent.wSet(index, newChild);
Assert.assertFalse(parent.wContains(oldChild));
Assert.assertSame(NullEntity.instance, oldChild.wGetParent());
Assert.assertTrue(!EntityUtils.hasParent(oldChild));
Assert.assertSame(parent, newChild.wGetParent());
Assert.assertTrue(EntityUtils.hasParent(newChild));
parent.wSet(index, oldChild);
Assert.assertSame(parent, oldChild.wGetParent());
Assert.assertTrue(EntityUtils.hasParent(oldChild));
Assert.assertSame(NullEntity.instance, newChild.wGetParent());
Assert.assertTrue(!EntityUtils.hasParent(newChild));
}
Aggregations