Skip to content
Snippets Groups Projects
Commit 367d95d1 authored by brinn's avatar brinn
Browse files

fix: make tests run with JRE6

SVN: 18672
parent e9f96900
No related branches found
No related tags found
No related merge requests found
......@@ -79,7 +79,7 @@ public final class MethodUtilsTest extends AssertJUnit
{
final Method method = Object.class.getMethods()[0];
final String methodDescription = MethodUtils.describeMethod(method);
assertEquals("Object.hashCode", methodDescription);
assertEquals("Object." + Object.class.getMethods()[0].getName(), methodDescription);
}
//
......
......@@ -32,8 +32,6 @@ import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
*
*
* @author Franz-Josef Elmer
*/
public class XMLInfraStructureTest extends AssertJUnit
......@@ -41,7 +39,7 @@ public class XMLInfraStructureTest extends AssertJUnit
private static final class MockContentHandler extends DefaultHandler
{
private List<String> texts = new ArrayList<String>();
@Override
public void characters(char[] ch, int start, int length) throws SAXException
{
......@@ -58,72 +56,60 @@ public class XMLInfraStructureTest extends AssertJUnit
return texts.toString();
}
}
private static final String EXAMPLE_XSD =
"<?xml version='1.0'?>\n"
+ "<xs:schema targetNamespace='http://my.host.org' xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n"
+ "<xs:element name='note'>\n"
+ " <xs:complexType>\n"
+ " <xs:sequence>\n"
+ "<xs:element name='note'>\n" + " <xs:complexType>\n" + " <xs:sequence>\n"
+ " <xs:element name='to' type='xs:string'/>\n"
+ " <xs:element name='from' type='xs:string'/>\n"
+ " <xs:element name='heading' type='xs:string'/>\n"
+ " <xs:element name='body' type='xs:string'/>\n"
+ " </xs:sequence>\n"
+ " </xs:complexType>\n"
+ "</xs:element>\n"
+ "</xs:schema>";
private static final String VALID_EXAMPLE_XML =
"<?xml version='1.0'?>\n" + "<n:note\n" + "xmlns:n='http://my.host.org'\n"
+ "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
+ "xsi:schemaLocation='http://my.host.org /note.xsd'>\n"
+ " <to>Albert</to>\n"
+ " <from>Isaac</from>\n"
+ " <heading>Space and Time</heading>\n"
+ " <body>New theory on space and time.</body>\n"
+ "</n:note>";
private static final String INVALID_EXAMPLE_XML =
"<?xml version='1.0'?>\n" + "<n:note\n" + "xmlns:n='http://my.host.org'\n"
+ "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
+ "xsi:schemaLocation='http://my.host.org /note.xsd'>\n"
+ " <to>Albert</to>\n"
+ " <from>Isaac</from>\n"
+ " <heading>Space and Time</heading>\n"
+ "</n:note>";
private static final String NOT_WELLFORMED_EXAMPLE_XML =
"<?xml version='1.0'?>\n" + "<n:note\n" + "xmlns:n='http://my.host.org'\n"
+ "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
+ "xsi:schemaLocation='http://my.host.org /note.xsd'>\n"
+ " <to>Albert</to>\n";
+ " <xs:element name='body' type='xs:string'/>\n" + " </xs:sequence>\n"
+ " </xs:complexType>\n" + "</xs:element>\n" + "</xs:schema>";
private static final String VALID_EXAMPLE_XML = "<?xml version='1.0'?>\n" + "<n:note\n"
+ "xmlns:n='http://my.host.org'\n"
+ "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
+ "xsi:schemaLocation='http://my.host.org /note.xsd'>\n" + " <to>Albert</to>\n"
+ " <from>Isaac</from>\n" + " <heading>Space and Time</heading>\n"
+ " <body>New theory on space and time.</body>\n" + "</n:note>";
private static final String INVALID_EXAMPLE_XML = "<?xml version='1.0'?>\n" + "<n:note\n"
+ "xmlns:n='http://my.host.org'\n"
+ "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
+ "xsi:schemaLocation='http://my.host.org /note.xsd'>\n" + " <to>Albert</to>\n"
+ " <from>Isaac</from>\n" + " <heading>Space and Time</heading>\n" + "</n:note>";
private static final String NOT_WELLFORMED_EXAMPLE_XML = "<?xml version='1.0'?>\n"
+ "<n:note\n" + "xmlns:n='http://my.host.org'\n"
+ "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
+ "xsi:schemaLocation='http://my.host.org /note.xsd'>\n" + " <to>Albert</to>\n";
private ContentHandler contentHandler;
private EntityResolver entityResolver;
@BeforeMethod
public void beforeMethod()
{
contentHandler = new MockContentHandler();
entityResolver = new EntityResolver()
{
public InputSource resolveEntity(String publicId, String systemId) throws SAXException,
IOException
{
assertEquals("file:///note.xsd", systemId);
return new InputSource(new StringReader(EXAMPLE_XSD));
}
};
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException
{
assertEquals("file:///note.xsd", systemId);
return new InputSource(new StringReader(EXAMPLE_XSD));
}
};
}
@Test
public void testCreateSchema()
{
XMLInfraStructure.createSchema(new ByteArrayInputStream(EXAMPLE_XSD.getBytes()));
}
@Test
public void testCreateInvalidSchema()
{
......@@ -136,53 +122,53 @@ public class XMLInfraStructureTest extends AssertJUnit
// ignored
}
}
@Test
public void testNoValidation()
{
XMLInfraStructure xmlInfraStructure = new XMLInfraStructure(false);
xmlInfraStructure.setEntityResolver(entityResolver);
xmlInfraStructure.parse(new StringReader(INVALID_EXAMPLE_XML), contentHandler);
assertEquals("[Albert, Isaac, Space and Time]", contentHandler.toString());
}
@Test
public void testValidXML()
{
XMLInfraStructure xmlInfraStructure = new XMLInfraStructure(true);
xmlInfraStructure.setEntityResolver(entityResolver);
xmlInfraStructure.parse(new StringReader(VALID_EXAMPLE_XML), contentHandler);
assertEquals("[Albert, Isaac, Space and Time, New theory on space and time.]",
contentHandler.toString());
}
@Test
public void testInvalidXML()
{
XMLInfraStructure xmlInfraStructure = new XMLInfraStructure(true);
xmlInfraStructure.setEntityResolver(entityResolver);
try
{
xmlInfraStructure.parse(new StringReader(INVALID_EXAMPLE_XML), contentHandler);
fail("Exception expected");
} catch (Exception ex)
{
assertEquals("org.xml.sax.SAXException: XML validation errors:\n"
+ "Error in line 9 column 10:cvc-complex-type.2.4.b: "
+ "The content of element 'n:note' is not complete. "
+ "One of '{\"\":body}' is expected.", ex.getMessage());
assertTrue(ex.getMessage(), ex.getMessage().indexOf(
"org.xml.sax.SAXException: XML validation errors:\n"
+ "Error in line 9 column 10:cvc-complex-type.2.4.b: "
+ "The content of element 'n:note' is not complete. ") >= 0);
}
}
@Test
public void testNotWellFormedXML()
{
XMLInfraStructure xmlInfraStructure = new XMLInfraStructure(true);
xmlInfraStructure.setEntityResolver(entityResolver);
try
{
xmlInfraStructure.parse(new StringReader(NOT_WELLFORMED_EXAMPLE_XML), contentHandler);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment