Search in sources :

Example 16 with XmlModel

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

the class PathExpressionsQueriesTest method testChildStepByIndex.

@Test
public void testChildStepByIndex() {
    Model model = new XmlModel().create();
    ModelDeclarations decls = model.getDeclarations();
    IEntity decl3 = decls.wGet(3);
    QueriesEntityFactory ef = QueriesEntityFactory.instance;
    IEntity result = BehaviorUtils.evaluateFirstResult(ef.createFilter(ef.createChildStep(), ef.createIndexTest(ef.createIntLiteral(3))), decls);
    Assert.assertSame(decl3, result);
}
Also used : ModelDeclarations(org.whole.lang.models.model.ModelDeclarations) IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) XmlModel(org.whole.lang.models.codebase.XmlModel) Model(org.whole.lang.models.model.Model) XmlModel(org.whole.lang.models.codebase.XmlModel) Test(org.junit.Test)

Example 17 with XmlModel

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

the class SelectQueriesTest method testSelectTemplateWithNestedQuery.

@Test
public void testSelectTemplateWithNestedQuery() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Model m = new XmlModel().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithNestedQuery");
    for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m)) {
        assertEquals(JavaEntityDescriptorEnum.ClassDeclaration, t.wGetEntityDescriptor());
        assertTrue(t.getBodyDeclarations().wSize() >= 2);
    }
}
Also used : ClassDeclaration(org.whole.lang.java.model.ClassDeclaration) PathExpression(org.whole.lang.queries.model.PathExpression) XmlModel(org.whole.lang.models.codebase.XmlModel) Model(org.whole.lang.models.model.Model) ITemplateManager(org.whole.lang.templates.ITemplateManager) XmlModel(org.whole.lang.models.codebase.XmlModel) Test(org.junit.Test)

Example 18 with XmlModel

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

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

the class SelectQueriesTest method testSelectTemplateWithFreeVariable.

@Test
public void testSelectTemplateWithFreeVariable() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Model m = new XmlModel().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithFreeVariable");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m, bm)) {
        assertEquals(JavaEntityDescriptorEnum.ClassDeclaration, t.wGetEntityDescriptor());
        if (bm.wIsSet("freeVariable")) {
            assertEquals(bm.wStringValue("freeVariable"), t.getName().wStringValue());
            bm.wUnset("freeVariable");
        } else {
            assertTrue(t.getName().wIsAdapter());
            bm.wDefValue("freeVariable", "MyClassName");
        }
    }
}
Also used : ClassDeclaration(org.whole.lang.java.model.ClassDeclaration) PathExpression(org.whole.lang.queries.model.PathExpression) 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 20 with XmlModel

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

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