Index: xml/c1675/CastorAnyAttributeTest.java =================================================================== --- xml/c1675/CastorAnyAttributeTest.java (Revision 0) +++ xml/c1675/CastorAnyAttributeTest.java (Revision 0) @@ -0,0 +1,76 @@ +package xml.c1675; + +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; + +import junit.framework.TestCase; + +import org.exolab.castor.xml.schema.ComplexType; +import org.exolab.castor.xml.schema.Schema; +import org.exolab.castor.xml.schema.Wildcard; +import org.exolab.castor.xml.schema.reader.SchemaReader; +import org.exolab.castor.xml.schema.writer.SchemaWriter; +import org.xml.sax.InputSource; + +/** + * A unit test for testing the Castor SchemaWriter class with schemas that contain + * xs:anyAttribute's. + */ +public class CastorAnyAttributeTest extends TestCase +{ + private static final String TEST_SCHEMA = "\r\n" + + "\r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + "\r\n"; + + /** + * Parses a schema into a Schema object. + * + * @param aSchemaString the schema to load + * @return a Castor Schema + * @throws IOException + */ + private static Schema loadSchema(String aSchemaString) throws IOException + { + InputSource iSource = new InputSource(new StringReader(aSchemaString)); + SchemaReader reader = new SchemaReader(iSource); + return reader.read(); + } + + /** + * Serializes a schema to a String using the Castor SchemaWriter. + * + * @param aSchema The schema to serialize + * @return A serialized schema + */ + private static String serializeSchema(Schema aSchema) throws Exception + { + StringWriter stringWriter = new StringWriter(); + SchemaWriter schemaWriter = new SchemaWriter(stringWriter); + schemaWriter.write(aSchema); + + return stringWriter.getBuffer().toString(); + } + + /** + * Test that an xs:anyAttribute is serialized properly by the Castor SchemaWriter + * class. + */ + public void testAnyAttributeSerialization() throws Exception + { + Schema originalSchema = loadSchema(TEST_SCHEMA); + String serializedSchema = serializeSchema(originalSchema); + Schema reloadedSchema = loadSchema(serializedSchema); + ComplexType complexType = reloadedSchema.getComplexType("DataSetType"); + Wildcard wildcard = complexType.getAnyAttribute(); + assertNotNull("Wildcard is null: anyAttribute serialization failed.", wildcard); + String processContent = wildcard.getProcessContent(); + assertEquals("lax", processContent); + } +}