Search in sources :

Example 1 with XmlModel

use of org.whole.lang.models.codebase.XmlModel in project whole by wholeplatform.

the class ControlQueriesTest method testDo1.

@Test
public void testDo1() {
    Model model = new XmlModel().create();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("do1");
    IEntity result = BehaviorUtils.evaluateFirstResult(query, model);
    assertTrue(result instanceof ClassDeclaration);
    assertEquals("HelloWorld", ((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 2 with XmlModel

use of org.whole.lang.models.codebase.XmlModel in project whole by wholeplatform.

the class ControlQueriesTest method testIf2.

@Test
public void testIf2() {
    Model model = new XmlModel().create();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("if2");
    IEntity result = BehaviorUtils.evaluateFirstResult(query, model);
    assertTrue(result instanceof ClassDeclaration);
    assertEquals(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 3 with XmlModel

use of org.whole.lang.models.codebase.XmlModel in project whole by wholeplatform.

the class ControlQueriesTest method testFor1.

@Test
public void testFor1() {
    Model model = new XmlModel().create();
    ModelDeclarations decls = model.getDeclarations();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("for1");
    int i = 0;
    for (IEntity name : BehaviorUtils.compileAndLazyEvaluate(query, model)) {
        while (!Matcher.match(ModelsEntityDescriptorEnum.SimpleEntity, decls.wGet(i))) i++;
        assertEquals(((SimpleEntity) decls.wGet(i++)).getName().wStringValue(), name.wStringValue());
    }
    assertTrue(i > 0);
}
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) XmlModel(org.whole.lang.models.codebase.XmlModel) ITemplateManager(org.whole.lang.templates.ITemplateManager) Test(org.junit.Test)

Example 4 with XmlModel

use of org.whole.lang.models.codebase.XmlModel in project whole by wholeplatform.

the class ControlQueriesTest method testIf1.

@Test
public void testIf1() {
    Model model = new XmlModel().create();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("if1");
    assertFalse(BehaviorUtils.compileAndLazyEvaluate(query, model.getDeclarations()).hasNext());
    IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model);
    assertTrue(iterator.hasNext());
    assertEquals(model.getName().getValue(), iterator.next().wStringValue());
    assertFalse(iterator.hasNext());
}
Also used : 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 5 with XmlModel

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

Aggregations

Test (org.junit.Test)26 XmlModel (org.whole.lang.models.codebase.XmlModel)26 Model (org.whole.lang.models.model.Model)25 PathExpression (org.whole.lang.queries.model.PathExpression)23 ITemplateManager (org.whole.lang.templates.ITemplateManager)22 IEntity (org.whole.lang.model.IEntity)17 ClassDeclaration (org.whole.lang.java.model.ClassDeclaration)10 IBindingManager (org.whole.lang.bindings.IBindingManager)9 SimpleEntity (org.whole.lang.models.model.SimpleEntity)7 FieldDeclaration (org.whole.lang.java.model.FieldDeclaration)6 ModelsModel (org.whole.lang.models.codebase.ModelsModel)5 Feature (org.whole.lang.models.model.Feature)4 Document (org.whole.lang.text.model.Document)4 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)3 ModelDeclarations (org.whole.lang.models.model.ModelDeclarations)2 Assignment (org.whole.lang.java.model.Assignment)1 BodyDeclarations (org.whole.lang.java.model.BodyDeclarations)1 ExpressionStatement (org.whole.lang.java.model.ExpressionStatement)1 MethodDeclaration (org.whole.lang.java.model.MethodDeclaration)1 SingleVariableDeclaration (org.whole.lang.java.model.SingleVariableDeclaration)1