diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/MethodUtilsTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/MethodUtilsTest.java index 1e7631d7ccb2b334fe7e81c0851685c9158e5fa6..4e5ca60c0793a464d0c1b22a4dc8cdcdbd47e761 100644 --- a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/MethodUtilsTest.java +++ b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/MethodUtilsTest.java @@ -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); } // diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/XMLInfraStructureTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/XMLInfraStructureTest.java index 5a7bef88edec8bf41d48199e99928c203466a084..2b51a43bbe2e87864192c44082ac427951baa3c4 100644 --- a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/XMLInfraStructureTest.java +++ b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/XMLInfraStructureTest.java @@ -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);