Search in sources :

Example 21 with JavaModelInputImpl

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

the class SchemaGeneratorTestCase method getTransformerPropertyBuilder.

@Test
public void getTransformerPropertyBuilder() {
    JavaModelInputImpl jModelInput = new JavaModelInputImpl(DOMAIN_CLASSES, new JavaModelImpl(new JaxbClassLoader(Thread.currentThread().getContextClassLoader(), DOMAIN_CLASSES)));
    Helper helper = new Helper(jModelInput.getJavaModel());
    Generator generator = new Generator(jModelInput);
    TypeInfo typeInfo = generator.getAnnotationsProcessor().getTypeInfos().get(EMPLOYEE_CLASS_NAME);
    Property normalHoursProperty = typeInfo.getProperties().get(XML_TRANSFORMATION_PROPERTY_NAME);
    ChildSchemaGenerator childSchemaGenerator = new ChildSchemaGenerator(helper);
    TransformerPropertyBuilder transformerPropertyBuilder = childSchemaGenerator.getTransformerPropertyBuilder(normalHoursProperty, typeInfo);
    assertNotNull(transformerPropertyBuilder);
}
Also used : JavaModelInputImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl) ChildSchemaGenerator(org.eclipse.persistence.testing.moxy.unit.jaxb.compiler.builder.ChildSchemaGenerator) JavaModelImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl) TransformerPropertyBuilder(org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder) TypeInfo(org.eclipse.persistence.jaxb.compiler.TypeInfo) Property(org.eclipse.persistence.jaxb.compiler.Property) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) Generator(org.eclipse.persistence.jaxb.compiler.Generator) ChildSchemaGenerator(org.eclipse.persistence.testing.moxy.unit.jaxb.compiler.builder.ChildSchemaGenerator) Test(org.junit.Test)

Example 22 with JavaModelInputImpl

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

the class TransformerPropertyBuilderTestCase method testTransformerPropertyBuilder.

@Test
public void testTransformerPropertyBuilder() {
    InputStream inputStream = ClassLoader.getSystemResourceAsStream(BINDINGS_DOC);
    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);
    Map<String, XmlBindings> bindings = JAXBContextFactory.getXmlBindingsFromProperties(properties, Thread.currentThread().getContextClassLoader());
    JavaModelInputImpl jModelInput = new JavaModelInputImpl(DOMAIN_CLASSES, new JavaModelImpl(new JaxbClassLoader(Thread.currentThread().getContextClassLoader(), DOMAIN_CLASSES)));
    Helper helper = new Helper(jModelInput.getJavaModel());
    Generator generator = new Generator(jModelInput, bindings, Thread.currentThread().getContextClassLoader(), "", false);
    TypeInfo typeInfo = generator.getAnnotationsProcessor().getTypeInfos().get(EMPLOYEE_CLASS_NAME);
    Property normalHoursProperty = typeInfo.getProperties().get(XML_TRANSFORMATION_PROPERTY_NAME);
    ChildSchemaGenerator childSchemaGenerator = new ChildSchemaGenerator(helper);
    TransformerPropertyBuilder transformerPropertyBuilder = childSchemaGenerator.getTransformerPropertyBuilder(normalHoursProperty, typeInfo);
    // Indirect call of org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder.getPropertyName(...) and org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder.buildPropertyFromTransformer(...)
    // Indirect call of org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder.getTransformerJavaClass(...) with booth options writeTransformer.isSetTransformerClass() true,false
    List<Property> props = transformerPropertyBuilder.buildProperties();
    assertEquals(2, props.size());
    // Verification of result of org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder.getPropertyName(...)
    // Verify property names
    assertEquals("start-time", props.get(0).getPropertyName());
    assertEquals("end-time", props.get(1).getPropertyName());
    // Verification of result of org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder.getReturnTypeFromTransformer(...)
    // Verify property types
    assertEquals(String.class.getName(), props.get(0).getType().getName());
    assertEquals(String.class.getName(), props.get(1).getType().getName());
    assertEquals(NormalHoursAttributeTransformer.class.getName(), normalHoursProperty.getXmlTransformation().getXmlReadTransformer().getTransformerClass());
    assertEquals(StartTimeTransformer.class.getName(), normalHoursProperty.getXmlTransformation().getXmlWriteTransformer().get(0).getTransformerClass());
    assertEquals(String.class.getName(), normalHoursProperty.getGenericType().getName());
    // Indirect call of org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder.getTransformerJavaClass(...) with invalid TransformerClass name
    try {
        normalHoursProperty.getXmlTransformation().getXmlWriteTransformer().get(0).setTransformerClass("xxx.xxx.WrongClassName");
        transformerPropertyBuilder.buildProperties();
        fail("Expected JAXBException.");
    } catch (JAXBException expected) {
        assertEquals(50054, expected.getErrorCode());
    }
}
Also used : XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) JavaModelImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl) NormalHoursAttributeTransformer(org.eclipse.persistence.testing.jaxb.externalizedmetadata.mappings.xmltransformation.NormalHoursAttributeTransformer) HashMap(java.util.HashMap) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(org.eclipse.persistence.exceptions.JAXBException) StartTimeTransformer(org.eclipse.persistence.testing.jaxb.externalizedmetadata.mappings.xmltransformation.StartTimeTransformer) TypeInfo(org.eclipse.persistence.jaxb.compiler.TypeInfo) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) JavaModelInputImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl) Helper(org.eclipse.persistence.jaxb.javamodel.Helper) TransformerPropertyBuilder(org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder) Property(org.eclipse.persistence.jaxb.compiler.Property) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) Generator(org.eclipse.persistence.jaxb.compiler.Generator) Test(org.junit.Test)

Example 23 with JavaModelInputImpl

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

the class SchemaGenXMLRootElementTestCases method testName002Negative.

public void testName002Negative() throws Exception {
    boolean exception = false;
    String msg = null;
    String src = "org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlrootelement/Name002n.xml";
    try {
        Class<?>[] jClasses = new Class<?>[] { Name002.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(new File(tmpdir, "schema1.xsd"));
        Validator validator = theSchema.newValidator();
        StreamSource ss = new StreamSource(new File(src));
        validator.validate(ss);
    } catch (Exception ex) {
        exception = true;
        msg = ex.getMessage();
    }
    assertFalse("Schema validation did not fail as expected: " + msg, 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)

Example 24 with JavaModelInputImpl

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

the class SchemaGenXMLRootElementTestCases method testName001Negative.

public void testName001Negative() throws Exception {
    boolean exception = false;
    String src = "org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlrootelement/Name001n.xml";
    try {
        Class<?>[] jClasses = new Class<?>[] { Name001.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(new File(tmpdir, "schema1.xsd"));
        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)

Example 25 with JavaModelInputImpl

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

the class SchemaGenXMLRootElementTestCases method testNamespace001Negative.

public void testNamespace001Negative() throws Exception {
    boolean exception = false;
    String msg = null;
    String src = "org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlrootelement/NameSpace001n.xml";
    try {
        Class<?>[] jClasses = new Class<?>[] { NameSpace001.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(new File(tmpdir, "schema2.xsd"));
        Validator validator = theSchema.newValidator();
        StreamSource ss = new StreamSource(new File(src));
        validator.validate(ss);
    } catch (Exception ex) {
        exception = true;
        msg = ex.getMessage();
    }
    assertFalse("Schema validation did not fail as expected: " + msg, 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