Search in sources :

Example 1 with ModelsModel

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

the class ModelFragmentsBuilderTest method testModelFeaturesBuilderWithFeatureEvents.

@Test
public void testModelFeaturesBuilderWithFeatureEvents() {
    ITemplateFactory<Model> modelsModel = new ModelsModelWithFeatureEvents();
    Features features = ModelsEntityFactory.instance.createFeatures(0);
    modelsModel.apply(new SpecificBuilderAdapterOperation(new ModelFeaturesBuilder(features)));
    int count = 0;
    Model model = modelsModel.create();
    AbstractPatternFilterIterator<Feature> i = IteratorFactory.<Feature>descendantOrSelfMatcherIterator().withPattern(ModelsEntityDescriptorEnum.Feature);
    i.reset(model);
    for (Feature feature : i) if (EntityUtils.isNotResolver(feature))
        count++;
    assertEquals(features.wSize(), count);
}
Also used : ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) Features(org.whole.lang.models.model.Features) ModelFeaturesBuilder(org.whole.lang.builders.builder.ModelFeaturesBuilder) Feature(org.whole.lang.models.model.Feature) Test(org.junit.Test)

Example 2 with ModelsModel

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

the class ModelFragmentsBuilderTest method testModelFeaturesBuilder.

@Test
public void testModelFeaturesBuilder() {
    ITemplateFactory<Model> modelsModel = new ModelsModel();
    final Features features = ModelsEntityFactory.instance.createFeatures(0);
    modelsModel.apply(new SpecificBuilderAdapterOperation(new ModelFeaturesBuilder(features)));
    int count = 0;
    Model model = modelsModel.create();
    AbstractPatternFilterIterator<Feature> i = IteratorFactory.<Feature>descendantOrSelfMatcherIterator().withPattern(ModelsEntityDescriptorEnum.Feature);
    i.reset(model);
    for (Feature feature : i) if (EntityUtils.isNotResolver(feature))
        count++;
    assertEquals(features.wSize(), count);
}
Also used : ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) Features(org.whole.lang.models.model.Features) ModelsModel(org.whole.lang.models.codebase.ModelsModel) ModelFeaturesBuilder(org.whole.lang.builders.builder.ModelFeaturesBuilder) Feature(org.whole.lang.models.model.Feature) Test(org.junit.Test)

Example 3 with ModelsModel

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

the class PersistenceTest method testSingleBuilder2Xml.

@Test
public void testSingleBuilder2Xml() {
    ModelBuilderOperation op = new ModelBuilderOperation();
    new ModelsModel().apply(new XmlStoreProducerBuilderOperation(op));
    IEntity xmlModel = op.wGetResult();
    PrettyPrinterOperation.prettyPrint(xmlModel);
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) XmlStoreProducerBuilderOperation(org.whole.lang.xml.util.XmlStoreProducerBuilderOperation) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 4 with ModelsModel

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

the class ControlQueriesTest method testChoose4.

@Test
public void testChoose4() {
    Model model = new ModelsModel().create();
    ModelDeclarations decls = model.getDeclarations();
    IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("choose4");
    int i = 0;
    IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model, bm);
    while (iterator.hasNext()) {
        IEntity result = iterator.next();
        assertSame(result, bm.wGet("type"));
        assertTrue(result instanceof ClassDeclaration);
        ClassDeclaration classDecl = (ClassDeclaration) result;
        IEntity decl = decls.wGet(i++);
        String name = "", superClassName = "";
        switch(decl.wGetEntityOrd()) {
            case ModelsEntityDescriptorEnum.SimpleEntity_ord:
                SimpleEntity simpleEntity = (SimpleEntity) decl;
                name = simpleEntity.getName().wStringValue();
                superClassName = "AbstractSimpleEntity";
                break;
            case ModelsEntityDescriptorEnum.CompositeEntity_ord:
                CompositeEntity compositeEntity = (CompositeEntity) decl;
                name = compositeEntity.getName().wStringValue();
                superClassName = "AbstractCompositeEntity";
                break;
            case ModelsEntityDescriptorEnum.DataEntity_ord:
                DataEntity dataEntity = (DataEntity) decl;
                name = dataEntity.getName().wStringValue();
                superClassName = "AbstractDataEntity";
                break;
            case ModelsEntityDescriptorEnum.EnumEntity_ord:
                EnumEntity enumEntity = (EnumEntity) decl;
                name = enumEntity.getName().wStringValue();
                superClassName = "AbstractEnumEntity";
                break;
        }
        assertEquals(name, classDecl.getName().wStringValue());
        assertEquals(superClassName, classDecl.getSuperclassType().wStringValue());
    }
}
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) ClassDeclaration(org.whole.lang.java.model.ClassDeclaration) 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) IBindingManager(org.whole.lang.bindings.IBindingManager) 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 5 with ModelsModel

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

the class ControlQueriesTest method testChoose3.

@Test
public void testChoose3() {
    Model model = new ModelsModel().create();
    ModelDeclarations decls = model.getDeclarations();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("choose3");
    int i = 0;
    IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model);
    while (iterator.hasNext()) {
        IEntity result = iterator.next();
        IEntity decl = decls.wGet(i++);
        switch(decl.wGetEntityOrd()) {
            case ModelsEntityDescriptorEnum.SimpleEntity_ord:
                Features features = ((SimpleEntity) decl).getFeatures();
                if (!features.isEmpty())
                    assertEquals(features.get(0).getName().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.CompositeEntity_ord:
                CompositeEntity compositeEntity = (CompositeEntity) decl;
                assertEquals(compositeEntity.getComponentType().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.DataEntity_ord:
                DataEntity dataEntity = (DataEntity) decl;
                assertEquals(dataEntity.getDataType().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.EnumEntity_ord:
                EnumEntity enumEntity = (EnumEntity) decl;
                assertEquals(enumEntity.getValues().wGet(0).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) 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) 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)

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