Permalink
Browse files

Added correctness tests for all of the parsers, fixed some bugs, and …

…added a SimpleXML implementation and a sax-based dsl4xml implementation
  • Loading branch information...
1 parent 57c9a54 commit 7957e85d94cabc472f1258c2ace8f3b9e7d72762 @steveliles committed Apr 23, 2012
Showing with 462 additions and 68 deletions.
  1. +4 −4 .classpath
  2. +7 −1 src/main/java/com/sjl/dsl4xml/performance/ChartTemplate.java
  3. +43 −6 src/main/java/com/sjl/dsl4xml/performance/PerformanceComparisonMain.java
  4. +1 −0 src/main/java/com/sjl/dsl4xml/performance/ReadingThread.java
  5. +2 −3 src/main/java/com/sjl/dsl4xml/performance/chart-template.html
  6. +11 −0 src/main/java/com/sjl/dsl4xml/performance/model/Author.java
  7. +2 −1 src/main/java/com/sjl/dsl4xml/performance/model/Tweet.java
  8. +2 −2 src/main/java/com/sjl/dsl4xml/performance/parsers/DOMTweetsReader.java
  9. +43 −9 src/main/java/com/sjl/dsl4xml/performance/parsers/DOMXPathTweetsReader.java
  10. +2 −2 ...ava/com/sjl/dsl4xml/performance/parsers/{Dsl4XmlTweetsReader.java → Dsl4XmlPullTweetsReader.java}
  11. +45 −0 src/main/java/com/sjl/dsl4xml/performance/parsers/Dsl4XmlSAXTweetsReader.java
  12. +67 −8 src/main/java/com/sjl/dsl4xml/performance/parsers/SAXTweetsReader.java
  13. +0 −29 src/main/java/com/sjl/dsl4xml/performance/parsers/SimpleXMLReader.java
  14. +54 −0 src/main/java/com/sjl/dsl4xml/performance/parsers/SimpleXMLTweetsReader.java
  15. +63 −0 src/test/java/com/sjl/dsl4xml/performance/parsers/AbstractTestForTweetsReaders.java
  16. +12 −0 src/test/java/com/sjl/dsl4xml/performance/parsers/DOMParserTweetsReaderTest.java
  17. +12 −0 src/test/java/com/sjl/dsl4xml/performance/parsers/DOMXPathParserTweetsReaderTest.java
  18. +2 −2 ...m/sjl/dsl4xml/performance/parsers/{Dsl4XmlPerformanceTest.java → Dsl4XmlPullPerformanceTest.java}
  19. +12 −0 src/test/java/com/sjl/dsl4xml/performance/parsers/Dsl4XmlPullTweetsReaderTest.java
  20. +17 −0 src/test/java/com/sjl/dsl4xml/performance/parsers/Dsl4XmlSAXPerformanceTest.java
  21. +12 −0 src/test/java/com/sjl/dsl4xml/performance/parsers/Dsl4XmlSAXTweetsReaderTest.java
  22. +12 −0 src/test/java/com/sjl/dsl4xml/performance/parsers/PullParserTweetsReaderTest.java
  23. +12 −0 src/test/java/com/sjl/dsl4xml/performance/parsers/SAXParserTweetsReaderTest.java
  24. +12 −0 src/test/java/com/sjl/dsl4xml/performance/parsers/SJXPTweetsReaderTest.java
  25. +1 −1 src/test/java/com/sjl/dsl4xml/performance/parsers/SimpleXMLPerformanceTest.java
  26. +12 −0 src/test/java/com/sjl/dsl4xml/performance/parsers/SimpleXMLTweetsReaderTest.java
View
8 .classpath
@@ -3,17 +3,17 @@
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="output" path="target/classes"/>
<classpathentry kind="var" path="M2_REPO/com/google/android/android/4.0.1.2/android-4.0.1.2.jar"/>
- <classpathentry kind="var" path="M2_REPO/commons-codec/commons-codec/1.3/commons-codec-1.3.jar"/>
- <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-codec/commons-codec/1.3/commons-codec-1.3.jar" sourcepath="M2_REPO/commons-codec/commons-codec/1.3/commons-codec-1.3-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar" sourcepath="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/com/sjl/dsl4xml/0.1.3-SNAPSHOT/dsl4xml-0.1.3-SNAPSHOT.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpclient/4.0.1/httpclient-4.0.1.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpcore/4.0.1/httpcore-4.0.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/json/json/20080701/json-20080701.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/json/json/20080701/json-20080701.jar" sourcepath="M2_REPO/org/json/json/20080701/json-20080701-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/junit/junit/4.4/junit-4.4.jar" sourcepath="M2_REPO/junit/junit/4.4/junit-4.4-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/khronos/opengl-api/gl1.1-android-2.1_r1/opengl-api-gl1.1-android-2.1_r1.jar"/>
<classpathentry kind="var" path="M2_REPO/org/simpleframework/simple-xml/2.6.2/simple-xml-2.6.2.jar"/>
<classpathentry kind="var" path="M2_REPO/com/thebuzzmedia/sjxp/2.2/sjxp-2.2.jar"/>
- <classpathentry kind="var" path="M2_REPO/stax/stax/1.2.0/stax-1.2.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/stax/stax/1.2.0/stax-1.2.0.jar" sourcepath="M2_REPO/stax/stax/1.2.0/stax-1.2.0-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/stax/stax-api/1.0.1/stax-api-1.0.1.jar"/>
<classpathentry kind="var" path="M2_REPO/xerces/xmlParserAPIs/2.6.2/xmlParserAPIs-2.6.2.jar"/>
<classpathentry kind="var" path="M2_REPO/xpp3/xpp3/1.1.4c/xpp3-1.1.4c.jar"/>
View
8 src/main/java/com/sjl/dsl4xml/performance/ChartTemplate.java
@@ -25,7 +25,13 @@ public void addNumberColumn(String aName) {
}
public void addRow(List<Object> aRowValues) {
- data.append("\r\n").append(aRowValues.toString()).append(",");
+ data.append("\r\n");
+ data.append("['").append(aRowValues.get(0)).append("',");
+ for (int i=1; i<aRowValues.size(); i++) {
+ data.append(aRowValues.get(i)).append(",");
+ }
+ data.setLength(data.length()-1);
+ data.append("],");
}
public String toHtmlString() {
View
49 src/main/java/com/sjl/dsl4xml/performance/PerformanceComparisonMain.java
@@ -11,16 +11,21 @@
public static void main(String... anArgs) throws Exception {
PerformanceComparisonMain _cp = new PerformanceComparisonMain();
- _cp.comparePerformance(8, 500, new File(anArgs[0]));
+ _cp.comparePerformance(4, 50, new File(anArgs[0]));
}
public void comparePerformance(int aConcurrency, int anIterations, File aResultsFile)
throws Exception {
byte[] _xml = Streams.readInputIntoByteArray(Tweets.class.getResourceAsStream("twitter-atom.xml"));
List<PerformanceTestRunner> _runners = Arrays.asList(
- newDOMRunner(), newSAXRunner(), newPullParserRunner(),
- newDsl4XmlRunner(), newSJXPRunner()
+ newDOMRunner(),
+ newSAXRunner(),
+ newPullParserRunner(),
+ newDsl4XmlPullRunner(),
+ newDsl4XmlSAXRunner(),
+ newSJXPRunner(),
+ newSimpleXMLRunner()
);
// warm up and discard the first results
@@ -106,17 +111,33 @@ public TweetsReader newReader() throws Exception {
);
}
- private PerformanceTestRunner newDsl4XmlRunner() {
+ private PerformanceTestRunner newDsl4XmlPullRunner() {
return new PerformanceTestRunner(
new TweetsReaderFactory() {
@Override
public String getParserType() {
- return "dsl4xml";
+ return "dsl4xml (pull)";
}
@Override
public TweetsReader newReader() throws Exception {
- return new Dsl4XmlTweetsReader();
+ return new Dsl4XmlPullTweetsReader();
+ }
+ }
+ );
+ }
+
+ private PerformanceTestRunner newDsl4XmlSAXRunner() {
+ return new PerformanceTestRunner(
+ new TweetsReaderFactory() {
+ @Override
+ public String getParserType() {
+ return "dsl4xml (SAX)";
+ }
+
+ @Override
+ public TweetsReader newReader() throws Exception {
+ return new Dsl4XmlSAXTweetsReader();
}
}
);
@@ -137,4 +158,20 @@ public TweetsReader newReader() throws Exception {
}
);
}
+
+ private PerformanceTestRunner newSimpleXMLRunner() {
+ return new PerformanceTestRunner(
+ new TweetsReaderFactory() {
+ @Override
+ public String getParserType() {
+ return "SimpleXML";
+ }
+
+ @Override
+ public TweetsReader newReader() throws Exception {
+ return new SimpleXMLTweetsReader();
+ }
+ }
+ );
+ }
}
View
1 src/main/java/com/sjl/dsl4xml/performance/ReadingThread.java
@@ -32,6 +32,7 @@ public void run() {
Tweets _tw = reader.read(_in);
if (_tw.size() != 15)
throw new RuntimeException("Expected 15 tweets but read " + _tw.size());
+
}
} catch (Exception anExc) {
anExc.printStackTrace();
View
5 src/main/java/com/sjl/dsl4xml/performance/chart-template.html
@@ -6,7 +6,7 @@
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
- data.addColumn('number', 'Concurrency (threads)');
+ data.addColumn('string', 'Concurrency (threads)');
::column-defs::
@@ -16,12 +16,11 @@
var options = {
title: 'Parsing Throughput (higher is better)',
- curveType: 'function',
hAxis: { title: 'Concurrency (threads)' },
vAxis: { title: 'Throughput (docs/sec)' }
};
- var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
+ var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
View
11 src/main/java/com/sjl/dsl4xml/performance/model/Author.java
@@ -27,4 +27,15 @@ public String getUri() {
public void setUri(String aUri) {
uri = aUri;
}
+
+ public boolean equals(Object anObject) {
+ if (anObject instanceof Author) {
+ Author _other = (Author) anObject;
+ return (
+ ((name != null) ? name.equals(_other.name) : (_other.name == null)) &&
+ ((uri != null) ? uri.equals(_other.uri) : (_other.uri == null))
+ );
+ }
+ return false;
+ }
}
View
3 src/main/java/com/sjl/dsl4xml/performance/model/Tweet.java
@@ -4,6 +4,7 @@
import org.simpleframework.xml.*;
+@Root(name="entry", strict=false)
public class Tweet {
@Element
@@ -15,7 +16,7 @@
@Element
private Content content;
- @Element(name="twitter:lang")
+ @Element(name="lang")
private String language;
@Element
View
4 src/main/java/com/sjl/dsl4xml/performance/parsers/DOMTweetsReader.java
@@ -64,7 +64,7 @@ private void unmarshallEntry(Element aTweetEl, Tweet aTo)
Content _content = new Content();
aTo.setContent(_content);
unmarshallContent((Element)_n, _content);
- } else if ("lang".equals(_n.getNodeName())) {
+ } else if ("twitter:lang".equals(_n.getNodeName())) {
aTo.setLanguage(getPCData(_n));
} else if ("author".equals(_n.getNodeName())) {
Author _author = new Author();
@@ -77,7 +77,7 @@ private void unmarshallEntry(Element aTweetEl, Tweet aTo)
private void unmarshallContent(Element aContentEl, Content aTo) {
aTo.setType(aContentEl.getAttribute("type"));
- aTo.setValue(aContentEl.getNodeValue());
+ aTo.setValue(getPCData(aContentEl));
}
private void unmarshallAuthor(Element anAuthorEl, Author aTo) {
View
52 src/main/java/com/sjl/dsl4xml/performance/parsers/DOMXPathTweetsReader.java
@@ -4,6 +4,7 @@
import java.text.*;
import java.util.*;
+import javax.xml.namespace.*;
import javax.xml.parsers.*;
import javax.xml.xpath.*;
@@ -30,21 +31,54 @@
public DOMXPathTweetsReader()
throws Exception {
- builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ DocumentBuilderFactory _dbf = DocumentBuilderFactory.newInstance();
+ _dbf.setNamespaceAware(true);
+ builder = _dbf.newDocumentBuilder();
factory = XPathFactory.newInstance();
- entry = factory.newXPath().compile("/feed/entry");
- published = factory.newXPath().compile(".//published");
- title = factory.newXPath().compile(".//title");
- contentType = factory.newXPath().compile(".//content/@type");
- content = factory.newXPath().compile(".//content");
- lang = factory.newXPath().compile(".//twitter:lang");
- authorName = factory.newXPath().compile(".//author/name");
- authorUri = factory.newXPath().compile(".//author/uri");
+ NamespaceContext _ctx = new NamespaceContext() {
+ public String getNamespaceURI(String aPrefix) {
+ String _uri;
+ if (aPrefix.equals("atom"))
+ _uri = "http://www.w3.org/2005/Atom";
+ else if (aPrefix.equals("twitter"))
+ _uri = "http://api.twitter.com/";
+ else
+ _uri = null;
+ return _uri;
+ }
+
+ @Override
+ public String getPrefix(String aArg0) {
+ return null;
+ }
+
+ @Override
+ @SuppressWarnings("rawtypes")
+ public Iterator getPrefixes(String aArg0) {
+ return null;
+ }
+ };
+
+ entry = newXPath(factory, _ctx, "/atom:feed/atom:entry");
+ published = newXPath(factory, _ctx, ".//atom:published");
+ title = newXPath(factory, _ctx, ".//atom:title");
+ contentType = newXPath(factory, _ctx, ".//atom:content/@type");
+ content = newXPath(factory, _ctx, ".//atom:content");
+ lang = newXPath(factory, _ctx, ".//twitter:lang");
+ authorName = newXPath(factory, _ctx, ".//atom:author/atom:name");
+ authorUri = newXPath(factory, _ctx, ".//atom:author/atom:uri");
dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
}
+ private XPathExpression newXPath(XPathFactory aFactory, NamespaceContext aCtx, String anXPath)
+ throws Exception {
+ XPath _xp = factory.newXPath();
+ _xp.setNamespaceContext(aCtx);
+ return _xp.compile(anXPath);
+ }
+
@Override
public String getParserName() {
return "W3C DOM/XPath";
View
4 ...formance/parsers/Dsl4XmlTweetsReader.java → ...ance/parsers/Dsl4XmlPullTweetsReader.java
@@ -9,11 +9,11 @@
import com.sjl.dsl4xml.performance.model.*;
import com.sjl.dsl4xml.support.convert.*;
-public class Dsl4XmlTweetsReader implements TweetsReader {
+public class Dsl4XmlPullTweetsReader implements TweetsReader {
private DocumentReader<Tweets> reader;
- public Dsl4XmlTweetsReader() {
+ public Dsl4XmlPullTweetsReader() {
reader = mappingOf(Tweets.class).to(
tag("entry", Tweet.class).with(
tag("published"),
View
45 src/main/java/com/sjl/dsl4xml/performance/parsers/Dsl4XmlSAXTweetsReader.java
@@ -0,0 +1,45 @@
+package com.sjl.dsl4xml.performance.parsers;
+
+import static com.sjl.dsl4xml.SAXDocumentReader.*;
+
+import java.io.*;
+
+import com.sjl.dsl4xml.*;
+import com.sjl.dsl4xml.performance.*;
+import com.sjl.dsl4xml.performance.model.*;
+import com.sjl.dsl4xml.support.convert.*;
+
+public class Dsl4XmlSAXTweetsReader implements TweetsReader {
+
+ private SAXDocumentReader<Tweets> reader;
+
+ public Dsl4XmlSAXTweetsReader() {
+ reader = mappingOf("feed", Tweets.class).to(
+ tag("entry", Tweet.class).with(
+ tag("published"),
+ tag("title"),
+ tag("content", Content.class).with(
+ attributes("type")
+ ).withPCDataMappedTo("value"),
+ tag("twitter:lang").
+ withPCDataMappedTo("language"),
+ tag("author", Author.class).with(
+ tag("name"),
+ tag("uri")
+ )
+ )
+ );
+
+ reader.registerConverters(new ThreadSafeDateConverter("yyyy-MM-dd'T'HH:mm:ss"));
+ }
+
+ @Override
+ public String getParserName() {
+ return "DSL4XML (SAX)";
+ }
+
+ @Override
+ public Tweets read(InputStream anInputStream) throws Exception {
+ return reader.read(anInputStream, "utf-8");
+ }
+}
View
75 src/main/java/com/sjl/dsl4xml/performance/parsers/SAXTweetsReader.java
@@ -6,6 +6,7 @@
import javax.xml.parsers.*;
import org.xml.sax.*;
+import org.xml.sax.ext.*;
import org.xml.sax.helpers.*;
import com.sjl.dsl4xml.performance.*;
@@ -23,6 +24,7 @@ public SAXTweetsReader()
reader = _p.getXMLReader();
handler = new TweetsHandler();
reader.setContentHandler(handler);
+ reader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
}
@Override
@@ -36,21 +38,24 @@ public Tweets read(InputStream anInputStream) throws Exception {
return handler.getResult();
}
- private static class TweetsHandler extends DefaultHandler {
+ private static class TweetsHandler
+ extends DefaultLexicalHandler {
private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
private Tweets tweets;
private Tweet tweet;
private Content content;
private Author author;
private String currentElement;
+ private StringBuilder chars;
public Tweets getResult() {
return tweets;
}
@Override
public void startDocument() throws SAXException {
+ chars = new StringBuilder();
tweets = new Tweets();
}
@@ -60,6 +65,8 @@ public void startElement(
String aQName, Attributes aAttributes
) throws SAXException {
currentElement = aQName;
+ chars.setLength(0);
+
if ("entry".equals(aQName)) {
tweets.addTweet(tweet = new Tweet());
} else if ("content".equals(aQName)) {
@@ -73,29 +80,81 @@ public void startElement(
@Override
public void endElement(String aUri, String aLocalName, String aQName)
throws SAXException {
+ if (chars.length() > 0) {
+ setCharacterValue(chars);
+ }
+
currentElement = null;
}
+
+ @Override
+ public void startEntity(String aName)
+ throws SAXException {
+ }
+
+ @Override
+ public void endEntity(String aName)
+ throws SAXException {
+ }
@Override
public void characters(char[] aCh, int aStart, int aLength)
+ throws SAXException {
+ chars.append(aCh, aStart, aLength);
+ }
+
+ private void setCharacterValue(StringBuilder aCharacters)
throws SAXException {
if ("published".equals(currentElement)) {
try {
- tweet.setPublished(dateFormat.parse(new String(aCh, aStart, aLength)));
+ tweet.setPublished(dateFormat.parse(aCharacters.toString()));
} catch (ParseException anExc) {
throw new SAXException(anExc);
}
} else if (("title".equals(currentElement)) && (tweet != null)) {
- tweet.setTitle(new String(aCh, aStart, aLength));
+ tweet.setTitle(aCharacters.toString());
} else if ("content".equals(currentElement)) {
- content.setValue(new String(aCh, aStart, aLength));
- } else if ("lang".equals(currentElement)) {
- tweet.setLanguage(new String(aCh, aStart, aLength));
+ content.setValue(aCharacters.toString());
+ } else if ("twitter:lang".equals(currentElement)) {
+ tweet.setLanguage(aCharacters.toString());
} else if ("name".equals(currentElement)) {
- author.setName(new String(aCh, aStart, aLength));
+ author.setName(aCharacters.toString());
} else if ("uri".equals(currentElement)) {
- author.setUri(new String(aCh, aStart, aLength));
+ author.setUri(aCharacters.toString());
}
}
}
+
+ static class DefaultLexicalHandler
+ extends DefaultHandler
+ implements LexicalHandler {
+
+ @Override
+ public void comment(char[] aArg0, int aArg1, int aArg2)
+ throws SAXException {}
+
+ @Override
+ public void endCDATA()
+ throws SAXException {}
+
+ @Override
+ public void endDTD()
+ throws SAXException {}
+
+ @Override
+ public void endEntity(String aName)
+ throws SAXException {}
+
+ @Override
+ public void startCDATA()
+ throws SAXException {}
+
+ @Override
+ public void startDTD(String aArg0, String aArg1, String aArg2)
+ throws SAXException {}
+
+ @Override
+ public void startEntity(String aName)
+ throws SAXException {}
+ }
}
View
29 src/main/java/com/sjl/dsl4xml/performance/parsers/SimpleXMLReader.java
@@ -1,29 +0,0 @@
-package com.sjl.dsl4xml.performance.parsers;
-
-import java.io.*;
-
-import org.simpleframework.xml.*;
-import org.simpleframework.xml.core.*;
-
-import com.sjl.dsl4xml.performance.*;
-import com.sjl.dsl4xml.performance.model.*;
-
-public class SimpleXMLReader implements TweetsReader {
-
- private Serializer serializer;
-
- public SimpleXMLReader() {
- serializer = new Persister();
- }
-
- @Override
- public String getParserName() {
- return "SimpleXML";
- }
-
- @Override
- public Tweets read(InputStream anInputStream) throws Exception {
- return serializer.read(Tweets.class, anInputStream);
- }
-
-}
View
54 src/main/java/com/sjl/dsl4xml/performance/parsers/SimpleXMLTweetsReader.java
@@ -0,0 +1,54 @@
+package com.sjl.dsl4xml.performance.parsers;
+
+import java.io.*;
+import java.text.*;
+import java.util.*;
+
+import org.simpleframework.xml.*;
+import org.simpleframework.xml.convert.*;
+import org.simpleframework.xml.convert.Converter;
+import org.simpleframework.xml.core.*;
+import org.simpleframework.xml.strategy.*;
+import org.simpleframework.xml.stream.*;
+
+import com.sjl.dsl4xml.performance.*;
+import com.sjl.dsl4xml.performance.model.*;
+
+public class SimpleXMLTweetsReader implements TweetsReader {
+
+ private Serializer serializer;
+
+ public SimpleXMLTweetsReader() throws Exception {
+ Registry _registry = new Registry();
+ Strategy _strategy = new RegistryStrategy(_registry);
+
+ _registry.bind(Date.class, new DateConverter());
+
+ serializer = new Persister(_strategy);
+ }
+
+ @Override
+ public String getParserName() {
+ return "SimpleXML";
+ }
+
+ @Override
+ public Tweets read(InputStream anInputStream) throws Exception {
+ return serializer.read(Tweets.class, anInputStream);
+ }
+
+ private class DateConverter implements Converter<Date>{
+ private DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+
+ @Override
+ public Date read(InputNode aNode) throws Exception {
+ return df.parse(aNode.getValue());
+ }
+
+ @Override
+ public void write(OutputNode aArg0, Date aArg1)
+ throws Exception {
+ // don't care
+ }
+ }
+}
View
63 src/test/java/com/sjl/dsl4xml/performance/parsers/AbstractTestForTweetsReaders.java
@@ -0,0 +1,63 @@
+package com.sjl.dsl4xml.performance.parsers;
+
+import java.io.*;
+import java.util.*;
+
+import org.junit.*;
+
+import com.sjl.dsl4xml.performance.*;
+import com.sjl.dsl4xml.performance.model.*;
+
+public abstract class AbstractTestForTweetsReaders {
+
+ @Test
+ public void testParsesAtomFeedCorrectly()
+ throws Exception {
+ TweetsReader _reader = newReader();
+
+ Tweets _result = _reader.read(getInputStream());
+ Assert.assertEquals(15, _result.size());
+
+ Tweet _first = _result.get(0);
+
+ Assert.assertEquals(new Date(1333962624000L), _first.getPublished());
+ Assert.assertEquals(
+ "Note de lecture : Succeeding with Use Cases par Richard" +
+ " Denney http://t.co/5lcCXWsO #bookReview #useCases #UML",
+ _first.getTitle()
+ );
+
+ Assert.assertEquals("html", _first.getContent().getType());
+ Assert.assertEquals(
+ "Note de lecture : Succeeding with Use Cases par Richard" +
+ " Denney <a href=\"http://t.co/5lcCXWsO\">http://t.co/5lcCXWsO</a>" +
+ " <a href=\"http://search.twitter.com/search?q=%23bookReview\" " +
+ "title=\"#bookReview\" class=\" \">#bookReview</a> " +
+ "<a href=\"http://search.twitter.com/search?q=%23useCases\" " +
+ "title=\"#useCases\" class=\" \">#useCases</a> <em>" +
+ "<a href=\"http://search.twitter.com/search?q=%23UML\" " +
+ "title=\"#UML\" class=\" \">#UML</a></em>",
+ _first.getContent().getValue()
+ );
+ Assert.assertEquals("en", _first.getLanguage());
+
+ Assert.assertEquals(
+ getExpectedAuthor(),
+ _first.getAuthor()
+ );
+ }
+
+ private InputStream getInputStream() {
+ return Tweets.class.getResourceAsStream("twitter-atom.xml");
+ }
+
+ private Author getExpectedAuthor() {
+ Author _a = new Author();
+ _a.setName("addinquy (Christophe Addinquy)");
+ _a.setUri("http://twitter.com/addinquy");
+ return _a;
+ }
+
+ protected abstract TweetsReader newReader() throws Exception;
+
+}
View
12 src/test/java/com/sjl/dsl4xml/performance/parsers/DOMParserTweetsReaderTest.java
@@ -0,0 +1,12 @@
+package com.sjl.dsl4xml.performance.parsers;
+
+import com.sjl.dsl4xml.performance.*;
+
+public class DOMParserTweetsReaderTest extends AbstractTestForTweetsReaders {
+
+ @Override
+ protected TweetsReader newReader() throws Exception {
+ return new DOMTweetsReader();
+ }
+
+}
View
12 src/test/java/com/sjl/dsl4xml/performance/parsers/DOMXPathParserTweetsReaderTest.java
@@ -0,0 +1,12 @@
+package com.sjl.dsl4xml.performance.parsers;
+
+import com.sjl.dsl4xml.performance.*;
+
+public class DOMXPathParserTweetsReaderTest extends AbstractTestForTweetsReaders {
+
+ @Override
+ protected TweetsReader newReader() throws Exception {
+ return new DOMXPathTweetsReader();
+ }
+
+}
View
4 ...mance/parsers/Dsl4XmlPerformanceTest.java → ...e/parsers/Dsl4XmlPullPerformanceTest.java
@@ -2,7 +2,7 @@
import com.sjl.dsl4xml.performance.*;
-public class Dsl4XmlPerformanceTest extends PerformanceTestBase {
+public class Dsl4XmlPullPerformanceTest extends PerformanceTestBase {
@Override
protected String getParserName() {
@@ -11,7 +11,7 @@ protected String getParserName() {
@Override
protected TweetsReader newTweetsReader() throws Exception {
- return new Dsl4XmlTweetsReader();
+ return new Dsl4XmlPullTweetsReader();
}
}
View
12 src/test/java/com/sjl/dsl4xml/performance/parsers/Dsl4XmlPullTweetsReaderTest.java
@@ -0,0 +1,12 @@
+package com.sjl.dsl4xml.performance.parsers;
+
+import com.sjl.dsl4xml.performance.*;
+
+public class Dsl4XmlPullTweetsReaderTest extends AbstractTestForTweetsReaders {
+
+ @Override
+ protected TweetsReader newReader() throws Exception {
+ return new Dsl4XmlPullTweetsReader();
+ }
+
+}
View
17 src/test/java/com/sjl/dsl4xml/performance/parsers/Dsl4XmlSAXPerformanceTest.java
@@ -0,0 +1,17 @@
+package com.sjl.dsl4xml.performance.parsers;
+
+import com.sjl.dsl4xml.performance.*;
+
+public class Dsl4XmlSAXPerformanceTest extends PerformanceTestBase {
+
+ @Override
+ protected String getParserName() {
+ return "dsl4xml (sax-parsing)";
+ }
+
+ @Override
+ protected TweetsReader newTweetsReader() throws Exception {
+ return new Dsl4XmlSAXTweetsReader();
+ }
+
+}
View
12 src/test/java/com/sjl/dsl4xml/performance/parsers/Dsl4XmlSAXTweetsReaderTest.java
@@ -0,0 +1,12 @@
+package com.sjl.dsl4xml.performance.parsers;
+
+import com.sjl.dsl4xml.performance.*;
+
+public class Dsl4XmlSAXTweetsReaderTest extends AbstractTestForTweetsReaders {
+
+ @Override
+ protected TweetsReader newReader() throws Exception {
+ return new Dsl4XmlSAXTweetsReader();
+ }
+
+}
View
12 src/test/java/com/sjl/dsl4xml/performance/parsers/PullParserTweetsReaderTest.java
@@ -0,0 +1,12 @@
+package com.sjl.dsl4xml.performance.parsers;
+
+import com.sjl.dsl4xml.performance.*;
+
+public class PullParserTweetsReaderTest extends AbstractTestForTweetsReaders {
+
+ @Override
+ protected TweetsReader newReader() throws Exception {
+ return new PullParserTweetsReader();
+ }
+
+}
View
12 src/test/java/com/sjl/dsl4xml/performance/parsers/SAXParserTweetsReaderTest.java
@@ -0,0 +1,12 @@
+package com.sjl.dsl4xml.performance.parsers;
+
+import com.sjl.dsl4xml.performance.*;
+
+public class SAXParserTweetsReaderTest extends AbstractTestForTweetsReaders {
+
+ @Override
+ protected TweetsReader newReader() throws Exception {
+ return new SAXTweetsReader();
+ }
+
+}
View
12 src/test/java/com/sjl/dsl4xml/performance/parsers/SJXPTweetsReaderTest.java
@@ -0,0 +1,12 @@
+package com.sjl.dsl4xml.performance.parsers;
+
+import com.sjl.dsl4xml.performance.*;
+
+public class SJXPTweetsReaderTest extends AbstractTestForTweetsReaders {
+
+ @Override
+ protected TweetsReader newReader() throws Exception {
+ return new SJXPTweetsReader();
+ }
+
+}
View
2 src/test/java/com/sjl/dsl4xml/performance/parsers/SimpleXMLPerformanceTest.java
@@ -11,7 +11,7 @@ protected String getParserName() {
@Override
protected TweetsReader newTweetsReader() throws Exception {
- return new SimpleXMLReader();
+ return new SimpleXMLTweetsReader();
}
}
View
12 src/test/java/com/sjl/dsl4xml/performance/parsers/SimpleXMLTweetsReaderTest.java
@@ -0,0 +1,12 @@
+package com.sjl.dsl4xml.performance.parsers;
+
+import com.sjl.dsl4xml.performance.*;
+
+public class SimpleXMLTweetsReaderTest extends AbstractTestForTweetsReaders {
+
+ @Override
+ protected TweetsReader newReader() throws Exception {
+ return new SimpleXMLTweetsReader();
+ }
+
+}

0 comments on commit 7957e85

Please sign in to comment.