use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.
the class SchemaGenMapTestCases method testMapSchemaGeneration.
/**
* Exception case - Schema for Map should be generated without any exception.
*/
public void testMapSchemaGeneration() {
Class<?>[] loadedClasses = { MapTest.class };
org.eclipse.persistence.jaxb.compiler.Generator generator = new Generator(new JavaModelInputImpl(loadedClasses, new JavaModelImpl(MapTest.class.getClassLoader())));
MySchemaOutputResolver outputResolver = new MySchemaOutputResolver();
boolean exception = false;
try {
generator.generateSchemaFiles(outputResolver, null);
} catch (Exception e) {
exception = true;
}
assertFalse("Unexpected exception occured", exception);
}
use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.
the class ExternalizedMetadataTestCases method createXmlContext.
/**
* Convenience method that returns a newly created XMLContext based on an array of classes.
*/
protected XMLContext createXmlContext(Class<?>[] classes) {
try {
ClassLoader classLoader = new JaxbClassLoader(Thread.currentThread().getContextClassLoader());
Generator generator = new Generator(new JavaModelInputImpl(classes, new JavaModelImpl(classLoader)));
CoreProject proj = generator.generateProject();
ConversionManager manager = new ConversionManager();
manager.setLoader(classLoader);
for (Iterator<ClassDescriptor> descriptorIt = proj.getOrderedDescriptors().iterator(); descriptorIt.hasNext(); ) {
ClassDescriptor descriptor = descriptorIt.next();
if (descriptor.getJavaClass() == null) {
descriptor.setJavaClass(manager.convertClassNameToClass(descriptor.getJavaClassName()));
}
}
return new XMLContext((Project) proj, classLoader);
} catch (Exception e) {
e.printStackTrace();
fail("XmlContext creation failed");
}
return null;
}
use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.
the class JAXBContextTransformationMappingTestCases method testInvalidMethod.
/**
* Test exception handling: in this case the method name that has been
* set is invalid (wrong number or type of params. An exception should
* be thrown.
*
* Negative test.
*/
public void testInvalidMethod() {
InputStream inputStream = ClassLoader.getSystemResourceAsStream(METADATA_FILE_BAD_METHOD);
HashMap<String, Source> metadataSourceMap = new HashMap<>();
metadataSourceMap.put("org.eclipse.persistence.testing.jaxb.externalizedmetadata.mappings.xmltransformation", new StreamSource(inputStream));
Map<String, Object> properties = new HashMap<>();
properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataSourceMap);
int exceptionCount = 0;
try {
JAXBContext jaxbContext = JAXBContextFactory.createContext(new Class<?>[] { Employee.class }, properties, Thread.currentThread().getContextClassLoader());
} catch (JAXBException e) {
exceptionCount++;
}
assertTrue("The expected exception was never thrown.", exceptionCount > 0);
exceptionCount--;
// test exception from SchemaGenerator
try {
Map<String, XmlBindings> bindings = JAXBContextFactory.getXmlBindingsFromProperties(properties, Thread.currentThread().getContextClassLoader());
JavaModelInputImpl jModelInput = new JavaModelInputImpl(new Class<?>[] { Employee.class }, new JavaModelImpl(new JaxbClassLoader(Thread.currentThread().getContextClassLoader(), new Class<?>[] { Employee.class })));
Generator generator = new Generator(jModelInput, bindings, Thread.currentThread().getContextClassLoader(), "", false);
generator.generateSchema();
} catch (Exception e) {
exceptionCount++;
}
assertTrue("The expected exception was never thrown.", exceptionCount > 0);
}
use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.
the class RequiredAnnotationTestCases method testAnnotationsProcessor.
public void testAnnotationsProcessor() throws Exception {
try {
JaxbClassLoader classLoader = new JaxbClassLoader(Thread.currentThread().getContextClassLoader());
Generator generator = new Generator(new JavaModelInputImpl(new Class<?>[] { RequiredTestObject.class, RequiredTestSubObject.class }, new JavaModelImpl(classLoader)));
Project proj = (Project) generator.generateProject();
ClassDescriptor descriptor = proj.getDescriptorForAlias("RequiredTestObject");
DatabaseMapping mapping = descriptor.getMappingForAttributeName("direct");
boolean isRequired = ((XMLField) mapping.getField()).isRequired();
assertTrue("The ('direct') mapping's XMLField's isRequired flag was not set to 'true' despite XML Annotation", isRequired);
mapping = descriptor.getMappingForAttributeName("directAttribute");
isRequired = ((XMLField) mapping.getField()).isRequired();
assertTrue("The ('directAttribute') mapping's XMLField's isRequired flag was not set to 'true' despite XML Annotation", isRequired);
mapping = descriptor.getMappingForAttributeName("directCollection");
isRequired = ((XMLField) mapping.getField()).isRequired();
assertTrue("The ('directCollection') mapping's XMLField's isRequired flag was not set to 'true' despite XML Annotation", isRequired);
mapping = descriptor.getMappingForAttributeName("compositeObject");
isRequired = ((XMLField) mapping.getField()).isRequired();
assertTrue("The ('compositeObject') mapping's XMLField's isRequired flag was not set to 'true' despite XML Annotation", isRequired);
mapping = descriptor.getMappingForAttributeName("compositeCollection");
isRequired = ((XMLField) mapping.getField()).isRequired();
assertTrue("The ('compositeCollection') mapping's XMLField's isRequired flag was not set to 'true' despite XML Annotation", isRequired);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.
the class BeanValidationBindingsTestCase method generateSchema.
private void generateSchema(Class<?>[] classes) throws FileNotFoundException {
JavaModelImpl javaModel = new JavaModelImpl(Thread.currentThread().getContextClassLoader());
JavaModelInputImpl modelInput = new JavaModelInputImpl(classes, javaModel);
modelInput.setFacets(true);
Generator gen = new Generator(modelInput);
gen.generateSchemaFiles(PATH_TO_SCHEMA_DIRECTORY, null);
}
Aggregations