Search in sources :

Example 51 with PathExpression

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

the class XsdMappingTest method testModelsToXmlSchemaXXX.

@Test
public void testModelsToXmlSchemaXXX() throws Exception {
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    PathExpression path = new ModelToXmlSchemaQuery().create();
    Model model = (Model) ModelsTemplateManager.instance().create("Models model");
    String uri = model.getUri().getValue();
    ILanguageKit lk = ReflectionFactory.getLanguageKit(uri);
    IEntity tuple = BehaviorUtils.evaluateFirstResult(path, model, bm);
    Assert.assertNotNull(tuple);
    InterpreterOperation.interpret(tuple.wGet(1));
    ITemplateManager tm = lk.getTemplateManager();
    IEntity entity = tm.create("Editors model");
    IPersistenceProvider pp = new StringPersistenceProvider();
    XsiPersistenceKit.instance().writeModel(entity, pp);
    IEntity entity2 = XsiPersistenceKit.instance().readModel(pp);
    boolean matches = Matcher.match(entity, entity2);
    Assert.assertTrue(matches);
}
Also used : ModelToXmlSchemaQuery(org.whole.lang.xsd.codebase.ModelToXmlSchemaQuery) PathExpression(org.whole.lang.queries.model.PathExpression) StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Model(org.whole.lang.models.model.Model) ITemplateManager(org.whole.lang.templates.ITemplateManager) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) ILanguageKit(org.whole.lang.reflect.ILanguageKit) Test(org.junit.Test)

Example 52 with PathExpression

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

the class PathExpressionsQueriesTest method testVariableJoinTest4.

@Test
public void testVariableJoinTest4() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new QueriesGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("recursiveProduction4");
    StringBuilder names = new StringBuilder();
    for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g)) names.append(p.getName().getValue());
    Assert.assertEquals("ExpressionPathExpressionStepExpressionPredicate", names.toString());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) Production(org.whole.lang.grammars.model.Production) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) Test(org.junit.Test)

Example 53 with PathExpression

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

the class PathExpressionsQueriesTest method testVariableJoinTest5.

@Test
public void testVariableJoinTest5() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new QueriesGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("recursiveProduction5");
    StringBuilder names = new StringBuilder();
    for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g)) names.append(p.getName().getValue());
    Assert.assertEquals("ExpressionPathExpressionStepExpressionPredicate", names.toString());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) Production(org.whole.lang.grammars.model.Production) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) Test(org.junit.Test)

Example 54 with PathExpression

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

the class PathExpressionsQueriesTest method testPathOfChildSteps.

@Test
public void testPathOfChildSteps() {
    Model model = new XmlModel().create();
    IEntity decl3 = model.getDeclarations().wGet(3);
    QueriesEntityFactory ef = QueriesEntityFactory.instance;
    PathExpression pe = ef.createPath(ef.createFeatureStep("declarations"), ef.createFilter(ef.createChildStep(), ef.createIndexTest(ef.createIntLiteral(3))));
    IEntity result = BehaviorUtils.evaluateFirstResult(pe, model);
    Assert.assertSame(decl3, result);
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) XmlModel(org.whole.lang.models.codebase.XmlModel) Model(org.whole.lang.models.model.Model) XmlModel(org.whole.lang.models.codebase.XmlModel) Test(org.junit.Test)

Example 55 with PathExpression

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

the class PathExpressionsQueriesTest method testProduct1.

@Test
public void testProduct1() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("testProduct1");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    int count = 0;
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(pe1, g, bm)) {
        String vname = ((Production) bm.wGet("pp")).getName().getValue() + "x" + ((Production) bm.wGet("lp")).getName().getValue();
        String tname = ((Production) tuple.wGet(0)).getName().getValue() + "x" + ((Production) tuple.wGet(1)).getName().getValue();
        Assert.assertEquals(vname, tname);
        count++;
    }
    Assert.assertEquals(g.getPhraseStructure().wSize() * g.getLexicalStructure().wSize(), count);
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) 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) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) PrettyPrinterOperation.toPrettyPrintString(org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString) 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