Search in sources :

Example 61 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class RewriteQueriesTest method testUpdate5.

@Test
public void testUpdate5() {
    Model model = new ModelsModel().create();
    ModelDeclarations declarations = model.getDeclarations();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("update5");
    List<String> dataEntityNames = new ArrayList<String>();
    for (int i = 0; i < declarations.wSize(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl))
            dataEntityNames.add(((DataEntity) decl).getName().getValue());
    }
    for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.SimpleName, entity));
    Iterator<String> dataEntityNamesIterator = dataEntityNames.iterator();
    for (int i = 0; i < declarations.wSize() && dataEntityNamesIterator.hasNext(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.SimpleEntity, decl))
            assertEquals(dataEntityNamesIterator.next(), ((SimpleEntity) decl).getName().getValue());
    }
    dataEntityNamesIterator = dataEntityNames.iterator();
    for (int i = 0; i < declarations.wSize() && dataEntityNamesIterator.hasNext(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.CompositeEntity, decl))
            assertEquals(dataEntityNamesIterator.next(), ((CompositeEntity) decl).getName().getValue());
    }
}
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) ArrayList(java.util.ArrayList) ITemplateManager(org.whole.lang.templates.ITemplateManager) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 62 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class RewriteQueriesTest method testUpdate10.

@Test
public void testUpdate10() {
    Model model = new ModelsModel().create();
    ModelDeclarations declarations = model.getDeclarations();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("update10");
    for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.SimpleName, entity));
    for (int i = 0; i < declarations.wSize(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl)) {
            String name = ((DataEntity) decl).getName().getValue();
            assertEquals(StringUtils.toLowerCap(name), name);
        }
    }
}
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) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 63 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class RewriteQueriesTest method testDelete2.

@Test
public void testDelete2() {
    Grammar model = new TestXmlGrammar().create();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("delete2");
    for (Name name : BehaviorUtils.<Name>compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(GrammarsEntityDescriptorEnum.Name, name));
    for (IEntity name : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(EntityUtils.isResolver(name));
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Name(org.whole.lang.grammars.model.Name) Test(org.junit.Test)

Example 64 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class RewriteQueriesTest method testUpdate11.

@Test
public void testUpdate11() {
    Model model = new ModelsModel().create();
    ModelDeclarations declarations = model.getDeclarations();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("update11");
    for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.SimpleName, entity) || Matcher.match(ModelsEntityDescriptorEnum.DataType, entity));
    for (int i = 0; i < declarations.wSize(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl)) {
            String name = ((DataEntity) decl).getName().getValue();
            assertEquals(StringUtils.toLowerCap(name), name);
            assertEquals("MyDataType", ((DataEntity) decl).getDataType().getValue());
        }
    }
}
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 65 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class RewriteQueriesTest method testDelete1.

@Test
public void testDelete1() {
    Model model = new ModelsModel().create();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("delete1");
    for (DataEntity dataEntity : BehaviorUtils.<DataEntity>compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.DataEntity, dataEntity));
    assertFalse(BehaviorUtils.compileAndLazyEvaluate(query, model).hasNext());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) 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)

Aggregations

PathExpression (org.whole.lang.queries.model.PathExpression)97 Test (org.junit.Test)94 ITemplateManager (org.whole.lang.templates.ITemplateManager)87 IEntity (org.whole.lang.model.IEntity)67 IBindingManager (org.whole.lang.bindings.IBindingManager)45 Model (org.whole.lang.models.model.Model)43 Grammar (org.whole.lang.grammars.model.Grammar)40 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)39 XmlModel (org.whole.lang.models.codebase.XmlModel)28 ModelsModel (org.whole.lang.models.codebase.ModelsModel)23 Production (org.whole.lang.grammars.model.Production)20 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)18 ModelDeclarations (org.whole.lang.models.model.ModelDeclarations)18 SimpleEntity (org.whole.lang.models.model.SimpleEntity)13 ClassDeclaration (org.whole.lang.java.model.ClassDeclaration)11 DataEntity (org.whole.lang.models.model.DataEntity)10 Feature (org.whole.lang.models.model.Feature)9 NonTerminal (org.whole.lang.grammars.model.NonTerminal)8 FieldDeclaration (org.whole.lang.java.model.FieldDeclaration)7 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)6