Search in sources :

Example 1 with Document

use of org.whole.lang.text.model.Document 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 2 with Document

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

Example 3 with Document

use of org.whole.lang.text.model.Document in project whole by wholeplatform.

the class SelectQueriesTest method testBindingScopes2.

@Test
public void testBindingScopes2() {
    Model model = new XmlModel().create();
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("selectBindingScopes2");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        Document d = (Document) tuple.wGet(0);
        SimpleEntity e = (SimpleEntity) tuple.wGet(1);
        String eName = e.getName().getValue();
        assertEquals(eName, d.wGet(0).wGet(1).wStringValue());
        assertEquals(eName, d.wGet(0).wGet(2).wStringValue());
        assertEquals(eName + eName, d.wGet(1).wGet(1).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) 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 4 with Document

use of org.whole.lang.text.model.Document in project whole by wholeplatform.

the class SelectQueriesTest method testBindingScopes.

@Test
public void testBindingScopes() {
    Model m = new XmlModel().create();
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("selectBindingScopes");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    BindingsTester bt = new BindingsTester(bm);
    bm.wDefValue("bindingsTester", bt);
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, m, bm)) {
        Document d = (Document) tuple.wGet(0);
        SimpleEntity e = (SimpleEntity) tuple.wGet(1);
        String eName = e.getName().getValue();
        assertEquals(eName, d.wGet(0).wGet(1).wStringValue());
        assertEquals(eName + eName, d.wGet(1).wGet(1).wStringValue());
        assertEquals(eName + eName + eName + eName, d.wGet(2).wGet(1).wStringValue());
        for (int f = 0; f < e.getFeatures().wSize(); f++) {
            assertEquals(eName + eName + eName + eName + eName + eName + eName + eName, d.wGet(3).wGet(1 + f).wStringValue());
            assertEquals("true", d.wGet(4).wGet(1 + f).wStringValue());
            assertEquals("true", d.wGet(5).wGet(1 + f).wStringValue());
        }
        assertEquals(3, d.wGet(6).wSize());
        assertTrue(EntityUtils.isVariable(d.wGet(6).wGet(1)));
        assertTrue(EntityUtils.isVariable(d.wGet(6).wGet(2)));
    }
}
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)

Aggregations

Test (org.junit.Test)4 IBindingManager (org.whole.lang.bindings.IBindingManager)4 IEntity (org.whole.lang.model.IEntity)4 XmlModel (org.whole.lang.models.codebase.XmlModel)4 Model (org.whole.lang.models.model.Model)4 PathExpression (org.whole.lang.queries.model.PathExpression)4 ITemplateManager (org.whole.lang.templates.ITemplateManager)4 Document (org.whole.lang.text.model.Document)4 SimpleEntity (org.whole.lang.models.model.SimpleEntity)3