Search in sources :

Example 21 with SimpleEntity

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());
    }
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) SimpleEntity(org.whole.lang.models.model.SimpleEntity) XmlModel(org.whole.lang.models.codebase.XmlModel) Model(org.whole.lang.models.model.Model) XmlModel(org.whole.lang.models.codebase.XmlModel) ITemplateManager(org.whole.lang.templates.ITemplateManager) Feature(org.whole.lang.models.model.Feature) FieldDeclaration(org.whole.lang.java.model.FieldDeclaration) Test(org.junit.Test)

Example 22 with SimpleEntity

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());
    }
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) SimpleEntity(org.whole.lang.models.model.SimpleEntity) XmlModel(org.whole.lang.models.codebase.XmlModel) Model(org.whole.lang.models.model.Model) IBindingManager(org.whole.lang.bindings.IBindingManager) ITemplateManager(org.whole.lang.templates.ITemplateManager) XmlModel(org.whole.lang.models.codebase.XmlModel) Test(org.junit.Test)

Example 23 with SimpleEntity

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)));
    }
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) SimpleEntity(org.whole.lang.models.model.SimpleEntity) XmlModel(org.whole.lang.models.codebase.XmlModel) Model(org.whole.lang.models.model.Model) IBindingManager(org.whole.lang.bindings.IBindingManager) XmlModel(org.whole.lang.models.codebase.XmlModel) ITemplateManager(org.whole.lang.templates.ITemplateManager) Document(org.whole.lang.text.model.Document) Test(org.junit.Test)

Example 24 with SimpleEntity

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());
}
Also used : EnumEntity(org.whole.lang.models.model.EnumEntity) IEntity(org.whole.lang.model.IEntity) SimpleEntity(org.whole.lang.models.model.SimpleEntity) ITemplateManager(org.whole.lang.templates.ITemplateManager) Feature(org.whole.lang.models.model.Feature) EnumValues(org.whole.lang.models.model.EnumValues) ModelDeclarations(org.whole.lang.models.model.ModelDeclarations) PathExpression(org.whole.lang.queries.model.PathExpression) XmlModel(org.whole.lang.models.codebase.XmlModel) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) CompositeEntity(org.whole.lang.models.model.CompositeEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 25 with SimpleEntity

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));
}
Also used : SimpleEntity(org.whole.lang.models.model.SimpleEntity) Test(org.junit.Test)

Aggregations

SimpleEntity (org.whole.lang.models.model.SimpleEntity)29 Test (org.junit.Test)22 IEntity (org.whole.lang.model.IEntity)14 Model (org.whole.lang.models.model.Model)13 PathExpression (org.whole.lang.queries.model.PathExpression)13 ITemplateManager (org.whole.lang.templates.ITemplateManager)13 XmlModel (org.whole.lang.models.codebase.XmlModel)12 IBindingManager (org.whole.lang.bindings.IBindingManager)9 ModelsModel (org.whole.lang.models.codebase.ModelsModel)7 ModelDeclarations (org.whole.lang.models.model.ModelDeclarations)7 CompositeEntity (org.whole.lang.models.model.CompositeEntity)6 DataEntity (org.whole.lang.models.model.DataEntity)5 EnumEntity (org.whole.lang.models.model.EnumEntity)5 Feature (org.whole.lang.models.model.Feature)5 Features (org.whole.lang.models.model.Features)5 EnumValues (org.whole.lang.models.model.EnumValues)3 Document (org.whole.lang.text.model.Document)3 ClassDeclaration (org.whole.lang.java.model.ClassDeclaration)2 ModelsEntityFactory (org.whole.lang.models.factories.ModelsEntityFactory)2 ArrayList (java.util.ArrayList)1