Search in sources :

Example 26 with Model

use of org.whole.lang.models.model.Model 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 27 with Model

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

the class SelectQueriesTest method testSelectTemplateWithNestedRelativeQuery.

@Test
public void testSelectTemplateWithNestedRelativeQuery() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Model m = new XmlModel().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithNestedRelativeQuery");
    PathExpression pe2 = (PathExpression) tm.create("selectTemplateWithNestedQuery");
    IEntityIterator<ClassDeclaration> i2 = BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe2, m);
    for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m)) {
        assertTrue(i2.hasNext());
        assertTrue(Matcher.match(i2.next(), t));
    }
}
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 28 with Model

use of org.whole.lang.models.model.Model 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 29 with Model

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

the class MatcherTest method testMultipleRename.

@Test
public void testMultipleRename() {
    Model modelPattern = new ModelPattern().create();
    Variable var1 = (Variable) modelPattern.getDeclarations().wGet(0).wGet(ModelsFeatureDescriptorEnum.features).wGet(0).wGet(ModelsFeatureDescriptorEnum.type).wGetAdaptee(false);
    Variable var2 = (Variable) modelPattern.getDeclarations().wGet(1).wGet(ModelsFeatureDescriptorEnum.name).wGetAdaptee(false);
    assertEquals("dataEntity", var1.getVarName().getValue());
    assertEquals("dataEntity", var2.getVarName().getValue());
    Matcher.rename(modelPattern, "dataEntity", "DE", false);
    assertEquals("DE", var1.getVarName().getValue());
    assertEquals("DE", var2.getVarName().getValue());
}
Also used : Variable(org.whole.lang.commons.model.Variable) TestingModel(org.whole.lang.testentities.codebase.TestingModel) Model(org.whole.lang.models.model.Model) Test(org.junit.Test)

Example 30 with Model

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

the class MatcherTest method testMultipleSubstitute.

@Test
public void testMultipleSubstitute() {
    Model modelPattern = new ModelPattern().create();
    IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
    bindings.wDefValue("dataEntity", "DE");
    IBindingScope args = BindingManagerFactory.instance.createSimpleScope();
    args.wDefValue("dataEntity", "DE");
    Matcher.substitute(modelPattern, args, false);
    SimpleName var1 = (SimpleName) modelPattern.getDeclarations().wGet(0).wGet(ModelsFeatureDescriptorEnum.features).wGet(0).wGet(ModelsFeatureDescriptorEnum.type);
    SimpleName var2 = (SimpleName) modelPattern.getDeclarations().wGet(1).wGet(ModelsFeatureDescriptorEnum.name);
    assertEquals("DE", var1.wStringValue());
    assertEquals("DE", var2.wStringValue());
    assertNotSame(var1, var2);
}
Also used : IBindingScope(org.whole.lang.bindings.IBindingScope) SimpleName(org.whole.lang.models.model.SimpleName) TestingModel(org.whole.lang.testentities.codebase.TestingModel) Model(org.whole.lang.models.model.Model) IBindingManager(org.whole.lang.bindings.IBindingManager) 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