use of org.eclipse.persistence.jaxb.compiler.Generator 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);
}
use of org.eclipse.persistence.jaxb.compiler.Generator 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);
}
Aggregations