Search in sources :

Example 11 with ModelTemplate

use of org.whole.lang.templates.ModelTemplate in project whole by wholeplatform.

the class JSONPersistencesTest method testParseAndGenerateWithBuilderOperation.

@Test
public void testParseAndGenerateWithBuilderOperation() throws Exception {
    IEntity sampleModel = JSONSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getClass().getResourceAsStream("sample.json")));
    StringPersistenceProvider pp = new StringPersistenceProvider();
    JsonGenerator generator = new JsonFactory().createGenerator(pp.getOutputStream());
    generator.useDefaultPrettyPrinter();
    JSONGeneratorBuilderOperation op = new JSONGeneratorBuilderOperation(generator);
    new ModelTemplate(sampleModel).apply(op);
    generator.close();
    assertEquals(sampleString, pp.getStore());
}
Also used : ModelTemplate(org.whole.lang.templates.ModelTemplate) StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) JSONGeneratorBuilderOperation(org.whole.lang.json.util.JSONGeneratorBuilderOperation) Test(org.junit.Test)

Example 12 with ModelTemplate

use of org.whole.lang.templates.ModelTemplate in project whole by wholeplatform.

the class PersistenceTest method testSingleBuilder2Java.

@Test
public void testSingleBuilder2Java() {
    ModelBuilderOperation op = new ModelBuilderOperation();
    JavaStoreProducerBuilderOperation javaOp = new JavaStoreProducerBuilderOperation(op);
    ((JavaStoreProducerBuilder) javaOp.wGetBuilder()).buildStartCompilationUnit("test", "Test");
    try {
        Properties props = PropertiesUtils.translate(System.getProperties());
        props.getEntries().wAdd(0, createResolver(PropertiesEntityDescriptorEnum.Property));
        new ModelTemplate(props).apply(javaOp);
    } catch (IOException e) {
        e.printStackTrace();
    }
    // new TopDownTraversal(new ModelsModel().create()).apply(javaOp);
    ((JavaStoreProducerBuilder) javaOp.wGetBuilder()).buildEndCompilationUnit();
    // new ModelsModel().apply(new JavaStoreProducerBuilderOperation(op));
    IEntity model = op.wGetResult();
    PrettyPrinterOperation.prettyPrint(model);
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) JavaStoreProducerBuilder(org.whole.lang.java.util.JavaStoreProducerBuilder) IEntity(org.whole.lang.model.IEntity) JavaStoreProducerBuilderOperation(org.whole.lang.java.util.JavaStoreProducerBuilderOperation) IOException(java.io.IOException) Properties(org.whole.lang.properties.model.Properties) Test(org.junit.Test)

Example 13 with ModelTemplate

use of org.whole.lang.templates.ModelTemplate 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 14 with ModelTemplate

use of org.whole.lang.templates.ModelTemplate 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)

Example 15 with ModelTemplate

use of org.whole.lang.templates.ModelTemplate in project whole by wholeplatform.

the class GenericForwardSpecificBuilderTest method testMultiLanguage.

@Test
public void testMultiLanguage() throws Exception {
    IEntity entity = XmlBuilderPersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/queries/util/BindVariablesInPathTemplates.xwl"));
    ModelBuilderOperation mop = new ModelBuilderOperation();
    ModelTemplate template = new ModelTemplate(entity);
    template.apply(new GenericForwardSpecificBuilder(mop));
    IEntity newEntity = mop.wGetResult();
    // to match variables fill variables with defaults
    IEntityIterator<IEntity> variableIterator = IteratorFactory.<IEntity>descendantOrSelfMatcherIterator().withPattern(GenericMatcherFactory.instance.isVariableMatcher());
    variableIterator.reset(entity);
    IEntityIterator<IEntity> newVariableIterator = IteratorFactory.<IEntity>descendantOrSelfMatcherIterator().withPattern(GenericMatcherFactory.instance.isVariableMatcher());
    newVariableIterator.reset(newEntity);
    while (variableIterator.hasNext()) {
        assertTrue(newVariableIterator.hasNext());
        Variable variable = (Variable) variableIterator.next().wGetAdaptee(false);
        Variable newVariable = (Variable) newVariableIterator.next().wGetAdaptee(false);
        EntityDescriptor<?> ed = variable.getVarType().getValue();
        EntityDescriptor<?> newEd = newVariable.getVarType().getValue();
        assertEquals(ed, newEd);
        String name = variable.getVarName().getValue();
        String newName = newVariable.getVarName().getValue();
        assertEquals(name, newName);
        IEntity replacement = GenericEntityFactory.instance.create(ed);
        variableIterator.set(replacement);
        newVariableIterator.set(EntityUtils.clone(replacement));
    }
    assertTrue(Matcher.match(entity, newEntity));
}
Also used : ModelTemplate(org.whole.lang.templates.ModelTemplate) Variable(org.whole.lang.commons.model.Variable) IEntity(org.whole.lang.model.IEntity) ClasspathPersistenceProvider(org.whole.lang.codebase.ClasspathPersistenceProvider) Test(org.junit.Test)

Aggregations

ModelTemplate (org.whole.lang.templates.ModelTemplate)15 IEntity (org.whole.lang.model.IEntity)11 Test (org.junit.Test)7 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)6 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)4 XmlStoreProducerBuilderOperation (org.whole.lang.xml.util.XmlStoreProducerBuilderOperation)4 PrintWriter (java.io.PrintWriter)3 XmlStoreProducerBuilder (org.whole.lang.xml.util.XmlStoreProducerBuilder)3 IOException (java.io.IOException)2 IBindingManager (org.whole.lang.bindings.IBindingManager)2 JavaStoreProducerBuilder (org.whole.lang.java.util.JavaStoreProducerBuilder)2 JavaStoreProducerBuilderOperation (org.whole.lang.java.util.JavaStoreProducerBuilderOperation)2 ModelsModel (org.whole.lang.models.codebase.ModelsModel)2 XmlGenericBuilderAdapter (org.whole.lang.xml.builders.XmlGenericBuilderAdapter)2 XmlPrettyPrinterBuilderOperation (org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation)2 Document (org.whole.lang.xml.model.Document)2 SaxHandlerBuilderOperation (org.whole.lang.xml.util.SaxHandlerBuilderOperation)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 File (java.io.File)1