Apache Nutch is an extensible and scalable web crawler
Better tests.
Yossi Tamarid72591a76957
diff --git a/src/plugin/index-jexl-filter/src/test/org/apache/nutch/indexer/filter/TestJexlIndexingFilter.java b/src/plugin/index-jexl-filter/src/test/org/apache/nutch/indexer/filter/TestJexlIndexingFilter.javaindex a55670277..286d29651 100644--- a/src/plugin/index-jexl-filter/src/test/org/apache/nutch/indexer/filter/TestJexlIndexingFilter.java+++ b/src/plugin/index-jexl-filter/src/test/org/apache/nutch/indexer/filter/TestJexlIndexingFilter.java@@ -28,12 +28,16 @@ import org.apache.nutch.parse.ParseImpl;import org.apache.nutch.parse.ParseStatus;import org.apache.nutch.util.NutchConfiguration;import org.junit.Assert;+import org.junit.Rule;import org.junit.Test;+import org.junit.rules.ExpectedException;public class TestJexlIndexingFilter {+ @Rule+ public ExpectedException thrown = ExpectedException.none();@Test- public void testBasicIndexingFilter() throws Exception {+ public void testAllowMatchingDocument() throws Exception {Configuration conf = NutchConfiguration.create();conf.set("index.jexl.filter", "doc.lang[0]=='en'");@@ -57,24 +61,56 @@ public class TestJexlIndexingFilter {doc.add("lang", "en");- try {- NutchDocument result = filter.filter(doc, parse, new Text("http://nutch.apache.org/index.html"), crawlDatum, inlinks);- Assert.assertNotNull(result);- Assert.assertEquals(doc, result);- } catch (Exception e) {- e.printStackTrace();- Assert.fail(e.getMessage());- }-- doc.removeField("lang");+ NutchDocument result = filter.filter(doc, parse, new Text("http://nutch.apache.org/index.html"), crawlDatum, inlinks);+ Assert.assertNotNull(result);+ Assert.assertEquals(doc, result);+ }++ @Test+ public void testBlockNotMatchingDocuments() throws Exception {+ Configuration conf = NutchConfiguration.create();+ conf.set("index.jexl.filter", "doc.lang[0]=='en'");++ JexlIndexingFilter filter = new JexlIndexingFilter();+ filter.setConf(conf);+ Assert.assertNotNull(filter);++ NutchDocument doc = new NutchDocument();++ String title = "The Foo Page";+ Outlink[] outlinks = new Outlink[] { new Outlink("http://foo.com/", "Foo") };+ Metadata metaData = new Metadata();+ metaData.add("Language", "en/us");+ ParseData parseData = new ParseData(ParseStatus.STATUS_SUCCESS, title, outlinks, metaData);+ ParseImpl parse = new ParseImpl("this is a sample foo bar page. hope you enjoy it.", parseData);++ CrawlDatum crawlDatum = new CrawlDatum();+ crawlDatum.setFetchTime(100L);++ Inlinks inlinks = new Inlinks();+doc.add("lang", "ru");- try {- NutchDocument result = filter.filter(doc, parse, new Text("http://nutch.apache.org/index.html"), crawlDatum, inlinks);- Assert.assertNull(result);- } catch (Exception e) {- e.printStackTrace();- Assert.fail(e.getMessage());- }+ NutchDocument result = filter.filter(doc, parse, new Text("http://nutch.apache.org/index.html"), crawlDatum, inlinks);+ Assert.assertNull(result);+ }++ @Test+ public void testMissingConfiguration() throws Exception {+ Configuration conf = NutchConfiguration.create();++ JexlIndexingFilter filter = new JexlIndexingFilter();+ thrown.expect(RuntimeException.class);+ filter.setConf(conf);+ }++ @Test+ public void testInvalidExpression() throws Exception {+ Configuration conf = NutchConfiguration.create();+ conf.set("index.jexl.filter", "doc.lang[0]=<>:='en'");++ JexlIndexingFilter filter = new JexlIndexingFilter();+ thrown.expect(RuntimeException.class);+ filter.setConf(conf);}}