} catch (WSDLException e) {
fail("Can't instantiate the WSDLFactory object.");
}
// Create a schema for use in the tests and add it to a types section.
InlinedSchema schema = new InlinedSchemaImpl();
XmlSchema xs1 = null;
URI schemaNS = null;
try
{
String schemaString = "<schema xmlns=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.sample.org\">"
+ "<complexType name=\"myType\">"
+ "<sequence>"
+ "<element name=\"element\" type=\"string\"/>"
+ "</sequence>"
+ "</complexType>"
+ "<element name=\"myElement\" type=\"string\"/>"
+ "</schema>";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder builder=dbf.newDocumentBuilder();
Reader reader = new StringReader(schemaString);
InputSource is = new InputSource(reader);
Document schemaDoc1 = builder.parse(is);
XmlSchemaCollection xsc = new XmlSchemaCollection();
xs1 = xsc.read(schemaDoc1.getDocumentElement());
schemaNS = new URI("http://www.sample.org");
schema.setSchemaDefinition(xs1);
schema.setNamespace(schemaNS);
TypesElement types = factory.newDescription().addTypesElement();
types.addSchema(schema);
}
catch(Exception e)
{
fail("An error occurred while creating the sample types section.");
}
// Test that a null namespace returns true.
handler.reset();
try
{
DescriptionElement descElem = factory.newDescription();
TypesElement types = descElem.addTypesElement();
types.addSchema(schema);
if(!val.testAssertionSchema1066(descElem, null, reporter))
{
fail("The testAssertionSchema1066 method returned false for a null namespace.");
}
}
catch(WSDLException e)
{
fail("There was a problem running the test assertion method " + e);
}
// Test that a reference to a namespace that is defined inline
// does not return an error.
handler.reset();
try
{
DescriptionElement descElem = factory.newDescription();
TypesElement types = descElem.addTypesElement();
types.addSchema(schema);
if(!val.testAssertionSchema1066(descElem, new QName("http://www.sample.org", "myElement"), reporter))
{
fail("The testAssertionSchema1066 method returned false for a namespace that has been defined inline.");
}
}
catch(WSDLException e)
{
fail("There was a problem running the test assertion method " + e);
}
// Test that a reference to a namespace that is imported
// does not return an error.
handler.reset();
try
{
DescriptionElement descElem = factory.newDescription();
TypesElement typesImported = descElem.addTypesElement();
ImportedSchema importedSchema = new ImportedSchemaImpl();
importedSchema.setSchemaDefinition(xs1);
importedSchema.setNamespace(schemaNS);
typesImported.addSchema(importedSchema);
if(!val.testAssertionSchema1066(descElem, new QName("http://www.sample.org", "myElement"), reporter))
{
fail("The testAssertionSchema1066 method returned false for a namespace that has been imported.");
}
}
catch(WSDLException e)
{
fail("There was a problem running the test assertion method " + e);
}
// Test that a reference to the XML Schema namespace does not return an error.
handler.reset();
try
{
DescriptionElement descElem = factory.newDescription();
//descElem.setTypesElement(types);
if(!val.testAssertionSchema1066(descElem, new QName(Constants.TYPE_XSD_2001, "myElement"), reporter))
{
fail("The testAssertionSchema1066 method returned false for the XML Schema namespace.");
}
}
catch(WSDLException e)
{
fail("There was a problem running the test assertion method " + e);
}
// Test that a reference to a namespace that has not been defined inline or imported returns an error.
// This test also checks that the method functions correctly with no defined types element.
handler.reset();
try
{
DescriptionElement descElem = factory.newDescription();
//descElem.setTypesElement(types);
if(val.testAssertionSchema1066(descElem, new QName("http://www.sample2.org", "myElement"), reporter))
{
fail("The testAssertionSchema1066 method returned true for a namespace that is not available..");
}
}
catch(WSDLException e)
{
fail("There was a problem running the test assertion method " + e);
}
// Test that a reference to an inline schema that does not define a
// target namespace (the targetNamespace is null) does not return an
// error.
handler.reset();
try
{
DescriptionElement descElem = factory.newDescription();
TypesElement typesImported = descElem.addTypesElement();
InlinedSchema inlinedSchema = new InlinedSchemaImpl();
typesImported.addSchema(inlinedSchema);
InlinedSchema inlinedSchema2 = new InlinedSchemaImpl();
inlinedSchema2.setNamespace(schemaNS);
typesImported.addSchema(inlinedSchema2);
if(!val.testAssertionSchema1066(descElem, new QName("http://www.sample.org", "myElement"), reporter))
{
fail("The testAssertionSchema1066 method returned false for a namespace that has been imported.");