Search in sources :

Example 21 with ModelsModel

use of org.whole.lang.models.codebase.ModelsModel 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 22 with ModelsModel

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

the class ControlQueriesTest method testChoose1.

@Test
public void testChoose1() {
    Model model = new ModelsModel().create();
    ModelDeclarations decls = model.getDeclarations();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("choose1");
    assertFalse(BehaviorUtils.compileAndLazyEvaluate(query, model).hasNext());
    int i = 0;
    while (!Matcher.match(ModelsEntityDescriptorEnum.SimpleEntity, decls.wGet(i))) i++;
    SimpleEntity simpleEntity = (SimpleEntity) decls.wGet(i);
    int j = 0;
    for (IEntity name : BehaviorUtils.compileAndLazyEvaluate(query, simpleEntity)) {
        assertEquals(((Feature) simpleEntity.getFeatures().wGet(j++)).getName().wStringValue(), name.wStringValue());
    }
    assertEquals(simpleEntity.getFeatures().wSize(), j);
    while (!Matcher.match(ModelsEntityDescriptorEnum.CompositeEntity, decls.wGet(i))) i++;
    CompositeEntity compositeEntity = (CompositeEntity) decls.wGet(i);
    IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, compositeEntity);
    assertTrue(iterator.hasNext());
    assertEquals(compositeEntity.getComponentType().wStringValue(), iterator.next().wStringValue());
    assertFalse(iterator.hasNext());
    while (!Matcher.match(ModelsEntityDescriptorEnum.EnumEntity, decls.wGet(i))) i++;
    EnumEntity enumEntity = (EnumEntity) decls.wGet(i);
    iterator = BehaviorUtils.compileAndLazyEvaluate(query, enumEntity);
    assertTrue(iterator.hasNext());
    assertTrue(iterator.next() instanceof EnumValues);
    assertFalse(iterator.hasNext());
}
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) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 23 with ModelsModel

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

the class PersistenceTest method testSingleModel2Xml.

@Test
public void testSingleModel2Xml() {
    ModelBuilderOperation op = new ModelBuilderOperation();
    IEntity model = new ModelsModel().create();
    new ModelTemplate(model).apply(new XmlStoreProducerBuilderOperation(op));
    IEntity xmlModel = op.wGetResult();
    PrettyPrinterOperation.prettyPrint(xmlModel);
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) 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 24 with ModelsModel

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

the class PersistenceTest method testXMLPersistence.

@Test
public void testXMLPersistence() {
    IEntity model1 = new TestEntities().create();
    IEntity model2 = xmlRoundtrip(model1);
    assertTrue(Matcher.match(model1, model2));
    model1 = new ModelsModel().create();
    model2 = xmlRoundtrip(model1);
    assertTrue(Matcher.match(model1, model2));
    model1 = new WholeLanguage().create();
    model2 = xmlRoundtrip(model1);
    assertTrue(Matcher.match(model1, model2));
}
Also used : TestEntities(org.whole.lang.models.codebase.TestEntities) IEntity(org.whole.lang.model.IEntity) WholeLanguage(org.whole.lang.misc.codebase.WholeLanguage) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 25 with ModelsModel

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

the class PushPullOperationsTest method testModel2PushPullOp.

@Test
public void testModel2PushPullOp() {
    IEntity model = new ModelsModel().create();
    new ModelTemplate(model).apply(new PrettyPrinterBuilderOperation());
}
Also used : ModelTemplate(org.whole.lang.templates.ModelTemplate) IEntity(org.whole.lang.model.IEntity) 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