elharo commented on code in PR #98:
URL: https://github.com/apache/xerces-j/pull/98#discussion_r3543605074
##########
tests/dom/rename/Test.java:
##########
@@ -77,138 +78,203 @@ public class Test implements UserDataHandler {
// Xerces specific feature
protected static final boolean DEFAULT_DEFERRED_DOM = true;
- //
- // Public methods
- //
+ private Document document;
+
+ protected void setUp() throws Exception {
+ ParserWrapper parser = (ParserWrapper)
+ Class.forName(DEFAULT_PARSER_NAME).newInstance();
+ try {
+ parser.setFeature(NAMESPACES_FEATURE_ID, DEFAULT_NAMESPACES);
+ }
+ catch (SAXException e) {
+ // ignore
+ }
+ try {
+ parser.setFeature(VALIDATION_FEATURE_ID, DEFAULT_VALIDATION);
+ }
+ catch (SAXException e) {
+ // ignore
+ }
+ try {
+ parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID,
+ DEFAULT_SCHEMA_VALIDATION);
+ }
+ catch (SAXException e) {
+ // ignore
+ }
+ try {
+ parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID,
+ DEFAULT_SCHEMA_FULL_CHECKING);
+ }
+ catch (SAXException e) {
+ // ignore
+ }
+ if (parser instanceof dom.wrappers.Xerces) {
+ try {
+ parser.setFeature(DEFERRED_DOM_FEATURE_ID,
+ DEFAULT_DEFERRED_DOM);
+ }
+ catch (SAXException e) {
+ // ignore
+ }
+ }
+ try {
+ document = parser.parse("tests/dom/rename/input.xml");
+ }
+ catch (SAXParseException e) {
+ fail("Parse error: " + e.getMessage());
+ }
+ catch (Exception e) {
+ String msg = e.getMessage();
+ if (e instanceof SAXException) {
+ msg = ((SAXException)e).getException().getMessage();
+ }
+ fail("Parse error: " + msg);
+ }
+ }
+
+ public void testRename() {
+ doTestRename(document);
+ }
/** Performs the actual test. */
- public void test(Document doc) {
+ public void doTestRename(Document doc) {
System.out.println("DOM rename Test...");
Review Comment:
println no longer needed, here or anywhere else
##########
tests/dom/rename/Test.java:
##########
@@ -77,138 +78,203 @@ public class Test implements UserDataHandler {
// Xerces specific feature
protected static final boolean DEFAULT_DEFERRED_DOM = true;
- //
- // Public methods
- //
+ private Document document;
+
+ protected void setUp() throws Exception {
+ ParserWrapper parser = (ParserWrapper)
+ Class.forName(DEFAULT_PARSER_NAME).newInstance();
+ try {
+ parser.setFeature(NAMESPACES_FEATURE_ID, DEFAULT_NAMESPACES);
+ }
+ catch (SAXException e) {
+ // ignore
+ }
+ try {
+ parser.setFeature(VALIDATION_FEATURE_ID, DEFAULT_VALIDATION);
+ }
+ catch (SAXException e) {
+ // ignore
+ }
+ try {
+ parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID,
+ DEFAULT_SCHEMA_VALIDATION);
+ }
+ catch (SAXException e) {
+ // ignore
+ }
+ try {
+ parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID,
+ DEFAULT_SCHEMA_FULL_CHECKING);
+ }
+ catch (SAXException e) {
+ // ignore
+ }
+ if (parser instanceof dom.wrappers.Xerces) {
+ try {
+ parser.setFeature(DEFERRED_DOM_FEATURE_ID,
+ DEFAULT_DEFERRED_DOM);
+ }
+ catch (SAXException e) {
+ // ignore
+ }
+ }
+ try {
+ document = parser.parse("tests/dom/rename/input.xml");
+ }
+ catch (SAXParseException e) {
+ fail("Parse error: " + e.getMessage());
+ }
+ catch (Exception e) {
+ String msg = e.getMessage();
+ if (e instanceof SAXException) {
+ msg = ((SAXException)e).getException().getMessage();
+ }
+ fail("Parse error: " + msg);
+ }
+ }
+
+ public void testRename() {
+ doTestRename(document);
+ }
/** Performs the actual test. */
- public void test(Document doc) {
+ public void doTestRename(Document doc) {
System.out.println("DOM rename Test...");
// getting the first "email" element
NodeList elements = doc.getElementsByTagName("email");
Element child = (Element) elements.item(0);
- Assertion.verify(child != null);
- Assertion.equals(child.getNodeName(), "email");
+ assertTrue("child should not be null", child != null);
+ assertEquals("nodeName should be email", "email", child.getNodeName());
// default must be there
Attr at = child.getAttributeNode("defaultEmailAttr");
- Assertion.verify(at != null);
- Assertion.equals(at.getValue(), "defaultEmailValue");
- Assertion.verify(at.getSpecified() == false);
+ assertTrue("defaultEmailAttr should not be null", at != null);
+ assertEquals("default value of defaultEmailAttr", "defaultEmailValue",
at.getValue());
+ assertTrue("defaultEmailAttr should not be specified",
!at.getSpecified());
// attach some data
child.setUserData("mydata", "yo", this);
- Assertion.equals((String) child.getUserData("mydata"), "yo");
+ assertEquals("user data should be 'yo'", "yo", (String)
child.getUserData("mydata"));
// renaming an element without a url
Element newChild = (Element) doc.renameNode(child, null, "url");
- Assertion.equals(newChild.getNodeName(), "url");
- Assertion.verify(newChild.getNamespaceURI() == null);
+ assertEquals("renamed node name should be url", "url",
newChild.getNodeName());
+ assertTrue("namespace should be null", newChild.getNamespaceURI() ==
null);
// old default must no longer be there
- Assertion.verify(newChild.hasAttribute("defaultEmailAttr") == false);
- Assertion.verify(at.getSpecified() == true);
+ assertTrue("should not have defaultEmailAttr after rename",
+ !newChild.hasAttribute("defaultEmailAttr"));
+ assertTrue("defaultEmailAttr should now be specified",
at.getSpecified());
// new default must be there
at = newChild.getAttributeNode("defaultUrlAttr");
- Assertion.verify(at != null);
- Assertion.equals(at.getValue(), "defaultUrlValue");
- Assertion.verify(at.getSpecified() == false);
+ assertTrue("defaultUrlAttr should not be null", at != null);
+ assertEquals("default value of defaultUrlAttr", "defaultUrlValue",
at.getValue());
+ assertTrue("defaultUrlAttr should not be specified",
!at.getSpecified());
// data must still be there
- Assertion.equals((String) newChild.getUserData("mydata"), "yo");
+ assertEquals("user data should still be 'yo'", "yo", (String)
newChild.getUserData("mydata"));
// and handler must have been called if new node was created
if (newChild != child) {
- Assertion.verify(lastOperation == UserDataHandler.NODE_RENAMED);
- Assertion.verify(lastKey == "mydata");
- Assertion.equals((String) lastData, "yo");
- Assertion.verify(lastSource == child);
- Assertion.verify(lastDestination == newChild);
+ assertTrue("operation should be NODE_RENAMED",
+ lastOperation == UserDataHandler.NODE_RENAMED);
+ assertEquals("key should be 'mydata'", "mydata", lastKey);
+ assertEquals("data should be 'yo'", "yo", (String) lastData);
+ assertTrue("source should be original child", lastSource == child);
+ assertTrue("destination should be new child", lastDestination ==
newChild);
resetHandlerData();
}
// renaming an element with a url
Element newChild2 = (Element) doc.renameNode(newChild, "ns1", "foo");
- Assertion.equals(newChild2.getNodeName(), "foo");
- Assertion.equals(newChild2.getNamespaceURI(), "ns1");
- Assertion.verify(newChild2.hasAttribute("defaultUrlAttr") == false);
+ assertEquals("renamed node name should be foo", "foo",
newChild2.getNodeName());
+ assertEquals("namespace should be ns1", "ns1",
newChild2.getNamespaceURI());
+ assertTrue("should not have defaultUrlAttr after rename",
+ !newChild2.hasAttribute("defaultUrlAttr"));
// data must still be there
- Assertion.equals((String) newChild2.getUserData("mydata"), "yo");
+ assertEquals("user data should still be 'yo'",
+ "yo", (String) newChild2.getUserData("mydata"));
// and handler must have been called if new node was created
if (newChild2 != newChild) {
- Assertion.verify(lastOperation == UserDataHandler.NODE_RENAMED);
- Assertion.verify(lastKey == "mydata");
- Assertion.equals((String) lastData, "yo");
- Assertion.verify(lastSource == newChild);
- Assertion.verify(lastDestination == newChild2);
+ assertTrue("operation should be NODE_RENAMED",
+ lastOperation == UserDataHandler.NODE_RENAMED);
+ assertEquals("key should be 'mydata'", "mydata", lastKey);
+ assertEquals("data should be 'yo'", "yo", (String) lastData);
+ assertTrue("source should be previous child", lastSource ==
newChild);
+ assertTrue("destination should be new child2", lastDestination ==
newChild2);
resetHandlerData();
}
// getting the second "email" element
child = (Element) elements.item(1);
- Assertion.verify(child != null);
- Assertion.equals(child.getNodeName(), "email");
+ assertTrue("second child should not be null", child != null);
+ assertEquals("second child nodeName should be email", "email",
child.getNodeName());
// default must be there
at = child.getAttributeNode("defaultEmailAttr");
- Assertion.verify(at != null);
- Assertion.equals(at.getValue(), "defaultEmailValue");
- Assertion.verify(at.getSpecified() == false);
+ assertTrue("second child defaultEmailAttr should not be null", at !=
null);
+ assertEquals("second child default value", "defaultEmailValue",
at.getValue());
+ assertTrue("second child defaultEmailAttr should not be specified",
!at.getSpecified());
// attach some data
at.setUserData("mydata", "yo", this);
- Assertion.equals((String) at.getUserData("mydata"), "yo");
+ assertEquals("attr user data should be 'yo'", "yo", (String)
at.getUserData("mydata"));
// renaming an attribute without a url
Attr newAt = (Attr) doc.renameNode(at, null, "foo");
- Assertion.verify(newAt != null);
- Assertion.equals(newAt.getNodeName(), "foo");
- Assertion.equals(newAt.getNamespaceURI(), null);
- Assertion.equals(newAt.getValue(), "defaultEmailValue");
- Assertion.verify(newAt.getSpecified() == true);
- Assertion.verify(child.hasAttribute("foo") == true);
+ assertTrue("renamed attr should not be null", newAt != null);
+ assertEquals("renamed attr name should be foo", "foo",
newAt.getNodeName());
+ assertTrue("renamed attr namespace should be null",
newAt.getNamespaceURI() == null);
+ assertEquals("renamed attr value should remain", "defaultEmailValue",
newAt.getValue());
+ assertTrue("renamed attr should be specified", newAt.getSpecified());
+ assertTrue("child should have 'foo' attribute",
child.hasAttribute("foo"));
// default must be back
- Assertion.verify(child.hasAttribute("defaultEmailAttr") == true);
+ assertTrue("defaultEmailAttr should be present",
child.hasAttribute("defaultEmailAttr"));
// data must still be there
- Assertion.equals((String) newAt.getUserData("mydata"), "yo");
+ assertEquals("attr user data should still be 'yo'",
+ "yo", (String) newAt.getUserData("mydata"));
// and handler must have been called if new node was created
if (newAt != at) {
- Assertion.verify(lastOperation == UserDataHandler.NODE_RENAMED);
- Assertion.verify(lastKey == "mydata");
- Assertion.equals((String) lastData, "yo");
- Assertion.verify(lastSource == at);
- Assertion.verify(lastDestination == newAt);
+ assertTrue("operation should be NODE_RENAMED",
+ lastOperation == UserDataHandler.NODE_RENAMED);
+ assertEquals("key should be 'mydata'", "mydata", lastKey);
+ assertEquals("data should be 'yo'", "yo", (String) lastData);
+ assertTrue("source should be original attr", lastSource == at);
+ assertTrue("destination should be new attr", lastDestination ==
newAt);
resetHandlerData();
}
// renaming an attribute with a url
Attr newAt2 = (Attr) doc.renameNode(newAt, "ns1", "bar");
- Assertion.verify(newAt2 != null);
- Assertion.equals(newAt2.getNodeName(), "bar");
- Assertion.equals(newAt2.getNamespaceURI(), "ns1");
- Assertion.equals(newAt2.getValue(), "defaultEmailValue");
- Assertion.verify(newAt2.getSpecified() == true);
- Assertion.verify(child.hasAttributeNS("ns1", "bar") == true);
+ assertTrue("renamed attr2 should not be null", newAt2 != null);
+ assertEquals("renamed attr2 name should be bar", "bar",
newAt2.getNodeName());
+ assertEquals("renamed attr2 namespace should be ns1", "ns1",
newAt2.getNamespaceURI());
+ assertEquals("renamed attr2 value should remain", "defaultEmailValue",
newAt2.getValue());
+ assertTrue("renamed attr2 should be specified", newAt2.getSpecified());
+ assertTrue("child should have ns1:bar attribute",
+ child.hasAttributeNS("ns1", "bar"));
// data must still be there
- Assertion.equals((String) newAt2.getUserData("mydata"), "yo");
+ assertEquals("attr2 user data should still be 'yo'",
+ "yo", (String) newAt2.getUserData("mydata"));
// and handler must have been called if new node was created
if (newAt2 != newAt) {
- Assertion.verify(lastOperation == UserDataHandler.NODE_RENAMED);
- Assertion.verify(lastKey == "mydata");
- Assertion.equals((String) lastData, "yo");
- Assertion.verify(lastSource == newAt);
- Assertion.verify(lastDestination == newAt2);
+ assertTrue("operation should be NODE_RENAMED",
+ lastOperation == UserDataHandler.NODE_RENAMED);
+ assertEquals("key should be 'mydata'", "mydata", lastKey);
+ assertEquals("data should be 'yo'", "yo", (String) lastData);
+ assertTrue("source should be previous attr", lastSource == newAt);
+ assertTrue("destination should be new attr2", lastDestination ==
newAt2);
resetHandlerData();
}
System.out.println("done.");
Review Comment:
println no longer needed, here or anywhere else
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]