Search in sources :

Example 16 with Model

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

the class ControlQueriesTest method testIf3.

@Test
public void testIf3() {
    Model model = new XmlModel().create();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("if3");
    IEntity result = BehaviorUtils.evaluateFirstResult(query, model);
    assertTrue(result instanceof ClassDeclaration);
    assertEquals(StringUtils.toUpperCap(model.getName().getValue()), ((ClassDeclaration) result).getName().getValue());
}
Also used : ClassDeclaration(org.whole.lang.java.model.ClassDeclaration) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) XmlModel(org.whole.lang.models.codebase.XmlModel) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) XmlModel(org.whole.lang.models.codebase.XmlModel) ITemplateManager(org.whole.lang.templates.ITemplateManager) Test(org.junit.Test)

Example 17 with Model

use of org.whole.lang.models.model.Model 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());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) 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) FieldDeclaration(org.whole.lang.java.model.FieldDeclaration) Test(org.junit.Test)

Example 18 with Model

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

the class RewriteQueriesTest method testUpdate7.

@Test
public void testUpdate7() {
    Model model = new ModelsModel().create();
    ModelDeclarations declarations = model.getDeclarations();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("update7");
    for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.SimpleName, entity));
    for (int i = 0; i < declarations.wSize(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl))
            assertEquals("DataEntityName", ((DataEntity) decl).getName().getValue());
    }
}
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) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 19 with Model

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

the class RewriteQueriesTest method testUpdate6.

@Test
public void testUpdate6() {
    Model model = new ModelsModel().create();
    ModelDeclarations declarations = model.getDeclarations();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("update6");
    for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.SimpleName, entity));
    for (int i = 0; i < declarations.wSize(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl))
            assertEquals("DataEntityName", ((DataEntity) decl).getName().getValue());
    }
}
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) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 20 with Model

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

the class RewriteQueriesTest method testUpdate4.

@Test
public void testUpdate4() {
    Model model = new ModelsModel().create();
    ModelDeclarations declarations = model.getDeclarations();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("update4");
    List<String> dataEntityNames = new ArrayList<String>();
    for (int i = 0; i < declarations.wSize(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl))
            dataEntityNames.add(((DataEntity) decl).getName().getValue());
    }
    for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.SimpleName, entity));
    Iterator<String> dataEntityNamesIterator = dataEntityNames.iterator();
    for (int i = 0; i < declarations.wSize() && dataEntityNamesIterator.hasNext(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.SimpleEntity, decl))
            assertEquals(dataEntityNamesIterator.next(), ((SimpleEntity) decl).getName().getValue());
    }
    for (int i = 0; i < declarations.wSize(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl))
            assertTrue(EntityUtils.isResolver(((DataEntity) decl).getName()));
    }
}
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) ArrayList(java.util.ArrayList) ITemplateManager(org.whole.lang.templates.ITemplateManager) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Aggregations

Model (org.whole.lang.models.model.Model)62 Test (org.junit.Test)55 PathExpression (org.whole.lang.queries.model.PathExpression)43 ITemplateManager (org.whole.lang.templates.ITemplateManager)41 IEntity (org.whole.lang.model.IEntity)40 XmlModel (org.whole.lang.models.codebase.XmlModel)30 ModelsModel (org.whole.lang.models.codebase.ModelsModel)25 ModelDeclarations (org.whole.lang.models.model.ModelDeclarations)19 IBindingManager (org.whole.lang.bindings.IBindingManager)15 SimpleEntity (org.whole.lang.models.model.SimpleEntity)14 ClassDeclaration (org.whole.lang.java.model.ClassDeclaration)12 DataEntity (org.whole.lang.models.model.DataEntity)10 Feature (org.whole.lang.models.model.Feature)9 ArrayList (java.util.ArrayList)6 FieldDeclaration (org.whole.lang.java.model.FieldDeclaration)6 CompositeEntity (org.whole.lang.models.model.CompositeEntity)4 Features (org.whole.lang.models.model.Features)4 EditorsModel (org.whole.lang.models.codebase.EditorsModel)3 EnumEntity (org.whole.lang.models.model.EnumEntity)3 SimpleName (org.whole.lang.models.model.SimpleName)3