test.com.generationjava.web.XmlWTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gj-scrape Show documentation
Show all versions of gj-scrape Show documentation
Simple scraping component of GenJava-Core.
package com.generationjava.web;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
public class XmlWTest extends TestCase {
private String testXml = "test ";
public XmlWTest(String name) {
super(name);
}
//-----------------------------------------------------------------------
// To test:
// XmlW.escapeXml
// XmlW.unescapeXml
// XmlW.getContent
public void testEscape() {
String toEscape = "4 is < 7 & 7 is > 4 but \"7\" and '4' make error. ";
String expected = "4 is < 7 & 7 is > 4 but "7" and '4' make error. ";
assertEquals( expected, XmlW.escapeXml( toEscape ) );
}
public void testUnescape() {
String toUnescape = "4 is < 7 & 7 is > 4 but "7" and '4' make error. ";
String expected = "4 is < 7 & 7 is > 4 but \"7\" and '4' make error. ";
assertEquals( expected, XmlW.unescapeXml( toUnescape ) );
}
public void testSymmetry() {
String expected = "4 is < 7 & 7 is > 4 but \"7\" and '4' make error. ";
assertEquals( expected, XmlW.unescapeXml( XmlW.escapeXml( expected ) ) );
}
public void testRemove() {
assertEquals( "FOO", XmlW.removeXml("FOO ") );
assertEquals( "FOO", XmlW.removeXml("FOO ") );
assertEquals( "FOO", XmlW.removeXml(" FOO ") );
assertEquals( "FOO", XmlW.removeXml("FOO") );
assertEquals( "some comment", XmlW.removeXml("some comment
") );
assertEquals( "", XmlW.removeXml("") );
}
public void testGetAttribute() {
assertEquals( "foo", XmlW.getAttribute( this.testXml, "thing" ) );
}
public void testGetIndexOpeningTag() {
assertEquals( 0, XmlW.getIndexOpeningTag(this.testXml, "bar") );
}
public void testGetIndexClosingTag() {
assertEquals( 36, XmlW.getIndexClosingTag(this.testXml, "bar") );
}
public void testGetContent() {
assertEquals( "test", XmlW.getContent(this.testXml, "bar") );
}
public void testSingleQuoteAttribute() {
assertEquals( "single", XmlW.getAttribute(this.testXml, "other" ) );
}
}