Search in sources :

Example 6 with SimpleEntity

use of org.whole.lang.models.model.SimpleEntity in project whole by wholeplatform.

the class ControlQueriesTest method testChoose3.

@Test
public void testChoose3() {
    Model model = new ModelsModel().create();
    ModelDeclarations decls = model.getDeclarations();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("choose3");
    int i = 0;
    IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model);
    while (iterator.hasNext()) {
        IEntity result = iterator.next();
        IEntity decl = decls.wGet(i++);
        switch(decl.wGetEntityOrd()) {
            case ModelsEntityDescriptorEnum.SimpleEntity_ord:
                Features features = ((SimpleEntity) decl).getFeatures();
                if (!features.isEmpty())
                    assertEquals(features.get(0).getName().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.CompositeEntity_ord:
                CompositeEntity compositeEntity = (CompositeEntity) decl;
                assertEquals(compositeEntity.getComponentType().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.DataEntity_ord:
                DataEntity dataEntity = (DataEntity) decl;
                assertEquals(dataEntity.getDataType().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.EnumEntity_ord:
                EnumEntity enumEntity = (EnumEntity) decl;
                assertEquals(enumEntity.getValues().wGet(0).wStringValue(), result.wStringValue());
                break;
        }
    }
}
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) 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) Features(org.whole.lang.models.model.Features) DataEntity(org.whole.lang.models.model.DataEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 7 with SimpleEntity

use of org.whole.lang.models.model.SimpleEntity in project whole by wholeplatform.

the class ControlQueriesTest method testQueryDecl5.

@Test
public void testQueryDecl5() {
    Model model = new ModelsModel().create();
    ModelDeclarations decls = model.getDeclarations();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("queryDecl5");
    int count = 0;
    int index = 0;
    for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        IEntity decl = decls.wGet(index++);
        switch(decl.wGetEntityOrd()) {
            case ModelsEntityDescriptorEnum.SimpleEntity_ord:
                Features features = ((SimpleEntity) decl).getFeatures();
                if (!features.isEmpty())
                    assertEquals(features.get(0).getName().wStringValue(), p.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.CompositeEntity_ord:
                assertEquals(((CompositeEntity) decl).getComponentType().wStringValue(), p.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.DataEntity_ord:
                assertEquals(((DataEntity) decl).getName().wStringValue(), p.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.EnumEntity_ord:
                assertTrue(Matcher.matchImpl(ModelsEntityDescriptorEnum.EnumEntity, p));
                break;
        }
        count++;
    }
    assertEquals(33, count);
}
Also used : ModelDeclarations(org.whole.lang.models.model.ModelDeclarations) 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) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) IBindingManager(org.whole.lang.bindings.IBindingManager) CompositeEntity(org.whole.lang.models.model.CompositeEntity) ITemplateManager(org.whole.lang.templates.ITemplateManager) Features(org.whole.lang.models.model.Features) DataEntity(org.whole.lang.models.model.DataEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 8 with SimpleEntity

use of org.whole.lang.models.model.SimpleEntity in project whole by wholeplatform.

the class ControlQueriesTest method testChoose2.

@Test
public void testChoose2() {
    Model model = new ModelsModel().create();
    ModelDeclarations decls = model.getDeclarations();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("choose2");
    int i = 0;
    IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model);
    while (iterator.hasNext()) {
        IEntity result;
        IEntity decl = decls.wGet(i++);
        switch(decl.wGetEntityOrd()) {
            case ModelsEntityDescriptorEnum.SimpleEntity_ord:
                IEntity features = ((SimpleEntity) decl).getFeatures();
                for (int j = 0; j < features.wSize(); j++) {
                    result = iterator.next();
                    assertEquals(((Feature) features.wGet(j)).getName().wStringValue(), result.wStringValue());
                }
                break;
            case ModelsEntityDescriptorEnum.CompositeEntity_ord:
                result = iterator.next();
                CompositeEntity compositeEntity = (CompositeEntity) decl;
                assertEquals(compositeEntity.getComponentType().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.DataEntity_ord:
                result = iterator.next();
                DataEntity dataEntity = (DataEntity) decl;
                assertEquals(dataEntity.getDataType().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.EnumEntity_ord:
                EnumValues enumValues = ((EnumEntity) decl).getValues();
                if (enumValues.wIsEmpty())
                    iterator.next();
                else
                    for (int j = 0; j < enumValues.wSize(); j++) {
                        result = iterator.next();
                        assertEquals(enumValues.wGet(j).wStringValue(), result.wStringValue());
                    }
                break;
        }
    }
}
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) DataEntity(org.whole.lang.models.model.DataEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 9 with SimpleEntity

use of org.whole.lang.models.model.SimpleEntity 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);
    }
}
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 10 with SimpleEntity

use of org.whole.lang.models.model.SimpleEntity 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());
    }
}
Also used : ClassDeclaration(org.whole.lang.java.model.ClassDeclaration) 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) 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