Search in sources :

Example 66 with ITemplateManager

use of org.whole.lang.templates.ITemplateManager 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 67 with ITemplateManager

use of org.whole.lang.templates.ITemplateManager 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)

Example 68 with ITemplateManager

use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.

the class RewriteQueriesTest method testUpdate1.

@Test
public void testUpdate1() {
    Model model = new ModelsModel().create();
    ModelDeclarations declarations = model.getDeclarations();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("update1");
    for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.SimpleName, entity) || Matcher.match(ModelsEntityDescriptorEnum.DataType, entity));
    assertEquals("MyModelName", model.getName().getValue());
    int j = 0;
    for (int i = 0; i < declarations.wSize(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl)) {
            if (j++ == 0) {
                assertEquals("MyFirstName", ((DataEntity) decl).getName().getValue());
                assertEquals("MyFirstDataType", ((DataEntity) decl).getDataType().getValue());
            } else {
                assertEquals("MySecondName", ((DataEntity) decl).getName().getValue());
                return;
            }
        }
    }
}
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 69 with ITemplateManager

use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.

the class SelectQueriesTest method testSelectTemplateWithNestedQuery.

@Test
public void testSelectTemplateWithNestedQuery() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Model m = new XmlModel().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithNestedQuery");
    for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m)) {
        assertEquals(JavaEntityDescriptorEnum.ClassDeclaration, t.wGetEntityDescriptor());
        assertTrue(t.getBodyDeclarations().wSize() >= 2);
    }
}
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 70 with ITemplateManager

use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.

the class SelectQueriesTest method testSelectTemplateFromPatternWithWhere.

@Test
public void testSelectTemplateFromPatternWithWhere() {
    Model m = new XmlModel().create();
    Feature feature = (Feature) ((SimpleEntity) m.getDeclarations().wGet(0)).getFeatures().wGet(0);
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateFromPatternWithWhere");
    for (FieldDeclaration field : BehaviorUtils.<FieldDeclaration>compileAndLazyEvaluate(pe1, feature)) {
        assertEquals(feature.getName().wStringValue(), field.getFragments().wGet(0).wGet(0).wStringValue());
        assertEquals(StringUtils.toUpperCap(feature.getType().wStringValue()), field.getType().wStringValue());
    }
}
Also used : 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) Feature(org.whole.lang.models.model.Feature) FieldDeclaration(org.whole.lang.java.model.FieldDeclaration) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)96 ITemplateManager (org.whole.lang.templates.ITemplateManager)96 PathExpression (org.whole.lang.queries.model.PathExpression)87 IEntity (org.whole.lang.model.IEntity)61 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)47 Grammar (org.whole.lang.grammars.model.Grammar)46 Model (org.whole.lang.models.model.Model)41 IBindingManager (org.whole.lang.bindings.IBindingManager)40 XmlModel (org.whole.lang.models.codebase.XmlModel)27 Production (org.whole.lang.grammars.model.Production)26 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)25 ModelsModel (org.whole.lang.models.codebase.ModelsModel)23 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 NonTerminal (org.whole.lang.grammars.model.NonTerminal)9 Feature (org.whole.lang.models.model.Feature)9 FieldDeclaration (org.whole.lang.java.model.FieldDeclaration)7 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)7