Search in sources :

Example 6 with ModelsModel

use of org.whole.lang.models.codebase.ModelsModel in project whole by wholeplatform.

the class ControlQueriesTest method testQueryDecl5.

@Test
public void testQueryDecl5() {
    Model model = new ModelsModel().create();
    ModelDeclarations decls = model.getDeclarations();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("queryDecl5");
    int count = 0;
    int index = 0;
    for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        IEntity decl = decls.wGet(index++);
        switch(decl.wGetEntityOrd()) {
            case ModelsEntityDescriptorEnum.SimpleEntity_ord:
                Features features = ((SimpleEntity) decl).getFeatures();
                if (!features.isEmpty())
                    assertEquals(features.get(0).getName().wStringValue(), p.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.CompositeEntity_ord:
                assertEquals(((CompositeEntity) decl).getComponentType().wStringValue(), p.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.DataEntity_ord:
                assertEquals(((DataEntity) decl).getName().wStringValue(), p.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.EnumEntity_ord:
                assertTrue(Matcher.matchImpl(ModelsEntityDescriptorEnum.EnumEntity, p));
                break;
        }
        count++;
    }
    assertEquals(33, count);
}
Also used : ModelDeclarations(org.whole.lang.models.model.ModelDeclarations) 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) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) IBindingManager(org.whole.lang.bindings.IBindingManager) CompositeEntity(org.whole.lang.models.model.CompositeEntity) ITemplateManager(org.whole.lang.templates.ITemplateManager) Features(org.whole.lang.models.model.Features) DataEntity(org.whole.lang.models.model.DataEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 7 with ModelsModel

use of org.whole.lang.models.codebase.ModelsModel in project whole by wholeplatform.

the class ControlQueriesTest method testChoose2.

@Test
public void testChoose2() {
    Model model = new ModelsModel().create();
    ModelDeclarations decls = model.getDeclarations();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("choose2");
    int i = 0;
    IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model);
    while (iterator.hasNext()) {
        IEntity result;
        IEntity decl = decls.wGet(i++);
        switch(decl.wGetEntityOrd()) {
            case ModelsEntityDescriptorEnum.SimpleEntity_ord:
                IEntity features = ((SimpleEntity) decl).getFeatures();
                for (int j = 0; j < features.wSize(); j++) {
                    result = iterator.next();
                    assertEquals(((Feature) features.wGet(j)).getName().wStringValue(), result.wStringValue());
                }
                break;
            case ModelsEntityDescriptorEnum.CompositeEntity_ord:
                result = iterator.next();
                CompositeEntity compositeEntity = (CompositeEntity) decl;
                assertEquals(compositeEntity.getComponentType().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.DataEntity_ord:
                result = iterator.next();
                DataEntity dataEntity = (DataEntity) decl;
                assertEquals(dataEntity.getDataType().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.EnumEntity_ord:
                EnumValues enumValues = ((EnumEntity) decl).getValues();
                if (enumValues.wIsEmpty())
                    iterator.next();
                else
                    for (int j = 0; j < enumValues.wSize(); j++) {
                        result = iterator.next();
                        assertEquals(enumValues.wGet(j).wStringValue(), result.wStringValue());
                    }
                break;
        }
    }
}
Also used : EnumEntity(org.whole.lang.models.model.EnumEntity) IEntity(org.whole.lang.model.IEntity) SimpleEntity(org.whole.lang.models.model.SimpleEntity) ITemplateManager(org.whole.lang.templates.ITemplateManager) Feature(org.whole.lang.models.model.Feature) EnumValues(org.whole.lang.models.model.EnumValues) ModelDeclarations(org.whole.lang.models.model.ModelDeclarations) PathExpression(org.whole.lang.queries.model.PathExpression) XmlModel(org.whole.lang.models.codebase.XmlModel) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) CompositeEntity(org.whole.lang.models.model.CompositeEntity) DataEntity(org.whole.lang.models.model.DataEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 8 with ModelsModel

use of org.whole.lang.models.codebase.ModelsModel in project whole by wholeplatform.

the class RewriteQueriesTest method testUpdate7.

@Test
public void testUpdate7() {
    Model model = new ModelsModel().create();
    ModelDeclarations declarations = model.getDeclarations();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("update7");
    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))
            assertEquals("DataEntityName", ((DataEntity) 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) ITemplateManager(org.whole.lang.templates.ITemplateManager) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 9 with ModelsModel

use of org.whole.lang.models.codebase.ModelsModel in project whole by wholeplatform.

the class RewriteQueriesTest method testUpdate6.

@Test
public void testUpdate6() {
    Model model = new ModelsModel().create();
    ModelDeclarations declarations = model.getDeclarations();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("update6");
    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))
            assertEquals("DataEntityName", ((DataEntity) 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) ITemplateManager(org.whole.lang.templates.ITemplateManager) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 10 with ModelsModel

use of org.whole.lang.models.codebase.ModelsModel in project whole by wholeplatform.

the class RewriteQueriesTest method testUpdate4.

@Test
public void testUpdate4() {
    Model model = new ModelsModel().create();
    ModelDeclarations declarations = model.getDeclarations();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("update4");
    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());
    }
    for (int i = 0; i < declarations.wSize(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl))
            assertTrue(EntityUtils.isResolver(((DataEntity) decl).getName()));
    }
}
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)

Aggregations

ModelsModel (org.whole.lang.models.codebase.ModelsModel)26 Test (org.junit.Test)25 IEntity (org.whole.lang.model.IEntity)22 Model (org.whole.lang.models.model.Model)20 PathExpression (org.whole.lang.queries.model.PathExpression)18 ITemplateManager (org.whole.lang.templates.ITemplateManager)18 ModelDeclarations (org.whole.lang.models.model.ModelDeclarations)17 DataEntity (org.whole.lang.models.model.DataEntity)10 SimpleEntity (org.whole.lang.models.model.SimpleEntity)6 XmlModel (org.whole.lang.models.codebase.XmlModel)5 CompositeEntity (org.whole.lang.models.model.CompositeEntity)5 Features (org.whole.lang.models.model.Features)5 EnumEntity (org.whole.lang.models.model.EnumEntity)4 Feature (org.whole.lang.models.model.Feature)4 ArrayList (java.util.ArrayList)3 IBindingManager (org.whole.lang.bindings.IBindingManager)2 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)2 ModelFeaturesBuilder (org.whole.lang.builders.builder.ModelFeaturesBuilder)2 EnumValues (org.whole.lang.models.model.EnumValues)2 ModelTemplate (org.whole.lang.templates.ModelTemplate)2