Search in sources :

Example 11 with Feature

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

Example 12 with Feature

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

the class SelectQueriesTest method testSelectTemplateAs.

@Test
public void testSelectTemplateAs() {
    Model model = new XmlModel().create();
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("selectTemplateAs");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        FieldDeclaration f = (FieldDeclaration) tuple.wGet(0);
        Feature e = (Feature) tuple.wGet(1);
        FieldDeclaration field = (FieldDeclaration) bm.wGet("field");
        assertSame(f, field);
        String ptype = e.getType().wStringValue();
        assertEquals(ptype, field.getType().wStringValue());
    }
}
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) Feature(org.whole.lang.models.model.Feature) FieldDeclaration(org.whole.lang.java.model.FieldDeclaration) Test(org.junit.Test)

Example 13 with Feature

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

the class SelectQueriesTest method testSelectTemplateFromPathWithPattern.

@Test
public void testSelectTemplateFromPathWithPattern() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Model m = new XmlModel().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateFromPathWithPattern");
    IEntityIterator<Feature> featureIterator = IteratorFactory.<Feature>descendantOrSelfMatcherIterator().withPattern(ModelsEntityDescriptorEnum.Feature);
    featureIterator.reset(m);
    for (FieldDeclaration field : BehaviorUtils.<FieldDeclaration>compileAndLazyEvaluate(pe1, m)) {
        Feature feature = featureIterator.next();
        assertEquals(feature.getType().wStringValue(), field.getType().wStringValue());
        assertEquals(feature.getName().wStringValue(), field.getFragments().wGet(0).wGet(0).wStringValue());
    }
}
Also used : 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) Feature(org.whole.lang.models.model.Feature) FieldDeclaration(org.whole.lang.java.model.FieldDeclaration) Test(org.junit.Test)

Example 14 with Feature

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

the class SelectQueriesTest method testSelectTupleOfTemplatesAs.

@Test
public void testSelectTupleOfTemplatesAs() {
    Model model = new XmlModel().create();
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("selectTupleOfTemplatesAs");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        FieldDeclaration f = (FieldDeclaration) tuple.wGet(0);
        SingleVariableDeclaration p = (SingleVariableDeclaration) tuple.wGet(1);
        ExpressionStatement s = (ExpressionStatement) tuple.wGet(2);
        Feature e = (Feature) tuple.wGet(3);
        String ptype = e.getType().wStringValue();
        String pname = e.getName().wStringValue();
        assertSame(f, bm.wGet("field"));
        assertEquals(ptype, f.getType().wStringValue());
        assertSame(p, bm.wGet("param"));
        assertEquals(ptype, p.getType().wStringValue());
        assertEquals(pname, p.getName().wStringValue());
        assertSame(s, bm.wGet("init"));
        assertEquals(pname, ((Assignment) s.getExpression()).getRightHandSide().wStringValue());
    }
}
Also used : Assignment(org.whole.lang.java.model.Assignment) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) SingleVariableDeclaration(org.whole.lang.java.model.SingleVariableDeclaration) ExpressionStatement(org.whole.lang.java.model.ExpressionStatement) 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) Feature(org.whole.lang.models.model.Feature) FieldDeclaration(org.whole.lang.java.model.FieldDeclaration) Test(org.junit.Test)

Example 15 with Feature

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

the class SelectQueriesTest method testSelectTupleWithTemplates.

@Test
public void testSelectTupleWithTemplates() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Grammar model = new TestXmlGrammar().create();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    PathExpression query = (PathExpression) tm.create("selectTupleWithTemplates");
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        FieldDeclaration fd = (FieldDeclaration) tuple.wGet(0);
        Feature f = (Feature) tuple.wGet(1);
        As e = (As) tuple.wGet(2);
        assertEquals(e.getName().getValue(), fd.getFragments().wGet(0).wGet(0).wStringValue());
        assertEquals(e.getRule().wStringValue(), fd.getType().wStringValue());
        assertEquals(e.getName().getValue(), f.getName().wStringValue());
        assertEquals(e.getRule().wStringValue(), f.getType().wStringValue());
    }
}
Also used : As(org.whole.lang.grammars.model.As) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) IBindingManager(org.whole.lang.bindings.IBindingManager) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Feature(org.whole.lang.models.model.Feature) FieldDeclaration(org.whole.lang.java.model.FieldDeclaration) Test(org.junit.Test)

Aggregations

Feature (org.whole.lang.models.model.Feature)18 Test (org.junit.Test)13 IEntity (org.whole.lang.model.IEntity)9 PathExpression (org.whole.lang.queries.model.PathExpression)9 ITemplateManager (org.whole.lang.templates.ITemplateManager)9 Model (org.whole.lang.models.model.Model)8 XmlModel (org.whole.lang.models.codebase.XmlModel)6 FieldDeclaration (org.whole.lang.java.model.FieldDeclaration)5 SimpleEntity (org.whole.lang.models.model.SimpleEntity)5 IBindingManager (org.whole.lang.bindings.IBindingManager)4 ModelsModel (org.whole.lang.models.codebase.ModelsModel)4 Grammar (org.whole.lang.grammars.model.Grammar)3 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)3 Features (org.whole.lang.models.model.Features)3 ModelFeaturesBuilder (org.whole.lang.builders.builder.ModelFeaturesBuilder)2 Variable (org.whole.lang.commons.model.Variable)2 As (org.whole.lang.grammars.model.As)2 CompositeEntity (org.whole.lang.models.model.CompositeEntity)2 EnumEntity (org.whole.lang.models.model.EnumEntity)2 EnumValues (org.whole.lang.models.model.EnumValues)2