Search in sources :

Example 26 with JavaModelInputImpl

use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.

the class SchemaGenXMLTypeTestCases method testBaseType001cPositive.

public void testBaseType001cPositive() throws Exception {
    boolean exception = false;
    String msg = null;
    InputStream src = null;
    File newXsd = new File(tmpdir, "schema1.xsd");
    if (newXsd.exists() && newXsd.isFile() && newXsd.delete()) {
        System.err.println("removed existing: " + newXsd.getAbsolutePath());
    }
    try {
        src = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmltype/BaseType001p.xml");
        Class<?>[] jClasses = new Class<?>[] { BaseType001c.class };
        Generator gen = new Generator(new JavaModelInputImpl(jClasses, new JavaModelImpl(Thread.currentThread().getContextClassLoader())));
        gen.generateSchemaFiles(tmpdir, null);
        SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema theSchema = sFact.newSchema(newXsd);
        Validator validator = theSchema.newValidator();
        StreamSource ss = new StreamSource(src);
        validator.validate(ss);
    } catch (Exception ex) {
        exception = true;
        msg = ex.toString();
    } finally {
        if (null != src) {
            try {
                src.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    assertTrue("Schema validation failed unexpectedly: " + msg, exception == false);
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) JavaModelImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl) InputStream(java.io.InputStream) Schema(javax.xml.validation.Schema) StreamSource(javax.xml.transform.stream.StreamSource) JavaModelInputImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl) File(java.io.File) Validator(javax.xml.validation.Validator) Generator(org.eclipse.persistence.jaxb.compiler.Generator)

Example 27 with JavaModelInputImpl

use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.

the class SchemaGenXMLTypeTestCases method testBaseType001cNegative.

public void testBaseType001cNegative() throws Exception {
    boolean exception = false;
    String src = "org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmltype/BaseType001n.xml";
    File newXsd = new File(tmpdir, "schema0.xsd");
    if (newXsd.exists() && newXsd.isFile() && newXsd.delete()) {
        System.err.println("removed existing: " + newXsd.getAbsolutePath());
    }
    try {
        Class<?>[] jClasses = new Class<?>[] { BaseType001c.class };
        Generator gen = new Generator(new JavaModelInputImpl(jClasses, new JavaModelImpl(Thread.currentThread().getContextClassLoader())));
        gen.generateSchemaFiles(tmpdir, null);
        SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema theSchema = sFact.newSchema(newXsd);
        Validator validator = theSchema.newValidator();
        StreamSource ss = new StreamSource(new File(src));
        validator.validate(ss);
    } catch (Exception ex) {
        exception = true;
    }
    assertFalse("Schema validation did not fail as expected: ", exception == false);
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) JavaModelImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl) Schema(javax.xml.validation.Schema) StreamSource(javax.xml.transform.stream.StreamSource) JavaModelInputImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl) File(java.io.File) Validator(javax.xml.validation.Validator) Generator(org.eclipse.persistence.jaxb.compiler.Generator)

Aggregations

JavaModelImpl (org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl)27 JavaModelInputImpl (org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl)27 Generator (org.eclipse.persistence.jaxb.compiler.Generator)26 StreamSource (javax.xml.transform.stream.StreamSource)18 File (java.io.File)15 Schema (javax.xml.validation.Schema)14 SchemaFactory (javax.xml.validation.SchemaFactory)14 Validator (javax.xml.validation.Validator)14 JaxbClassLoader (org.eclipse.persistence.internal.jaxb.JaxbClassLoader)10 InputStream (java.io.InputStream)9 JAXBException (jakarta.xml.bind.JAXBException)4 HashMap (java.util.HashMap)4 Source (javax.xml.transform.Source)4 CoreProject (org.eclipse.persistence.core.sessions.CoreProject)4 Property (org.eclipse.persistence.jaxb.compiler.Property)4 TypeInfo (org.eclipse.persistence.jaxb.compiler.TypeInfo)4 XmlBindings (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings)4 Test (org.junit.Test)4 JAXBContext (jakarta.xml.bind.JAXBContext)3 IOException (java.io.IOException)3