Search in sources :

Example 21 with Model

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

the class RewriteQueriesTest method testUpdate9.

@Test
public void testUpdate9() {
    Model model = new ModelsModel().create();
    ModelDeclarations declarations = model.getDeclarations();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("update9");
    for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.DataEntity, entity));
    for (int i = 0; i < declarations.wSize(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl)) {
            assertEquals("Object", ((DataEntity) decl).getDataType().getValue());
            assertTrue(((DataEntity) decl).getName().getValue().startsWith("My"));
        }
    }
}
Also used : ModelDeclarations(org.whole.lang.models.model.ModelDeclarations) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) ITemplateManager(org.whole.lang.templates.ITemplateManager) DataEntity(org.whole.lang.models.model.DataEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 22 with Model

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

the class RewriteQueriesTest method testUpdate8.

@Test
public void testUpdate8() {
    Model model = new ModelsModel().create();
    ModelDeclarations declarations = model.getDeclarations();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("update8");
    for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.DataEntity, entity));
    for (int i = 0; i < declarations.wSize(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl)) {
            assertEquals("Object", ((DataEntity) decl).getDataType().getValue());
            assertTrue(((DataEntity) decl).getName().getValue().startsWith("My"));
        }
    }
}
Also used : ModelDeclarations(org.whole.lang.models.model.ModelDeclarations) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) ITemplateManager(org.whole.lang.templates.ITemplateManager) DataEntity(org.whole.lang.models.model.DataEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 23 with Model

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

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

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

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