Search in sources :

Example 21 with ModelDeclarations

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

the class RewriteQueriesTest method testUpdate1.

@Test
public void testUpdate1() {
    Model model = new ModelsModel().create();
    ModelDeclarations declarations = model.getDeclarations();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("update1");
    for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.SimpleName, entity) || Matcher.match(ModelsEntityDescriptorEnum.DataType, entity));
    assertEquals("MyModelName", model.getName().getValue());
    int j = 0;
    for (int i = 0; i < declarations.wSize(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl)) {
            if (j++ == 0) {
                assertEquals("MyFirstName", ((DataEntity) decl).getName().getValue());
                assertEquals("MyFirstDataType", ((DataEntity) decl).getDataType().getValue());
            } else {
                assertEquals("MySecondName", ((DataEntity) decl).getName().getValue());
                return;
            }
        }
    }
}
Also used : ModelDeclarations(org.whole.lang.models.model.ModelDeclarations) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) ITemplateManager(org.whole.lang.templates.ITemplateManager) DataEntity(org.whole.lang.models.model.DataEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 22 with ModelDeclarations

use of org.whole.lang.models.model.ModelDeclarations 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)

Aggregations

ModelDeclarations (org.whole.lang.models.model.ModelDeclarations)22 Test (org.junit.Test)21 IEntity (org.whole.lang.model.IEntity)19 Model (org.whole.lang.models.model.Model)19 ModelsModel (org.whole.lang.models.codebase.ModelsModel)18 PathExpression (org.whole.lang.queries.model.PathExpression)18 ITemplateManager (org.whole.lang.templates.ITemplateManager)18 DataEntity (org.whole.lang.models.model.DataEntity)9 XmlModel (org.whole.lang.models.codebase.XmlModel)7 SimpleEntity (org.whole.lang.models.model.SimpleEntity)7 CompositeEntity (org.whole.lang.models.model.CompositeEntity)5 EnumEntity (org.whole.lang.models.model.EnumEntity)4 ArrayList (java.util.ArrayList)3 Features (org.whole.lang.models.model.Features)3 IBindingManager (org.whole.lang.bindings.IBindingManager)2 EnumValues (org.whole.lang.models.model.EnumValues)2 Feature (org.whole.lang.models.model.Feature)2 ModelDeclaration (org.whole.lang.models.model.ModelDeclaration)2 ClassDeclaration (org.whole.lang.java.model.ClassDeclaration)1 ModelsEntityFactory (org.whole.lang.models.factories.ModelsEntityFactory)1