Search in sources :

Example 6 with StreamPersistenceProvider

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());
}
Also used : StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) Test(org.junit.Test)

Example 7 with StreamPersistenceProvider

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));
}
Also used : IEntity(org.whole.lang.model.IEntity) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) Test(org.junit.Test)

Example 8 with StreamPersistenceProvider

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());
}
Also used : XmlPrettyPrinterBuilderOperation(org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) StringWriter(java.io.StringWriter) IEntity(org.whole.lang.model.IEntity) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) PrintWriter(java.io.PrintWriter)

Example 9 with StreamPersistenceProvider

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();
    }
}
Also used : PrintStream(java.io.PrintStream) XmlStoreProducerBuilder(org.whole.lang.xml.util.XmlStoreProducerBuilder) IEntity(org.whole.lang.model.IEntity) BPELModel(org.whole.lang.models.codebase.BPELModel) OutputStream(java.io.OutputStream) IOException(java.io.IOException) XmlStoreProducerBuilderOperation(org.whole.lang.xml.util.XmlStoreProducerBuilderOperation) Date(java.util.Date) IOException(java.io.IOException) XmlPrettyPrinterBuilderOperation(org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) PrintWriter(java.io.PrintWriter)

Example 10 with StreamPersistenceProvider

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));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) IBuilderOperation(org.whole.lang.builders.IBuilderOperation) XmlNormalizerBuilderOperation(org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation) XmlGenericBuilderAdapter(org.whole.lang.xml.builders.XmlGenericBuilderAdapter) Schema(org.whole.lang.xsd.model.Schema) IBindingManager(org.whole.lang.bindings.IBindingManager) IXmlBuilder(org.whole.lang.xml.builders.IXmlBuilder) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) Document(org.whole.lang.xml.model.Document) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)28 IEntity (org.whole.lang.model.IEntity)24 Test (org.junit.Test)20 Category (org.junit.experimental.categories.Category)13 InputStream (java.io.InputStream)12 StreamSource (javax.xml.transform.stream.StreamSource)9 Schema (javax.xml.validation.Schema)9 Validator (javax.xml.validation.Validator)9 IPersistenceProvider (org.whole.lang.codebase.IPersistenceProvider)9 IBindingManager (org.whole.lang.bindings.IBindingManager)4 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)4 ModelTemplate (org.whole.lang.templates.ModelTemplate)4 File (java.io.File)3 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)3 XmlNormalizerBuilderOperation (org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation)3 JsonFactory (com.fasterxml.jackson.core.JsonFactory)2 PrintWriter (java.io.PrintWriter)2 StringPersistenceProvider (org.whole.lang.codebase.StringPersistenceProvider)2 XmlPrettyPrinterBuilderOperation (org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1