use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.
the class PropertyTypeTestCases method testPropertyTypes.
public void testPropertyTypes() throws Exception {
JaxbClassLoader classLoader = new JaxbClassLoader(Thread.currentThread().getContextClassLoader());
Generator generator = new Generator(new JavaModelInputImpl(new Class<?>[] { TestObject.class }, new JavaModelImpl(this.classLoader)));
CoreProject proj = generator.generateProject();
TypeInfo info = generator.getAnnotationsProcessor().getTypeInfos().get("org.eclipse.persistence.testing.jaxb.annotations.TestObject");
Property booleanProp = info.getProperties().get("booleanTest");
JavaClass type = booleanProp.getType();
assertEquals("java.lang.Boolean", type.getRawName());
Property booleanListProp = info.getProperties().get("booleanListTest");
type = booleanListProp.getType();
assertEquals("java.util.List", type.getRawName());
Property byteArrayProp = info.getProperties().get("byteArrayTest");
type = byteArrayProp.getType();
assertEquals("java.lang.String", type.getRawName());
Property byteArrayListProp = info.getProperties().get("byteArrayListTest");
type = byteArrayListProp.getType();
assertEquals("java.util.List", type.getRawName());
assertEquals("java.lang.String", byteArrayListProp.getGenericType().getRawName());
}
use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.
the class SchemaGenImportTestCases method testSchemaGenerationWithImport.
public void testSchemaGenerationWithImport() {
Class<?>[] jClasses = new Class<?>[] { Address.class, Employee.class };
Generator gen = new Generator(new JavaModelInputImpl(jClasses, new JavaModelImpl(Thread.currentThread().getContextClassLoader())));
File outDir = setOutDir();
try {
Files.copy(getFile(PACKAGE_RESOURCE + "someExistingSchema.xsd").toPath(), new File(outDir, "someExistingSchema.xsd").toPath());
} catch (IOException e1) {
throw new RuntimeException(e1);
}
MySystemIDSchemaOutputResolver mysor = new MySystemIDSchemaOutputResolver(outDir);
gen.generateSchemaFiles(mysor, null);
// validate a valid instance doc against the generated employee schema
SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema employeeSchema = null;
try {
employeeSchema = sFact.newSchema(mysor.schemaFiles.get(EMPLOYEE_NS));
} catch (SAXException e) {
e.printStackTrace();
fail("SchemaFactory could not create Employee schema");
}
StreamSource ss;
Validator validator = employeeSchema.newValidator();
try {
ss = new StreamSource(getFile(XML_RESOURCE));
validator.validate(ss);
} catch (Exception ex) {
ex.printStackTrace();
fail("An unexpected exception occurred");
}
try {
ss = new StreamSource(getFile(INVALID_XML_RESOURCE));
validator.validate(ss);
} catch (Exception ex) {
return;
}
fail("The expected exception never occurred");
}
use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.
the class SchemaGenImportTestCases method testRelativeSchemaLocationWithNoSlash.
/**
* Test's that the import schema location can be relativized given a
* source schema with no path info in the name, i.e. "employee.xsd".
* No exception should occur.
*/
public void testRelativeSchemaLocationWithNoSlash() {
File outDir = setOutDir();
try {
Class<?>[] jClasses = new Class<?>[] { Address.class, Employee.class };
Generator gen = new Generator(new JavaModelInputImpl(jClasses, new JavaModelImpl(Thread.currentThread().getContextClassLoader())));
gen.generateSchemaFiles(outDir.getAbsolutePath(), null);
} catch (Exception x) {
x.printStackTrace();
fail("An unexpected exception occurred during schema generation: " + x.getMessage());
}
}
use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.
the class SchemaGenEmployeeTestCases method xtestAbstractSuperclassInvaildDoc.
/**
* In this test the xsi:type of the root element set to the abstract superclass,
* which should cause a validation exception.
*/
public void xtestAbstractSuperclassInvaildDoc() throws Exception {
boolean exception = false;
String msg = null;
String src = "org/eclipse/persistence/testing/jaxb/schemagen/employee/invalid_inheritance.xml";
File newXsd = new File(tmpdir, "schema1.xsd");
if (newXsd.exists() && newXsd.isFile() && newXsd.delete()) {
System.err.println("removed existing: " + newXsd.getAbsolutePath());
}
try {
Class<?>[] jClasses = new Class<?>[] { MyAbstractTestType.class, MyTestSubType.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;
msg = ex.toString();
}
assertTrue("Schema validation did not fail as expected: " + msg, exception);
}
use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.
the class SchemaGenEmployeeTestCases method xtestEmployeeSchemaGenMissingRequiredAttribute.
/**
* The following test expects a schema validation exception to occur.
* This is due to the fact that the supplied instance document does
* not contain a 'firstName' element, which is required as the
* corresponding field in the Employee class contains the following
* annotation: @XmlElement(required = true)
*/
public void xtestEmployeeSchemaGenMissingRequiredAttribute() throws Exception {
boolean exception = false;
String src = "org/eclipse/persistence/testing/jaxb/schemagen/employee/employee_missing_required_attribute.xml";
String msg = "";
File newXsd = new File(tmpdir, "schema1.xsd");
if (newXsd.exists() && newXsd.isFile() && newXsd.delete()) {
System.err.println("removed existing: " + newXsd.getAbsolutePath());
}
try {
Class<?>[] jClasses = new Class<?>[] { Address.class, Employee.class, PhoneNumber.class, Department.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;
msg = ex.getLocalizedMessage();
}
assertTrue("Schema validation passed unexpectedly", exception);
assertTrue("An unexpected exception occurred: " + msg, msg.contains("id"));
}
Aggregations