Search in sources :

Example 16 with StreamPersistenceProvider

use of org.whole.lang.codebase.StreamPersistenceProvider in project whole by wholeplatform.

the class XsdMappingTest method testDatatypes.

@Category(SlowTests.class)
@Test
public void testDatatypes() throws Exception {
    InputStream is = loader.getResourceAsStream("datatypes.xsd");
    StreamSource ss = new StreamSource(is);
    Schema schema = factory.newSchema(ss);
    is = loader.getResourceAsStream("datatypes.xml");
    Validator v = schema.newValidator();
    v.validate(new StreamSource(is));
    is = loader.getResourceAsStream("datatypes.xml");
    IPersistenceProvider pp = new StreamPersistenceProvider(is);
    pp.getBindings().wDefValue("packageName", "org.whole.lang.xsd.mapping.samples");
    IEntity model = XsiPersistenceKit.instance().readModel(pp);
    Assert.assertTrue(Matcher.match(new DatatypesInstance().create(), model));
}
Also used : DatatypesInstance(org.whole.lang.xsd.mapping.samples.DatatypesInstance) IEntity(org.whole.lang.model.IEntity) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Schema(javax.xml.validation.Schema) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) Validator(javax.xml.validation.Validator) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 17 with StreamPersistenceProvider

use of org.whole.lang.codebase.StreamPersistenceProvider in project whole by wholeplatform.

the class XsiModelTemplateTest method testXsiModelTemplate.

@Category({ KnownFailingTests.class, SlowTests.class })
@Test
public void testXsiModelTemplate() throws Exception {
    fail();
    IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
    bm.wDefValue("folderLocation", new File("test/org/whole/lang/xsd/templates").getAbsolutePath());
    bm.wDefValue("packageName", "");
    XsdDeployStrategies.setDeployStrategy(bm, XsdDeployStrategies.ALL);
    String fileName = "S202SCTDIRPFRAA0001.C.xml";
    IEntity xsiModel = XsiPersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream(fileName), null, bm));
    CommonsEntityFactory.instance.createRootFragment(xsiModel.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    IEntity xmlModel = XmlSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream(fileName), null, bm));
    CommonsEntityFactory.instance.createRootFragment(xmlModel.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    ModelBuilderOperation mop = new ModelBuilderOperation();
    XmlNormalizerBuilderOperation xnbo = new XmlNormalizerBuilderOperation(mop);
    XsiModelTemplate xsiModelTemplate = new XsiModelTemplate(xsiModel);
    xsiModelTemplate.apply(xnbo);
    IEntity xmlModelFromXsiModel = mop.wGetResult();
    Assert.assertTrue(Matcher.match(xmlModelFromXsiModel, xmlModel));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) XmlNormalizerBuilderOperation(org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation) IBindingManager(org.whole.lang.bindings.IBindingManager) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) File(java.io.File) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 18 with StreamPersistenceProvider

use of org.whole.lang.codebase.StreamPersistenceProvider in project whole by wholeplatform.

the class XsiModelTemplateTest method testXsdModelTemplate.

@Test
public void testXsdModelTemplate() throws Exception {
    String pacs002FileName = "pacs.002.001.02S2.xsd";
    IEntity xsdPacs002 = loadXMLSchema(pacs002FileName);
    CommonsEntityFactory.instance.createRootFragment(xsdPacs002.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    IEntity xmlPacs002 = XmlSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream(pacs002FileName)));
    CommonsEntityFactory.instance.createRootFragment(xmlPacs002.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    ModelBuilderOperation mop = new ModelBuilderOperation();
    XmlNormalizerBuilderOperation xnbo = new XmlNormalizerBuilderOperation(mop);
    XsdModelTemplate xsdModelTemplate = new XsdModelTemplate(xsdPacs002);
    xsdModelTemplate.apply(xnbo);
    IEntity xmlModelFromXsdPacs002 = mop.wGetResult();
    Assert.assertTrue(OrderedMatcher.match(xmlModelFromXsdPacs002, xmlPacs002, comparatorsMap));
    String credTrfFileName = "SCTCcfBlkCredTrf.xsd";
    IEntity xsdCredTrf = loadXMLSchema(credTrfFileName);
    CommonsEntityFactory.instance.createRootFragment(xsdCredTrf.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    IEntity xmlCredTrf = XmlSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream(credTrfFileName)));
    CommonsEntityFactory.instance.createRootFragment(xmlCredTrf.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    mop = new ModelBuilderOperation();
    xnbo = new XmlNormalizerBuilderOperation(mop);
    xsdModelTemplate = new XsdModelTemplate(xsdCredTrf);
    xsdModelTemplate.apply(xnbo);
    IEntity xmlModelFromXsdCredTrf = mop.wGetResult();
    Assert.assertTrue(OrderedMatcher.match(xmlModelFromXsdCredTrf, xmlCredTrf, comparatorsMap));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) XmlNormalizerBuilderOperation(org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) Test(org.junit.Test)

Example 19 with StreamPersistenceProvider

use of org.whole.lang.codebase.StreamPersistenceProvider in project whole by wholeplatform.

the class XsdLanguageTest method loadSchemaInstance.

private void loadSchemaInstance(String schemaFileName, String... instanceFileNames) throws Exception {
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    String folderLocation = new File("test/org/whole/lang/xsd/util").getAbsolutePath();
    bm.wDefValue("folderLocation", folderLocation);
    bm.wDefValue("packageName", "");
    Schema xsd = loadXsd(schemaFileName);
    InterpreterOperation.interpret(xsd, bm);
    for (String instanceFileName : instanceFileNames) XsiPersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream(instanceFileName)));
}
Also used : Schema(org.whole.lang.xsd.model.Schema) IBindingManager(org.whole.lang.bindings.IBindingManager) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) File(java.io.File)

Example 20 with StreamPersistenceProvider

use of org.whole.lang.codebase.StreamPersistenceProvider in project whole by wholeplatform.

the class XsdLanguageTest method testArtifactsMappedModel.

@Category(KnownFailingTests.class)
@Test
public void testArtifactsMappedModel() {
    try {
        IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
        PathExpression path = new ModelToXmlSchemaQuery().create();
        IEntity model = XmlBuilderPersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/artifacts/ArtifactsModel.xwl"));
        Assert.assertNotNull(BehaviorUtils.evaluateFirstResult(path, model, bm));
        InterpreterOperation.interpret(bm.wGet("mapping"));
        bm.wDefValue("folderLocation", new File("test/org/whole/lang/xsd/util").getAbsolutePath());
        bm.wDefValue("packageName", "");
        IEntity artifacts = XsiPersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream("Artifacts.xml"), null, bm));
        Assert.assertTrue(Matcher.match(new Artifacts().create(), artifacts));
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : ModelToXmlSchemaQuery(org.whole.lang.xsd.codebase.ModelToXmlSchemaQuery) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) ClasspathPersistenceProvider(org.whole.lang.codebase.ClasspathPersistenceProvider) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) File(java.io.File) 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