Search in sources :

Example 1 with SchemaModelGeneratorProperties

use of org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties in project eclipselink by eclipse-ee4j.

the class GenerateSingleSchemaTestCases method testElementFormQualifiedNoDefaultRootElement.

/**
 * Test global complex type generation.  Element form default is qualified.
 */
public void testElementFormQualifiedNoDefaultRootElement() throws Exception {
    Schema generatedSchema = null;
    Document tDoc = null;
    Document cDoc = null;
    try {
        boolean setSchemaContext = true;
        boolean setDefaultRootElement = false;
        SchemaModelGeneratorProperties props = new SchemaModelGeneratorProperties();
        props.addProperty(MYNS, SchemaModelGeneratorProperties.ELEMENT_FORM_QUALIFIED_KEY, true);
        Project prj = new TestProject(setSchemaContext, setDefaultRootElement, MYNS);
        loginProject(prj);
        List<Descriptor> descriptorsToProcess = setupDescriptorList(prj);
        Map<String, Schema> generatedSchemas = sg.generateSchemas(descriptorsToProcess, props);
        generatedSchema = generatedSchemas.get(MYNS);
        assertNotNull("No schema was generated for namespace [" + MYNS + "]", generatedSchema);
        // debugging
        // writeSchema(generatedSchema);
        tDoc = getDocument(generatedSchema);
        cDoc = getDocument(ELEMENT_FORM_QUALIFIED_NO_DRE_RESOURCE);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail();
    }
    assertNotNull("Schema to Document conversion failed", tDoc);
    assertNotNull("A problem occurred loading the control schema", cDoc);
    assertTrue("Schema comparsion failed", comparer.isSchemaEqual(cDoc, tDoc));
}
Also used : Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) SchemaModelGeneratorProperties(org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Document(org.w3c.dom.Document)

Example 2 with SchemaModelGeneratorProperties

use of org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties in project eclipselink by eclipse-ee4j.

the class GenerateSingleSchemaTestCases method testElementFormQualifiedNoSchemaContext.

/**
 * Test global element and anonymous complex type generation. Element form
 * default is qualified.
 */
public void testElementFormQualifiedNoSchemaContext() throws Exception {
    Schema generatedSchema = null;
    Document tDoc = null;
    Document cDoc = null;
    try {
        boolean setSchemaContext = false;
        boolean setDefaultRootElement = true;
        SchemaModelGeneratorProperties props = new SchemaModelGeneratorProperties();
        props.addProperty(MYNS, SchemaModelGeneratorProperties.ELEMENT_FORM_QUALIFIED_KEY, true);
        Project prj = new TestProject(setSchemaContext, setDefaultRootElement, MYNS);
        loginProject(prj);
        List<Descriptor> descriptorsToProcess = setupDescriptorList(prj);
        Map<String, Schema> generatedSchemas = sg.generateSchemas(descriptorsToProcess, props);
        generatedSchema = generatedSchemas.get(MYNS);
        assertNotNull("No schema was generated for namespace [" + MYNS + "]", generatedSchema);
        // debugging
        // writeSchema(generatedSchema);
        tDoc = getDocument(generatedSchema);
        cDoc = getDocument(ELEMENT_FORM_QUALIFIED_NO_CTX_RESOURCE);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail();
    }
    assertNotNull("Schema to Document conversion failed", tDoc);
    assertNotNull("A problem occurred loading the control schema", cDoc);
    assertTrue("Schema comparsion failed", comparer.isSchemaEqual(cDoc, tDoc));
}
Also used : Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) SchemaModelGeneratorProperties(org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Document(org.w3c.dom.Document)

Example 3 with SchemaModelGeneratorProperties

use of org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties in project eclipselink by eclipse-ee4j.

the class GenerateSingleSchemaTestCases method testElementFormUnqualifiedNoCtxNoDRE.

/**
 * No schema should be generated since there is no default root element
 * or schema context set on any descriptors
 */
public void testElementFormUnqualifiedNoCtxNoDRE() throws Exception {
    Schema generatedSchema = null;
    try {
        boolean setSchemaContext = false;
        boolean setDefaultRootElement = false;
        Project prj = new TestProject(setSchemaContext, setDefaultRootElement);
        loginProject(prj);
        List<Descriptor> descriptorsToProcess = setupDescriptorList(prj);
        SchemaModelGeneratorProperties props = new SchemaModelGeneratorProperties();
        props.addProperty(MYEMPTYNS, SchemaModelGeneratorProperties.ELEMENT_FORM_QUALIFIED_KEY, false);
        Map<String, Schema> generatedSchemas = sg.generateSchemas(descriptorsToProcess, props);
        generatedSchema = generatedSchemas.get(MYEMPTYNS);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail();
    }
    assertNull("A schema should not have been generated", generatedSchema);
}
Also used : Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) SchemaModelGeneratorProperties(org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties)

Example 4 with SchemaModelGeneratorProperties

use of org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties in project eclipselink by eclipse-ee4j.

the class GenerateSingleSchemaTestCases method testElementFormUnqualifiedNoDefaultRootElement.

/**
 * Test global complex type generation.  Element form default is unqualified.
 * Element refs will be generated for local elements whose type is that of
 * a global complex type.  In these cases, global elements will be
 * generated for the refs.
 */
public void testElementFormUnqualifiedNoDefaultRootElement() throws Exception {
    Schema generatedSchema = null;
    Document tDoc = null;
    Document cDoc = null;
    try {
        boolean setSchemaContext = true;
        boolean setDefaultRootElement = false;
        SchemaModelGeneratorProperties props = new SchemaModelGeneratorProperties();
        props.addProperty(MYEMPTYNS, SchemaModelGeneratorProperties.ELEMENT_FORM_QUALIFIED_KEY, false);
        Project prj = new TestProject(setSchemaContext, setDefaultRootElement);
        loginProject(prj);
        List<Descriptor> descriptorsToProcess = setupDescriptorList(prj);
        Map<String, Schema> generatedSchemas = sg.generateSchemas(descriptorsToProcess, props);
        generatedSchema = generatedSchemas.get(MYEMPTYNS);
        assertNotNull("No schema was generated for namespace [" + MYEMPTYNS + "]", generatedSchema);
        // debugging
        // writeSchema(generatedSchema);
        tDoc = getDocument(generatedSchema);
        cDoc = getDocument(ELEMENT_FORM_UNQUALIFIED_NO_DRE_RESOURCE);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail();
    }
    assertNotNull("Schema to Document conversion failed", tDoc);
    assertNotNull("A problem occurred loading the control schema", cDoc);
    assertTrue("Schema comparsion failed", comparer.isSchemaEqual(cDoc, tDoc));
}
Also used : Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) SchemaModelGeneratorProperties(org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Document(org.w3c.dom.Document)

Example 5 with SchemaModelGeneratorProperties

use of org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties in project eclipselink by eclipse-ee4j.

the class PathbasedMappingTestCases method testSchemaGenValidationFailure.

public void testSchemaGenValidationFailure() throws Exception {
    Schema generatedSchema = null;
    Document tDoc = null;
    Document cDoc = null;
    boolean exception = false;
    try {
        SchemaModelGeneratorProperties props = new SchemaModelGeneratorProperties();
        props.addProperty(MYNS, SchemaModelGeneratorProperties.ELEMENT_FORM_QUALIFIED_KEY, false);
        XMLContext xCtx = new XMLContext("org.eclipse.persistence.testing.oxm.schemamodelgenerator.mappings.pathbased");
        Project prj = xCtx.getSession(0).getProject();
        loginProject(prj);
        List<Descriptor> descriptorsToProcess = setupDescriptorList(prj);
        Map<String, Schema> generatedSchemas = sg.generateSchemas(descriptorsToProcess, props);
        generatedSchema = generatedSchemas.get(MYNS);
        assertNotNull("No schema was generated for namespace [" + MYNS + "]", generatedSchema);
        writeSchema(generatedSchema);
        tDoc = getDocument(generatedSchema);
        cDoc = getDocument(XSD_RESOURCE);
        assertNotNull("Schema to Document conversion failed", tDoc);
        assertNotNull("A problem occurred loading the control schema", cDoc);
        assertTrue("Schema comparsion failed", comparer.isSchemaEqual(cDoc, tDoc));
        SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
        javax.xml.validation.Schema theSchema = sFact.newSchema(new File(TMP_DIR, "generatedSchema.xsd"));
        Validator validator = theSchema.newValidator();
        StreamSource ss = new StreamSource(new File(INVALID_XML_RESOURCE));
        validator.validate(ss);
    } catch (Exception ex) {
        exception = true;
    }
    assertTrue("Schema did not fail as expected: ", exception == true);
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) XMLContext(org.eclipse.persistence.oxm.XMLContext) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) StreamSource(javax.xml.transform.stream.StreamSource) Document(org.w3c.dom.Document) Project(org.eclipse.persistence.sessions.Project) SchemaModelGeneratorProperties(org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) File(java.io.File) Validator(javax.xml.validation.Validator)

Aggregations

Descriptor (org.eclipse.persistence.internal.oxm.mappings.Descriptor)13 SchemaModelGeneratorProperties (org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties)13 Schema (org.eclipse.persistence.internal.oxm.schema.model.Schema)13 Project (org.eclipse.persistence.sessions.Project)13 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)11 Document (org.w3c.dom.Document)10 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)9 SchemaModelProject (org.eclipse.persistence.internal.oxm.schema.SchemaModelProject)9 File (java.io.File)2 StreamSource (javax.xml.transform.stream.StreamSource)2 SchemaFactory (javax.xml.validation.SchemaFactory)2 Validator (javax.xml.validation.Validator)2 XMLContext (org.eclipse.persistence.oxm.XMLContext)2 TestProject (org.eclipse.persistence.testing.oxm.schemamodelgenerator.TestProject)2 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1