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());
}
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);
}
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);
}
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());
}
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));
}
Aggregations