📄 documenttest_java.htm
字号:
roundtrip.sendToWriter( secondroundwriter );
StringReader secondroundreader = new StringReader( secondroundwriter.toString() );
XMLDocument secondroundtrip = (XMLDocument) instantiator.newInstance( roundtrip.getMimeType(), secondroundreader );
System.out.println( secondroundtrip.toString() );
} catch( Throwable everything ) {
everything.printStackTrace();
fail( "Caught an unexpected exception - " + everything.toString() );
}
}
public void testLiteXMLStructuredDoc() {
try {
_test( LiteXMLDocument.INSTANTIATOR, MimeMediaType.XML_DEFAULTENCODING );
_testConstructors( LiteXMLDocument.INSTANTIATOR, MimeMediaType.XML_DEFAULTENCODING );
_testAttributesSolo( LiteXMLDocument.INSTANTIATOR, MimeMediaType.XML_DEFAULTENCODING );
_testLiteXMLEmptyElement( LiteXMLDocument.INSTANTIATOR, MimeMediaType.XML_DEFAULTENCODING );
} catch( Throwable everything ) {
everything.printStackTrace();
fail( "Caught an unexpected exception - " + everything.toString() );
}
}
public void testDOMXMLStructuredDoc() {
StructuredDocumentFactory.Instantiator domInstantiator = null;
try {
domInstantiator = (StructuredDocumentFactory.Instantiator) Class.forName("net.jxta.impl.document.DOMXMLDocument").getField("INSTANTIATOR").get(null);
} catch( ClassNotFoundException noDOM ) {
;
} catch( NoSuchFieldException noDOM ) {
;
} catch( IllegalAccessException noDOM ) {
;
}
try {
if( null != domInstantiator ) {
_test( domInstantiator, MimeMediaType.XML_DEFAULTENCODING );
_testConstructors( domInstantiator, MimeMediaType.XML_DEFAULTENCODING );
_testAttributesSolo( domInstantiator, MimeMediaType.XML_DEFAULTENCODING );
}
} catch( Throwable everything ) {
everything.printStackTrace();
fail( "Caught an unexpected exception - " + everything.toString() );
}
}
public void testPlainTextDoc() {
try {
_test( PlainTextDocument.INSTANTIATOR, MimeMediaType.TEXT_DEFAULTENCODING );
_testConstructors( PlainTextDocument.INSTANTIATOR, MimeMediaType.TEXT_DEFAULTENCODING );
_testAttributesSolo( PlainTextDocument.INSTANTIATOR, MimeMediaType.TEXT_DEFAULTENCODING );
} catch( Throwable everything ) {
everything.printStackTrace();
fail( "Caught an unexpected exception - " + everything.toString() );
}
}
public void testExtensionMapping() {
MimeMediaType refMime = new MimeMediaType("Text/Xml");
String refExt = "xml";
String ext = StructuredDocumentFactory.getFileExtensionForMimeType( refMime );
MimeMediaType mime = StructuredDocumentFactory.getMimeTypeForFileExtension( ext );
assertTrue( "mime type was not the same after reflex mapping", refMime.equals( mime ) );
assertTrue( "extension was not the same after reflex mapping", refExt.equals( ext ) );
}
public void testIssue102() {
String WORKS =
"<xml><stooges>Moe, Larry, &#x41;&#65;&#0666;& Curly</stooges></xml>";
String DOES_NOT_WORK =
"<xml><stooges>Moe, Larry, & Joe</stooges></xml>";
LiteXMLBug works = new LiteXMLBug( WORKS );
LiteXMLBug doesNotWork = new LiteXMLBug( DOES_NOT_WORK );
}
public void testIssue1282() {
try {
//create document
MimeMediaType mime = new MimeMediaType("text/xml");
XMLDocument document = (XMLDocument) LiteXMLDocument.INSTANTIATOR.newInstance( mime, "items" );
for (int i = 0; i < 10; i++) {
XMLElement testElem = document.createElement("item");
document.appendChild(testElem);
testElem.addAttribute("name", "n" + i);
if (i == 3) {
for (int j = 0; j < 2; j++) {
XMLElement childElem = document.createElement("item");
testElem.appendChild(childElem);
childElem.addAttribute("name", "ch" + j);
}
}
}
// Serialize the message
ByteArrayOutputStream out = new ByteArrayOutputStream();
document.sendToStream( out );
InputStream is = new ByteArrayInputStream( out.toByteArray() );
XMLDocument document2 = (XMLDocument) StructuredDocumentFactory.newStructuredDocument( mime, is);
Enumeration eachOrig = document.getChildren();
Enumeration eachNew = document2.getChildren();
while( eachOrig.hasMoreElements() ) {
if( !eachNew.hasMoreElements() ) {
fail( "Enumeration did not end at same time." );
}
XMLElement anOrig = (XMLElement) eachOrig.nextElement();
XMLElement aNew = (XMLElement) eachNew.nextElement();
assertEquals( "Elements names should be equivalent", aNew.getKey(), anOrig.getKey() );
assertEquals( "Elements values should be equivalent", aNew.getValue(), anOrig.getValue() );
Attribute anOrigName = anOrig.getAttribute( "name" );
Attribute aNewName = aNew.getAttribute( "name" );
assertEquals( "Element attribute name should be equivalent", anOrigName.getValue(), aNewName.getValue() );
}
if( eachNew.hasMoreElements() ) {
fail( "Enumeration did not end at same time." );
}
} catch( Throwable everything ) {
everything.printStackTrace();
fail( "Caught an unexpected exception - " + everything.getMessage() );
}
}
public void testIssue1372() {
XMLDocument document = null;
XMLDocument document2 = null;
try {
for (int depth = 1; depth <= 10; depth++) {
// create document
document = (XMLDocument) LiteXMLDocument.INSTANTIATOR.newInstance(MimeMediaType.XML_DEFAULTENCODING,
"items");
for (int elemCount = 1; elemCount <= 2; elemCount++) {
XMLElement parentElem = document;
for (int layer = 1; layer <= depth; layer++) {
XMLElement testElem = document.createElement("item");
parentElem.appendChild(testElem);
testElem.addAttribute("name",
depth + "-" + elemCount + ":" +
layer);
parentElem = testElem;
}
}
// Serialize the message
StringWriter out = new StringWriter();
document.sendToWriter(out);
Reader is = new StringReader(out.toString());
document2 = (XMLDocument) StructuredDocumentFactory.newStructuredDocument(MimeMediaType.XML_DEFAULTENCODING,
is);
Enumeration eachOrig = document.getChildren();
Enumeration eachNew = document2.getChildren();
// FIXME 20050607 bondolo comparison doesn't recurse.
while (eachOrig.hasMoreElements()) {
if (!eachNew.hasMoreElements()) {
fail("Enumeration did not end at same time.");
}
XMLElement anOrig = (XMLElement) eachOrig.nextElement();
XMLElement aNew = (XMLElement) eachNew.nextElement();
assertEquals("Elements names should be equivalent",
aNew.getKey(), anOrig.getKey());
assertEquals("Elements values should be equivalent",
aNew.getValue(), anOrig.getValue());
Attribute anOrigName = anOrig.getAttribute("name");
Attribute aNewName = aNew.getAttribute("name");
assertEquals("Element attribute name should be equivalent",
anOrigName.getValue(), aNewName.getValue());
}
if (eachNew.hasMoreElements()) {
fail("Enumeration did not end at same time.");
}
}
} catch( Throwable everything ) {
System.err.flush();
System.out.flush();
everything.printStackTrace( System.err );
fail( "Caught an unexpected exception - " + everything.getMessage() );
}
}
public void testIssue13XX() {
XMLDocument document = null;
try {
Reader is = new StringReader( badlittleimpl );
document = (XMLDocument) StructuredDocumentFactory.newStructuredDocument( MimeMediaType.XML_DEFAULTENCODING, is);
System.err.println( document );
} catch( Throwable everything ) {
System.err.flush();
System.out.flush();
everything.printStackTrace( System.err );
fail( "Caught an unexpected exception - " + everything.getMessage() );
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
junit.textui.TestRunner.run(suite());
System.err.flush();
System.out.flush();
}
}
</PRE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -