use of org.whole.lang.codebase.StreamPersistenceProvider in project whole by wholeplatform.
the class JSONPersistencesTest method testPersistenceKit.
@Test
public void testPersistenceKit() throws Exception {
IEntity sampleModel = JSONSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getClass().getResourceAsStream("sample.json")));
StringPersistenceProvider pp = new StringPersistenceProvider();
JSONSourcePersistenceKit.instance().writeModel(sampleModel, pp);
assertEquals(sampleString, pp.getStore());
}
use of org.whole.lang.codebase.StreamPersistenceProvider in project whole by wholeplatform.
the class JDTJavaSourcePersistenceTest method testReadModel.
@Test
public void testReadModel() throws Exception {
IEntity fromSource = JDTJavaSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getClass().getResourceAsStream("TestSuite.txt")));
IEntity fromTemplate = new TestSuiteTemplate().create();
Assert.assertTrue(Matcher.match(fromSource, fromTemplate));
}
use of org.whole.lang.codebase.StreamPersistenceProvider in project whole by wholeplatform.
the class XmlPrettyPrinterBuilderTest method comparePrettyPrints.
private void comparePrettyPrints(String filename) throws Exception {
IEntity model = XmlSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getClass().getResourceAsStream(filename)));
StringWriter stringWriter = new StringWriter();
XmlPrettyPrinterBuilderOperation xppbop = new XmlPrettyPrinterBuilderOperation(new PrintWriter(stringWriter, true));
new ModelTemplate(model).apply(new XmlGenericBuilderAdapter((IXmlBuilder) xppbop.wGetBuilder(XmlLanguageKit.URI)));
assertEquals(toPrettyPrintString(model), stringWriter.toString());
}
use of org.whole.lang.codebase.StreamPersistenceProvider in project whole by wholeplatform.
the class XmlPrettyPrinterBuilderTest method _testPerformance.
public void _testPerformance() {
IEntity model = new BPELModel().create();
PrintStream nullPrintStream = new PrintStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
// do nothing
}
});
try {
long timestamp = new Date().getTime();
for (int i = 0; i < 1000; i++) {
XmlPrettyPrinterBuilderOperation op = new XmlPrettyPrinterBuilderOperation(new PrintWriter(nullPrintStream));
XmlStoreProducerBuilderOperation xmlOp = new XmlStoreProducerBuilderOperation(op);
((XmlStoreProducerBuilder) xmlOp.wGetBuilder()).buildStartDocument();
new ModelTemplate(model).apply(xmlOp);
((XmlStoreProducerBuilder) xmlOp.wGetBuilder()).buildEndDocument();
}
long timediff = new Date().getTime() - timestamp;
System.out.println("PrettyPrinterBuilder elapsed time: " + timediff + "ms");
timestamp = new Date().getTime();
for (int i = 0; i < 1000; i++) XmlBuilderPersistenceKit.instance().writeModel(model, new StreamPersistenceProvider(nullPrintStream));
timediff = new Date().getTime() - timestamp;
System.out.println("PrettyPrinterVisitor elapsed time: " + timediff + "ms");
} catch (Exception e) {
fail();
}
}
use of org.whole.lang.codebase.StreamPersistenceProvider in project whole by wholeplatform.
the class XsdModelBuilderTest method testBuilderAPI.
@Category(KnownFailingTests.class)
@Test
public void testBuilderAPI() throws Exception {
Schema xsdFromInputStream = (Schema) XsdPersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream("datatypes.xsd")));
Document document = (Document) XmlSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream("datatypes.xsd")));
IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
bm.wDefValue("mergeCDataSect", true);
XsdDeployStrategies.setDeployStrategy(bm, XsdDeployStrategies.ALL);
ModelBuilderOperation mop = new ModelBuilderOperation();
IBuilderOperation xsdBuilderOperation = new XmlSpecific2XsdBuilderAdapterOperation(mop, bm);
XmlNormalizerBuilderOperation normalizerOp = new XmlNormalizerBuilderOperation(xsdBuilderOperation, bm);
ModelTemplate template = new ModelTemplate(document);
template.apply(new XmlGenericBuilderAdapter((IXmlBuilder) normalizerOp.wGetBuilder(XmlLanguageKit.URI)));
Schema xsdFromXmlModel = (Schema) mop.wGetResult();
Assert.assertTrue(Matcher.match(xsdFromInputStream, xsdFromXmlModel));
}
Aggregations