Search in sources :

Example 6 with XmlModel

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

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

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

the class SelectQueriesTest method testSelectTemplateWithJavaHelpers.

@Test
public void testSelectTemplateWithJavaHelpers() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Model m = new XmlModel().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithJavaHelpers");
    for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m)) {
        assertEquals(JavaEntityDescriptorEnum.ClassDeclaration, t.wGetEntityDescriptor());
        String cname = t.getName().wStringValue();
        assertTrue(Character.isUpperCase(cname.charAt(0)) && cname.endsWith("Impl"));
        for (int i = 0; i < t.getBodyDeclarations().wSize(); i++) {
            FieldDeclaration fd = (FieldDeclaration) t.getBodyDeclarations().wGet(i);
            assertTrue(Character.isUpperCase(fd.getType().wStringValue().charAt(0)));
        }
    }
}
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) FieldDeclaration(org.whole.lang.java.model.FieldDeclaration) Test(org.junit.Test)

Example 9 with XmlModel

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

Example 10 with XmlModel

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

the class SelectQueriesTest method testBindingScopes3.

@Test
public void testBindingScopes3() {
    Model model = new XmlModel().create();
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("selectBindingScopes3");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        Document d = (Document) tuple.wGet(0);
        IEntity nameData = tuple.wGet(1);
        String name = nameData.wStringValue();
        String entityName = bm.wStringValue("entityName");
        assertEquals(name, d.wGet(0).wGet(1).wStringValue());
        assertEquals(name, entityName);
        assertFalse(bm.wIsSet("fromName"));
    }
}
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) XmlModel(org.whole.lang.models.codebase.XmlModel) ITemplateManager(org.whole.lang.templates.ITemplateManager) Document(org.whole.lang.text.model.Document) 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