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));
}
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));
}
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);
}
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));
}
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);
}
Aggregations