Apache Nutch is an extensible and scalable web crawler
NUTCH-1737 Upgrade to recent JUnit 4.x
Lewis John McGibbneyecc304aac02f
diff --git a/CHANGES.txt b/CHANGES.txtindex 212baaba8..56e36eac8 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -2,6 +2,8 @@ Nutch Change LogNutch Current Development+* NUTCH-1737 Upgrade to recent JUnit 4.x (lewismc)+* NUTCH-1733 parse-html to support HTML5 charset definitions (snagel)* NUTCH-1671 indexchecker to add digest field (snagel, lufeng)diff --git a/build.xml b/build.xmlindex a3e45b091..f0c752b6c 100644--- a/build.xml+++ b/build.xml@@ -924,6 +924,8 @@<source path="${basedir}/src/plugin/index-basic/src/java/" /><source path="${basedir}/src/plugin/index-basic/src/test/" /><source path="${basedir}/src/plugin/indexer-solr/src/java/" />+ <source path="${basedir}/src/plugin/indexer-elastic/src/java/" />+ <source path="${basedir}/src/plugin/indexer-dummy/src/java/" /><source path="${basedir}/src/plugin/index-metadata/src/java/" /><source path="${basedir}/src/plugin/index-more/src/java/" /><source path="${basedir}/src/plugin/index-more/src/test/" />@@ -984,6 +986,8 @@<source path="${basedir}/src/plugin/urlnormalizer-pass/src/test/" /><source path="${basedir}/src/plugin/urlnormalizer-regex/src/java/" /><source path="${basedir}/src/plugin/urlnormalizer-regex/src/test/" />+ <source path="${basedir}/src/plugin/urlnormalizer-querystring/src/java/" />+ <source path="${basedir}/src/plugin/urlnormalizer-querystring/src/test/" /><output path="${basedir}/build/classes" /></classpath>diff --git a/ivy/ivy.xml b/ivy/ivy.xmlindex 994f14f63..152eb5bfc 100644--- a/ivy/ivy.xml+++ b/ivy/ivy.xml@@ -80,7 +80,7 @@<!--Configuration: test --><!--artifacts needed for testing -->- <dependency org="junit" name="junit" rev="3.8.1" conf="*->default" />+ <dependency org="junit" name="junit" rev="4.11" conf="*->default" /><dependency org="org.apache.hadoop" name="hadoop-test" rev="1.2.0"conf="test->default" />diff --git a/pom.xml b/pom.xmlindex e24629b91..c48ef1c03 100644--- a/pom.xml+++ b/pom.xml@@ -221,7 +221,7 @@<dependency><groupId>junit</groupId><artifactId>junit</artifactId>- <version>3.8.1</version>+ <version>4.11</version><optional>true</optional></dependency><dependency>diff --git a/src/plugin/creativecommons/src/test/org/creativecommons/nutch/TestCCParseFilter.java b/src/plugin/creativecommons/src/test/org/creativecommons/nutch/TestCCParseFilter.javaindex e81cdc845..253f6e8e9 100755--- a/src/plugin/creativecommons/src/test/org/creativecommons/nutch/TestCCParseFilter.java+++ b/src/plugin/creativecommons/src/test/org/creativecommons/nutch/TestCCParseFilter.java@@ -23,18 +23,17 @@ import org.apache.nutch.parse.ParseUtil;import org.apache.nutch.protocol.Content;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;+import org.junit.Assert;+import org.junit.Test;-import java.util.Properties;import java.io.*;-import java.net.URL;-import junit.framework.TestCase;--public class TestCCParseFilter extends TestCase {+public class TestCCParseFilter {private static final File testDir =new File(System.getProperty("test.input"));+ @Testpublic void testPages() throws Exception {pageTest(new File(testDir, "anchor.html"), "http://foo.com/","http://creativecommons.org/licenses/by-nc-sa/1.0", "a", null);@@ -69,9 +68,9 @@ public class TestCCParseFilter extends TestCase {Parse parse = new ParseUtil(conf).parse(content).get(content.getUrl());Metadata metadata = parse.getData().getParseMeta();- assertEquals(license, metadata.get("License-Url"));- assertEquals(location, metadata.get("License-Location"));- assertEquals(type, metadata.get("Work-Type"));+ Assert.assertEquals(license, metadata.get("License-Url"));+ Assert.assertEquals(location, metadata.get("License-Location"));+ Assert.assertEquals(type, metadata.get("Work-Type"));}}diff --git a/src/plugin/feed/src/test/org/apache/nutch/parse/feed/TestFeedParser.java b/src/plugin/feed/src/test/org/apache/nutch/parse/feed/TestFeedParser.javaindex 28f142479..ee3048777 100644--- a/src/plugin/feed/src/test/org/apache/nutch/parse/feed/TestFeedParser.java+++ b/src/plugin/feed/src/test/org/apache/nutch/parse/feed/TestFeedParser.java@@ -21,6 +21,8 @@ package org.apache.nutch.parse.feed;import java.util.Iterator;import java.util.Map;+import org.junit.Assert;+import org.junit.Test;// APACHE importsimport org.slf4j.Logger;import org.slf4j.LoggerFactory;@@ -37,9 +39,6 @@ import org.apache.nutch.protocol.ProtocolFactory;import org.apache.nutch.protocol.ProtocolNotFound;import org.apache.nutch.util.NutchConfiguration;-// Junit imports-import junit.framework.TestCase;-/**** @author mattmann@@ -47,7 +46,7 @@ import junit.framework.TestCase;* Test Suite for the {@link FeedParser}.**/-public class TestFeedParser extends TestCase {+public class TestFeedParser {private String fileSeparator = System.getProperty("file.separator");@@ -62,16 +61,6 @@ public class TestFeedParser extends TestCase {public static final Logger LOG = LoggerFactory.getLogger(TestFeedParser.class.getName());- /**- * Default Constructor.- *- * @param name- * The name of this {@link TestCase}.- */- public TestFeedParser(String name) {- super(name);- }-/*** Calls the {@link FeedParser} on a sample RSS file and checks that there are* 3 {@link ParseResult} entries including the below 2 links:@@ -87,6 +76,7 @@ public class TestFeedParser extends TestCase {* @throws ParseException* If the {@link Parser}Layer cannot be loaded.*/+ @Testpublic void testParseFetchChannel() throws ProtocolNotFound, ParseException {String urlString;Protocol protocol;@@ -104,7 +94,7 @@ public class TestFeedParser extends TestCase {parseResult = new ParseUtil(conf).parseByExtensionId("feed", content);- assertEquals(3, parseResult.size());+ Assert.assertEquals(3, parseResult.size());boolean hasLink1 = false, hasLink2 = false, hasLink3=false;@@ -121,12 +111,12 @@ public class TestFeedParser extends TestCase {hasLink3 = true;}- assertNotNull(entry.getValue());- assertNotNull(entry.getValue().getData());+ Assert.assertNotNull(entry.getValue());+ Assert.assertNotNull(entry.getValue().getData());}if (!hasLink1 || !hasLink2 || !hasLink3) {- fail("Outlinks read from sample rss file are not correct!");+ Assert.fail("Outlinks read from sample rss file are not correct!");}}diff --git a/src/plugin/index-anchor/src/test/org/apache/nutch/indexer/anchor/TestAnchorIndexingFilter.java b/src/plugin/index-anchor/src/test/org/apache/nutch/indexer/anchor/TestAnchorIndexingFilter.javaindex 21df1970c..b9d7d43c7 100644--- a/src/plugin/index-anchor/src/test/org/apache/nutch/indexer/anchor/TestAnchorIndexingFilter.java+++ b/src/plugin/index-anchor/src/test/org/apache/nutch/indexer/anchor/TestAnchorIndexingFilter.java@@ -16,8 +16,6 @@*/package org.apache.nutch.indexer.anchor;-import junit.framework.TestCase;-import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.io.Text;import org.apache.nutch.crawl.CrawlDatum;@@ -27,6 +25,8 @@ import org.apache.nutch.indexer.NutchDocument;import org.apache.nutch.parse.ParseData;import org.apache.nutch.parse.ParseImpl;import org.apache.nutch.util.NutchConfiguration;+import org.junit.Assert;+import org.junit.Test;/*** JUnit test case which tests@@ -36,14 +36,15 @@ import org.apache.nutch.util.NutchConfiguration;* @author lewismc**/-public class TestAnchorIndexingFilter extends TestCase {+public class TestAnchorIndexingFilter {+ @Testpublic void testDeduplicateAnchor() throws Exception {Configuration conf = NutchConfiguration.create();conf.setBoolean("anchorIndexingFilter.deduplicate", true);AnchorIndexingFilter filter = new AnchorIndexingFilter();filter.setConf(conf);- assertNotNull(filter);+ Assert.assertNotNull(filter);NutchDocument doc = new NutchDocument();ParseImpl parse = new ParseImpl("foo bar", new ParseData());Inlinks inlinks = new Inlinks();@@ -54,11 +55,11 @@ public class TestAnchorIndexingFilter extends TestCase {filter.filter(doc, parse, new Text("http://nutch.apache.org/index.html"), new CrawlDatum(), inlinks);} catch(Exception e){e.printStackTrace();- fail(e.getMessage());+ Assert.fail(e.getMessage());}- assertNotNull(doc);- assertTrue("test if there is an anchor at all", doc.getFieldNames().contains("anchor"));- assertEquals("test dedup, we expect 2", 2, doc.getField("anchor").getValues().size());+ Assert.assertNotNull(doc);+ Assert.assertTrue("test if there is an anchor at all", doc.getFieldNames().contains("anchor"));+ Assert.assertEquals("test dedup, we expect 2", 2, doc.getField("anchor").getValues().size());}}diff --git a/src/plugin/index-basic/src/test/org/apache/nutch/indexer/basic/TestBasicIndexingFilter.java b/src/plugin/index-basic/src/test/org/apache/nutch/indexer/basic/TestBasicIndexingFilter.javaindex c038cddca..1208522a9 100644--- a/src/plugin/index-basic/src/test/org/apache/nutch/indexer/basic/TestBasicIndexingFilter.java+++ b/src/plugin/index-basic/src/test/org/apache/nutch/indexer/basic/TestBasicIndexingFilter.java@@ -28,9 +28,10 @@ import org.apache.nutch.parse.ParseData;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.Test;import java.util.Date;-import junit.framework.TestCase;/*** JUnit test case which tests@@ -43,8 +44,9 @@ import junit.framework.TestCase;**/-public class TestBasicIndexingFilter extends TestCase {+public class TestBasicIndexingFilter {+ @Testpublic void testBasicIndexingFilter() throws Exception {Configuration conf = NutchConfiguration.create();conf.setInt("indexer.max.title.length", 10);@@ -53,7 +55,7 @@ public class TestBasicIndexingFilter extends TestCase {BasicIndexingFilter filter = new BasicIndexingFilter();filter.setConf(conf);- assertNotNull(filter);+ Assert.assertNotNull(filter);NutchDocument doc = new NutchDocument();@@ -73,15 +75,15 @@ public class TestBasicIndexingFilter extends TestCase {filter.filter(doc, parse, new Text("http://nutch.apache.org/index.html"), crawlDatum, inlinks);} catch(Exception e){e.printStackTrace();- fail(e.getMessage());+ Assert.fail(e.getMessage());}- assertNotNull(doc);- assertEquals("test title, expect \"The Foo Pa\"", "The Foo Pa", doc.getField("title").getValues().get(0));- assertEquals("test domain, expect \"apache.org\"", "apache.org", doc.getField("domain").getValues().get(0));- assertEquals("test host, expect \"nutch.apache.org\"", "nutch.apache.org", doc.getField("host").getValues().get(0));- assertEquals("test url, expect \"http://nutch.apache.org/index.html\"", "http://nutch.apache.org/index.html",+ Assert.assertNotNull(doc);+ Assert.assertEquals("test title, expect \"The Foo Pa\"", "The Foo Pa", doc.getField("title").getValues().get(0));+ Assert.assertEquals("test domain, expect \"apache.org\"", "apache.org", doc.getField("domain").getValues().get(0));+ Assert.assertEquals("test host, expect \"nutch.apache.org\"", "nutch.apache.org", doc.getField("host").getValues().get(0));+ Assert.assertEquals("test url, expect \"http://nutch.apache.org/index.html\"", "http://nutch.apache.org/index.html",doc.getField("url").getValues().get(0));- assertEquals("test content", "this is a sample foo", doc.getField("content").getValues().get(0));- assertEquals("test fetch time", new Date(100L), (Date)doc.getField("tstamp").getValues().get(0));+ Assert.assertEquals("test content", "this is a sample foo", doc.getField("content").getValues().get(0));+ Assert.assertEquals("test fetch time", new Date(100L), (Date)doc.getField("tstamp").getValues().get(0));}}diff --git a/src/plugin/index-more/src/test/org/apache/nutch/indexer/more/TestMoreIndexingFilter.java b/src/plugin/index-more/src/test/org/apache/nutch/indexer/more/TestMoreIndexingFilter.javaindex 159243927..547a083a6 100644--- a/src/plugin/index-more/src/test/org/apache/nutch/indexer/more/TestMoreIndexingFilter.java+++ b/src/plugin/index-more/src/test/org/apache/nutch/indexer/more/TestMoreIndexingFilter.java@@ -29,17 +29,19 @@ import org.apache.nutch.parse.ParseData;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.Test;-import junit.framework.TestCase;--public class TestMoreIndexingFilter extends TestCase {+public class TestMoreIndexingFilter {+ @Testpublic void testContentType() throws IndexingException {Configuration conf = NutchConfiguration.create();assertContentType(conf, "text/html", "text/html");assertContentType(conf, "text/html; charset=UTF-8", "text/html");}+ @Testpublic void testGetParts() {String[] parts = MoreIndexingFilter.getParts("text/html");assertParts(parts, 2, "text", "html");@@ -48,12 +50,13 @@ public class TestMoreIndexingFilter extends TestCase {/*** @since NUTCH-901*/+ @Testpublic void testNoParts(){Configuration conf = NutchConfiguration.create();conf.setBoolean("moreIndexingFilter.indexMimeTypeParts", false);MoreIndexingFilter filter = new MoreIndexingFilter();filter.setConf(conf);- assertNotNull(filter);+ Assert.assertNotNull(filter);NutchDocument doc = new NutchDocument();ParseImpl parse = new ParseImpl("foo bar", new ParseData());@@ -62,14 +65,15 @@ public class TestMoreIndexingFilter extends TestCase {}catch(Exception e){e.printStackTrace();- fail(e.getMessage());+ Assert.fail(e.getMessage());}- assertNotNull(doc);- assertTrue(doc.getFieldNames().contains("type"));- assertEquals(1, doc.getField("type").getValues().size());- assertEquals("text/html", doc.getFieldValue("type"));+ Assert.assertNotNull(doc);+ Assert.assertTrue(doc.getFieldNames().contains("type"));+ Assert.assertEquals(1, doc.getField("type").getValues().size());+ Assert.assertEquals("text/html", doc.getFieldValue("type"));}+ @Testpublic void testContentDispositionTitle() throws IndexingException {Configuration conf = NutchConfiguration.create();@@ -82,13 +86,13 @@ public class TestMoreIndexingFilter extends TestCase {new ParseStatus(), "title", new Outlink[0], metadata)), new Text("http://www.example.com/"), new CrawlDatum(), new Inlinks());- assertEquals("content-disposition not detected", "filename.ext", doc.getFieldValue("title"));+ Assert.assertEquals("content-disposition not detected", "filename.ext", doc.getFieldValue("title"));}private void assertParts(String[] parts, int count, String... expected) {- assertEquals(count, parts.length);+ Assert.assertEquals(count, parts.length);for (int i = 0; i < expected.length; i++) {- assertEquals(expected[i], parts[i]);+ Assert.assertEquals(expected[i], parts[i]);}}@@ -100,6 +104,6 @@ public class TestMoreIndexingFilter extends TestCase {NutchDocument doc = filter.filter(new NutchDocument(), new ParseImpl("text", new ParseData(new ParseStatus(), "title", new Outlink[0], metadata)), new Text("http://www.example.com/"), new CrawlDatum(), new Inlinks());- assertEquals("mime type not detected", expected, doc.getFieldValue("type"));+ Assert.assertEquals("mime type not detected", expected, doc.getFieldValue("type"));}}diff --git a/src/plugin/index-static/src/test/org/apache/nutch/indexer/staticfield/TestStaticFieldIndexerTest.java b/src/plugin/index-static/src/test/org/apache/nutch/indexer/staticfield/TestStaticFieldIndexerTest.javaindex 65c274949..52773e736 100644--- a/src/plugin/index-static/src/test/org/apache/nutch/indexer/staticfield/TestStaticFieldIndexerTest.java+++ b/src/plugin/index-static/src/test/org/apache/nutch/indexer/staticfield/TestStaticFieldIndexerTest.java@@ -23,8 +23,9 @@ import org.apache.nutch.crawl.Inlinks;import org.apache.nutch.indexer.NutchDocument;import org.apache.nutch.parse.ParseImpl;import org.apache.nutch.util.NutchConfiguration;--import junit.framework.TestCase;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;/*** JUnit test case which tests@@ -36,7 +37,7 @@ import junit.framework.TestCase;* @author tejasp*/-public class TestStaticFieldIndexerTest extends TestCase {+public class TestStaticFieldIndexerTest {Configuration conf;@@ -46,7 +47,8 @@ public class TestStaticFieldIndexerTest extends TestCase {Text url;StaticFieldIndexer filter;- protected void setUp() throws Exception {+ @Before+ public void setUp() throws Exception {conf = NutchConfiguration.create();parse = new ParseImpl();url = new Text("http://nutch.apache.org/index.html");@@ -59,9 +61,10 @@ public class TestStaticFieldIndexerTest extends TestCase {* Test that empty {@code index.static} does not add anything to the document* @throws Exception*/+ @Testpublic void testEmptyIndexStatic() throws Exception {- assertNotNull(filter);+ Assert.assertNotNull(filter);filter.setConf(conf);NutchDocument doc = new NutchDocument();@@ -70,22 +73,23 @@ public class TestStaticFieldIndexerTest extends TestCase {filter.filter(doc, parse, url, crawlDatum, inlinks);} catch (Exception e) {e.printStackTrace();- fail(e.getMessage());+ Assert.fail(e.getMessage());}- assertNotNull(doc);- assertTrue("tests if no field is set for empty index.static", doc.getFieldNames().isEmpty());+ Assert.assertNotNull(doc);+ Assert.assertTrue("tests if no field is set for empty index.static", doc.getFieldNames().isEmpty());}/*** Test that valid field:value pairs are added to the document* @throws Exception*/+ @Testpublic void testNormalScenario() throws Exception {conf.set("index.static","field1:val1, field2 : val2 val3 , field3, field4 :val4 , ");- assertNotNull(filter);+ Assert.assertNotNull(filter);filter.setConf(conf);NutchDocument doc = new NutchDocument();@@ -94,17 +98,17 @@ public class TestStaticFieldIndexerTest extends TestCase {filter.filter(doc, parse, url, crawlDatum, inlinks);} catch (Exception e) {e.printStackTrace();- fail(e.getMessage());+ Assert.fail(e.getMessage());}- assertNotNull(doc);- assertFalse("test if doc is not empty", doc.getFieldNames().isEmpty());- assertEquals("test if doc has 3 fields", 3, doc.getFieldNames().size());- assertTrue("test if doc has field1", doc.getField("field1").getValues()+ Assert.assertNotNull(doc);+ Assert.assertFalse("test if doc is not empty", doc.getFieldNames().isEmpty());+ Assert.assertEquals("test if doc has 3 fields", 3, doc.getFieldNames().size());+ Assert.assertTrue("test if doc has field1", doc.getField("field1").getValues().contains("val1"));- assertTrue("test if doc has field2", doc.getField("field2").getValues()+ Assert.assertTrue("test if doc has field2", doc.getField("field2").getValues().contains("val2"));- assertTrue("test if doc has field4", doc.getField("field4").getValues()+ Assert.assertTrue("test if doc has field4", doc.getField("field4").getValues().contains("val4"));}}diff --git a/src/plugin/language-identifier/src/test/org/apache/nutch/analysis/lang/TestHTMLLanguageParser.java b/src/plugin/language-identifier/src/test/org/apache/nutch/analysis/lang/TestHTMLLanguageParser.javaindex e807431e8..13ef33f49 100644--- a/src/plugin/language-identifier/src/test/org/apache/nutch/analysis/lang/TestHTMLLanguageParser.java+++ b/src/plugin/language-identifier/src/test/org/apache/nutch/analysis/lang/TestHTMLLanguageParser.java@@ -16,13 +16,10 @@*/package org.apache.nutch.analysis.lang;---// JUnit importsimport java.io.BufferedReader;import java.io.InputStreamReader;-import junit.framework.TestCase;+// Nutch importsimport org.apache.nutch.metadata.Metadata;@@ -31,9 +28,11 @@ import org.apache.nutch.parse.ParseUtil;import org.apache.nutch.protocol.Content;import org.apache.nutch.util.NutchConfiguration;import org.apache.tika.language.LanguageIdentifier;+import org.junit.Assert;+import org.junit.Test;-public class TestHTMLLanguageParser extends TestCase {+public class TestHTMLLanguageParser {private static String URL = "http://foo.bar/";@@ -50,6 +49,7 @@ public class TestHTMLLanguageParser extends TestCase {/*** Test parsing of language identifiers from html**/+ @Testpublic void testMetaHTMLParsing() {try {@@ -58,16 +58,17 @@ public class TestHTMLLanguageParser extends TestCase {for (int t = 0; t < docs.length; t++) {Content content = getContent(docs[t]);Parse parse = parser.parse(content).get(content.getUrl());- assertEquals(metalanguages[t], (String) parse.getData().getParseMeta().get(Metadata.LANGUAGE));+ Assert.assertEquals(metalanguages[t], (String) parse.getData().getParseMeta().get(Metadata.LANGUAGE));}} catch (Exception e) {e.printStackTrace(System.out);- fail(e.toString());+ Assert.fail(e.toString());}}/** Test of <code>LanguageParser.parseLanguage(String)</code> method. */+ @Testpublic void testParseLanguage() {String tests[][] = {{ "(SCHEME=ISO.639-1) sv", "sv" },@@ -117,7 +118,7 @@ public class TestHTMLLanguageParser extends TestCase {};for (int i=0; i<44; i++) {- assertEquals(tests[i][1], HTMLLanguageParser.LanguageParser.parseLanguage(tests[i][0]));+ Assert.assertEquals(tests[i][1], HTMLLanguageParser.LanguageParser.parseLanguage(tests[i][0]));}}@@ -129,6 +130,7 @@ public class TestHTMLLanguageParser extends TestCase {}+ @Testpublic void testLanguageIndentifier() {try {long total = 0;@@ -150,7 +152,7 @@ public class TestHTMLLanguageParser extends TestCase {if (testLine.length() > 256) {identifier = new LanguageIdentifier(testLine);lang = identifier.getLanguage();- assertEquals(tokens[1], lang);+ Assert.assertEquals(tokens[1], lang);}}testFile.close();@@ -162,14 +164,14 @@ public class TestHTMLLanguageParser extends TestCase {lang = identifier.getLanguage();System.out.println(lang);total += System.currentTimeMillis() - start;- assertEquals(tokens[1], lang);+ Assert.assertEquals(tokens[1], lang);}}in.close();System.out.println("Total Time=" + total);} catch (Exception e) {e.printStackTrace();- fail(e.toString());+ Assert.fail(e.toString());}}diff --git a/src/plugin/lib-http/src/test/org/apache/nutch/protocol/http/api/TestRobotRulesParser.java b/src/plugin/lib-http/src/test/org/apache/nutch/protocol/http/api/TestRobotRulesParser.javaindex 0aefc449f..b358f1e51 100644--- a/src/plugin/lib-http/src/test/org/apache/nutch/protocol/http/api/TestRobotRulesParser.java+++ b/src/plugin/lib-http/src/test/org/apache/nutch/protocol/http/api/TestRobotRulesParser.java@@ -17,8 +17,10 @@package org.apache.nutch.protocol.http.api;+import org.junit.Assert;+import org.junit.Test;+import crawlercommons.robots.BaseRobotRules;-import junit.framework.TestCase;/*** JUnit test case which tests@@ -26,14 +28,14 @@ import junit.framework.TestCase;* 2. that crawl delay is extracted correctly from the robots file**/-public class TestRobotRulesParser extends TestCase {+public class TestRobotRulesParser {private static final String CONTENT_TYPE = "text/plain";private static final String SINGLE_AGENT = "Agent1";private static final String MULTIPLE_AGENTS = "Agent2, Agent1";private static final String UNKNOWN_AGENT = "AgentABC";private static final String CR = "\r";-+private static final String ROBOTS_STRING ="User-Agent: Agent1 #foo" + CR+ "Disallow: /a" + CR@@ -50,7 +52,7 @@ public class TestRobotRulesParser extends TestCase {+ "" + CR+ "User-Agent: *" + CR+ "Disallow: /foo/bar/" + CR; // no crawl delay for other agents-+private static final String[] TEST_PATHS = new String[] {"http://example.com/a","http://example.com/a/bloh/foo.html",@@ -72,20 +74,22 @@ public class TestRobotRulesParser extends TestCase {private HttpRobotRulesParser parser;private BaseRobotRules rules;+ public TestRobotRulesParser () {+ }public TestRobotRulesParser(String name) {- super(name);parser = new HttpRobotRulesParser();}/**- * Test that the robots rules are interpreted correctly by the robots rules parser.- */+ * Test that the robots rules are interpreted correctly by the robots rules parser.+ */+ @Testpublic void testRobotsAgent() {rules = parser.parseRules("testRobotsAgent", ROBOTS_STRING.getBytes(), CONTENT_TYPE, SINGLE_AGENT);for(int counter = 0; counter < TEST_PATHS.length; counter++) {- assertTrue("testing on agent (" + SINGLE_AGENT + "), and "- + "path " + TEST_PATHS[counter]+ Assert.assertTrue("testing on agent (" + SINGLE_AGENT + "), and "+ + "path " + TEST_PATHS[counter]+ " got " + rules.isAllowed(TEST_PATHS[counter]),rules.isAllowed(TEST_PATHS[counter]) == RESULTS[counter]);}@@ -93,24 +97,25 @@ public class TestRobotRulesParser extends TestCase {rules = parser.parseRules("testRobotsAgent", ROBOTS_STRING.getBytes(), CONTENT_TYPE, MULTIPLE_AGENTS);for(int counter = 0; counter < TEST_PATHS.length; counter++) {- assertTrue("testing on agents (" + MULTIPLE_AGENTS + "), and "- + "path " + TEST_PATHS[counter]+ Assert.assertTrue("testing on agents (" + MULTIPLE_AGENTS + "), and "+ + "path " + TEST_PATHS[counter]+ " got " + rules.isAllowed(TEST_PATHS[counter]),rules.isAllowed(TEST_PATHS[counter]) == RESULTS[counter]);}}/**- * Test that the crawl delay is extracted from the robots file for respective agent.- * If its not specified for a given agent, default value must be returned.- */+ * Test that the crawl delay is extracted from the robots file for respective agent.+ * If its not specified for a given agent, default value must be returned.+ */+ @Testpublic void testCrawlDelay() {// for SINGLE_AGENT, the crawl delay of 10 sec ie. 10000 msec must be returned by the parserrules = parser.parseRules("testCrawlDelay", ROBOTS_STRING.getBytes(), CONTENT_TYPE, SINGLE_AGENT);- assertTrue("testing crawl delay for agent "+ SINGLE_AGENT +" : ", (rules.getCrawlDelay() == 10000));-+ Assert.assertTrue("testing crawl delay for agent "+ SINGLE_AGENT +" : ", (rules.getCrawlDelay() == 10000));+// for UNKNOWN_AGENT, the default crawl delay must be returned.rules = parser.parseRules("testCrawlDelay", ROBOTS_STRING.getBytes(), CONTENT_TYPE, UNKNOWN_AGENT);- assertTrue("testing crawl delay for agent "+ UNKNOWN_AGENT +" : ", (rules.getCrawlDelay() == Long.MIN_VALUE));+ Assert.assertTrue("testing crawl delay for agent "+ UNKNOWN_AGENT +" : ", (rules.getCrawlDelay() == Long.MIN_VALUE));}}diff --git a/src/plugin/lib-regex-filter/src/test/org/apache/nutch/urlfilter/api/RegexURLFilterBaseTest.java b/src/plugin/lib-regex-filter/src/test/org/apache/nutch/urlfilter/api/RegexURLFilterBaseTest.javaindex c783067d4..356cc6cf6 100644--- a/src/plugin/lib-regex-filter/src/test/org/apache/nutch/urlfilter/api/RegexURLFilterBaseTest.java+++ b/src/plugin/lib-regex-filter/src/test/org/apache/nutch/urlfilter/api/RegexURLFilterBaseTest.java@@ -24,10 +24,7 @@ import java.io.Reader;import java.util.ArrayList;import java.util.List;-// JUnit imports-import junit.framework.TestCase;--// Commons Logging imports+import org.junit.Assert;import org.slf4j.Logger;import org.slf4j.LoggerFactory;@@ -40,30 +37,26 @@ import org.apache.nutch.net.URLFilter;** @author Jérôme Charron*/-public abstract class RegexURLFilterBaseTest extends TestCase {-+public abstract class RegexURLFilterBaseTest {+/** My logger */protected static final Logger LOG = LoggerFactory.getLogger(RegexURLFilterBaseTest.class);private final static String SEPARATOR = System.getProperty("file.separator");private final static String SAMPLES = System.getProperty("test.data", ".");-- public RegexURLFilterBaseTest(String testName) {- super(testName);- }-+protected abstract URLFilter getURLFilter(Reader rules);protected void bench(int loops, String file) {try {bench(loops,- new FileReader(SAMPLES + SEPARATOR + file + ".rules"),- new FileReader(SAMPLES + SEPARATOR + file + ".urls"));+ new FileReader(SAMPLES + SEPARATOR + file + ".rules"),+ new FileReader(SAMPLES + SEPARATOR + file + ".urls"));} catch (Exception e) {- fail(e.toString());+ Assert.fail(e.toString());}}-+protected void bench(int loops, Reader rules, Reader urls) {long start = System.currentTimeMillis();try {@@ -73,40 +66,40 @@ public abstract class RegexURLFilterBaseTest extends TestCase {test(filter, expected);}} catch (Exception e) {- fail(e.toString());+ Assert.fail(e.toString());}LOG.info("bench time (" + loops + ") " +- (System.currentTimeMillis()-start) + "ms");+ (System.currentTimeMillis()-start) + "ms");}-+protected void test(String file) {try {test(new FileReader(SAMPLES + SEPARATOR + file + ".rules"),- new FileReader(SAMPLES + SEPARATOR + file + ".urls"));+ new FileReader(SAMPLES + SEPARATOR + file + ".urls"));} catch (Exception e) {- fail(e.toString());+ Assert.fail(e.toString());}}-+protected void test(Reader rules, Reader urls) {try {test(getURLFilter(rules), readURLFile(urls));} catch (Exception e) {- fail(e.toString());+ Assert.fail(e.toString());}}-+protected void test(URLFilter filter, FilteredURL[] expected) {for (int i=0; i<expected.length; i++) {String result = filter.filter(expected[i].url);if (result != null) {- assertTrue(expected[i].url, expected[i].sign);+ Assert.assertTrue(expected[i].url, expected[i].sign);} else {- assertFalse(expected[i].url, expected[i].sign);+ Assert.assertFalse(expected[i].url, expected[i].sign);}}}-+private static FilteredURL[] readURLFile(Reader reader) throws IOException {BufferedReader in = new BufferedReader(reader);List<FilteredURL> list = new ArrayList<FilteredURL>();@@ -118,9 +111,9 @@ public abstract class RegexURLFilterBaseTest extends TestCase {}return (FilteredURL[]) list.toArray(new FilteredURL[list.size()]);}-+private static class FilteredURL {-+boolean sign;String url;@@ -138,5 +131,5 @@ public abstract class RegexURLFilterBaseTest extends TestCase {url = line.substring(1);}}-+}diff --git a/src/plugin/parse-ext/src/test/org/apache/nutch/parse/ext/TestExtParser.java b/src/plugin/parse-ext/src/test/org/apache/nutch/parse/ext/TestExtParser.javaindex cb4256828..1057a4292 100644--- a/src/plugin/parse-ext/src/test/org/apache/nutch/parse/ext/TestExtParser.java+++ b/src/plugin/parse-ext/src/test/org/apache/nutch/parse/ext/TestExtParser.java@@ -21,18 +21,17 @@ import org.apache.nutch.protocol.ProtocolFactory;import org.apache.nutch.protocol.Protocol;import org.apache.nutch.protocol.Content;import org.apache.nutch.protocol.ProtocolException;-import org.apache.nutch.parse.Parse;-import org.apache.nutch.parse.ParseImpl;import org.apache.nutch.parse.ParseUtil;import org.apache.nutch.parse.ParseException;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;-import org.apache.hadoop.io.Text;import org.apache.nutch.crawl.CrawlDatum;--import junit.framework.TestCase;+import org.junit.After;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;import java.io.File;import java.io.FileOutputStream;@@ -49,7 +48,7 @@ import java.io.IOException;** @author John Xing*/-public class TestExtParser extends TestCase {+public class TestExtParser {private File tempFile = null;private String urlString = null;private Content content = null;@@ -59,10 +58,7 @@ public class TestExtParser extends TestCase {// echo -n "nutch rocks nutch rocks nutch rocks" | md5sumprivate String expectedMD5sum = "df46711a1a48caafc98b1c3b83aa1526";- public TestExtParser(String name) {- super(name);- }-+ @Beforeprotected void setUp() throws ProtocolException, IOException {// prepare a temp file with expectedText as its content// This system property is defined in ./src/plugin/build-plugin.xml@@ -76,7 +72,7 @@ public class TestExtParser extends TestCase {// otherwise in java.io.tmpdirtempFile = File.createTempFile("nutch.test.plugin.ExtParser.",".txt");}- urlString = tempFile.toURL().toString();+ urlString = tempFile.toURI().toURL().toString();FileOutputStream fos = new FileOutputStream(tempFile);fos.write(expectedText.getBytes());@@ -88,6 +84,7 @@ public class TestExtParser extends TestCase {protocol = null;}+ @Afterprotected void tearDown() {// clean contentcontent = null;@@ -97,6 +94,7 @@ public class TestExtParser extends TestCase {// tempFile.delete();}+ @Testpublic void testIt() throws ParseException {String contentType;@@ -114,13 +112,13 @@ public class TestExtParser extends TestCase {contentType = "application/vnd.nutch.example.cat";content.setContentType(contentType);parse = new ParseUtil(conf).parseByExtensionId("parse-ext", content).get(content.getUrl());- assertEquals(expectedText,parse.getText());+ Assert.assertEquals(expectedText,parse.getText());// check external parser that does 'md5sum'contentType = "application/vnd.nutch.example.md5sum";content.setContentType(contentType);parse = new ParseUtil(conf).parseByExtensionId("parse-ext", content).get(content.getUrl());- assertTrue(parse.getText().startsWith(expectedMD5sum));+ Assert.assertTrue(parse.getText().startsWith(expectedMD5sum));}}diff --git a/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestDOMContentUtils.java b/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestDOMContentUtils.javaindex ef3c49ae8..6bb45420b 100644--- a/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestDOMContentUtils.java+++ b/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestDOMContentUtils.java@@ -17,8 +17,6 @@package org.apache.nutch.parse.html;-import junit.framework.TestCase;-import org.apache.nutch.parse.Outlink;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;@@ -30,6 +28,9 @@ import java.util.ArrayList;import java.util.StringTokenizer;import org.cyberneko.html.parsers.*;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;import org.xml.sax.*;import org.w3c.dom.*;import org.apache.html.dom.*;@@ -37,125 +38,125 @@ import org.apache.html.dom.*;/*** Unit tests for DOMContentUtils.*/-public class TestDOMContentUtils extends TestCase {+public class TestDOMContentUtils {private static final String[] testPages= {new String("<html><head><title> title </title><script> script </script>"- + "</head><body> body <a href=\"http://www.nutch.org\">"- + " anchor </a><!--comment-->"- + "</body></html>"),- new String("<html><head><title> title </title><script> script </script>"- + "</head><body> body <a href=\"/\">"- + " home </a><!--comment-->"- + "<style> style </style>"- + " <a href=\"bot.html\">"- + " bots </a>"- + "</body></html>"),- new String("<html><head><title> </title>"- + "</head><body> "- + "<a href=\"/\"> separate this "- + "<a href=\"ok\"> from this"- + "</a></a>"- + "</body></html>"),- // this one relies on certain neko fixup behavior, possibly- // distributing the anchors into the LI's-but not the other- // anchors (outside of them, instead)! So you get a tree that- // looks like:- // ... <li> <a href=/> home </a> </li>- // <li> <a href=/> <a href="1"> 1 </a> </a> </li>- // <li> <a href=/> <a href="1"> <a href="2"> 2 </a> </a> </a> </li>- new String("<html><head><title> my title </title>"- + "</head><body> body "- + "<ul>"- + "<li> <a href=\"/\"> home"- + "<li> <a href=\"1\"> 1"- + "<li> <a href=\"2\"> 2"- + "</ul>"- + "</body></html>"),- // test frameset link extraction. The invalid frame in the middle will be- // fixed to a third standalone frame.- new String("<html><head><title> my title </title>"- + "</head><frameset rows=\"20,*\"> "- + "<frame src=\"top.html\">"- + "</frame>"- + "<frameset cols=\"20,*\">"- + "<frame src=\"left.html\">"- + "<frame src=\"invalid.html\"/>"- + "</frame>"- + "<frame src=\"right.html\">"- + "</frame>"- + "</frameset>"- + "</frameset>"- + "</body></html>"),- // test <area> and <iframe> link extraction + url normalization- new String("<html><head><title> my title </title>"- + "</head><body>"- + "<img src=\"logo.gif\" usemap=\"#green\" border=\"0\">"- + "<map name=\"green\">"- + "<area shape=\"polygon\" coords=\"19,44,45,11,87\" href=\"../index.html\">"- + "<area shape=\"rect\" coords=\"128,132,241,179\" href=\"#bottom\">"- + "<area shape=\"circle\" coords=\"68,211,35\" href=\"../bot.html\">"- + "</map>"- + "<a name=\"bottom\"/><h1> the bottom </h1> "- + "<iframe src=\"../docs/index.html\"/>"- + "</body></html>"),- // test whitespace processing for plain text extraction- new String("<html><head>\n <title> my\t\n title\r\n </title>\n"- + " </head>\n"- + " <body>\n"- + " <h1> Whitespace\ttest </h1> \n"- + "\t<a href=\"../index.html\">\n \twhitespace test\r\n\t</a> \t\n"- + " <p> This is<span> a whitespace<span></span> test</span>. Newlines\n"- + "should appear as space too.</p><p>Tabs\tare spaces too.\n</p>"- + " This\t<b>is a</b> break -><br>and the line after<i> break</i>.<br>\n"- + "<table>"- + " <tr><td>one</td><td>two</td><td>three</td></tr>\n"- + " <tr><td>space here </td><td> space there</td><td>no space</td></tr>"- + "\t<tr><td>one\r\ntwo</td><td>two\tthree</td><td>three\r\tfour</td></tr>\n"- + "</table>put some text here<Br>and there."- + "<h2>End\tthis\rmadness\n!</h2>\r\n"- + " . . . ."- + "</body> </html>"),+ + "</head><body> body <a href=\"http://www.nutch.org\">"+ + " anchor </a><!--comment-->"+ + "</body></html>"),+ new String("<html><head><title> title </title><script> script </script>"+ + "</head><body> body <a href=\"/\">"+ + " home </a><!--comment-->"+ + "<style> style </style>"+ + " <a href=\"bot.html\">"+ + " bots </a>"+ + "</body></html>"),+ new String("<html><head><title> </title>"+ + "</head><body> "+ + "<a href=\"/\"> separate this "+ + "<a href=\"ok\"> from this"+ + "</a></a>"+ + "</body></html>"),+ // this one relies on certain neko fixup behavior, possibly+ // distributing the anchors into the LI's-but not the other+ // anchors (outside of them, instead)! So you get a tree that+ // looks like:+ // ... <li> <a href=/> home </a> </li>+ // <li> <a href=/> <a href="1"> 1 </a> </a> </li>+ // <li> <a href=/> <a href="1"> <a href="2"> 2 </a> </a> </a> </li>+ new String("<html><head><title> my title </title>"+ + "</head><body> body "+ + "<ul>"+ + "<li> <a href=\"/\"> home"+ + "<li> <a href=\"1\"> 1"+ + "<li> <a href=\"2\"> 2"+ + "</ul>"+ + "</body></html>"),+ // test frameset link extraction. The invalid frame in the middle will be+ // fixed to a third standalone frame.+ new String("<html><head><title> my title </title>"+ + "</head><frameset rows=\"20,*\"> "+ + "<frame src=\"top.html\">"+ + "</frame>"+ + "<frameset cols=\"20,*\">"+ + "<frame src=\"left.html\">"+ + "<frame src=\"invalid.html\"/>"+ + "</frame>"+ + "<frame src=\"right.html\">"+ + "</frame>"+ + "</frameset>"+ + "</frameset>"+ + "</body></html>"),+ // test <area> and <iframe> link extraction + url normalization+ new String("<html><head><title> my title </title>"+ + "</head><body>"+ + "<img src=\"logo.gif\" usemap=\"#green\" border=\"0\">"+ + "<map name=\"green\">"+ + "<area shape=\"polygon\" coords=\"19,44,45,11,87\" href=\"../index.html\">"+ + "<area shape=\"rect\" coords=\"128,132,241,179\" href=\"#bottom\">"+ + "<area shape=\"circle\" coords=\"68,211,35\" href=\"../bot.html\">"+ + "</map>"+ + "<a name=\"bottom\"/><h1> the bottom </h1> "+ + "<iframe src=\"../docs/index.html\"/>"+ + "</body></html>"),+ // test whitespace processing for plain text extraction+ new String("<html><head>\n <title> my\t\n title\r\n </title>\n"+ + " </head>\n"+ + " <body>\n"+ + " <h1> Whitespace\ttest </h1> \n"+ + "\t<a href=\"../index.html\">\n \twhitespace test\r\n\t</a> \t\n"+ + " <p> This is<span> a whitespace<span></span> test</span>. Newlines\n"+ + "should appear as space too.</p><p>Tabs\tare spaces too.\n</p>"+ + " This\t<b>is a</b> break -><br>and the line after<i> break</i>.<br>\n"+ + "<table>"+ + " <tr><td>one</td><td>two</td><td>three</td></tr>\n"+ + " <tr><td>space here </td><td> space there</td><td>no space</td></tr>"+ + "\t<tr><td>one\r\ntwo</td><td>two\tthree</td><td>three\r\tfour</td></tr>\n"+ + "</table>put some text here<Br>and there."+ + "<h2>End\tthis\rmadness\n!</h2>\r\n"+ + " . . . ."+ + "</body> </html>"),- // test that <a rel=nofollow> links are not returned- new String("<html><head></head><body>"- + "<a href=\"http://www.nutch.org\" rel=\"nofollow\"> ignore </a>"- + "<a rel=\"nofollow\" href=\"http://www.nutch.org\"> ignore </a>"- + "</body></html>"),- // test that POST form actions are skipped- new String("<html><head></head><body>"- + "<form method='POST' action='/search.jsp'><input type=text>"- + "<input type=submit><p>test1</p></form>"- + "<form method='GET' action='/dummy.jsp'><input type=text>"- + "<input type=submit><p>test2</p></form></body></html>"),- // test that all form actions are skipped- new String("<html><head></head><body>"- + "<form method='POST' action='/search.jsp'><input type=text>"- + "<input type=submit><p>test1</p></form>"- + "<form method='GET' action='/dummy.jsp'><input type=text>"- + "<input type=submit><p>test2</p></form></body></html>"),- new String("<html><head><title> title </title>"- + "</head><body>"- + "<a href=\";x\">anchor1</a>"- + "<a href=\"g;x\">anchor2</a>"- + "<a href=\"g;x?y#s\">anchor3</a>"- + "</body></html>"),- new String("<html><head><title> title </title>"- + "</head><body>"- + "<a href=\"g\">anchor1</a>"- + "<a href=\"g?y#s\">anchor2</a>"- + "<a href=\"?y=1\">anchor3</a>"- + "<a href=\"?y=1#s\">anchor4</a>"- + "<a href=\"?y=1;somethingelse\">anchor5</a>"- + "</body></html>"),- new String("<html><head><title> title </title>"- + "</head><body>"- + "<a href=\"g\"><!--no anchor--></a>"- + "<a href=\"g1\"> <!--whitespace--> </a>"- + "<a href=\"g2\"> <img src=test.gif alt='bla bla'> </a>"- + "</body></html>"),+ // test that <a rel=nofollow> links are not returned+ new String("<html><head></head><body>"+ + "<a href=\"http://www.nutch.org\" rel=\"nofollow\"> ignore </a>"+ + "<a rel=\"nofollow\" href=\"http://www.nutch.org\"> ignore </a>"+ + "</body></html>"),+ // test that POST form actions are skipped+ new String("<html><head></head><body>"+ + "<form method='POST' action='/search.jsp'><input type=text>"+ + "<input type=submit><p>test1</p></form>"+ + "<form method='GET' action='/dummy.jsp'><input type=text>"+ + "<input type=submit><p>test2</p></form></body></html>"),+ // test that all form actions are skipped+ new String("<html><head></head><body>"+ + "<form method='POST' action='/search.jsp'><input type=text>"+ + "<input type=submit><p>test1</p></form>"+ + "<form method='GET' action='/dummy.jsp'><input type=text>"+ + "<input type=submit><p>test2</p></form></body></html>"),+ new String("<html><head><title> title </title>"+ + "</head><body>"+ + "<a href=\";x\">anchor1</a>"+ + "<a href=\"g;x\">anchor2</a>"+ + "<a href=\"g;x?y#s\">anchor3</a>"+ + "</body></html>"),+ new String("<html><head><title> title </title>"+ + "</head><body>"+ + "<a href=\"g\">anchor1</a>"+ + "<a href=\"g?y#s\">anchor2</a>"+ + "<a href=\"?y=1\">anchor3</a>"+ + "<a href=\"?y=1#s\">anchor4</a>"+ + "<a href=\"?y=1;somethingelse\">anchor5</a>"+ + "</body></html>"),+ new String("<html><head><title> title </title>"+ + "</head><body>"+ + "<a href=\"g\"><!--no anchor--></a>"+ + "<a href=\"g1\"> <!--whitespace--> </a>"+ + "<a href=\"g2\"> <img src=test.gif alt='bla bla'> </a>"+ + "</body></html>"),};-+private static int SKIP = 9;private static String[] testBaseHrefs= {@@ -173,12 +174,12 @@ public class TestDOMContentUtils extends TestCase {"http://www.nutch.org/;something","http://www.nutch.org/"};-+private static final DocumentFragment testDOMs[]=- new DocumentFragment[testPages.length];+ new DocumentFragment[testPages.length];private static URL[] testBaseHrefURLs=- new URL[testPages.length];+ new URL[testPages.length];private static final String[] answerText= {@@ -194,12 +195,12 @@ public class TestDOMContentUtils extends TestCase {+ "one two three space here space there no space "+ "one two two three three four put some text here and there. "+ "End this madness ! . . . .",- "ignore ignore",- "test1 test2",- "test1 test2",- "title anchor1 anchor2 anchor3",- "title anchor1 anchor2 anchor3 anchor4 anchor5",- "title"+ "ignore ignore",+ "test1 test2",+ "test1 test2",+ "title anchor1 anchor2 anchor3",+ "title anchor1 anchor2 anchor3 anchor4 anchor5",+ "title"};private static final String[] answerTitle= {@@ -220,15 +221,12 @@ public class TestDOMContentUtils extends TestCase {// note: should be in page-orderprivate static Outlink[][] answerOutlinks;-+private static Configuration conf;private static DOMContentUtils utils = null;-- public TestDOMContentUtils(String name) {- super(name);- }- private static void setup() {+ @Before+ public void setup() {conf = NutchConfiguration.create();conf.setBoolean("parser.html.form.use_action", true);utils = new DOMContentUtils(conf);@@ -239,83 +237,83 @@ public class TestDOMContentUtils extends TestCase {true);} catch (SAXException e) {}for (int i= 0; i < testPages.length; i++) {- DocumentFragment node=+ DocumentFragment node=new HTMLDocumentImpl().createDocumentFragment();- try {- parser.parse(+ try {+ parser.parse(new InputSource(- new ByteArrayInputStream(testPages[i].getBytes()) ),- node);- testBaseHrefURLs[i]= new URL(testBaseHrefs[i]);- } catch (Exception e) {- assertTrue("caught exception: " + e, false);- }+ new ByteArrayInputStream(testPages[i].getBytes()) ),+ node);+ testBaseHrefURLs[i]= new URL(testBaseHrefs[i]);+ } catch (Exception e) {+ Assert.assertTrue("caught exception: " + e, false);+ }testDOMs[i]= node;}try {- answerOutlinks = new Outlink[][]{- {- new Outlink("http://www.nutch.org", "anchor"),- },- {- new Outlink("http://www.nutch.org/", "home"),- new Outlink("http://www.nutch.org/docs/bot.html", "bots"),- },- {- new Outlink("http://www.nutch.org/", "separate this"),- new Outlink("http://www.nutch.org/docs/ok", "from this"),- },- {- new Outlink("http://www.nutch.org/", "home"),- new Outlink("http://www.nutch.org/docs/1", "1"),- new Outlink("http://www.nutch.org/docs/2", "2"),- },- {- new Outlink("http://www.nutch.org/frames/top.html", ""),- new Outlink("http://www.nutch.org/frames/left.html", ""),- new Outlink("http://www.nutch.org/frames/invalid.html", ""),- new Outlink("http://www.nutch.org/frames/right.html", ""),- },- {- new Outlink("http://www.nutch.org/maps/logo.gif", ""),- new Outlink("http://www.nutch.org/index.html", ""),- new Outlink("http://www.nutch.org/maps/#bottom", ""),- new Outlink("http://www.nutch.org/bot.html", ""),- new Outlink("http://www.nutch.org/docs/index.html", ""),- },- {- new Outlink("http://www.nutch.org/index.html", "whitespace test"),- },- {- },- {- new Outlink("http://www.nutch.org/dummy.jsp", "test2"),- },- {- },- {- new Outlink("http://www.nutch.org/;x", "anchor1"),- new Outlink("http://www.nutch.org/g;x", "anchor2"),- new Outlink("http://www.nutch.org/g;x?y#s", "anchor3")- },- {- // this is tricky - see RFC3986 section 5.4.1 example 7- new Outlink("http://www.nutch.org/g", "anchor1"),- new Outlink("http://www.nutch.org/g?y#s", "anchor2"),- new Outlink("http://www.nutch.org/;something?y=1", "anchor3"),- new Outlink("http://www.nutch.org/;something?y=1#s", "anchor4"),- new Outlink("http://www.nutch.org/;something?y=1;somethingelse", "anchor5")- },- {- new Outlink("http://www.nutch.org/g", ""),- new Outlink("http://www.nutch.org/g1", ""),- new Outlink("http://www.nutch.org/g2", "bla bla"),- new Outlink("http://www.nutch.org/test.gif", "bla bla"),- }+ answerOutlinks = new Outlink[][]{+ {+ new Outlink("http://www.nutch.org", "anchor"),+ },+ {+ new Outlink("http://www.nutch.org/", "home"),+ new Outlink("http://www.nutch.org/docs/bot.html", "bots"),+ },+ {+ new Outlink("http://www.nutch.org/", "separate this"),+ new Outlink("http://www.nutch.org/docs/ok", "from this"),+ },+ {+ new Outlink("http://www.nutch.org/", "home"),+ new Outlink("http://www.nutch.org/docs/1", "1"),+ new Outlink("http://www.nutch.org/docs/2", "2"),+ },+ {+ new Outlink("http://www.nutch.org/frames/top.html", ""),+ new Outlink("http://www.nutch.org/frames/left.html", ""),+ new Outlink("http://www.nutch.org/frames/invalid.html", ""),+ new Outlink("http://www.nutch.org/frames/right.html", ""),+ },+ {+ new Outlink("http://www.nutch.org/maps/logo.gif", ""),+ new Outlink("http://www.nutch.org/index.html", ""),+ new Outlink("http://www.nutch.org/maps/#bottom", ""),+ new Outlink("http://www.nutch.org/bot.html", ""),+ new Outlink("http://www.nutch.org/docs/index.html", ""),+ },+ {+ new Outlink("http://www.nutch.org/index.html", "whitespace test"),+ },+ {+ },+ {+ new Outlink("http://www.nutch.org/dummy.jsp", "test2"),+ },+ {+ },+ {+ new Outlink("http://www.nutch.org/;x", "anchor1"),+ new Outlink("http://www.nutch.org/g;x", "anchor2"),+ new Outlink("http://www.nutch.org/g;x?y#s", "anchor3")+ },+ {+ // this is tricky - see RFC3986 section 5.4.1 example 7+ new Outlink("http://www.nutch.org/g", "anchor1"),+ new Outlink("http://www.nutch.org/g?y#s", "anchor2"),+ new Outlink("http://www.nutch.org/;something?y=1", "anchor3"),+ new Outlink("http://www.nutch.org/;something?y=1#s", "anchor4"),+ new Outlink("http://www.nutch.org/;something?y=1;somethingelse", "anchor5")+ },+ {+ new Outlink("http://www.nutch.org/g", ""),+ new Outlink("http://www.nutch.org/g1", ""),+ new Outlink("http://www.nutch.org/g2", "bla bla"),+ new Outlink("http://www.nutch.org/test.gif", "bla bla"),+ }};-+} catch (MalformedURLException e) {-+}}@@ -334,6 +332,7 @@ public class TestDOMContentUtils extends TestCase {return true;}+ @Testpublic void testGetText() {if (testDOMs[0] == null)setup();@@ -341,14 +340,15 @@ public class TestDOMContentUtils extends TestCase {StringBuffer sb= new StringBuffer();utils.getText(sb, testDOMs[i]);String text= sb.toString();- assertTrue("expecting text: " + answerText[i]- + System.getProperty("line.separator")- + System.getProperty("line.separator")- + "got text: "+ text,- equalsIgnoreWhitespace(answerText[i], text));+ Assert.assertTrue("expecting text: " + answerText[i]+ + System.getProperty("line.separator")+ + System.getProperty("line.separator")+ + "got text: "+ text,+ equalsIgnoreWhitespace(answerText[i], text));}}+ @Testpublic void testGetTitle() {if (testDOMs[0] == null)setup();@@ -356,14 +356,15 @@ public class TestDOMContentUtils extends TestCase {StringBuffer sb= new StringBuffer();utils.getTitle(sb, testDOMs[i]);String text= sb.toString();- assertTrue("expecting text: " + answerText[i]- + System.getProperty("line.separator")- + System.getProperty("line.separator")- + "got text: "+ text,- equalsIgnoreWhitespace(answerTitle[i], text));+ Assert.assertTrue("expecting text: " + answerText[i]+ + System.getProperty("line.separator")+ + System.getProperty("line.separator")+ + "got text: "+ text,+ equalsIgnoreWhitespace(answerTitle[i], text));}}+ @Testpublic void testGetOutlinks() {if (testDOMs[0] == null)setup();@@ -398,31 +399,31 @@ public class TestDOMContentUtils extends TestCase {private static final void compareOutlinks(Outlink[] o1, Outlink[] o2) {if (o1.length != o2.length) {- assertTrue("got wrong number of outlinks (expecting " + o1.length- + ", got " + o2.length + ")"- + System.getProperty("line.separator")- + "answer: " + System.getProperty("line.separator")- + outlinksString(o1)- + System.getProperty("line.separator")- + "got: " + System.getProperty("line.separator")- + outlinksString(o2)- + System.getProperty("line.separator"),- false- );+ Assert.assertTrue("got wrong number of outlinks (expecting " + o1.length+ + ", got " + o2.length + ")"+ + System.getProperty("line.separator")+ + "answer: " + System.getProperty("line.separator")+ + outlinksString(o1)+ + System.getProperty("line.separator")+ + "got: " + System.getProperty("line.separator")+ + outlinksString(o2)+ + System.getProperty("line.separator"),+ false+ );}for (int i= 0; i < o1.length; i++) {if (!o1[i].equals(o2[i])) {- assertTrue("got wrong outlinks at position " + i- + System.getProperty("line.separator")- + "answer: " + System.getProperty("line.separator")- + "'" + o1[i].getToUrl() + "', anchor: '" + o1[i].getAnchor() + "'"- + System.getProperty("line.separator")- + "got: " + System.getProperty("line.separator")- + "'" + o2[i].getToUrl() + "', anchor: '" + o2[i].getAnchor() + "'",- false- );-+ Assert.assertTrue("got wrong outlinks at position " + i+ + System.getProperty("line.separator")+ + "answer: " + System.getProperty("line.separator")+ + "'" + o1[i].getToUrl() + "', anchor: '" + o1[i].getAnchor() + "'"+ + System.getProperty("line.separator")+ + "got: " + System.getProperty("line.separator")+ + "'" + o2[i].getToUrl() + "', anchor: '" + o2[i].getAnchor() + "'",+ false+ );+}}}diff --git a/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestHtmlParser.java b/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestHtmlParser.javaindex db2a01499..0be1cd8bc 100644--- a/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestHtmlParser.java+++ b/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestHtmlParser.java@@ -21,16 +21,17 @@ import java.nio.charset.Charset;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.metadata.Metadata;+import org.apache.nutch.parse.html.HtmlParser;import org.apache.nutch.parse.Parse;import org.apache.nutch.parse.Parser;import org.apache.nutch.protocol.Content;import org.apache.nutch.util.NutchConfiguration;+import org.junit.Assert;+import org.junit.Test;import org.slf4j.Logger;import org.slf4j.LoggerFactory;-import junit.framework.TestCase;--public class TestHtmlParser extends TestCase {+public class TestHtmlParser {public static final Logger LOG = LoggerFactory.getLogger(TestHtmlParser.class);@@ -90,12 +91,11 @@ public class TestHtmlParser extends TestCase {+ encodingTestContent}};-+private Configuration conf;private Parser parser;-- public TestHtmlParser(String name) {- super(name);++ public TestHtmlParser() {conf = NutchConfiguration.create();parser = new HtmlParser();parser.setConf(conf);@@ -107,7 +107,8 @@ public class TestHtmlParser extends TestCase {new Content(dummyUrl, dummyUrl, contentBytes, "text/html", new Metadata(),conf)).get(dummyUrl);}-++ @Testpublic void testEncodingDetection() {for (String[] testPage : encodingTestPages) {String name = testPage[0];@@ -121,14 +122,14 @@ public class TestHtmlParser extends TestCase {LOG.info("title:\t" + title);LOG.info("keywords:\t" + keywords);LOG.info("text:\t" + text);- assertEquals("Title not extracted properly (" + name + ")",+ Assert.assertEquals("Title not extracted properly (" + name + ")",encodingTestKeywords, title);for (String keyword : encodingTestKeywords.split(",\\s*")) {- assertTrue(keyword + " not found in text (" + name + ")",+ Assert.assertTrue(keyword + " not found in text (" + name + ")",text.contains(keyword));}if (keywords != null) {- assertEquals("Keywords not extracted properly (" + name + ")",+ Assert.assertEquals("Keywords not extracted properly (" + name + ")",encodingTestKeywords, keywords);}}diff --git a/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestRobotsMetaProcessor.java b/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestRobotsMetaProcessor.javaindex e98584496..f53d389c3 100644--- a/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestRobotsMetaProcessor.java+++ b/src/plugin/parse-html/src/test/org/apache/nutch/parse/html/TestRobotsMetaProcessor.java@@ -17,23 +17,20 @@package org.apache.nutch.parse.html;-import junit.framework.TestCase;-import org.apache.nutch.parse.HTMLMetaTags;import java.io.ByteArrayInputStream;import java.net.URL;import org.cyberneko.html.parsers.*;+import org.junit.Assert;+import org.junit.Test;import org.xml.sax.*;import org.w3c.dom.*;import org.apache.html.dom.*;/** Unit tests for HTMLMetaProcessor. */-public class TestRobotsMetaProcessor extends TestCase {- public TestRobotsMetaProcessor(String name) {- super(name);- }+public class TestRobotsMetaProcessor {/*@@ -46,71 +43,71 @@ public class TestRobotsMetaProcessor extends TestCase {<META HTTP-EQUIV="Pragma" CONTENT="no-cache">- */+ */public static String[] tests=- {- "<html><head><title>test page</title>"- + "<META NAME=\"ROBOTS\" CONTENT=\"NONE\"> "- + "<META HTTP-EQUIV=\"PRAGMA\" CONTENT=\"NO-CACHE\"> "- + "</head><body>"- + " some text"- + "</body></html>",-- "<html><head><title>test page</title>"- + "<meta name=\"robots\" content=\"all\"> "- + "<meta http-equiv=\"pragma\" content=\"no-cache\"> "- + "</head><body>"- + " some text"- + "</body></html>",-+ {"<html><head><title>test page</title>"- + "<MeTa NaMe=\"RoBoTs\" CoNtEnT=\"nOnE\"> "- + "<MeTa HtTp-EqUiV=\"pRaGmA\" cOnTeNt=\"No-CaChE\"> "- + "</head><body>"- + " some text"- + "</body></html>",-- "<html><head><title>test page</title>"- + "<meta name=\"robots\" content=\"none\"> "- + "</head><body>"- + " some text"- + "</body></html>",-- "<html><head><title>test page</title>"- + "<meta name=\"robots\" content=\"noindex,nofollow\"> "- + "</head><body>"- + " some text"- + "</body></html>",-- "<html><head><title>test page</title>"- + "<meta name=\"robots\" content=\"noindex,follow\"> "- + "</head><body>"- + " some text"- + "</body></html>",-- "<html><head><title>test page</title>"- + "<meta name=\"robots\" content=\"index,nofollow\"> "- + "</head><body>"- + " some text"- + "</body></html>",-- "<html><head><title>test page</title>"- + "<meta name=\"robots\" content=\"index,follow\"> "- + "<base href=\"http://www.nutch.org/\">"- + "</head><body>"- + " some text"- + "</body></html>",-- "<html><head><title>test page</title>"- + "<meta name=\"robots\"> "- + "<base href=\"http://www.nutch.org/base/\">"- + "</head><body>"- + " some text"- + "</body></html>",-- };+ + "<META NAME=\"ROBOTS\" CONTENT=\"NONE\"> "+ + "<META HTTP-EQUIV=\"PRAGMA\" CONTENT=\"NO-CACHE\"> "+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<meta name=\"robots\" content=\"all\"> "+ + "<meta http-equiv=\"pragma\" content=\"no-cache\"> "+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<MeTa NaMe=\"RoBoTs\" CoNtEnT=\"nOnE\"> "+ + "<MeTa HtTp-EqUiV=\"pRaGmA\" cOnTeNt=\"No-CaChE\"> "+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<meta name=\"robots\" content=\"none\"> "+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<meta name=\"robots\" content=\"noindex,nofollow\"> "+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<meta name=\"robots\" content=\"noindex,follow\"> "+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<meta name=\"robots\" content=\"index,nofollow\"> "+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<meta name=\"robots\" content=\"index,follow\"> "+ + "<base href=\"http://www.nutch.org/\">"+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<meta name=\"robots\"> "+ + "<base href=\"http://www.nutch.org/base/\">"+ + "</head><body>"+ + " some text"+ + "</body></html>",++ };public static final boolean[][] answers= {{true, true, true}, // NONE@@ -126,25 +123,26 @@ public class TestRobotsMetaProcessor extends TestCase {private URL[][] currURLsAndAnswers;+ @Testpublic void testRobotsMetaProcessor() {DOMFragmentParser parser= new DOMFragmentParser();;try {currURLsAndAnswers= new URL[][] {- {new URL("http://www.nutch.org"), null},- {new URL("http://www.nutch.org"), null},- {new URL("http://www.nutch.org"), null},- {new URL("http://www.nutch.org"), null},- {new URL("http://www.nutch.org"), null},- {new URL("http://www.nutch.org"), null},- {new URL("http://www.nutch.org"), null},- {new URL("http://www.nutch.org/foo/"),- new URL("http://www.nutch.org/")},- {new URL("http://www.nutch.org"),- new URL("http://www.nutch.org/base/")}+ {new URL("http://www.nutch.org"), null},+ {new URL("http://www.nutch.org"), null},+ {new URL("http://www.nutch.org"), null},+ {new URL("http://www.nutch.org"), null},+ {new URL("http://www.nutch.org"), null},+ {new URL("http://www.nutch.org"), null},+ {new URL("http://www.nutch.org"), null},+ {new URL("http://www.nutch.org/foo/"),+ new URL("http://www.nutch.org/")},+ {new URL("http://www.nutch.org"),+ new URL("http://www.nutch.org/base/")}};} catch (Exception e) {- assertTrue("couldn't make test URLs!", false);+ Assert.assertTrue("couldn't make test URLs!", false);}for (int i= 0; i < tests.length; i++) {@@ -160,22 +158,22 @@ public class TestRobotsMetaProcessor extends TestCase {HTMLMetaTags robotsMeta= new HTMLMetaTags();HTMLMetaProcessor.getMetaTags(robotsMeta, node,- currURLsAndAnswers[i][0]);-- assertTrue("got index wrong on test " + i,- robotsMeta.getNoIndex() == answers[i][0]);- assertTrue("got follow wrong on test " + i,- robotsMeta.getNoFollow() == answers[i][1]);- assertTrue("got cache wrong on test " + i,- robotsMeta.getNoCache() == answers[i][2]);- assertTrue("got base href wrong on test " + i + " (got "- + robotsMeta.getBaseHref() + ")",- ( (robotsMeta.getBaseHref() == null)- && (currURLsAndAnswers[i][1] == null) )- || ( (robotsMeta.getBaseHref() != null)- && robotsMeta.getBaseHref().equals(- currURLsAndAnswers[i][1]) ) );-+ currURLsAndAnswers[i][0]);++ Assert.assertTrue("got index wrong on test " + i,+ robotsMeta.getNoIndex() == answers[i][0]);+ Assert.assertTrue("got follow wrong on test " + i,+ robotsMeta.getNoFollow() == answers[i][1]);+ Assert.assertTrue("got cache wrong on test " + i,+ robotsMeta.getNoCache() == answers[i][2]);+ Assert.assertTrue("got base href wrong on test " + i + " (got "+ + robotsMeta.getBaseHref() + ")",+ ( (robotsMeta.getBaseHref() == null)+ && (currURLsAndAnswers[i][1] == null) )+ || ( (robotsMeta.getBaseHref() != null)+ && robotsMeta.getBaseHref().equals(+ currURLsAndAnswers[i][1]) ) );+}}diff --git a/src/plugin/parse-metatags/src/test/org/apache/nutch/parse/html/TestMetatagParser.java b/src/plugin/parse-metatags/src/test/org/apache/nutch/parse/html/TestMetatagParser.javaindex fa8b2b05f..24e935b17 100644--- a/src/plugin/parse-metatags/src/test/org/apache/nutch/parse/html/TestMetatagParser.java+++ b/src/plugin/parse-metatags/src/test/org/apache/nutch/parse/html/TestMetatagParser.java@@ -20,8 +20,6 @@ package org.apache.nutch.parse.html;import java.util.Set;import java.util.TreeSet;-import junit.framework.TestCase;-import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.io.Text;import org.apache.nutch.crawl.CrawlDatum;@@ -32,8 +30,10 @@ import org.apache.nutch.protocol.Content;import org.apache.nutch.protocol.Protocol;import org.apache.nutch.protocol.ProtocolFactory;import org.apache.nutch.util.NutchConfiguration;+import org.junit.Assert;+import org.junit.Test;-public class TestMetatagParser extends TestCase {+public class TestMetatagParser {private String fileSeparator = System.getProperty("file.separator");private String sampleDir = System.getProperty("test.data", ".");@@ -42,10 +42,6 @@ public class TestMetatagParser extends TestCase {private String description = "This is a test of description";private String keywords = "This is a test of keywords";- public TestMetatagParser(String name) {- super(name);- }-public Metadata parseMeta(String fileName, Configuration conf) {Metadata metadata = null;try {@@ -57,21 +53,23 @@ public class TestMetatagParser extends TestCase {metadata = parse.getData().getParseMeta();} catch (Exception e) {e.printStackTrace();- fail(e.toString());+ Assert.fail(e.toString());}return metadata;}+ @Testpublic void testIt() {Configuration conf = NutchConfiguration.create();// check that we get the same valuesMetadata parseMeta= parseMeta(sampleFile, conf);- assertEquals(description, parseMeta.get("metatag.description"));- assertEquals(keywords, parseMeta.get("metatag.keywords"));+ Assert.assertEquals(description, parseMeta.get("metatag.description"));+ Assert.assertEquals(keywords, parseMeta.get("metatag.keywords"));}+ @Testpublic void testMultiValueMetatags() {Configuration conf = NutchConfiguration.create();conf.set("metatags.names", "keywords;DC.creator");@@ -87,7 +85,7 @@ public class TestMetatagParser extends TestCase {}String[] expectedValues1 = {"Doug Cutting", "Michael Cafarella"};for (String val : expectedValues1) {- assertTrue(failMessage + val, valueSet.contains(val));+ Assert.assertTrue(failMessage + val, valueSet.contains(val));}valueSet.clear();@@ -96,7 +94,7 @@ public class TestMetatagParser extends TestCase {}String[] expectedValues2 = {"robot d'indexation", "web crawler", "Webcrawler"};for (String val : expectedValues2) {- assertTrue(failMessage + val, valueSet.contains(val));+ Assert.assertTrue(failMessage + val, valueSet.contains(val));}}diff --git a/src/plugin/parse-swf/src/test/org/apache/nutch/parse/swf/TestSWFParser.java b/src/plugin/parse-swf/src/test/org/apache/nutch/parse/swf/TestSWFParser.javaindex b6e08a3f0..c5745a8d0 100644--- a/src/plugin/parse-swf/src/test/org/apache/nutch/parse/swf/TestSWFParser.java+++ b/src/plugin/parse-swf/src/test/org/apache/nutch/parse/swf/TestSWFParser.java@@ -26,52 +26,27 @@ import org.apache.nutch.protocol.ProtocolFactory;import org.apache.nutch.protocol.Protocol;import org.apache.nutch.protocol.Content;import org.apache.nutch.protocol.ProtocolException;-import org.apache.nutch.parse.ParseUtil;import org.apache.nutch.parse.Parse;import org.apache.nutch.parse.ParseException;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;--import junit.framework.TestCase;+import org.junit.Assert;+import org.junit.Test;/*** Unit tests for SWFParser.*/-public class TestSWFParser extends TestCase {+public class TestSWFParser {private String fileSeparator = System.getProperty("file.separator");// This system property is defined in ./src/plugin/build-plugin.xmlprivate String sampleDir = System.getProperty("test.data",".");-+private String[] sampleFiles = new String[]{"test1.swf", "test2.swf", "test3.swf"};private String[] sampleTexts = new String[]{"test1.txt", "test2.txt", "test3.txt"};- public TestSWFParser(String name) {- super(name);- for (int i = 0; i < sampleFiles.length; i++) {- try {- // read the test string- FileInputStream fis = new FileInputStream(sampleDir + fileSeparator + sampleTexts[i]);- StringBuffer sb = new StringBuffer();- int len = 0;- InputStreamReader isr = new InputStreamReader(fis, "UTF-8");- char[] buf = new char[1024];- while ((len = isr.read(buf)) > 0) {- sb.append(buf, 0, len);- }- isr.close();- sampleTexts[i] = sb.toString().replaceAll("[ \t\r\n]+", " ").trim();- } catch (Exception e) {- e.printStackTrace();- }- }- }-- protected void setUp() {}-- protected void tearDown() {}-+ @Testpublic void testIt() throws ProtocolException, ParseException {String urlString;Protocol protocol;@@ -88,7 +63,28 @@ public class TestSWFParser extends TestCase {parse = new ParseUtil(conf).parse(content).get(content.getUrl());String text = parse.getText().replaceAll("[ \t\r\n]+", " ").trim();- assertTrue(sampleTexts[i].equals(text));+ Assert.assertTrue(sampleTexts[i].equals(text));+ }+ }++ public TestSWFParser() {+ for (int i = 0; i < sampleFiles.length; i++) {+ try {+ // read the test string+ FileInputStream fis = new FileInputStream(sampleDir + fileSeparator + sampleTexts[i]);+ StringBuffer sb = new StringBuffer();+ int len = 0;+ InputStreamReader isr = new InputStreamReader(fis, "UTF-8");+ char[] buf = new char[1024];+ while ((len = isr.read(buf)) > 0) {+ sb.append(buf, 0, len);+ }+ isr.close();+ sampleTexts[i] = sb.toString().replaceAll("[ \t\r\n]+", " ").trim();+ } catch (Exception e) {+ e.printStackTrace();+ }}}+}diff --git a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestDOMContentUtils.java b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestDOMContentUtils.javaindex 373a1e4df..611796dfd 100644--- a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestDOMContentUtils.java+++ b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestDOMContentUtils.java@@ -17,8 +17,6 @@package org.apache.nutch.tika;-import junit.framework.TestCase;-import org.apache.nutch.parse.Outlink;import org.apache.nutch.parse.tika.DOMContentUtils;import org.apache.hadoop.conf.Configuration;@@ -33,137 +31,140 @@ import org.xml.sax.*;import org.w3c.dom.*;import org.apache.html.dom.*;import org.cyberneko.html.parsers.DOMFragmentParser;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;/*** Unit tests for DOMContentUtils.*/-public class TestDOMContentUtils extends TestCase {+public class TestDOMContentUtils {private static final String[] testPages = {- new String("<html><head><title> title </title><script> script </script>"- + "</head><body> body <a href=\"http://www.nutch.org\">"- + " anchor </a><!--comment-->" + "</body></html>"),-- new String("<html><head><title> title </title><script> script </script>"- + "</head><body> body <a href=\"/\">" + " home </a><!--comment-->"- + "<style> style </style>" + " <a href=\"bot.html\">" + " bots </a>"- + "</body></html>"),-- new String("<html><head><title> </title>" + "</head><body> "- + "<a href=\"/\"> separate this " + "<a href=\"ok\"> from this"- + "</a></a>" + "</body></html>"),-- // this one relies on certain neko fixup behavior, possibly- // distributing the anchors into the LI's-but not the other- // anchors (outside of them, instead)! So you get a tree that- // looks like:- // ... <li> <a href=/> home </a> </li>- // <li> <a href=/> <a href="1"> 1 </a> </a> </li>- // <li> <a href=/> <a href="1"> <a href="2"> 2 </a> </a> </a> </li>- new String("<html><head><title> my title </title>"- + "</head><body> body " + "<ul>" + "<li> <a href=\"/\"> home"- + "<li> <a href=\"1\"> 1" + "<li> <a href=\"2\"> 2" + "</ul>"- + "</body></html>"),-- // test frameset link extraction. The invalid frame in the middle- // will be- // fixed to a third standalone frame.- new String("<html><head><title> my title </title>"- + "</head><frameset rows=\"20,*\"> " + "<frame src=\"top.html\">"- + "</frame>" + "<frameset cols=\"20,*\">"- + "<frame src=\"left.html\">" + "<frame src=\"invalid.html\"/>"- + "</frame>" + "<frame src=\"right.html\">" + "</frame>"- + "</frameset>" + "</frameset>" + "</body></html>"),-- // test <area> and <iframe> link extraction + url normalization- new String(- "<html><head><title> my title </title>"- + "</head><body>"- + "<img src=\"logo.gif\" usemap=\"#green\" border=\"0\">"- + "<map name=\"green\">"- + "<area shape=\"polygon\" coords=\"19,44,45,11,87\" href=\"../index.html\">"- + "<area shape=\"rect\" coords=\"128,132,241,179\" href=\"#bottom\">"- + "<area shape=\"circle\" coords=\"68,211,35\" href=\"../bot.html\">"- + "</map>" + "<a name=\"bottom\"/><h1> the bottom </h1> "- + "<iframe src=\"../docs/index.html\"/>" + "</body></html>"),-- // test whitespace processing for plain text extraction- new String(- "<html><head>\n <title> my\t\n title\r\n </title>\n"- + " </head>\n"- + " <body>\n"- + " <h1> Whitespace\ttest </h1> \n"- + "\t<a href=\"../index.html\">\n \twhitespace test\r\n\t</a> \t\n"- + " <p> This is<span> a whitespace<span></span> test</span>. Newlines\n"- + "should appear as space too.</p><p>Tabs\tare spaces too.\n</p>"- + " This\t<b>is a</b> break -><br>and the line after<i> break</i>.<br>\n"- + "<table>"- + " <tr><td>one</td><td>two</td><td>three</td></tr>\n"- + " <tr><td>space here </td><td> space there</td><td>no space</td></tr>"- + "\t<tr><td>one\r\ntwo</td><td>two\tthree</td><td>three\r\tfour</td></tr>\n"- + "</table>put some text here<Br>and there."- + "<h2>End\tthis\rmadness\n!</h2>\r\n"- + " . . . ." + "</body> </html>"),-- // test that <a rel=nofollow> links are not returned- new String("<html><head></head><body>"- + "<a href=\"http://www.nutch.org\" rel=\"nofollow\"> ignore </a>"- + "<a rel=\"nofollow\" href=\"http://www.nutch.org\"> ignore </a>"- + "</body></html>"),- // test that POST form actions are skipped- new String("<html><head></head><body>"- + "<form method='POST' action='/search.jsp'><input type=text>"- + "<input type=submit><p>test1</p></form>"- + "<form method='GET' action='/dummy.jsp'><input type=text>"- + "<input type=submit><p>test2</p></form></body></html>"),- // test that all form actions are skipped- new String("<html><head></head><body>"- + "<form method='POST' action='/search.jsp'><input type=text>"- + "<input type=submit><p>test1</p></form>"- + "<form method='GET' action='/dummy.jsp'><input type=text>"- + "<input type=submit><p>test2</p></form></body></html>"),- new String("<html><head><title> title </title>" + "</head><body>"- + "<a href=\";x\">anchor1</a>" + "<a href=\"g;x\">anchor2</a>"- + "<a href=\"g;x?y#s\">anchor3</a>" + "</body></html>"),- new String("<html><head><title> title </title>" + "</head><body>"- + "<a href=\"g\">anchor1</a>" + "<a href=\"g?y#s\">anchor2</a>"- + "<a href=\"?y=1\">anchor3</a>" + "<a href=\"?y=1#s\">anchor4</a>"- + "<a href=\"?y=1;somethingelse\">anchor5</a>" + "</body></html>"), };+ new String("<html><head><title> title </title><script> script </script>"+ + "</head><body> body <a href=\"http://www.nutch.org\">"+ + " anchor </a><!--comment-->" + "</body></html>"),++ new String("<html><head><title> title </title><script> script </script>"+ + "</head><body> body <a href=\"/\">" + " home </a><!--comment-->"+ + "<style> style </style>" + " <a href=\"bot.html\">" + " bots </a>"+ + "</body></html>"),++ new String("<html><head><title> </title>" + "</head><body> "+ + "<a href=\"/\"> separate this " + "<a href=\"ok\"> from this"+ + "</a></a>" + "</body></html>"),++ // this one relies on certain neko fixup behavior, possibly+ // distributing the anchors into the LI's-but not the other+ // anchors (outside of them, instead)! So you get a tree that+ // looks like:+ // ... <li> <a href=/> home </a> </li>+ // <li> <a href=/> <a href="1"> 1 </a> </a> </li>+ // <li> <a href=/> <a href="1"> <a href="2"> 2 </a> </a> </a> </li>+ new String("<html><head><title> my title </title>"+ + "</head><body> body " + "<ul>" + "<li> <a href=\"/\"> home"+ + "<li> <a href=\"1\"> 1" + "<li> <a href=\"2\"> 2" + "</ul>"+ + "</body></html>"),++ // test frameset link extraction. The invalid frame in the middle+ // will be+ // fixed to a third standalone frame.+ new String("<html><head><title> my title </title>"+ + "</head><frameset rows=\"20,*\"> " + "<frame src=\"top.html\">"+ + "</frame>" + "<frameset cols=\"20,*\">"+ + "<frame src=\"left.html\">" + "<frame src=\"invalid.html\"/>"+ + "</frame>" + "<frame src=\"right.html\">" + "</frame>"+ + "</frameset>" + "</frameset>" + "</body></html>"),++ // test <area> and <iframe> link extraction + url normalization+ new String(+ "<html><head><title> my title </title>"+ + "</head><body>"+ + "<img src=\"logo.gif\" usemap=\"#green\" border=\"0\">"+ + "<map name=\"green\">"+ + "<area shape=\"polygon\" coords=\"19,44,45,11,87\" href=\"../index.html\">"+ + "<area shape=\"rect\" coords=\"128,132,241,179\" href=\"#bottom\">"+ + "<area shape=\"circle\" coords=\"68,211,35\" href=\"../bot.html\">"+ + "</map>" + "<a name=\"bottom\"/><h1> the bottom </h1> "+ + "<iframe src=\"../docs/index.html\"/>" + "</body></html>"),++ // test whitespace processing for plain text extraction+ new String(+ "<html><head>\n <title> my\t\n title\r\n </title>\n"+ + " </head>\n"+ + " <body>\n"+ + " <h1> Whitespace\ttest </h1> \n"+ + "\t<a href=\"../index.html\">\n \twhitespace test\r\n\t</a> \t\n"+ + " <p> This is<span> a whitespace<span></span> test</span>. Newlines\n"+ + "should appear as space too.</p><p>Tabs\tare spaces too.\n</p>"+ + " This\t<b>is a</b> break -><br>and the line after<i> break</i>.<br>\n"+ + "<table>"+ + " <tr><td>one</td><td>two</td><td>three</td></tr>\n"+ + " <tr><td>space here </td><td> space there</td><td>no space</td></tr>"+ + "\t<tr><td>one\r\ntwo</td><td>two\tthree</td><td>three\r\tfour</td></tr>\n"+ + "</table>put some text here<Br>and there."+ + "<h2>End\tthis\rmadness\n!</h2>\r\n"+ + " . . . ." + "</body> </html>"),++ // test that <a rel=nofollow> links are not returned+ new String("<html><head></head><body>"+ + "<a href=\"http://www.nutch.org\" rel=\"nofollow\"> ignore </a>"+ + "<a rel=\"nofollow\" href=\"http://www.nutch.org\"> ignore </a>"+ + "</body></html>"),+ // test that POST form actions are skipped+ new String("<html><head></head><body>"+ + "<form method='POST' action='/search.jsp'><input type=text>"+ + "<input type=submit><p>test1</p></form>"+ + "<form method='GET' action='/dummy.jsp'><input type=text>"+ + "<input type=submit><p>test2</p></form></body></html>"),+ // test that all form actions are skipped+ new String("<html><head></head><body>"+ + "<form method='POST' action='/search.jsp'><input type=text>"+ + "<input type=submit><p>test1</p></form>"+ + "<form method='GET' action='/dummy.jsp'><input type=text>"+ + "<input type=submit><p>test2</p></form></body></html>"),+ new String("<html><head><title> title </title>" + "</head><body>"+ + "<a href=\";x\">anchor1</a>" + "<a href=\"g;x\">anchor2</a>"+ + "<a href=\"g;x?y#s\">anchor3</a>" + "</body></html>"),+ new String("<html><head><title> title </title>" + "</head><body>"+ + "<a href=\"g\">anchor1</a>" + "<a href=\"g?y#s\">anchor2</a>"+ + "<a href=\"?y=1\">anchor3</a>" + "<a href=\"?y=1#s\">anchor4</a>"+ + "<a href=\"?y=1;somethingelse\">anchor5</a>" + "</body></html>"), };private static int SKIP = 9;private static String[] testBaseHrefs = { "http://www.nutch.org",- "http://www.nutch.org/docs/foo.html", "http://www.nutch.org/docs/",- "http://www.nutch.org/docs/", "http://www.nutch.org/frames/",- "http://www.nutch.org/maps/", "http://www.nutch.org/whitespace/",- "http://www.nutch.org//", "http://www.nutch.org/",- "http://www.nutch.org/", "http://www.nutch.org/",- "http://www.nutch.org/;something" };+ "http://www.nutch.org/docs/foo.html", "http://www.nutch.org/docs/",+ "http://www.nutch.org/docs/", "http://www.nutch.org/frames/",+ "http://www.nutch.org/maps/", "http://www.nutch.org/whitespace/",+ "http://www.nutch.org//", "http://www.nutch.org/",+ "http://www.nutch.org/", "http://www.nutch.org/",+ "http://www.nutch.org/;something" };private static final DocumentFragment testDOMs[] = new DocumentFragment[testPages.length];private static URL[] testBaseHrefURLs = new URL[testPages.length];private static final String[] answerText = {- "title body anchor",- "title body home bots",- "separate this from this",- "my title body home 1 2",- "my title",- "my title the bottom",- "my title Whitespace test whitespace test "- + "This is a whitespace test . Newlines should appear as space too. "- + "Tabs are spaces too. This is a break -> and the line after break . "- + "one two three space here space there no space "- + "one two two three three four put some text here and there. "- + "End this madness ! . . . .", "ignore ignore", "test1 test2",- "test1 test2", "title anchor1 anchor2 anchor3",- "title anchor1 anchor2 anchor3 anchor4 anchor5" };+ "title body anchor",+ "title body home bots",+ "separate this from this",+ "my title body home 1 2",+ "my title",+ "my title the bottom",+ "my title Whitespace test whitespace test "+ + "This is a whitespace test . Newlines should appear as space too. "+ + "Tabs are spaces too. This is a break -> and the line after break . "+ + "one two three space here space there no space "+ + "one two two three three four put some text here and there. "+ + "End this madness ! . . . .", "ignore ignore", "test1 test2",+ "test1 test2", "title anchor1 anchor2 anchor3",+ "title anchor1 anchor2 anchor3 anchor4 anchor5" };private static final String[] answerTitle = { "title", "title", "",- "my title", "my title", "my title", "my title", "", "", "", "title",- "title" };+ "my title", "my title", "my title", "my title", "", "", "", "title",+ "title" };// note: should be in page-orderprivate static Outlink[][] answerOutlinks;@@ -171,11 +172,8 @@ public class TestDOMContentUtils extends TestCase {private static Configuration conf;private static DOMContentUtils utils = null;- public TestDOMContentUtils(String name) {- super(name);- }-- private static void setup() throws Exception {+ @Before+ public void setup() throws Exception {conf = NutchConfiguration.create();conf.setBoolean("parser.html.form.use_action", true);utils = new DOMContentUtils(conf);@@ -191,43 +189,43 @@ public class TestDOMContentUtils extends TestCase {node);testBaseHrefURLs[i] = new URL(testBaseHrefs[i]);} catch (Exception e) {- assertTrue("caught exception: " + e, false);+ Assert.assertTrue("caught exception: " + e, false);}testDOMs[i] = node;}answerOutlinks = new Outlink[][] {{ new Outlink("http://www.nutch.org", "anchor"), },{ new Outlink("http://www.nutch.org/", "home"),- new Outlink("http://www.nutch.org/docs/bot.html", "bots"), },- { new Outlink("http://www.nutch.org/", "separate this"),+ new Outlink("http://www.nutch.org/docs/bot.html", "bots"), },+ { new Outlink("http://www.nutch.org/", "separate this"),new Outlink("http://www.nutch.org/docs/ok", "from this"), },- { new Outlink("http://www.nutch.org/", "home"),- new Outlink("http://www.nutch.org/docs/1", "1"),- new Outlink("http://www.nutch.org/docs/2", "2"), },- { new Outlink("http://www.nutch.org/frames/top.html", ""),- new Outlink("http://www.nutch.org/frames/left.html", ""),- new Outlink("http://www.nutch.org/frames/invalid.html", ""),- new Outlink("http://www.nutch.org/frames/right.html", ""), },- { new Outlink("http://www.nutch.org/maps/logo.gif", ""),- new Outlink("http://www.nutch.org/index.html", ""),- new Outlink("http://www.nutch.org/maps/#bottom", ""),- new Outlink("http://www.nutch.org/bot.html", ""),- new Outlink("http://www.nutch.org/docs/index.html", ""), },- { new Outlink("http://www.nutch.org/index.html", "whitespace test"), },- {},- { new Outlink("http://www.nutch.org/dummy.jsp", "test2"), },- {},- { new Outlink("http://www.nutch.org/;x", "anchor1"),- new Outlink("http://www.nutch.org/g;x", "anchor2"),- new Outlink("http://www.nutch.org/g;x?y#s", "anchor3") },- {- // this is tricky - see RFC3986 section 5.4.1 example 7- new Outlink("http://www.nutch.org/g", "anchor1"),- new Outlink("http://www.nutch.org/g?y#s", "anchor2"),- new Outlink("http://www.nutch.org/;something?y=1", "anchor3"),- new Outlink("http://www.nutch.org/;something?y=1#s", "anchor4"),- new Outlink("http://www.nutch.org/;something?y=1;somethingelse",- "anchor5") } };+ { new Outlink("http://www.nutch.org/", "home"),+ new Outlink("http://www.nutch.org/docs/1", "1"),+ new Outlink("http://www.nutch.org/docs/2", "2"), },+ { new Outlink("http://www.nutch.org/frames/top.html", ""),+ new Outlink("http://www.nutch.org/frames/left.html", ""),+ new Outlink("http://www.nutch.org/frames/invalid.html", ""),+ new Outlink("http://www.nutch.org/frames/right.html", ""), },+ { new Outlink("http://www.nutch.org/maps/logo.gif", ""),+ new Outlink("http://www.nutch.org/index.html", ""),+ new Outlink("http://www.nutch.org/maps/#bottom", ""),+ new Outlink("http://www.nutch.org/bot.html", ""),+ new Outlink("http://www.nutch.org/docs/index.html", ""), },+ { new Outlink("http://www.nutch.org/index.html", "whitespace test"), },+ {},+ { new Outlink("http://www.nutch.org/dummy.jsp", "test2"), },+ {},+ { new Outlink("http://www.nutch.org/;x", "anchor1"),+ new Outlink("http://www.nutch.org/g;x", "anchor2"),+ new Outlink("http://www.nutch.org/g;x?y#s", "anchor3") },+ {+ // this is tricky - see RFC3986 section 5.4.1 example 7+ new Outlink("http://www.nutch.org/g", "anchor1"),+ new Outlink("http://www.nutch.org/g?y#s", "anchor2"),+ new Outlink("http://www.nutch.org/;something?y=1", "anchor3"),+ new Outlink("http://www.nutch.org/;something?y=1#s", "anchor4"),+ new Outlink("http://www.nutch.org/;something?y=1;somethingelse",+ "anchor5") } };}@@ -246,6 +244,7 @@ public class TestDOMContentUtils extends TestCase {return true;}+ @Testpublic void testGetText() throws Exception {if (testDOMs[0] == null)setup();@@ -253,14 +252,15 @@ public class TestDOMContentUtils extends TestCase {StringBuffer sb = new StringBuffer();utils.getText(sb, testDOMs[i]);String text = sb.toString();- assertTrue(+ Assert.assertTrue("expecting text: " + answerText[i]+ System.getProperty("line.separator")+ System.getProperty("line.separator") + "got text: " + text,- equalsIgnoreWhitespace(answerText[i], text));+ equalsIgnoreWhitespace(answerText[i], text));}}+ @Testpublic void testGetTitle() throws Exception {if (testDOMs[0] == null)setup();@@ -268,14 +268,15 @@ public class TestDOMContentUtils extends TestCase {StringBuffer sb = new StringBuffer();utils.getTitle(sb, testDOMs[i]);String text = sb.toString();- assertTrue(+ Assert.assertTrue("expecting text: " + answerText[i]+ System.getProperty("line.separator")+ System.getProperty("line.separator") + "got text: " + text,- equalsIgnoreWhitespace(answerTitle[i], text));+ equalsIgnoreWhitespace(answerTitle[i], text));}}+ @Testpublic void testGetOutlinks() throws Exception {if (testDOMs[0] == null)setup();@@ -310,26 +311,26 @@ public class TestDOMContentUtils extends TestCase {private static final void compareOutlinks(Outlink[] o1, Outlink[] o2) {if (o1.length != o2.length) {- assertTrue(+ Assert.assertTrue("got wrong number of outlinks (expecting " + o1.length + ", got "+ o2.length + ")" + System.getProperty("line.separator")+ "answer: " + System.getProperty("line.separator")+ outlinksString(o1) + System.getProperty("line.separator")+ "got: " + System.getProperty("line.separator")+ outlinksString(o2) + System.getProperty("line.separator"),- false);+ false);}for (int i = 0; i < o1.length; i++) {if (!o1[i].equals(o2[i])) {- assertTrue(+ Assert.assertTrue("got wrong outlinks at position " + i- + System.getProperty("line.separator") + "answer: "- + System.getProperty("line.separator") + "'" + o1[i].getToUrl()- + "', anchor: '" + o1[i].getAnchor() + "'"- + System.getProperty("line.separator") + "got: "- + System.getProperty("line.separator") + "'" + o2[i].getToUrl()- + "', anchor: '" + o2[i].getAnchor() + "'", false);+ + System.getProperty("line.separator") + "answer: "+ + System.getProperty("line.separator") + "'" + o1[i].getToUrl()+ + "', anchor: '" + o1[i].getAnchor() + "'"+ + System.getProperty("line.separator") + "got: "+ + System.getProperty("line.separator") + "'" + o2[i].getToUrl()+ + "', anchor: '" + o2[i].getAnchor() + "'", false);}}}diff --git a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestFeedParser.java b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestFeedParser.javaindex ba542c59d..6b9f6a11e 100644--- a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestFeedParser.java+++ b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestFeedParser.java@@ -17,8 +17,8 @@package org.apache.nutch.tika;-import junit.framework.TestCase;-+import org.junit.Assert;+import org.junit.Test;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.apache.hadoop.conf.Configuration;@@ -43,88 +43,79 @@ import org.apache.nutch.util.NutchConfiguration;* Test Suite for the RSS feeds with the {@link TikaParser}.**/-public class TestFeedParser extends TestCase {-- private String fileSeparator = System.getProperty("file.separator");-- // This system property is defined in ./src/plugin/build-plugin.xml- private String sampleDir = System.getProperty("test.data", ".");-- private String[] sampleFiles = { "rsstest.rss" };-- public static final Logger LOG = LoggerFactory.getLogger(TestFeedParser.class- .getName());-- /**- * Default Constructor.- *- * @param name- * The name of this {@link TestCase}.- */- public TestFeedParser(String name) {- super(name);- }-- /**- * <p>- * The test method: tests out the following 2 asserts:- * </p>- *- * <ul>- * <li>There are 3 outlinks read from the sample rss file</li>- * <li>The 3 outlinks read are in fact the correct outlinks from the sample- * file</li>- * </ul>- */- public void testIt() throws ProtocolException, ParseException {- String urlString;- Protocol protocol;- Content content;- Parse parse;-- Configuration conf = NutchConfiguration.create();- for (int i = 0; i < sampleFiles.length; i++) {- urlString = "file:" + sampleDir + fileSeparator + sampleFiles[i];-- protocol = new ProtocolFactory(conf).getProtocol(urlString);- content = protocol.getProtocolOutput(new Text(urlString),- new CrawlDatum()).getContent();- parse = new ParseUtil(conf).parseByExtensionId("parse-tika",- content).get(content.getUrl());-- // check that there are 2 outlinks:- // unlike the original parse-rss- // tika ignores the URL and description of the channel-- // http://test.channel.com- // http://www-scf.usc.edu/~mattmann/- // http://www.nutch.org-- ParseData theParseData = parse.getData();-- Outlink[] theOutlinks = theParseData.getOutlinks();-- assertTrue("There aren't 2 outlinks read!",- theOutlinks.length == 2);-- // now check to make sure that those are the two outlinks- boolean hasLink1 = false, hasLink2 = false;-- for (int j = 0; j < theOutlinks.length; j++) {- if (theOutlinks[j].getToUrl().equals(- "http://www-scf.usc.edu/~mattmann/")) {- hasLink1 = true;- }-- if (theOutlinks[j].getToUrl().equals("http://www.nutch.org/")) {- hasLink2 = true;- }- }-- if (!hasLink1 || !hasLink2) {- fail("Outlinks read from sample rss file are not correct!");- }- }- }+public class TestFeedParser {++ private String fileSeparator = System.getProperty("file.separator");++ // This system property is defined in ./src/plugin/build-plugin.xml+ private String sampleDir = System.getProperty("test.data", ".");++ private String[] sampleFiles = { "rsstest.rss" };++ public static final Logger LOG = LoggerFactory.getLogger(TestFeedParser.class+ .getName());++ /**+ * <p>+ * The test method: tests out the following 2 asserts:+ * </p>+ *+ * <ul>+ * <li>There are 3 outlinks read from the sample rss file</li>+ * <li>The 3 outlinks read are in fact the correct outlinks from the sample+ * file</li>+ * </ul>+ */+ @Test+ public void testIt() throws ProtocolException, ParseException {+ String urlString;+ Protocol protocol;+ Content content;+ Parse parse;++ Configuration conf = NutchConfiguration.create();+ for (int i = 0; i < sampleFiles.length; i++) {+ urlString = "file:" + sampleDir + fileSeparator + sampleFiles[i];++ protocol = new ProtocolFactory(conf).getProtocol(urlString);+ content = protocol.getProtocolOutput(new Text(urlString),+ new CrawlDatum()).getContent();+ parse = new ParseUtil(conf).parseByExtensionId("parse-tika",+ content).get(content.getUrl());++ // check that there are 2 outlinks:+ // unlike the original parse-rss+ // tika ignores the URL and description of the channel++ // http://test.channel.com+ // http://www-scf.usc.edu/~mattmann/+ // http://www.nutch.org++ ParseData theParseData = parse.getData();++ Outlink[] theOutlinks = theParseData.getOutlinks();++ Assert.assertTrue("There aren't 2 outlinks read!",+ theOutlinks.length == 2);++ // now check to make sure that those are the two outlinks+ boolean hasLink1 = false, hasLink2 = false;++ for (int j = 0; j < theOutlinks.length; j++) {+ if (theOutlinks[j].getToUrl().equals(+ "http://www-scf.usc.edu/~mattmann/")) {+ hasLink1 = true;+ }++ if (theOutlinks[j].getToUrl().equals("http://www.nutch.org/")) {+ hasLink2 = true;+ }+ }++ if (!hasLink1 || !hasLink2) {+ Assert.fail("Outlinks read from sample rss file are not correct!");+ }+ }+ }}diff --git a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestImageMetadata.java b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestImageMetadata.javaindex c479a10c8..0df7083b1 100644--- a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestImageMetadata.java+++ b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestImageMetadata.java@@ -21,22 +21,20 @@ import org.apache.nutch.protocol.ProtocolFactory;import org.apache.nutch.protocol.Protocol;import org.apache.nutch.protocol.Content;import org.apache.nutch.protocol.ProtocolException;-import org.apache.nutch.parse.Parse;import org.apache.nutch.parse.ParseUtil;import org.apache.nutch.parse.ParseException;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;-import org.apache.hadoop.io.Text;import org.apache.nutch.crawl.CrawlDatum;--import junit.framework.TestCase;+import org.junit.Assert;+import org.junit.Test;/*** Test extraction of image metadata*/-public class TestImageMetadata extends TestCase {+public class TestImageMetadata {private String fileSeparator = System.getProperty("file.separator");// This system property is defined in ./src/plugin/build-plugin.xml@@ -46,10 +44,7 @@ public class TestImageMetadata extends TestCase {"nutch_logo_tm.gif",};- public TestImageMetadata(String name) {- super(name);- }-+ @Testpublic void testIt() throws ProtocolException, ParseException {String urlString;Protocol protocol;@@ -64,8 +59,8 @@ public class TestImageMetadata extends TestCase {content = protocol.getProtocolOutput(new Text(urlString), new CrawlDatum()).getContent();parse = new ParseUtil(conf).parseByExtensionId("parse-tika", content).get(content.getUrl());- assertEquals("121", parse.getData().getMeta("width"));- assertEquals("48", parse.getData().getMeta("height"));+ Assert.assertEquals("121", parse.getData().getMeta("width"));+ Assert.assertEquals("48", parse.getData().getMeta("height"));}}diff --git a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestMSWordParser.java b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestMSWordParser.javaindex ea0171f91..90f1309ae 100644--- a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestMSWordParser.java+++ b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestMSWordParser.java@@ -21,28 +21,25 @@ import org.apache.nutch.protocol.ProtocolFactory;import org.apache.nutch.protocol.Protocol;import org.apache.nutch.protocol.Content;import org.apache.nutch.protocol.ProtocolException;-import org.apache.nutch.parse.Parse;-import org.apache.nutch.parse.ParseImpl;import org.apache.nutch.parse.ParseUtil;import org.apache.nutch.parse.ParseException;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;-import org.apache.hadoop.io.Text;import org.apache.nutch.crawl.CrawlDatum;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;import java.io.File;-import java.io.FilenameFilter;--import junit.framework.TestCase;/*** Unit tests for MSWordParser.** @author John Xing*/-public class TestMSWordParser extends TestCase {+public class TestMSWordParser {private String fileSeparator = System.getProperty("file.separator");// This system property is defined in ./src/plugin/build-plugin.xml@@ -53,20 +50,15 @@ public class TestMSWordParser extends TestCase {private String[] sampleFiles = {"word97.doc"};private String expectedText = "This is a sample doc file prepared for nutch.";-- private Configuration conf;- public TestMSWordParser(String name) {- super(name);- }+ private Configuration conf;- protected void setUp() {+ @Before+ public void setUp() {conf = NutchConfiguration.create();conf.set("file.content.limit", "-1");}- protected void tearDown() {}-public String getTextContent(String fileName) throws ProtocolException, ParseException {String urlString = "file:" + sampleDir + fileSeparator + fileName;Protocol protocol = new ProtocolFactory(conf).getProtocol(urlString);@@ -74,19 +66,21 @@ public class TestMSWordParser extends TestCase {Parse parse = new ParseUtil(conf).parseByExtensionId("parse-tika", content).get(content.getUrl());return parse.getText();}-++ @Testpublic void testIt() throws ProtocolException, ParseException {for (int i=0; i<sampleFiles.length; i++) {String found = getTextContent(sampleFiles[i]);- assertTrue("text found : '"+found+"'",found.startsWith(expectedText));+ Assert.assertTrue("text found : '"+found+"'",found.startsWith(expectedText));}}+ @Testpublic void testOpeningDocs() throws ProtocolException, ParseException {String[] filenames = new File(sampleDir).list();- for (int i = 0; i < filenames.length; i++) {- if (filenames[i].endsWith(".doc")==false) continue;- assertTrue("cann't read content of " + filenames[i], getTextContent(filenames[i]).length() > 0);- }+ for (int i = 0; i < filenames.length; i++) {+ if (filenames[i].endsWith(".doc")==false) continue;+ Assert.assertTrue("cann't read content of " + filenames[i], getTextContent(filenames[i]).length() > 0);+ }}}diff --git a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestOOParser.java b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestOOParser.javaindex 49bc2fbbb..1c7205d92 100644--- a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestOOParser.java+++ b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestOOParser.java@@ -24,20 +24,19 @@ import org.apache.nutch.crawl.CrawlDatum;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.io.Text;import org.apache.nutch.protocol.*;-import org.apache.nutch.parse.Parse;import org.apache.nutch.parse.ParseException;import org.apache.nutch.parse.ParseUtil;import org.apache.nutch.util.NutchConfiguration;--import junit.framework.TestCase;+import org.junit.Assert;+import org.junit.Test;/*** Unit tests for OOParser.** @author Andrzej Bialecki*/-public class TestOOParser extends TestCase {+public class TestOOParser {private String fileSeparator = System.getProperty("file.separator");// This system property is defined in ./src/plugin/build-plugin.xml@@ -46,35 +45,11 @@ public class TestOOParser extends TestCase {// ./src/plugin/parse-oo/build.xml during plugin compilation.private String[] sampleFiles = {"ootest.odt", "ootest.sxw"};- private String sampleText = "ootest.txt";-private String expectedText;++ private String sampleText = "ootest.txt";- public TestOOParser(String name) {- super(name);- try {- // read the test string- FileInputStream fis = new FileInputStream(sampleDir + fileSeparator + sampleText);- StringBuffer sb = new StringBuffer();- int len = 0;- InputStreamReader isr = new InputStreamReader(fis, "UTF-8");- char[] buf = new char[1024];- while ((len = isr.read(buf)) > 0) {- sb.append(buf, 0, len);- }- isr.close();- expectedText = sb.toString();- // normalize space- expectedText = expectedText.replaceAll("[ \t\r\n]+", " ");- } catch (Exception e) {- e.printStackTrace();- }- }-- protected void setUp() {}-- protected void tearDown() {}-+ @Testpublic void testIt() throws ProtocolException, ParseException {String urlString;Content content;@@ -84,24 +59,45 @@ public class TestOOParser extends TestCase {ProtocolFactory factory = new ProtocolFactory(conf);System.out.println("Expected : "+expectedText);-+for (int i=0; i<sampleFiles.length; i++) {urlString = "file:" + sampleDir + fileSeparator + sampleFiles[i];if (sampleFiles[i].startsWith("ootest")==false) continue;-+protocol = factory.getProtocol(urlString);content = protocol.getProtocolOutput(new Text(urlString), new CrawlDatum()).getContent();parse = new ParseUtil(conf).parseByExtensionId("parse-tika", content).get(content.getUrl());-+String text = parse.getText().replaceAll("[ \t\r\n]+", " ").trim();// simply test for the presence of a text - the ordering of the elements may differ from what was expected// in the previous tests- assertTrue(text!=null && text.length() > 0);-+ Assert.assertTrue(text!=null && text.length() > 0);+System.out.println("Found "+sampleFiles[i]+": "+text);}}+ public TestOOParser() {+ try {+ // read the test string+ FileInputStream fis = new FileInputStream(sampleDir + fileSeparator + sampleText);+ StringBuffer sb = new StringBuffer();+ int len = 0;+ InputStreamReader isr = new InputStreamReader(fis, "UTF-8");+ char[] buf = new char[1024];+ while ((len = isr.read(buf)) > 0) {+ sb.append(buf, 0, len);+ }+ isr.close();+ expectedText = sb.toString();+ // normalize space+ expectedText = expectedText.replaceAll("[ \t\r\n]+", " ");+ } catch (Exception e) {+ e.printStackTrace();+ }+ }++}diff --git a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestPdfParser.java b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestPdfParser.javaindex df6f2f20e..dbd3b27b1 100644--- a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestPdfParser.java+++ b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestPdfParser.java@@ -21,24 +21,22 @@ import org.apache.nutch.protocol.ProtocolFactory;import org.apache.nutch.protocol.Protocol;import org.apache.nutch.protocol.Content;import org.apache.nutch.protocol.ProtocolException;-import org.apache.nutch.parse.Parse;import org.apache.nutch.parse.ParseUtil;import org.apache.nutch.parse.ParseException;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;-import org.apache.hadoop.io.Text;import org.apache.nutch.crawl.CrawlDatum;--import junit.framework.TestCase;+import org.junit.Assert;+import org.junit.Test;/*** Unit tests for PdfParser.** @author John Xing*/-public class TestPdfParser extends TestCase {+public class TestPdfParser {private String fileSeparator = System.getProperty("file.separator");// This system property is defined in ./src/plugin/build-plugin.xml@@ -53,14 +51,7 @@ public class TestPdfParser extends TestCase {private String expectedText = "A VERY SMALL PDF FILE";- public TestPdfParser(String name) {- super(name);- }-- protected void setUp() {}-- protected void tearDown() {}-+ @Testpublic void testIt() throws ProtocolException, ParseException {String urlString;Protocol protocol;@@ -76,7 +67,7 @@ public class TestPdfParser extends TestCase {parse = new ParseUtil(conf).parseByExtensionId("parse-tika", content).get(content.getUrl());int index = parse.getText().indexOf(expectedText);- assertTrue(index > 0);+ Assert.assertTrue(index > 0);}}diff --git a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestRTFParser.java b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestRTFParser.javaindex b3c3fe3ba..2d5663d23 100644--- a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestRTFParser.java+++ b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestRTFParser.java@@ -1,5 +1,3 @@-package org.apache.nutch.tika;-/*** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -16,9 +14,7 @@ package org.apache.nutch.tika;* See the License for the specific language governing permissions and* limitations under the License.*/--// JUnit imports-import junit.framework.TestCase;+package org.apache.nutch.tika;// Nutch importsimport org.apache.nutch.crawl.CrawlDatum;@@ -36,56 +32,49 @@ import org.apache.nutch.util.NutchConfiguration;// Hadoop importsimport org.apache.hadoop.conf.Configuration;import org.apache.hadoop.io.Text;+import org.junit.Assert;+import org.junit.Ignore;+import org.junit.Test;/*** Unit tests for TestRTFParser. (Adapted from John Xing msword unit tests).** @author Andy Hedges*/-public class TestRTFParser extends TestCase {-- private String fileSeparator = System.getProperty("file.separator");- // This system property is defined in ./src/plugin/build-plugin.xml- private String sampleDir = System.getProperty("test.data", ".");- // Make sure sample files are copied to "test.data" as specified in- // ./src/plugin/parse-rtf/build.xml during plugin compilation.- // Check ./src/plugin/parse-rtf/sample/README.txt for what they are.- private String rtfFile = "test.rtf";-- public TestRTFParser(String name) {- super(name);- }+public class TestRTFParser {- protected void setUp() {- }+ private String fileSeparator = System.getProperty("file.separator");+ // This system property is defined in ./src/plugin/build-plugin.xml+ private String sampleDir = System.getProperty("test.data", ".");+ // Make sure sample files are copied to "test.data" as specified in+ // ./src/plugin/parse-rtf/build.xml during plugin compilation.+ // Check ./src/plugin/parse-rtf/sample/README.txt for what they are.+ private String rtfFile = "test.rtf";- protected void tearDown() {- }+ @Ignore("There seems to be an issue with line 71 e.g. text.trim()")+ @Test+ public void testIt() throws ProtocolException, ParseException {- public void testIt() throws ProtocolException, ParseException {- /* Temporarily disabled - see Tika-748+ String urlString;+ Protocol protocol;+ Content content;+ Parse parse;- String urlString;- Protocol protocol;- Content content;- Parse parse;+ Configuration conf = NutchConfiguration.create();+ urlString = "file:" + sampleDir + fileSeparator + rtfFile;+ protocol = new ProtocolFactory(conf).getProtocol(urlString);+ content = protocol.getProtocolOutput(new Text(urlString),+ new CrawlDatum()).getContent();+ parse = new ParseUtil(conf).parseByExtensionId("parse-tika", content)+ .get(content.getUrl());+ String text = parse.getText();+ Assert.assertEquals("The quick brown fox jumps over the lazy dog", text.trim());- Configuration conf = NutchConfiguration.create();- urlString = "file:" + sampleDir + fileSeparator + rtfFile;- protocol = new ProtocolFactory(conf).getProtocol(urlString);- content = protocol.getProtocolOutput(new Text(urlString),- new CrawlDatum()).getContent();- parse = new ParseUtil(conf).parseByExtensionId("parse-tika", content)- .get(content.getUrl());- String text = parse.getText();- assertEquals("The quick brown fox jumps over the lazy dog", text.trim());+ String title = parse.getData().getTitle();+ Metadata meta = parse.getData().getParseMeta();- String title = parse.getData().getTitle();- Metadata meta = parse.getData().getParseMeta();+ Assert.assertEquals("test rft document", title);+ Assert.assertEquals("tests", meta.get(DublinCore.SUBJECT));- // METADATA extraction is not yet supported in Tika- // assertEquals("test rft document", title);- // assertEquals("tests", meta.get(DublinCore.SUBJECT));- */- }+ }}diff --git a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestRobotsMetaProcessor.java b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestRobotsMetaProcessor.javaindex b340e3562..09d541a40 100644--- a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestRobotsMetaProcessor.java+++ b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestRobotsMetaProcessor.java@@ -17,8 +17,6 @@package org.apache.nutch.tika;-import junit.framework.TestCase;-import org.apache.nutch.parse.HTMLMetaTags;import org.apache.nutch.parse.tika.HTMLMetaProcessor;@@ -29,12 +27,11 @@ import org.xml.sax.*;import org.w3c.dom.*;import org.apache.html.dom.*;import org.cyberneko.html.parsers.DOMFragmentParser;+import org.junit.Assert;+import org.junit.Test;/** Unit tests for HTMLMetaProcessor. */-public class TestRobotsMetaProcessor extends TestCase {- public TestRobotsMetaProcessor(String name) {- super(name);- }+public class TestRobotsMetaProcessor {/*@@ -47,71 +44,71 @@ public class TestRobotsMetaProcessor extends TestCase {<META HTTP-EQUIV="Pragma" CONTENT="no-cache">- */+ */public static String[] tests=- {- "<html><head><title>test page</title>"- + "<META NAME=\"ROBOTS\" CONTENT=\"NONE\"> "- + "<META HTTP-EQUIV=\"PRAGMA\" CONTENT=\"NO-CACHE\"> "- + "</head><body>"- + " some text"- + "</body></html>",-- "<html><head><title>test page</title>"- + "<meta name=\"robots\" content=\"all\"> "- + "<meta http-equiv=\"pragma\" content=\"no-cache\"> "- + "</head><body>"- + " some text"- + "</body></html>",-+ {"<html><head><title>test page</title>"- + "<MeTa NaMe=\"RoBoTs\" CoNtEnT=\"nOnE\"> "- + "<MeTa HtTp-EqUiV=\"pRaGmA\" cOnTeNt=\"No-CaChE\"> "- + "</head><body>"- + " some text"- + "</body></html>",-- "<html><head><title>test page</title>"- + "<meta name=\"robots\" content=\"none\"> "- + "</head><body>"- + " some text"- + "</body></html>",-- "<html><head><title>test page</title>"- + "<meta name=\"robots\" content=\"noindex,nofollow\"> "- + "</head><body>"- + " some text"- + "</body></html>",-- "<html><head><title>test page</title>"- + "<meta name=\"robots\" content=\"noindex,follow\"> "- + "</head><body>"- + " some text"- + "</body></html>",-- "<html><head><title>test page</title>"- + "<meta name=\"robots\" content=\"index,nofollow\"> "- + "</head><body>"- + " some text"- + "</body></html>",-- "<html><head><title>test page</title>"- + "<meta name=\"robots\" content=\"index,follow\"> "- + "<base href=\"http://www.nutch.org/\">"- + "</head><body>"- + " some text"- + "</body></html>",-- "<html><head><title>test page</title>"- + "<meta name=\"robots\"> "- + "<base href=\"http://www.nutch.org/base/\">"- + "</head><body>"- + " some text"- + "</body></html>",-- };+ + "<META NAME=\"ROBOTS\" CONTENT=\"NONE\"> "+ + "<META HTTP-EQUIV=\"PRAGMA\" CONTENT=\"NO-CACHE\"> "+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<meta name=\"robots\" content=\"all\"> "+ + "<meta http-equiv=\"pragma\" content=\"no-cache\"> "+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<MeTa NaMe=\"RoBoTs\" CoNtEnT=\"nOnE\"> "+ + "<MeTa HtTp-EqUiV=\"pRaGmA\" cOnTeNt=\"No-CaChE\"> "+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<meta name=\"robots\" content=\"none\"> "+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<meta name=\"robots\" content=\"noindex,nofollow\"> "+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<meta name=\"robots\" content=\"noindex,follow\"> "+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<meta name=\"robots\" content=\"index,nofollow\"> "+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<meta name=\"robots\" content=\"index,follow\"> "+ + "<base href=\"http://www.nutch.org/\">"+ + "</head><body>"+ + " some text"+ + "</body></html>",++ "<html><head><title>test page</title>"+ + "<meta name=\"robots\"> "+ + "<base href=\"http://www.nutch.org/base/\">"+ + "</head><body>"+ + " some text"+ + "</body></html>",++ };public static final boolean[][] answers= {{true, true, true}, // NONE@@ -127,25 +124,26 @@ public class TestRobotsMetaProcessor extends TestCase {private URL[][] currURLsAndAnswers;+ @Testpublic void testRobotsMetaProcessor() {DOMFragmentParser parser= new DOMFragmentParser();;try {currURLsAndAnswers= new URL[][] {- {new URL("http://www.nutch.org"), null},- {new URL("http://www.nutch.org"), null},- {new URL("http://www.nutch.org"), null},- {new URL("http://www.nutch.org"), null},- {new URL("http://www.nutch.org"), null},- {new URL("http://www.nutch.org"), null},- {new URL("http://www.nutch.org"), null},- {new URL("http://www.nutch.org/foo/"),- new URL("http://www.nutch.org/")},- {new URL("http://www.nutch.org"),- new URL("http://www.nutch.org/base/")}+ {new URL("http://www.nutch.org"), null},+ {new URL("http://www.nutch.org"), null},+ {new URL("http://www.nutch.org"), null},+ {new URL("http://www.nutch.org"), null},+ {new URL("http://www.nutch.org"), null},+ {new URL("http://www.nutch.org"), null},+ {new URL("http://www.nutch.org"), null},+ {new URL("http://www.nutch.org/foo/"),+ new URL("http://www.nutch.org/")},+ {new URL("http://www.nutch.org"),+ new URL("http://www.nutch.org/base/")}};} catch (Exception e) {- assertTrue("couldn't make test URLs!", false);+ Assert.assertTrue("couldn't make test URLs!", false);}for (int i= 0; i < tests.length; i++) {@@ -161,22 +159,22 @@ public class TestRobotsMetaProcessor extends TestCase {HTMLMetaTags robotsMeta= new HTMLMetaTags();HTMLMetaProcessor.getMetaTags(robotsMeta, node,- currURLsAndAnswers[i][0]);-- assertTrue("got index wrong on test " + i,- robotsMeta.getNoIndex() == answers[i][0]);- assertTrue("got follow wrong on test " + i,- robotsMeta.getNoFollow() == answers[i][1]);- assertTrue("got cache wrong on test " + i,- robotsMeta.getNoCache() == answers[i][2]);- assertTrue("got base href wrong on test " + i + " (got "- + robotsMeta.getBaseHref() + ")",- ( (robotsMeta.getBaseHref() == null)- && (currURLsAndAnswers[i][1] == null) )- || ( (robotsMeta.getBaseHref() != null)- && robotsMeta.getBaseHref().equals(- currURLsAndAnswers[i][1]) ) );-+ currURLsAndAnswers[i][0]);++ Assert.assertTrue("got index wrong on test " + i,+ robotsMeta.getNoIndex() == answers[i][0]);+ Assert.assertTrue("got follow wrong on test " + i,+ robotsMeta.getNoFollow() == answers[i][1]);+ Assert.assertTrue("got cache wrong on test " + i,+ robotsMeta.getNoCache() == answers[i][2]);+ Assert.assertTrue("got base href wrong on test " + i + " (got "+ + robotsMeta.getBaseHref() + ")",+ ( (robotsMeta.getBaseHref() == null)+ && (currURLsAndAnswers[i][1] == null) )+ || ( (robotsMeta.getBaseHref() != null)+ && robotsMeta.getBaseHref().equals(+ currURLsAndAnswers[i][1]) ) );+}}diff --git a/src/plugin/parse-zip/src/test/org/apache/nutch/parse/zip/TestZipParser.java b/src/plugin/parse-zip/src/test/org/apache/nutch/parse/zip/TestZipParser.javaindex 57c05e653..69ef48c10 100644--- a/src/plugin/parse-zip/src/test/org/apache/nutch/parse/zip/TestZipParser.java+++ b/src/plugin/parse-zip/src/test/org/apache/nutch/parse/zip/TestZipParser.java@@ -21,25 +21,22 @@ import org.apache.nutch.protocol.ProtocolFactory;import org.apache.nutch.protocol.Protocol;import org.apache.nutch.protocol.Content;import org.apache.nutch.protocol.ProtocolException;-import org.apache.nutch.parse.Parse;-import org.apache.nutch.parse.ParseImpl;import org.apache.nutch.parse.ParseUtil;import org.apache.nutch.parse.ParseException;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;-import org.apache.hadoop.io.Text;import org.apache.nutch.crawl.CrawlDatum;--import junit.framework.TestCase;+import org.junit.Assert;+import org.junit.Test;/*** Based on Unit tests for MSWordParser by John Xing** @author Rohit Kulkarni & Ashish Vaidya*/-public class TestZipParser extends TestCase {+public class TestZipParser {private String fileSeparator = System.getProperty("file.separator");// This system property is defined in ./src/plugin/build-plugin.xml@@ -51,14 +48,7 @@ public class TestZipParser extends TestCase {private String expectedText = "textfile.txt This is text file number 1 ";- public TestZipParser(String name) {- super(name);- }-- protected void setUp() {}-- protected void tearDown() {}-+ @Testpublic void testIt() throws ProtocolException, ParseException {String urlString;Protocol protocol;@@ -72,7 +62,7 @@ public class TestZipParser extends TestCase {protocol = new ProtocolFactory(conf).getProtocol(urlString);content = protocol.getProtocolOutput(new Text(urlString), new CrawlDatum()).getContent();parse = new ParseUtil(conf).parseByExtensionId("parse-zip",content).get(content.getUrl());- assertTrue(parse.getText().equals(expectedText));+ Assert.assertTrue(parse.getText().equals(expectedText));}}diff --git a/src/plugin/protocol-file/src/test/org/apache/nutch/protocol/file/TestProtocolFile.java b/src/plugin/protocol-file/src/test/org/apache/nutch/protocol/file/TestProtocolFile.javaindex 3618fc642..3f9e693a5 100644--- a/src/plugin/protocol-file/src/test/org/apache/nutch/protocol/file/TestProtocolFile.java+++ b/src/plugin/protocol-file/src/test/org/apache/nutch/protocol/file/TestProtocolFile.java@@ -30,9 +30,9 @@ import org.apache.nutch.protocol.ProtocolFactory;import org.apache.nutch.protocol.ProtocolOutput;import org.apache.nutch.protocol.ProtocolStatus;import org.apache.nutch.util.NutchConfiguration;--// Junit imports-import junit.framework.TestCase;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;/*** @author mattmann@@ -43,13 +43,13 @@ import junit.framework.TestCase;* </p>* .*/-public class TestProtocolFile extends TestCase {+public class TestProtocolFile {private String fileSeparator = System.getProperty("file.separator");private String sampleDir = System.getProperty("test.data", ".");private static final String[] testTextFiles = new String[] {- "testprotocolfile.txt", "testprotocolfile_(encoded).txt", "testprotocolfile_%28encoded%29.txt" };+ "testprotocolfile.txt", "testprotocolfile_(encoded).txt", "testprotocolfile_%28encoded%29.txt" };private static final CrawlDatum datum = new CrawlDatum();@@ -57,10 +57,12 @@ public class TestProtocolFile extends TestCase {private Configuration conf;- protected void setUp() {+ @Before+ public void setUp() {conf = NutchConfiguration.create();}+ @Testpublic void testSetContentType() throws ProtocolException {for (String testTextFile : testTextFiles) {setContentType(testTextFile);@@ -75,20 +77,20 @@ public class TestProtocolFile extends TestCase {*/public void setContentType(String testTextFile) throws ProtocolException {String urlString = "file:" + sampleDir + fileSeparator + testTextFile;- assertNotNull(urlString);+ Assert.assertNotNull(urlString);Protocol protocol = new ProtocolFactory(conf).getProtocol(urlString);ProtocolOutput output = protocol.getProtocolOutput(new Text(urlString),datum);- assertNotNull(output);- assertEquals("Status code: [" + output.getStatus().getCode()+ Assert.assertNotNull(output);+ Assert.assertEquals("Status code: [" + output.getStatus().getCode()+ "], not equal to: [" + ProtocolStatus.SUCCESS + "]: args: ["+ output.getStatus().getArgs() + "]", ProtocolStatus.SUCCESS, output.getStatus().getCode());- assertNotNull(output.getContent());- assertNotNull(output.getContent().getContentType());- assertEquals(expectedMimeType, output.getContent().getContentType());- assertNotNull(output.getContent().getMetadata());- assertEquals(expectedMimeType,+ Assert.assertNotNull(output.getContent());+ Assert.assertNotNull(output.getContent().getContentType());+ Assert.assertEquals(expectedMimeType, output.getContent().getContentType());+ Assert.assertNotNull(output.getContent().getMetadata());+ Assert.assertEquals(expectedMimeType,output.getContent().getMetadata().get(Response.CONTENT_TYPE));}diff --git a/src/plugin/protocol-httpclient/src/test/org/apache/nutch/protocol/httpclient/TestProtocolHttpClient.java b/src/plugin/protocol-httpclient/src/test/org/apache/nutch/protocol/httpclient/TestProtocolHttpClient.javaindex c1bf0aa8e..6e566fdfe 100644--- a/src/plugin/protocol-httpclient/src/test/org/apache/nutch/protocol/httpclient/TestProtocolHttpClient.java+++ b/src/plugin/protocol-httpclient/src/test/org/apache/nutch/protocol/httpclient/TestProtocolHttpClient.java@@ -18,8 +18,10 @@package org.apache.nutch.protocol.httpclient;import java.net.URL;-import java.net.MalformedURLException;-import junit.framework.TestCase;+import org.junit.After;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;import org.mortbay.jetty.Server;import org.mortbay.jetty.bio.SocketConnector;import org.mortbay.jetty.handler.ContextHandler;@@ -32,7 +34,7 @@ import org.apache.nutch.net.protocols.Response;/*** Test cases for protocol-httpclient.*/-public class TestProtocolHttpClient extends TestCase {+public class TestProtocolHttpClient {private Server server;private Configuration conf;@@ -40,7 +42,9 @@ public class TestProtocolHttpClient extends TestCase {private int port;private Http http = new Http();- protected void setUp() throws Exception {+ @SuppressWarnings("deprecation")+ @Before+ public void setUp() throws Exception {ContextHandler context = new ContextHandler();context.setContextPath("/");@@ -61,7 +65,8 @@ public class TestProtocolHttpClient extends TestCase {http.setConf(conf);}- protected void tearDown() throws Exception {+ @After+ public void tearDown() throws Exception {server.stop();}@@ -70,6 +75,7 @@ public class TestProtocolHttpClient extends TestCase {** @throws Exception If an error occurs or the test case fails.*/+ @Testpublic void testCookies() throws Exception {startServer(47500);fetchPage("/cookies.jsp", 200);@@ -82,6 +88,7 @@ public class TestProtocolHttpClient extends TestCase {** @throws Exception If an error occurs or the test case fails.*/+ @Testpublic void testNoPreemptiveAuth() throws Exception {startServer(47500);fetchPage("/noauth.jsp", 200);@@ -92,6 +99,7 @@ public class TestProtocolHttpClient extends TestCase {** @throws Exception If an error occurs or the test case fails.*/+ @Testpublic void testDefaultCredentials() throws Exception {startServer(47502);fetchPage("/basic.jsp", 200);@@ -102,6 +110,7 @@ public class TestProtocolHttpClient extends TestCase {** @throws Exception If an error occurs or the test case fails.*/+ @Testpublic void testBasicAuth() throws Exception {startServer(47500);fetchPage("/basic.jsp", 200);@@ -117,6 +126,7 @@ public class TestProtocolHttpClient extends TestCase {** @throws Exception If an error occurs or the test case fails.*/+ @Testpublic void testOtherRealmsNoAuth() throws Exception {startServer(47501);fetchPage("/basic.jsp", 200);@@ -129,6 +139,7 @@ public class TestProtocolHttpClient extends TestCase {** @throws Exception If an error occurs or the test case fails.*/+ @Testpublic void testDigestAuth() throws Exception {startServer(47500);fetchPage("/digest.jsp", 200);@@ -139,6 +150,7 @@ public class TestProtocolHttpClient extends TestCase {** @throws Exception If an error occurs or the test case fails.*/+ @Testpublic void testNtlmAuth() throws Exception {startServer(47501);fetchPage("/ntlm.jsp", 200);@@ -176,17 +188,6 @@ public class TestProtocolHttpClient extends TestCase {response = http.getResponse(url, new CrawlDatum(), true);int code = response.getCode();- assertEquals("HTTP Status Code for " + url, expectedCode, code);- }-- /**- * Returns an URL to the specified page.- *- * @param page Page available in the local Jetty- * server.- * @throws MalformedURLException If an URL can not be formed.- */- private URL getURL(String page) throws MalformedURLException {- return new URL("http", "127.0.0.1", port, page);+ Assert.assertEquals("HTTP Status Code for " + url, expectedCode, code);}}diff --git a/src/plugin/subcollection/src/test/org/apache/nutch/collection/TestSubcollection.java b/src/plugin/subcollection/src/test/org/apache/nutch/collection/TestSubcollection.javaindex 48a45b466..c625f2328 100644--- a/src/plugin/subcollection/src/test/org/apache/nutch/collection/TestSubcollection.java+++ b/src/plugin/subcollection/src/test/org/apache/nutch/collection/TestSubcollection.java@@ -21,31 +21,33 @@ import java.io.InputStream;import java.util.Collection;import org.apache.nutch.util.NutchConfiguration;+import org.junit.Assert;+import org.junit.Test;-import junit.framework.TestCase;--public class TestSubcollection extends TestCase {+public class TestSubcollection {/**Test filtering logic** @throws Exception*/+ @Testpublic void testFilter() throws Exception {Subcollection sc=new Subcollection(NutchConfiguration.create());sc.setWhiteList("www.nutch.org\nwww.apache.org");sc.setBlackList("jpg\nwww.apache.org/zecret/");//matches whitelist- assertEquals("http://www.apache.org/index.html", sc.filter("http://www.apache.org/index.html"));+ Assert.assertEquals("http://www.apache.org/index.html", sc.filter("http://www.apache.org/index.html"));//matches blacklist- assertEquals(null, sc.filter("http://www.apache.org/zecret/index.html"));- assertEquals(null, sc.filter("http://www.apache.org/img/image.jpg"));+ Assert.assertEquals(null, sc.filter("http://www.apache.org/zecret/index.html"));+ Assert.assertEquals(null, sc.filter("http://www.apache.org/img/image.jpg"));//no match- assertEquals(null, sc.filter("http://www.google.com/"));+ Assert.assertEquals(null, sc.filter("http://www.google.com/"));}+ @Testpublic void testInput(){StringBuffer xml=new StringBuffer();xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");@@ -69,38 +71,38 @@ public class TestSubcollection extends TestCase {CollectionManager cm=new CollectionManager();cm.parse(is);- Collection c=cm.getAll();+ Collection<?> c=cm.getAll();// test that size matches- assertEquals(1,c.size());+ Assert.assertEquals(1,c.size());Subcollection collection=(Subcollection)c.toArray()[0];//test collection id- assertEquals("nutch", collection.getId());+ Assert.assertEquals("nutch", collection.getId());//test collection name- assertEquals("nutch collection", collection.getName());+ Assert.assertEquals("nutch collection", collection.getName());//test whitelist- assertEquals(2,collection.whiteList.size());+ Assert.assertEquals(2,collection.whiteList.size());String wlUrl=(String)collection.whiteList.get(0);- assertEquals("http://lucene.apache.org/nutch/", wlUrl);+ Assert.assertEquals("http://lucene.apache.org/nutch/", wlUrl);wlUrl=(String)collection.whiteList.get(1);- assertEquals("http://wiki.apache.org/nutch/", wlUrl);+ Assert.assertEquals("http://wiki.apache.org/nutch/", wlUrl);//matches whitelist- assertEquals("http://lucene.apache.org/nutch/", collection.filter("http://lucene.apache.org/nutch/"));+ Assert.assertEquals("http://lucene.apache.org/nutch/", collection.filter("http://lucene.apache.org/nutch/"));//test blacklist- assertEquals(1,collection.blackList.size());+ Assert.assertEquals(1,collection.blackList.size());String blUrl=(String)collection.blackList.get(0);- assertEquals("http://www.xxx.yyy", blUrl);+ Assert.assertEquals("http://www.xxx.yyy", blUrl);//no match- assertEquals(null, collection.filter("http://www.google.com/"));+ Assert.assertEquals(null, collection.filter("http://www.google.com/"));}}diff --git a/src/plugin/urlfilter-automaton/src/test/org/apache/nutch/urlfilter/automaton/TestAutomatonURLFilter.java b/src/plugin/urlfilter-automaton/src/test/org/apache/nutch/urlfilter/automaton/TestAutomatonURLFilter.javaindex ea1731a94..ac104e025 100644--- a/src/plugin/urlfilter-automaton/src/test/org/apache/nutch/urlfilter/automaton/TestAutomatonURLFilter.java+++ b/src/plugin/urlfilter-automaton/src/test/org/apache/nutch/urlfilter/automaton/TestAutomatonURLFilter.java@@ -20,14 +20,11 @@ package org.apache.nutch.urlfilter.automaton;import java.io.IOException;import java.io.Reader;-// JUnit imports-import junit.framework.Test;-import junit.framework.TestSuite;-import junit.textui.TestRunner;import org.apache.nutch.net.*;-// Nutch importsimport org.apache.nutch.urlfilter.api.RegexURLFilterBaseTest;+import org.junit.Assert;+import org.junit.Test;/**@@ -36,28 +33,17 @@ import org.apache.nutch.urlfilter.api.RegexURLFilterBaseTest;* @author Jérôme Charron*/public class TestAutomatonURLFilter extends RegexURLFilterBaseTest {-- public TestAutomatonURLFilter(String testName) {- super(testName);- }-- public static Test suite() {- return new TestSuite(TestAutomatonURLFilter.class);- }-- public static void main(String[] args) {- TestRunner.run(suite());- }protected URLFilter getURLFilter(Reader rules) {try {return new AutomatonURLFilter(rules);} catch (IOException e) {- fail(e.toString());+ Assert.fail(e.toString());return null;}}+ @Testpublic void test() {test("WholeWebCrawling");test("IntranetCrawling");diff --git a/src/plugin/urlfilter-domain/src/test/org/apache/nutch/urlfilter/domain/TestDomainURLFilter.java b/src/plugin/urlfilter-domain/src/test/org/apache/nutch/urlfilter/domain/TestDomainURLFilter.javaindex 2b9fc96ae..e10bb8e29 100644--- a/src/plugin/urlfilter-domain/src/test/org/apache/nutch/urlfilter/domain/TestDomainURLFilter.java+++ b/src/plugin/urlfilter-domain/src/test/org/apache/nutch/urlfilter/domain/TestDomainURLFilter.java@@ -16,25 +16,18 @@*/package org.apache.nutch.urlfilter.domain;-import junit.framework.TestCase;--import org.slf4j.Logger;-import org.slf4j.LoggerFactory;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;+import org.junit.Assert;+import org.junit.Test;-public class TestDomainURLFilter- extends TestCase {+public class TestDomainURLFilter {- protected static final Logger LOG = LoggerFactory.getLogger(TestDomainURLFilter.class);private final static String SEPARATOR = System.getProperty("file.separator");private final static String SAMPLES = System.getProperty("test.data", ".");- public TestDomainURLFilter(String testName) {- super(testName);- }-+ @Testpublic void testFilter()throws Exception {@@ -42,16 +35,16 @@ public class TestDomainURLFilterConfiguration conf = NutchConfiguration.create();DomainURLFilter domainFilter = new DomainURLFilter(domainFile);domainFilter.setConf(conf);- assertNotNull(domainFilter.filter("http://lucene.apache.org"));- assertNotNull(domainFilter.filter("http://hadoop.apache.org"));- assertNotNull(domainFilter.filter("http://www.apache.org"));- assertNull(domainFilter.filter("http://www.google.com"));- assertNull(domainFilter.filter("http://mail.yahoo.com"));- assertNotNull(domainFilter.filter("http://www.foobar.net"));- assertNotNull(domainFilter.filter("http://www.foobas.net"));- assertNotNull(domainFilter.filter("http://www.yahoo.com"));- assertNotNull(domainFilter.filter("http://www.foobar.be"));- assertNull(domainFilter.filter("http://www.adobe.com"));+ Assert.assertNotNull(domainFilter.filter("http://lucene.apache.org"));+ Assert.assertNotNull(domainFilter.filter("http://hadoop.apache.org"));+ Assert.assertNotNull(domainFilter.filter("http://www.apache.org"));+ Assert.assertNull(domainFilter.filter("http://www.google.com"));+ Assert.assertNull(domainFilter.filter("http://mail.yahoo.com"));+ Assert.assertNotNull(domainFilter.filter("http://www.foobar.net"));+ Assert.assertNotNull(domainFilter.filter("http://www.foobas.net"));+ Assert.assertNotNull(domainFilter.filter("http://www.yahoo.com"));+ Assert.assertNotNull(domainFilter.filter("http://www.foobar.be"));+ Assert.assertNull(domainFilter.filter("http://www.adobe.com"));}}diff --git a/src/plugin/urlfilter-domainblacklist/src/test/org/apache/nutch/urlfilter/domainblacklist/TestDomainBlacklistURLFilter.java b/src/plugin/urlfilter-domainblacklist/src/test/org/apache/nutch/urlfilter/domainblacklist/TestDomainBlacklistURLFilter.javaindex 29b1f8ee3..03aff629f 100644--- a/src/plugin/urlfilter-domainblacklist/src/test/org/apache/nutch/urlfilter/domainblacklist/TestDomainBlacklistURLFilter.java+++ b/src/plugin/urlfilter-domainblacklist/src/test/org/apache/nutch/urlfilter/domainblacklist/TestDomainBlacklistURLFilter.java@@ -16,25 +16,17 @@*/package org.apache.nutch.urlfilter.domainblacklist;-import junit.framework.TestCase;--import org.slf4j.Logger;-import org.slf4j.LoggerFactory;+import org.junit.Assert;+import org.junit.Test;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;-public class TestDomainBlacklistURLFilter- extends TestCase {-- protected static final Logger LOG = LoggerFactory.getLogger(TestDomainBlacklistURLFilter.class);+public class TestDomainBlacklistURLFilter {private final static String SEPARATOR = System.getProperty("file.separator");private final static String SAMPLES = System.getProperty("test.data", ".");- public TestDomainBlacklistURLFilter(String testName) {- super(testName);- }-+ @Testpublic void testFilter()throws Exception {@@ -42,16 +34,16 @@ public class TestDomainBlacklistURLFilterConfiguration conf = NutchConfiguration.create();DomainBlacklistURLFilter domainBlacklistFilter = new DomainBlacklistURLFilter(domainBlacklistFile);domainBlacklistFilter.setConf(conf);- assertNull(domainBlacklistFilter.filter("http://lucene.apache.org"));- assertNull(domainBlacklistFilter.filter("http://hadoop.apache.org"));- assertNull(domainBlacklistFilter.filter("http://www.apache.org"));- assertNotNull(domainBlacklistFilter.filter("http://www.google.com"));- assertNotNull(domainBlacklistFilter.filter("http://mail.yahoo.com"));- assertNull(domainBlacklistFilter.filter("http://www.foobar.net"));- assertNull(domainBlacklistFilter.filter("http://www.foobas.net"));- assertNull(domainBlacklistFilter.filter("http://www.yahoo.com"));- assertNull(domainBlacklistFilter.filter("http://www.foobar.be"));- assertNotNull(domainBlacklistFilter.filter("http://www.adobe.com"));+ Assert.assertNull(domainBlacklistFilter.filter("http://lucene.apache.org"));+ Assert.assertNull(domainBlacklistFilter.filter("http://hadoop.apache.org"));+ Assert.assertNull(domainBlacklistFilter.filter("http://www.apache.org"));+ Assert.assertNotNull(domainBlacklistFilter.filter("http://www.google.com"));+ Assert.assertNotNull(domainBlacklistFilter.filter("http://mail.yahoo.com"));+ Assert.assertNull(domainBlacklistFilter.filter("http://www.foobar.net"));+ Assert.assertNull(domainBlacklistFilter.filter("http://www.foobas.net"));+ Assert.assertNull(domainBlacklistFilter.filter("http://www.yahoo.com"));+ Assert.assertNull(domainBlacklistFilter.filter("http://www.foobar.be"));+ Assert.assertNotNull(domainBlacklistFilter.filter("http://www.adobe.com"));}}diff --git a/src/plugin/urlfilter-regex/src/test/org/apache/nutch/urlfilter/regex/TestRegexURLFilter.java b/src/plugin/urlfilter-regex/src/test/org/apache/nutch/urlfilter/regex/TestRegexURLFilter.javaindex 1d10deb64..a0448bf9d 100644--- a/src/plugin/urlfilter-regex/src/test/org/apache/nutch/urlfilter/regex/TestRegexURLFilter.java+++ b/src/plugin/urlfilter-regex/src/test/org/apache/nutch/urlfilter/regex/TestRegexURLFilter.java@@ -20,14 +20,11 @@ package org.apache.nutch.urlfilter.regex;import java.io.IOException;import java.io.Reader;-// JUnit imports-import junit.framework.Test;-import junit.framework.TestSuite;-import junit.textui.TestRunner;import org.apache.nutch.net.*;-// Nutch importsimport org.apache.nutch.urlfilter.api.RegexURLFilterBaseTest;+import org.junit.Assert;+import org.junit.Test;/**@@ -36,28 +33,18 @@ import org.apache.nutch.urlfilter.api.RegexURLFilterBaseTest;* @author Jérôme Charron*/public class TestRegexURLFilter extends RegexURLFilterBaseTest {-- public TestRegexURLFilter(String testName) {- super(testName);- }-- public static Test suite() {- return new TestSuite(TestRegexURLFilter.class);- }-- public static void main(String[] args) {- TestRunner.run(suite());- }+protected URLFilter getURLFilter(Reader rules) {try {return new RegexURLFilter(rules);} catch (IOException e) {- fail(e.toString());+ Assert.fail(e.toString());return null;}}+ @Testpublic void test() {test("WholeWebCrawling");test("IntranetCrawling");diff --git a/src/plugin/urlfilter-suffix/src/test/org/apache/nutch/urlfilter/suffix/TestSuffixURLFilter.java b/src/plugin/urlfilter-suffix/src/test/org/apache/nutch/urlfilter/suffix/TestSuffixURLFilter.javaindex cec27a0cf..f2a53570c 100644--- a/src/plugin/urlfilter-suffix/src/test/org/apache/nutch/urlfilter/suffix/TestSuffixURLFilter.java+++ b/src/plugin/urlfilter-suffix/src/test/org/apache/nutch/urlfilter/suffix/TestSuffixURLFilter.java@@ -19,18 +19,16 @@ package org.apache.nutch.urlfilter.suffix;import java.io.IOException;import java.io.StringReader;-import junit.framework.Test;-import junit.framework.TestCase;-import junit.framework.TestSuite;-import junit.textui.TestRunner;-+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;/*** JUnit test for <code>SuffixURLFilter</code>.** @author Andrzej Bialecki*/-public class TestSuffixURLFilter extends TestCase {+public class TestSuffixURLFilter {private static final String suffixes ="# this is a comment\n" +"\n" +@@ -117,67 +115,62 @@ public class TestSuffixURLFilter extends TestCase {private SuffixURLFilter filter = null;- public TestSuffixURLFilter(String testName) {- super(testName);- }-- public static Test suite() {- return new TestSuite(TestSuffixURLFilter.class);- }-- public static void main(String[] args) {- TestRunner.run(suite());- }-+ @Beforepublic void setUp() throws IOException {filter = new SuffixURLFilter(new StringReader(suffixes));}+ @Testpublic void testModeAccept() {filter.setIgnoreCase(false);filter.setModeAccept(true);for (int i = 0; i < urls.length; i++) {- assertTrue(urlsModeAccept[i] == filter.filter(urls[i]));+ Assert.assertTrue(urlsModeAccept[i] == filter.filter(urls[i]));}}+ @Testpublic void testModeReject() {filter.setIgnoreCase(false);filter.setModeAccept(false);for (int i = 0; i < urls.length; i++) {- assertTrue(urlsModeReject[i] == filter.filter(urls[i]));+ Assert.assertTrue(urlsModeReject[i] == filter.filter(urls[i]));}}+ @Testpublic void testModeAcceptIgnoreCase() {filter.setIgnoreCase(true);filter.setModeAccept(true);for (int i = 0; i < urls.length; i++) {- assertTrue(urlsModeAcceptIgnoreCase[i] == filter.filter(urls[i]));+ Assert.assertTrue(urlsModeAcceptIgnoreCase[i] == filter.filter(urls[i]));}}+ @Testpublic void testModeRejectIgnoreCase() {filter.setIgnoreCase(true);filter.setModeAccept(false);for (int i = 0; i < urls.length; i++) {- assertTrue(urlsModeRejectIgnoreCase[i] == filter.filter(urls[i]));+ Assert.assertTrue(urlsModeRejectIgnoreCase[i] == filter.filter(urls[i]));}}+ @Testpublic void testModeAcceptAndNonPathFilter() {filter.setModeAccept(true);filter.setFilterFromPath(false);for (int i = 0; i < urls.length; i++) {- assertTrue(urlsModeAcceptAndNonPathFilter[i] == filter.filter(urls[i]));+ Assert.assertTrue(urlsModeAcceptAndNonPathFilter[i] == filter.filter(urls[i]));}}+ @Testpublic void testModeAcceptAndPathFilter() {filter.setModeAccept(true);filter.setFilterFromPath(true);for (int i = 0; i < urls.length; i++) {- assertTrue(urlsModeAcceptAndPathFilter[i] == filter.filter(urls[i]));+ Assert.assertTrue(urlsModeAcceptAndPathFilter[i] == filter.filter(urls[i]));}}diff --git a/src/plugin/urlfilter-validator/src/test/org/apache/nutch/urlfilter/validator/TestUrlValidator.java b/src/plugin/urlfilter-validator/src/test/org/apache/nutch/urlfilter/validator/TestUrlValidator.javaindex 9bebc7519..852d23545 100644--- a/src/plugin/urlfilter-validator/src/test/org/apache/nutch/urlfilter/validator/TestUrlValidator.java+++ b/src/plugin/urlfilter-validator/src/test/org/apache/nutch/urlfilter/validator/TestUrlValidator.java@@ -17,7 +17,8 @@package org.apache.nutch.urlfilter.validator;import org.apache.nutch.urlfilter.validator.UrlValidator;-import junit.framework.TestCase;+import org.junit.Assert;+import org.junit.Test;/*** JUnit test case which tests@@ -28,31 +29,32 @@ import junit.framework.TestCase;**/-public class TestUrlValidator extends TestCase {+public class TestUrlValidator {/*** Test method for {@link org.apache.nutch.urlfilter.validator.UrlValidator#filter(java.lang.String)}.*/+ @Testpublic void testFilter() {UrlValidator url_validator = new UrlValidator();- assertNotNull(url_validator);+ Assert.assertNotNull(url_validator);- assertNull("Filtering on a null object should return null", url_validator.filter(null));- assertNull("Invalid url: example.com/file[/].html", url_validator.filter("example.com/file[/].html"));- assertNull("Invalid url: http://www.example.com/space here.html", url_validator.filter("http://www.example.com/space here.html"));- assertNull("Invalid url: /main.html", url_validator.filter("/main.html"));- assertNull("Invalid url: www.example.com/main.html", url_validator.filter("www.example.com/main.html"));- assertNull("Invalid url: ftp:www.example.com/main.html", url_validator.filter("ftp:www.example.com/main.html"));- assertNull("Inalid url: http://999.000.456.32/nutch/trunk/README.txt",+ Assert.assertNull("Filtering on a null object should return null", url_validator.filter(null));+ Assert.assertNull("Invalid url: example.com/file[/].html", url_validator.filter("example.com/file[/].html"));+ Assert.assertNull("Invalid url: http://www.example.com/space here.html", url_validator.filter("http://www.example.com/space here.html"));+ Assert.assertNull("Invalid url: /main.html", url_validator.filter("/main.html"));+ Assert.assertNull("Invalid url: www.example.com/main.html", url_validator.filter("www.example.com/main.html"));+ Assert.assertNull("Invalid url: ftp:www.example.com/main.html", url_validator.filter("ftp:www.example.com/main.html"));+ Assert.assertNull("Inalid url: http://999.000.456.32/nutch/trunk/README.txt",url_validator.filter("http://999.000.456.32/nutch/trunk/README.txt"));- assertNull("Invalid url: http://www.example.com/ma|in\\toc.html", url_validator.filter(" http://www.example.com/ma|in\\toc.html"));+ Assert.assertNull("Invalid url: http://www.example.com/ma|in\\toc.html", url_validator.filter(" http://www.example.com/ma|in\\toc.html"));- assertNotNull("Valid url: https://issues.apache.org/jira/NUTCH-1127", url_validator.filter("https://issues.apache.org/jira/NUTCH-1127"));- assertNotNull("Valid url: http://domain.tld/function.cgi?url=http://fonzi.com/&name=Fonzi&mood=happy&coat=leather",+ Assert.assertNotNull("Valid url: https://issues.apache.org/jira/NUTCH-1127", url_validator.filter("https://issues.apache.org/jira/NUTCH-1127"));+ Assert.assertNotNull("Valid url: http://domain.tld/function.cgi?url=http://fonzi.com/&name=Fonzi&mood=happy&coat=leather",url_validator.filter("http://domain.tld/function.cgi?url=http://fonzi.com/&name=Fonzi&mood=happy&coat=leather"));- assertNotNull("Valid url: http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Ffeeds.feedburner.com%2Fperishablepress",+ Assert.assertNotNull("Valid url: http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Ffeeds.feedburner.com%2Fperishablepress",url_validator.filter("http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Ffeeds.feedburner.com%2Fperishablepress"));- assertNotNull("Valid url: ftp://alfa.bravo.pi/foo/bar/plan.pdf", url_validator.filter("ftp://alfa.bravo.pi/mike/check/plan.pdf"));+ Assert.assertNotNull("Valid url: ftp://alfa.bravo.pi/foo/bar/plan.pdf", url_validator.filter("ftp://alfa.bravo.pi/mike/check/plan.pdf"));}}diff --git a/src/plugin/urlnormalizer-basic/src/test/org/apache/nutch/net/urlnormalizer/basic/TestBasicURLNormalizer.java b/src/plugin/urlnormalizer-basic/src/test/org/apache/nutch/net/urlnormalizer/basic/TestBasicURLNormalizer.javaindex d93081626..f1eedf9f0 100644--- a/src/plugin/urlnormalizer-basic/src/test/org/apache/nutch/net/urlnormalizer/basic/TestBasicURLNormalizer.java+++ b/src/plugin/urlnormalizer-basic/src/test/org/apache/nutch/net/urlnormalizer/basic/TestBasicURLNormalizer.java@@ -20,21 +20,23 @@ package org.apache.nutch.net.urlnormalizer.basic;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.net.URLNormalizers;import org.apache.nutch.util.NutchConfiguration;--import junit.framework.TestCase;+import org.junit.Assert;+import org.junit.Test;/** Unit tests for BasicURLNormalizer. */-public class TestBasicURLNormalizer extends TestCase {+public class TestBasicURLNormalizer {private BasicURLNormalizer normalizer;+private Configuration conf;- public TestBasicURLNormalizer(String name) {- super(name);+ public TestBasicURLNormalizer() {normalizer = new BasicURLNormalizer();conf = NutchConfiguration.create();normalizer.setConf(conf);}++ @Testpublic void testNormalizer() throws Exception {// check that leading and trailing spaces are removednormalizeTest(" http://foo.com/ ", "http://foo.com/");@@ -106,14 +108,11 @@ public class TestBasicURLNormalizer extends TestCase {}private void normalizeTest(String weird, String normal) throws Exception {- assertEquals(normal, normalizer.normalize(weird, URLNormalizers.SCOPE_DEFAULT));+ Assert.assertEquals(normal, normalizer.normalize(weird, URLNormalizers.SCOPE_DEFAULT));}-+public static void main(String[] args) throws Exception {new TestBasicURLNormalizer("test").testNormalizer();}---}\ No newline at end of filediff --git a/src/plugin/urlnormalizer-host/src/test/org/apache/nutch/net/urlnormalizer/host/TestHostURLNormalizer.java b/src/plugin/urlnormalizer-host/src/test/org/apache/nutch/net/urlnormalizer/host/TestHostURLNormalizer.javaindex 8f018ada1..8e0bd602e 100644--- a/src/plugin/urlnormalizer-host/src/test/org/apache/nutch/net/urlnormalizer/host/TestHostURLNormalizer.java+++ b/src/plugin/urlnormalizer-host/src/test/org/apache/nutch/net/urlnormalizer/host/TestHostURLNormalizer.java@@ -16,19 +16,18 @@*/package org.apache.nutch.net.urlnormalizer.host;-import java.net.MalformedURLException;-import org.apache.hadoop.conf.Configuration;import org.apache.nutch.net.URLNormalizers;import org.apache.nutch.util.NutchConfiguration;+import org.junit.Assert;+import org.junit.Test;-import junit.framework.TestCase;--public class TestHostURLNormalizer extends TestCase {+public class TestHostURLNormalizer {private final static String SEPARATOR = System.getProperty("file.separator");private final static String SAMPLES = System.getProperty("test.data", ".");+ @Testpublic void testHostURLNormalizer() throws Exception {Configuration conf = NutchConfiguration.create();@@ -37,14 +36,14 @@ public class TestHostURLNormalizer extends TestCase {normalizer.setConf(conf);// Force www. sub domain when hitting link without sub domain- assertEquals("http://www.example.org/page.html", normalizer.normalize("http://example.org/page.html", URLNormalizers.SCOPE_DEFAULT));+ Assert.assertEquals("http://www.example.org/page.html", normalizer.normalize("http://example.org/page.html", URLNormalizers.SCOPE_DEFAULT));// Force no sub domain to www. URL's- assertEquals("http://example.net/path/to/something.html", normalizer.normalize("http://www.example.net/path/to/something.html", URLNormalizers.SCOPE_DEFAULT));+ Assert.assertEquals("http://example.net/path/to/something.html", normalizer.normalize("http://www.example.net/path/to/something.html", URLNormalizers.SCOPE_DEFAULT));// Force all sub domains to www.- assertEquals("http://example.com/?does=it&still=work", normalizer.normalize("http://example.com/?does=it&still=work", URLNormalizers.SCOPE_DEFAULT));- assertEquals("http://example.com/buh", normalizer.normalize("http://http.www.example.com/buh", URLNormalizers.SCOPE_DEFAULT));- assertEquals("http://example.com/blaat", normalizer.normalize("http://whatever.example.com/blaat", URLNormalizers.SCOPE_DEFAULT));+ Assert.assertEquals("http://example.com/?does=it&still=work", normalizer.normalize("http://example.com/?does=it&still=work", URLNormalizers.SCOPE_DEFAULT));+ Assert.assertEquals("http://example.com/buh", normalizer.normalize("http://http.www.example.com/buh", URLNormalizers.SCOPE_DEFAULT));+ Assert.assertEquals("http://example.com/blaat", normalizer.normalize("http://whatever.example.com/blaat", URLNormalizers.SCOPE_DEFAULT));}}diff --git a/src/plugin/urlnormalizer-pass/src/test/org/apache/nutch/net/urlnormalizer/pass/TestPassURLNormalizer.java b/src/plugin/urlnormalizer-pass/src/test/org/apache/nutch/net/urlnormalizer/pass/TestPassURLNormalizer.javaindex 301814930..f4643dd51 100644--- a/src/plugin/urlnormalizer-pass/src/test/org/apache/nutch/net/urlnormalizer/pass/TestPassURLNormalizer.java+++ b/src/plugin/urlnormalizer-pass/src/test/org/apache/nutch/net/urlnormalizer/pass/TestPassURLNormalizer.java@@ -16,17 +16,17 @@*/package org.apache.nutch.net.urlnormalizer.pass;-import java.net.MalformedURLException;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.net.URLNormalizers;import org.apache.nutch.util.NutchConfiguration;+import org.junit.Assert;+import org.junit.Test;-import junit.framework.TestCase;--public class TestPassURLNormalizer extends TestCase {+public class TestPassURLNormalizer {+ @Testpublic void testPassURLNormalizer() {Configuration conf = NutchConfiguration.create();@@ -37,9 +37,9 @@ public class TestPassURLNormalizer extends TestCase {try {result = normalizer.normalize(url, URLNormalizers.SCOPE_DEFAULT);} catch (MalformedURLException mue) {- fail(mue.toString());+ Assert.fail(mue.toString());}- assertEquals(url, result);+ Assert.assertEquals(url, result);}}diff --git a/src/plugin/urlnormalizer-regex/src/test/org/apache/nutch/net/urlnormalizer/regex/TestRegexURLNormalizer.java b/src/plugin/urlnormalizer-regex/src/test/org/apache/nutch/net/urlnormalizer/regex/TestRegexURLNormalizer.javaindex 196dba5fb..e569d5289 100644--- a/src/plugin/urlnormalizer-regex/src/test/org/apache/nutch/net/urlnormalizer/regex/TestRegexURLNormalizer.java+++ b/src/plugin/urlnormalizer-regex/src/test/org/apache/nutch/net/urlnormalizer/regex/TestRegexURLNormalizer.java@@ -26,16 +26,16 @@ import java.io.IOException;import java.io.InputStreamReader;import java.util.*;+import org.junit.Assert;+import org.junit.Test;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.net.URLNormalizers;import org.apache.nutch.util.NutchConfiguration;-import junit.framework.TestCase;-/** Unit tests for RegexUrlNormalizer. */-public class TestRegexURLNormalizer extends TestCase {+public class TestRegexURLNormalizer {private static final Logger LOG = LoggerFactory.getLogger(TestRegexURLNormalizer.class);private RegexURLNormalizer normalizer;@@ -47,8 +47,7 @@ public class TestRegexURLNormalizer extends TestCase {// Make sure sample files are copied to "test.data" as specified in// ./src/plugin/urlnormalizer-regex/build.xml during plugin compilation.- public TestRegexURLNormalizer(String name) throws IOException {- super(name);+ public TestRegexURLNormalizer() throws IOException {normalizer = new RegexURLNormalizer();conf = NutchConfiguration.create();normalizer.setConf(conf);@@ -73,11 +72,13 @@ public class TestRegexURLNormalizer extends TestCase {}}+ @Testpublic void testNormalizerDefault() throws Exception {normalizeTest((NormalizedURL[])testData.get(URLNormalizers.SCOPE_DEFAULT),URLNormalizers.SCOPE_DEFAULT);}+ @Testpublic void testNormalizerScope() throws Exception {Iterator<String> it = testData.keySet().iterator();while (it.hasNext()) {@@ -92,7 +93,7 @@ public class TestRegexURLNormalizer extends TestCase {String normalized = normalizer.normalize(urls[i].url, scope);String expected = urls[i].expectedURL;LOG.info("scope: " + scope + " url: " + url + " | normalized: " + normalized + " | expected: " + expected);- assertEquals(urls[i].expectedURL, normalized);+ Assert.assertEquals(urls[i].expectedURL, normalized);}}@@ -105,7 +106,7 @@ public class TestRegexURLNormalizer extends TestCase {normalizeTest(expected, scope);}} catch (Exception e) {- fail(e.toString());+ Assert.fail(e.toString());}LOG.info("bench time (" + loops + ") " +(System.currentTimeMillis() - start) + "ms");@@ -124,6 +125,7 @@ public class TestRegexURLNormalizer extends TestCase {private NormalizedURL[] readTestFile(String scope) throws IOException {File f = new File(sampleDir, "regex-normalize-" + scope + ".test");+ @SuppressWarnings("resource")BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));List<NormalizedURL> list = new ArrayList<NormalizedURL>();String line;@@ -158,7 +160,7 @@ public class TestRegexURLNormalizer extends TestCase {System.err.println("Invalid number of iterations: " + iter);System.exit(-1);}- TestRegexURLNormalizer test = new TestRegexURLNormalizer("test");+ TestRegexURLNormalizer test = new TestRegexURLNormalizer();NormalizedURL[] urls = (NormalizedURL[])test.testData.get(scope);if (urls == null) {LOG.warn("Missing test data for scope '" + scope + "', using default scope.");diff --git a/src/test/org/apache/nutch/crawl/TestCrawlDbFilter.java b/src/test/org/apache/nutch/crawl/TestCrawlDbFilter.javaindex 2d333dce4..88c945d6d 100644--- a/src/test/org/apache/nutch/crawl/TestCrawlDbFilter.java+++ b/src/test/org/apache/nutch/crawl/TestCrawlDbFilter.java@@ -27,9 +27,11 @@ import org.apache.hadoop.io.SequenceFile;import org.apache.hadoop.io.Text;import org.apache.hadoop.mapred.*;import org.apache.nutch.crawl.CrawlDBTestUtil.URLCrawlDatum;--import junit.framework.TestCase;import org.apache.nutch.util.NutchJob;+import org.junit.After;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;/*** CrawlDbFiltering test which tests for correct, error free url@@ -38,20 +40,22 @@ import org.apache.nutch.util.NutchJob;** @author lufeng*/-public class TestCrawlDbFilter extends TestCase {+public class TestCrawlDbFilter {Configuration conf;Path dbDir;Path newCrawlDb;final static Path testdir = new Path("build/test/crawldbfilter-test");FileSystem fs;- protected void setUp() throws Exception {+ @Before+ public void setUp() throws Exception {conf = CrawlDBTestUtil.createConfiguration();fs = FileSystem.get(conf);fs.delete(testdir, true);}- protected void tearDown() {+ @After+ public void tearDown() {delete(testdir);}@@ -67,6 +71,7 @@ public class TestCrawlDbFilter extends TestCase {** @throws Exception*/+ @Testpublic void testUrl404Purging() throws Exception {// create a CrawlDatum with DB GONE statusArrayList<URLCrawlDatum> list = new ArrayList<URLCrawlDatum>();@@ -106,7 +111,7 @@ public class TestCrawlDbFilter extends TestCase {ArrayList<URLCrawlDatum> l = readContents(fetchlist);// verify we got right amount of records- assertEquals(2, l.size());+ Assert.assertEquals(2, l.size());}/**diff --git a/src/test/org/apache/nutch/crawl/TestCrawlDbMerger.java b/src/test/org/apache/nutch/crawl/TestCrawlDbMerger.javaindex 48adaf78e..982252e0e 100644--- a/src/test/org/apache/nutch/crawl/TestCrawlDbMerger.java+++ b/src/test/org/apache/nutch/crawl/TestCrawlDbMerger.java@@ -28,10 +28,12 @@ import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.MapFile;import org.apache.hadoop.io.Text;import org.apache.nutch.util.NutchConfiguration;+import org.junit.After;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;-import junit.framework.TestCase;--public class TestCrawlDbMerger extends TestCase {+public class TestCrawlDbMerger {private static final Logger LOG = Logger.getLogger(CrawlDbMerger.class.getName());String url10 = "http://example.com/";@@ -53,6 +55,7 @@ public class TestCrawlDbMerger extends TestCase {Path testDir;CrawlDbReader reader;+ @Beforepublic void setUp() throws Exception {init1.add(url10);init1.add(url11);@@ -83,18 +86,18 @@ public class TestCrawlDbMerger extends TestCase {fs.mkdirs(testDir);}- @SuppressWarnings("deprecation")+ @Afterpublic void tearDown() {try {if (fs.exists(testDir))- fs.delete(testDir);+ fs.delete(testDir, true);} catch (Exception e) { }try {reader.close();} catch (Exception e) { }}- @SuppressWarnings("deprecation")+ @Testpublic void testMerge() throws Exception {Path crawldb1 = new Path(testDir, "crawldb1");Path crawldb2 = new Path(testDir, "crawldb2");@@ -118,11 +121,11 @@ public class TestCrawlDbMerger extends TestCase {System.out.println(" cd " + cd);System.out.println(" res " + res);// may not be null- assertNotNull(res);- assertTrue(cd.equals(res));+ Assert.assertNotNull(res);+ Assert.assertTrue(cd.equals(res));}reader.close();- fs.delete(testDir);+ fs.delete(testDir, true);}private void createCrawlDb(Configuration config, FileSystem fs, Path crawldb, TreeSet<String> init, CrawlDatum cd) throws Exception {diff --git a/src/test/org/apache/nutch/crawl/TestGenerator.java b/src/test/org/apache/nutch/crawl/TestGenerator.javaindex d889bdd98..7c5b982db 100644--- a/src/test/org/apache/nutch/crawl/TestGenerator.java+++ b/src/test/org/apache/nutch/crawl/TestGenerator.java@@ -27,18 +27,18 @@ import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.SequenceFile;import org.apache.hadoop.io.Text;import org.apache.nutch.crawl.CrawlDBTestUtil.URLCrawlDatum;--import junit.framework.TestCase;+import org.junit.After;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;/*** Basic generator test. 1. Insert entries in crawldb 2. Generates entries to* fetch 3. Verifies that number of generated urls match 4. Verifies that* highest scoring urls are generated*- * @author nutch-dev <nutch-dev at lucene.apache.org>- **/-public class TestGenerator extends TestCase {+public class TestGenerator {Configuration conf;@@ -50,13 +50,15 @@ public class TestGenerator extends TestCase {final static Path testdir = new Path("build/test/generator-test");- protected void setUp() throws Exception {+ @Before+ public void setUp() throws Exception {conf = CrawlDBTestUtil.createConfiguration();fs = FileSystem.get(conf);fs.delete(testdir, true);}- protected void tearDown() {+ @After+ public void tearDown() {delete(testdir);}@@ -72,6 +74,7 @@ public class TestGenerator extends TestCase {** @throws Exception*/+ @Testpublic void testGenerateHighest() throws Exception {final int NUM_RESULTS = 2;@@ -96,11 +99,11 @@ public class TestGenerator extends TestCase {Collections.sort(l, new ScoreComparator());// verify we got right amount of records- assertEquals(NUM_RESULTS, l.size());+ Assert.assertEquals(NUM_RESULTS, l.size());// verify we have the highest scoring urls- assertEquals("http://aaa/100", (l.get(0).url.toString()));- assertEquals("http://aaa/099", (l.get(1).url.toString()));+ Assert.assertEquals("http://aaa/100", (l.get(0).url.toString()));+ Assert.assertEquals("http://aaa/099", (l.get(1).url.toString()));}private String pad(int i) {@@ -131,6 +134,7 @@ public class TestGenerator extends TestCase {* Test that generator obeys the property "generate.max.per.host".* @throws Exception*/+ @Testpublic void testGenerateHostLimit() throws Exception{ArrayList<URLCrawlDatum> list = new ArrayList<URLCrawlDatum>();@@ -154,7 +158,7 @@ public class TestGenerator extends TestCase {ArrayList<URLCrawlDatum> fetchList = readContents(fetchlistPath);// verify we got right amount of records- assertEquals(1, fetchList.size());+ Assert.assertEquals(1, fetchList.size());myConfiguration = new Configuration(conf);myConfiguration.setInt(Generator.GENERATOR_MAX_COUNT, 3);@@ -167,7 +171,7 @@ public class TestGenerator extends TestCase {fetchList = readContents(fetchlistPath);// verify we got right amount of records- assertEquals(2, fetchList.size());+ Assert.assertEquals(2, fetchList.size());myConfiguration = new Configuration(conf);myConfiguration.setInt(Generator.GENERATOR_MAX_COUNT, 4);@@ -180,7 +184,7 @@ public class TestGenerator extends TestCase {fetchList = readContents(fetchlistPath);// verify we got right amount of records- assertEquals(3, fetchList.size());+ Assert.assertEquals(3, fetchList.size());}/**@@ -188,6 +192,7 @@ public class TestGenerator extends TestCase {* "generator.count.per.domain".* @throws Exception*/+ @Testpublic void testGenerateDomainLimit() throws Exception{ArrayList<URLCrawlDatum> list = new ArrayList<URLCrawlDatum>();@@ -210,7 +215,7 @@ public class TestGenerator extends TestCase {ArrayList<URLCrawlDatum> fetchList = readContents(fetchlistPath);// verify we got right amount of records- assertEquals(1, fetchList.size());+ Assert.assertEquals(1, fetchList.size());myConfiguration = new Configuration(myConfiguration);myConfiguration.setInt(Generator.GENERATOR_MAX_COUNT, 3);@@ -222,7 +227,7 @@ public class TestGenerator extends TestCase {fetchList = readContents(fetchlistPath);// verify we got right amount of records- assertEquals(2, fetchList.size());+ Assert.assertEquals(2, fetchList.size());myConfiguration = new Configuration(myConfiguration);myConfiguration.setInt(Generator.GENERATOR_MAX_COUNT, 4);@@ -235,7 +240,7 @@ public class TestGenerator extends TestCase {fetchList = readContents(fetchlistPath);// verify we got right amount of records- assertEquals(3, fetchList.size());+ Assert.assertEquals(3, fetchList.size());}/**@@ -243,6 +248,7 @@ public class TestGenerator extends TestCase {* @throws Exception* @throws IOException*/+ @Testpublic void testFilter() throws IOException, Exception{ArrayList<URLCrawlDatum> list = new ArrayList<URLCrawlDatum>();@@ -259,7 +265,7 @@ public class TestGenerator extends TestCase {Path generatedSegment = generateFetchlist(Integer.MAX_VALUE,myConfiguration, true);- assertNull("should be null (0 entries)", generatedSegment);+ Assert.assertNull("should be null (0 entries)", generatedSegment);generatedSegment = generateFetchlist(Integer.MAX_VALUE, myConfiguration, false);@@ -269,7 +275,7 @@ public class TestGenerator extends TestCase {ArrayList<URLCrawlDatum> fetchList = readContents(fetchlistPath);// verify nothing got filtered- assertEquals(list.size(), fetchList.size());+ Assert.assertEquals(list.size(), fetchList.size());}diff --git a/src/test/org/apache/nutch/crawl/TestInjector.java b/src/test/org/apache/nutch/crawl/TestInjector.javaindex 05b0d0be0..71bc240e1 100644--- a/src/test/org/apache/nutch/crawl/TestInjector.java+++ b/src/test/org/apache/nutch/crawl/TestInjector.java@@ -28,8 +28,10 @@ import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.SequenceFile;import org.apache.hadoop.io.Text;--import junit.framework.TestCase;+import org.junit.After;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;/*** Basic injector test:@@ -39,9 +41,8 @@ import junit.framework.TestCase;* 4. Injects more urls into webdb* 5. Reads crawldb entries and verifies contents*- * @author nutch-dev <nutch-dev at lucene.apache.org>*/-public class TestInjector extends TestCase {+public class TestInjector {private Configuration conf;private FileSystem fs;@@ -49,7 +50,8 @@ public class TestInjector extends TestCase {Path crawldbPath;Path urlPath;- protected void setUp() throws Exception {+ @Before+ public void setUp() throws Exception {conf = CrawlDBTestUtil.createConfiguration();urlPath=new Path(testdir,"urls");crawldbPath=new Path(testdir,"crawldb");@@ -58,10 +60,12 @@ public class TestInjector extends TestCase {if (fs.exists(crawldbPath)) fs.delete(crawldbPath, true);}- protected void tearDown() throws IOException{+ @After+ public void tearDown() throws IOException{fs.delete(testdir, true);}+ @Testpublic void testInject() throws IOException {ArrayList<String> urls=new ArrayList<String>();// We'll use a separate list for MD so we can still compare url with containsAll@@ -81,10 +85,10 @@ public class TestInjector extends TestCase {Collections.sort(read);Collections.sort(urls);- assertEquals(urls.size(), read.size());+ Assert.assertEquals(urls.size(), read.size());- assertTrue(read.containsAll(urls));- assertTrue(urls.containsAll(read));+ Assert.assertTrue(read.containsAll(urls));+ Assert.assertTrue(urls.containsAll(read));//inject more urlsArrayList<String> urls2=new ArrayList<String>();@@ -106,10 +110,10 @@ public class TestInjector extends TestCase {Collections.sort(urls);// We should have 100 less records because we've overwritten- assertEquals(urls.size() - 100, read.size());+ Assert.assertEquals(urls.size() - 100, read.size());- assertTrue(read.containsAll(urls));- assertTrue(urls.containsAll(read));+ Assert.assertTrue(read.containsAll(urls));+ Assert.assertTrue(urls.containsAll(read));// Check if we correctly preserved MDMap<String, CrawlDatum> records = readCrawldbRecords();@@ -121,11 +125,11 @@ public class TestInjector extends TestCase {for (String url : urls) {if (url.indexOf("http://zzz") == 0) {// Check for fetch interval- assertTrue(records.get(url).getFetchInterval() == 171717);+ Assert.assertTrue(records.get(url).getFetchInterval() == 171717);// Check for default score- assertTrue(records.get(url).getScore() != 1.0);+ Assert.assertTrue(records.get(url).getScore() != 1.0);// Check for MD key=value- assertEquals(writableValue, records.get(url).getMetaData().get(writableKey));+ Assert.assertEquals(writableValue, records.get(url).getMetaData().get(writableKey));}}}@@ -133,6 +137,7 @@ public class TestInjector extends TestCase {private List<String> readCrawldb() throws IOException{Path dbfile=new Path(crawldbPath,CrawlDb.CURRENT_NAME + "/part-00000/data");System.out.println("reading:" + dbfile);+ @SuppressWarnings("resource")SequenceFile.Reader reader=new SequenceFile.Reader(fs, dbfile, conf);ArrayList<String> read=new ArrayList<String>();@@ -150,6 +155,7 @@ public class TestInjector extends TestCase {private HashMap<String,CrawlDatum> readCrawldbRecords() throws IOException{Path dbfile=new Path(crawldbPath,CrawlDb.CURRENT_NAME + "/part-00000/data");System.out.println("reading:" + dbfile);+ @SuppressWarnings("resource")SequenceFile.Reader reader=new SequenceFile.Reader(fs, dbfile, conf);HashMap<String,CrawlDatum> read=new HashMap<String,CrawlDatum>();diff --git a/src/test/org/apache/nutch/crawl/TestLinkDbMerger.java b/src/test/org/apache/nutch/crawl/TestLinkDbMerger.javaindex 8a24cfc53..88d8cd6c1 100644--- a/src/test/org/apache/nutch/crawl/TestLinkDbMerger.java+++ b/src/test/org/apache/nutch/crawl/TestLinkDbMerger.java@@ -29,10 +29,12 @@ import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.MapFile;import org.apache.hadoop.io.Text;import org.apache.nutch.util.NutchConfiguration;+import org.junit.After;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;-import junit.framework.TestCase;--public class TestLinkDbMerger extends TestCase {+public class TestLinkDbMerger {private static final Logger LOG = Logger.getLogger(TestLinkDbMerger.class.getName());String url10 = "http://example.com/foo";@@ -76,6 +78,7 @@ public class TestLinkDbMerger extends TestCase {FileSystem fs;LinkDbReader reader;+ @Beforepublic void setUp() throws Exception {init1.put(url10, urls10);init1.put(url11, urls11);@@ -92,6 +95,7 @@ public class TestLinkDbMerger extends TestCase {fs.mkdirs(testDir);}+ @Afterpublic void tearDown() {try {if (fs.exists(testDir))@@ -102,6 +106,7 @@ public class TestLinkDbMerger extends TestCase {} catch (Exception e) { }}+ @Testpublic void testMerge() throws Exception {Configuration conf = NutchConfiguration.create();FileSystem fs = FileSystem.get(conf);@@ -123,7 +128,7 @@ public class TestLinkDbMerger extends TestCase {String[] vals = expected.get(url);Inlinks inlinks = reader.getInlinks(new Text(url));// may not be null- assertNotNull(inlinks);+ Assert.assertNotNull(inlinks);ArrayList<String> links = new ArrayList<String>();Iterator<?> it2 = inlinks.iterator();while (it2.hasNext()) {@@ -132,7 +137,7 @@ public class TestLinkDbMerger extends TestCase {}for (int i = 0; i < vals.length; i++) {LOG.fine(" -> " + vals[i]);- assertTrue(links.contains(vals[i]));+ Assert.assertTrue(links.contains(vals[i]));}}reader.close();diff --git a/src/test/org/apache/nutch/crawl/TestSignatureFactory.java b/src/test/org/apache/nutch/crawl/TestSignatureFactory.javaindex 199cfb624..97df27168 100644--- a/src/test/org/apache/nutch/crawl/TestSignatureFactory.java+++ b/src/test/org/apache/nutch/crawl/TestSignatureFactory.java@@ -18,17 +18,18 @@ package org.apache.nutch.crawl;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;+import org.junit.Assert;+import org.junit.Test;-import junit.framework.TestCase;--public class TestSignatureFactory extends TestCase {+public class TestSignatureFactory {+ @Testpublic void testGetSignature() {Configuration conf=NutchConfiguration.create();Signature signature1=SignatureFactory.getSignature(conf);Signature signature2=SignatureFactory.getSignature(conf);- assertNotNull(signature1);- assertNotNull(signature2);- assertEquals(signature1, signature2);+ Assert.assertNotNull(signature1);+ Assert.assertNotNull(signature2);+ Assert.assertEquals(signature1, signature2);}}diff --git a/src/test/org/apache/nutch/fetcher/TestFetcher.java b/src/test/org/apache/nutch/fetcher/TestFetcher.javaindex f4bf294c4..f3e8f524c 100644--- a/src/test/org/apache/nutch/fetcher/TestFetcher.java+++ b/src/test/org/apache/nutch/fetcher/TestFetcher.java@@ -32,10 +32,12 @@ import org.apache.nutch.metadata.Metadata;import org.apache.nutch.metadata.Nutch;import org.apache.nutch.parse.ParseData;import org.apache.nutch.protocol.Content;+import org.junit.After;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;import org.mortbay.jetty.Server;-import junit.framework.TestCase;-/*** Basic fetcher test* 1. generate seedlist@@ -43,10 +45,9 @@ import junit.framework.TestCase;* 3. generate* 3. fetch* 4. Verify contents- * @author nutch-dev <nutch-dev at lucene.apache.org>**/-public class TestFetcher extends TestCase {+public class TestFetcher {final static Path testdir=new Path("build/test/fetch-test");Configuration conf;@@ -56,7 +57,8 @@ public class TestFetcher extends TestCase {Path urlPath;Server server;- protected void setUp() throws Exception{+ @Before+ public void setUp() throws Exception{conf=CrawlDBTestUtil.createConfiguration();fs=FileSystem.get(conf);fs.delete(testdir, true);@@ -67,11 +69,13 @@ public class TestFetcher extends TestCase {server.start();}- protected void tearDown() throws Exception{+ @After+ public void tearDown() throws Exception{server.stop();fs.delete(testdir, true);}+ @Testpublic void testFetch() throws IOException {//generate seedlist@@ -108,10 +112,11 @@ public class TestFetcher extends TestCase {//verify politeness, time taken should be more than (num_of_pages +1)*delayint minimumTime=(int) ((urls.size()+1)*1000*conf.getFloat("fetcher.server.delay",5));- assertTrue(time > minimumTime);+ Assert.assertTrue(time > minimumTime);//verify contentPath content=new Path(new Path(generatedSegment[0], Content.DIR_NAME),"part-00000/data");+ @SuppressWarnings("resource")SequenceFile.Reader reader=new SequenceFile.Reader(fs, content, conf);ArrayList<String> handledurls=new ArrayList<String>();@@ -133,11 +138,11 @@ public class TestFetcher extends TestCase {Collections.sort(handledurls);//verify that enough pages were handled- assertEquals(urls.size(), handledurls.size());+ Assert.assertEquals(urls.size(), handledurls.size());//verify that correct pages were handled- assertTrue(handledurls.containsAll(urls));- assertTrue(urls.containsAll(handledurls));+ Assert.assertTrue(handledurls.containsAll(urls));+ Assert.assertTrue(urls.containsAll(handledurls));handledurls.clear();@@ -161,16 +166,17 @@ public class TestFetcher extends TestCase {Collections.sort(handledurls);- assertEquals(urls.size(), handledurls.size());+ Assert.assertEquals(urls.size(), handledurls.size());- assertTrue(handledurls.containsAll(urls));- assertTrue(urls.containsAll(handledurls));+ Assert.assertTrue(handledurls.containsAll(urls));+ Assert.assertTrue(urls.containsAll(handledurls));}private void addUrl(ArrayList<String> urls, String page) {urls.add("http://127.0.0.1:" + server.getConnectors()[0].getPort() + "/" + page);}+ @Testpublic void testAgentNameCheck() {boolean failedNoAgentName = false;@@ -187,7 +193,7 @@ public class TestFetcher extends TestCase {} catch (Exception e) {}- assertTrue(failedNoAgentName);+ Assert.assertTrue(failedNoAgentName);}}diff --git a/src/test/org/apache/nutch/indexer/TestIndexingFilters.java b/src/test/org/apache/nutch/indexer/TestIndexingFilters.javaindex bd6df3813..02ed9181a 100644--- a/src/test/org/apache/nutch/indexer/TestIndexingFilters.java+++ b/src/test/org/apache/nutch/indexer/TestIndexingFilters.java@@ -26,15 +26,16 @@ import org.apache.nutch.parse.ParseData;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.Test;-import junit.framework.TestCase;--public class TestIndexingFilters extends TestCase {+public class TestIndexingFilters {/*** Test behaviour when defined filter does not exist.* @throws IndexingException*/+ @Testpublic void testNonExistingIndexingFilter() throws IndexingException {Configuration conf = NutchConfiguration.create();conf.addResource("nutch-default.xml");@@ -53,7 +54,7 @@ public class TestIndexingFilters extends TestCase {/*** Test behaviour when NutchDOcument is null*/-+ @Testpublic void testNutchDocumentNullIndexingFilter() throws IndexingException{Configuration conf = NutchConfiguration.create();conf.addResource("nutch-default.xml");@@ -64,7 +65,7 @@ public class TestIndexingFilters extends TestCase {new ParseStatus(), "title", new Outlink[0], new Metadata())), new Text("http://www.example.com/"), new CrawlDatum(), new Inlinks());- assertNull(doc);+ Assert.assertNull(doc);}/**@@ -72,6 +73,7 @@ public class TestIndexingFilters extends TestCase {** @throws IndexingException*/+ @Testpublic void testFilterCacheIndexingFilter() throws IndexingException{Configuration conf = NutchConfiguration.create();conf.addResource("nutch-default.xml");@@ -98,7 +100,7 @@ public class TestIndexingFilters extends TestCase {NutchDocument fdoc2 = filters2.filter(new NutchDocument(),new ParseImpl("text",new ParseData(new ParseStatus(),"title",new Outlink[0],md)),new Text("http://www.example.com/"),new CrawlDatum(),new Inlinks());- assertEquals(fdoc1.getFieldNames().size(),fdoc2.getFieldNames().size());+ Assert.assertEquals(fdoc1.getFieldNames().size(),fdoc2.getFieldNames().size());}}diff --git a/src/test/org/apache/nutch/metadata/TestMetadata.java b/src/test/org/apache/nutch/metadata/TestMetadata.javaindex a14a77967..120b3e883 100644--- a/src/test/org/apache/nutch/metadata/TestMetadata.java+++ b/src/test/org/apache/nutch/metadata/TestMetadata.java@@ -22,29 +22,17 @@ import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.IOException;import java.util.Properties;-import junit.framework.Test;-import junit.framework.TestCase;-import junit.framework.TestSuite;-import junit.textui.TestRunner;++import org.junit.Assert;+import org.junit.Test;/*** JUnit based tests of class {@link org.apache.nutch.metadata.Metadata}.*/-public class TestMetadata extends TestCase {+public class TestMetadata {private static final String CONTENTTYPE = "contenttype";- public TestMetadata(String testName) {- super(testName);- }-- public static Test suite() {- return new TestSuite(TestMetadata.class);- }-- public static void main(String[] args) {- TestRunner.run(suite());- }/*** Test to ensure that only non-null values get written when the@@ -53,6 +41,7 @@ public class TestMetadata extends TestCase {* @since NUTCH-406**/+ @Testpublic void testWriteNonNull() {Metadata met = new Metadata();met.add(CONTENTTYPE, null);@@ -60,14 +49,14 @@ public class TestMetadata extends TestCase {met.add(CONTENTTYPE, "text/bogus2");met = writeRead(met);- assertNotNull(met);- assertEquals(met.size(), 1);+ Assert.assertNotNull(met);+ Assert.assertEquals(met.size(), 1);boolean hasBogus = false, hasBogus2 = false;String[] values = met.getValues(CONTENTTYPE);- assertNotNull(values);- assertEquals(values.length, 2);+ Assert.assertNotNull(values);+ Assert.assertEquals(values.length, 2);for (int i = 0; i < values.length; i++) {if (values[i].equals("text/bogus")) {@@ -79,193 +68,202 @@ public class TestMetadata extends TestCase {}}- assertTrue(hasBogus && hasBogus2);+ Assert.assertTrue(hasBogus && hasBogus2);}/** Test for the <code>add(String, String)</code> method. */+ @Testpublic void testAdd() {String[] values = null;Metadata meta = new Metadata();values = meta.getValues(CONTENTTYPE);- assertEquals(0, values.length);+ Assert.assertEquals(0, values.length);meta.add(CONTENTTYPE, "value1");values = meta.getValues(CONTENTTYPE);- assertEquals(1, values.length);- assertEquals("value1", values[0]);+ Assert.assertEquals(1, values.length);+ Assert.assertEquals("value1", values[0]);meta.add(CONTENTTYPE, "value2");values = meta.getValues(CONTENTTYPE);- assertEquals(2, values.length);- assertEquals("value1", values[0]);- assertEquals("value2", values[1]);+ Assert.assertEquals(2, values.length);+ Assert.assertEquals("value1", values[0]);+ Assert.assertEquals("value2", values[1]);// NOTE : For now, the same value can be added many times.// Should it be changed?meta.add(CONTENTTYPE, "value1");values = meta.getValues(CONTENTTYPE);- assertEquals(3, values.length);- assertEquals("value1", values[0]);- assertEquals("value2", values[1]);- assertEquals("value1", values[2]);+ Assert.assertEquals(3, values.length);+ Assert.assertEquals("value1", values[0]);+ Assert.assertEquals("value2", values[1]);+ Assert.assertEquals("value1", values[2]);}/** Test for the <code>set(String, String)</code> method. */+ @Testpublic void testSet() {String[] values = null;Metadata meta = new Metadata();values = meta.getValues(CONTENTTYPE);- assertEquals(0, values.length);+ Assert.assertEquals(0, values.length);meta.set(CONTENTTYPE, "value1");values = meta.getValues(CONTENTTYPE);- assertEquals(1, values.length);- assertEquals("value1", values[0]);+ Assert.assertEquals(1, values.length);+ Assert.assertEquals("value1", values[0]);meta.set(CONTENTTYPE, "value2");values = meta.getValues(CONTENTTYPE);- assertEquals(1, values.length);- assertEquals("value2", values[0]);+ Assert.assertEquals(1, values.length);+ Assert.assertEquals("value2", values[0]);meta.set(CONTENTTYPE, "new value 1");meta.add("contenttype", "new value 2");values = meta.getValues(CONTENTTYPE);- assertEquals(2, values.length);- assertEquals("new value 1", values[0]);- assertEquals("new value 2", values[1]);+ Assert.assertEquals(2, values.length);+ Assert.assertEquals("new value 1", values[0]);+ Assert.assertEquals("new value 2", values[1]);}/** Test for <code>setAll(Properties)</code> method. */+ @Testpublic void testSetProperties() {String[] values = null;Metadata meta = new Metadata();Properties props = new Properties();meta.setAll(props);- assertEquals(0, meta.size());+ Assert.assertEquals(0, meta.size());props.setProperty("name-one", "value1.1");meta.setAll(props);- assertEquals(1, meta.size());+ Assert.assertEquals(1, meta.size());values = meta.getValues("name-one");- assertEquals(1, values.length);- assertEquals("value1.1", values[0]);+ Assert.assertEquals(1, values.length);+ Assert.assertEquals("value1.1", values[0]);props.setProperty("name-two", "value2.1");meta.setAll(props);- assertEquals(2, meta.size());+ Assert.assertEquals(2, meta.size());values = meta.getValues("name-one");- assertEquals(1, values.length);- assertEquals("value1.1", values[0]);+ Assert.assertEquals(1, values.length);+ Assert.assertEquals("value1.1", values[0]);values = meta.getValues("name-two");- assertEquals(1, values.length);- assertEquals("value2.1", values[0]);+ Assert.assertEquals(1, values.length);+ Assert.assertEquals("value2.1", values[0]);}/** Test for <code>get(String)</code> method. */+ @Testpublic void testGet() {Metadata meta = new Metadata();- assertNull(meta.get("a-name"));+ Assert.assertNull(meta.get("a-name"));meta.add("a-name", "value-1");- assertEquals("value-1", meta.get("a-name"));+ Assert.assertEquals("value-1", meta.get("a-name"));meta.add("a-name", "value-2");- assertEquals("value-1", meta.get("a-name"));+ Assert.assertEquals("value-1", meta.get("a-name"));}/** Test for <code>isMultiValued()</code> method. */+ @Testpublic void testIsMultiValued() {Metadata meta = new Metadata();- assertFalse(meta.isMultiValued("key"));+ Assert.assertFalse(meta.isMultiValued("key"));meta.add("key", "value1");- assertFalse(meta.isMultiValued("key"));+ Assert.assertFalse(meta.isMultiValued("key"));meta.add("key", "value2");- assertTrue(meta.isMultiValued("key"));+ Assert.assertTrue(meta.isMultiValued("key"));}/** Test for <code>names</code> method. */+ @Testpublic void testNames() {String[] names = null;Metadata meta = new Metadata();names = meta.names();- assertEquals(0, names.length);+ Assert.assertEquals(0, names.length);meta.add("name-one", "value");names = meta.names();- assertEquals(1, names.length);- assertEquals("name-one", names[0]);+ Assert.assertEquals(1, names.length);+ Assert.assertEquals("name-one", names[0]);meta.add("name-two", "value");names = meta.names();- assertEquals(2, names.length);+ Assert.assertEquals(2, names.length);}/** Test for <code>remove(String)</code> method. */+ @Testpublic void testRemove() {Metadata meta = new Metadata();meta.remove("name-one");- assertEquals(0, meta.size());+ Assert.assertEquals(0, meta.size());meta.add("name-one", "value-1.1");meta.add("name-one", "value-1.2");meta.add("name-two", "value-2.2");- assertEquals(2, meta.size());- assertNotNull(meta.get("name-one"));- assertNotNull(meta.get("name-two"));+ Assert.assertEquals(2, meta.size());+ Assert.assertNotNull(meta.get("name-one"));+ Assert.assertNotNull(meta.get("name-two"));meta.remove("name-one");- assertEquals(1, meta.size());- assertNull(meta.get("name-one"));- assertNotNull(meta.get("name-two"));+ Assert.assertEquals(1, meta.size());+ Assert.assertNull(meta.get("name-one"));+ Assert.assertNotNull(meta.get("name-two"));meta.remove("name-two");- assertEquals(0, meta.size());- assertNull(meta.get("name-one"));- assertNull(meta.get("name-two"));+ Assert.assertEquals(0, meta.size());+ Assert.assertNull(meta.get("name-one"));+ Assert.assertNull(meta.get("name-two"));}/** Test for <code>equals(Object)</code> method. */+ @Testpublic void testObject() {Metadata meta1 = new Metadata();Metadata meta2 = new Metadata();- assertFalse(meta1.equals(null));- assertFalse(meta1.equals("String"));- assertTrue(meta1.equals(meta2));+ Assert.assertFalse(meta1.equals(null));+ Assert.assertFalse(meta1.equals("String"));+ Assert.assertTrue(meta1.equals(meta2));meta1.add("name-one", "value-1.1");- assertFalse(meta1.equals(meta2));+ Assert.assertFalse(meta1.equals(meta2));meta2.add("name-one", "value-1.1");- assertTrue(meta1.equals(meta2));+ Assert.assertTrue(meta1.equals(meta2));meta1.add("name-one", "value-1.2");- assertFalse(meta1.equals(meta2));+ Assert.assertFalse(meta1.equals(meta2));meta2.add("name-one", "value-1.2");- assertTrue(meta1.equals(meta2));+ Assert.assertTrue(meta1.equals(meta2));meta1.add("name-two", "value-2.1");- assertFalse(meta1.equals(meta2));+ Assert.assertFalse(meta1.equals(meta2));meta2.add("name-two", "value-2.1");- assertTrue(meta1.equals(meta2));+ Assert.assertTrue(meta1.equals(meta2));meta1.add("name-two", "value-2.2");- assertFalse(meta1.equals(meta2));+ Assert.assertFalse(meta1.equals(meta2));meta2.add("name-two", "value-2.x");- assertFalse(meta1.equals(meta2));+ Assert.assertFalse(meta1.equals(meta2));}/** Test for <code>Writable</code> implementation. */+ @Testpublic void testWritable() {Metadata result = null;Metadata meta = new Metadata();result = writeRead(meta);- assertEquals(0, result.size());+ Assert.assertEquals(0, result.size());meta.add("name-one", "value-1.1");result = writeRead(meta);- assertEquals(1, result.size());- assertEquals(1, result.getValues("name-one").length);- assertEquals("value-1.1", result.get("name-one"));+ Assert.assertEquals(1, result.size());+ Assert.assertEquals(1, result.getValues("name-one").length);+ Assert.assertEquals("value-1.1", result.get("name-one"));meta.add("name-two", "value-2.1");meta.add("name-two", "value-2.2");result = writeRead(meta);- assertEquals(2, result.size());- assertEquals(1, result.getValues("name-one").length);- assertEquals("value-1.1", result.getValues("name-one")[0]);- assertEquals(2, result.getValues("name-two").length);- assertEquals("value-2.1", result.getValues("name-two")[0]);- assertEquals("value-2.2", result.getValues("name-two")[1]);+ Assert.assertEquals(2, result.size());+ Assert.assertEquals(1, result.getValues("name-one").length);+ Assert.assertEquals("value-1.1", result.getValues("name-one")[0]);+ Assert.assertEquals(2, result.getValues("name-two").length);+ Assert.assertEquals("value-2.1", result.getValues("name-two")[0]);+ Assert.assertEquals("value-2.2", result.getValues("name-two")[1]);}private Metadata writeRead(Metadata meta) {@@ -276,7 +274,7 @@ public class TestMetadata extends TestCase {readed.readFields(new DataInputStream(new ByteArrayInputStream(out.toByteArray())));} catch (IOException ioe) {- fail(ioe.toString());+ Assert.fail(ioe.toString());}return readed;}diff --git a/src/test/org/apache/nutch/metadata/TestSpellCheckedMetadata.java b/src/test/org/apache/nutch/metadata/TestSpellCheckedMetadata.javaindex 3ebb4ddda..7b2ceeecb 100644--- a/src/test/org/apache/nutch/metadata/TestSpellCheckedMetadata.java+++ b/src/test/org/apache/nutch/metadata/TestSpellCheckedMetadata.java@@ -22,10 +22,9 @@ import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.IOException;import java.util.Properties;-import junit.framework.Test;-import junit.framework.TestCase;-import junit.framework.TestSuite;-import junit.textui.TestRunner;++import org.junit.Assert;+import org.junit.Test;/*** JUnit based tests of class@@ -34,232 +33,232 @@ import junit.textui.TestRunner;* @author Chris Mattmann* @author Jérôme Charron*/-public class TestSpellCheckedMetadata extends TestCase {+public class TestSpellCheckedMetadata {private static final int NUM_ITERATIONS = 10000;- public TestSpellCheckedMetadata(String testName) {- super(testName);- }-- public static Test suite() {- return new TestSuite(TestSpellCheckedMetadata.class);- }-- public static void main(String[] args) {- TestRunner.run(suite());- }-/** Test for the <code>getNormalizedName(String)</code> method. */+ @Testpublic void testGetNormalizedName() {- assertEquals("Content-Type", SpellCheckedMetadata+ Assert.assertEquals("Content-Type", SpellCheckedMetadata.getNormalizedName("Content-Type"));- assertEquals("Content-Type", SpellCheckedMetadata+ Assert.assertEquals("Content-Type", SpellCheckedMetadata.getNormalizedName("ContentType"));- assertEquals("Content-Type", SpellCheckedMetadata+ Assert.assertEquals("Content-Type", SpellCheckedMetadata.getNormalizedName("Content-type"));- assertEquals("Content-Type", SpellCheckedMetadata+ Assert.assertEquals("Content-Type", SpellCheckedMetadata.getNormalizedName("contenttype"));- assertEquals("Content-Type", SpellCheckedMetadata+ Assert.assertEquals("Content-Type", SpellCheckedMetadata.getNormalizedName("contentype"));- assertEquals("Content-Type", SpellCheckedMetadata+ Assert.assertEquals("Content-Type", SpellCheckedMetadata.getNormalizedName("contntype"));}/** Test for the <code>add(String, String)</code> method. */+ @Testpublic void testAdd() {String[] values = null;SpellCheckedMetadata meta = new SpellCheckedMetadata();values = meta.getValues("contentype");- assertEquals(0, values.length);+ Assert.assertEquals(0, values.length);meta.add("contentype", "value1");values = meta.getValues("contentype");- assertEquals(1, values.length);- assertEquals("value1", values[0]);+ Assert.assertEquals(1, values.length);+ Assert.assertEquals("value1", values[0]);meta.add("Content-Type", "value2");values = meta.getValues("contentype");- assertEquals(2, values.length);- assertEquals("value1", values[0]);- assertEquals("value2", values[1]);+ Assert.assertEquals(2, values.length);+ Assert.assertEquals("value1", values[0]);+ Assert.assertEquals("value2", values[1]);// NOTE : For now, the same value can be added many times.// Should it be changed?meta.add("ContentType", "value1");values = meta.getValues("Content-Type");- assertEquals(3, values.length);- assertEquals("value1", values[0]);- assertEquals("value2", values[1]);- assertEquals("value1", values[2]);+ Assert.assertEquals(3, values.length);+ Assert.assertEquals("value1", values[0]);+ Assert.assertEquals("value2", values[1]);+ Assert.assertEquals("value1", values[2]);}/** Test for the <code>set(String, String)</code> method. */+ @Testpublic void testSet() {String[] values = null;SpellCheckedMetadata meta = new SpellCheckedMetadata();values = meta.getValues("contentype");- assertEquals(0, values.length);+ Assert.assertEquals(0, values.length);meta.set("contentype", "value1");values = meta.getValues("contentype");- assertEquals(1, values.length);- assertEquals("value1", values[0]);+ Assert.assertEquals(1, values.length);+ Assert.assertEquals("value1", values[0]);meta.set("Content-Type", "value2");values = meta.getValues("contentype");- assertEquals(1, values.length);- assertEquals("value2", values[0]);+ Assert.assertEquals(1, values.length);+ Assert.assertEquals("value2", values[0]);meta.set("contenttype", "new value 1");meta.add("contenttype", "new value 2");values = meta.getValues("contentype");- assertEquals(2, values.length);- assertEquals("new value 1", values[0]);- assertEquals("new value 2", values[1]);+ Assert.assertEquals(2, values.length);+ Assert.assertEquals("new value 1", values[0]);+ Assert.assertEquals("new value 2", values[1]);}/** Test for <code>setAll(Properties)</code> method. */+ @Testpublic void testSetProperties() {String[] values = null;SpellCheckedMetadata meta = new SpellCheckedMetadata();Properties props = new Properties();meta.setAll(props);- assertEquals(0, meta.size());+ Assert.assertEquals(0, meta.size());props.setProperty("name-one", "value1.1");meta.setAll(props);- assertEquals(1, meta.size());+ Assert.assertEquals(1, meta.size());values = meta.getValues("name-one");- assertEquals(1, values.length);- assertEquals("value1.1", values[0]);+ Assert.assertEquals(1, values.length);+ Assert.assertEquals("value1.1", values[0]);props.setProperty("name-two", "value2.1");meta.setAll(props);- assertEquals(2, meta.size());+ Assert.assertEquals(2, meta.size());values = meta.getValues("name-one");- assertEquals(1, values.length);- assertEquals("value1.1", values[0]);+ Assert.assertEquals(1, values.length);+ Assert.assertEquals("value1.1", values[0]);values = meta.getValues("name-two");- assertEquals(1, values.length);- assertEquals("value2.1", values[0]);+ Assert.assertEquals(1, values.length);+ Assert.assertEquals("value2.1", values[0]);}/** Test for <code>get(String)</code> method. */+ @Testpublic void testGet() {SpellCheckedMetadata meta = new SpellCheckedMetadata();- assertNull(meta.get("a-name"));+ Assert.assertNull(meta.get("a-name"));meta.add("a-name", "value-1");- assertEquals("value-1", meta.get("a-name"));+ Assert.assertEquals("value-1", meta.get("a-name"));meta.add("a-name", "value-2");- assertEquals("value-1", meta.get("a-name"));+ Assert.assertEquals("value-1", meta.get("a-name"));}/** Test for <code>isMultiValued()</code> method. */+ @Testpublic void testIsMultiValued() {SpellCheckedMetadata meta = new SpellCheckedMetadata();- assertFalse(meta.isMultiValued("key"));+ Assert.assertFalse(meta.isMultiValued("key"));meta.add("key", "value1");- assertFalse(meta.isMultiValued("key"));+ Assert.assertFalse(meta.isMultiValued("key"));meta.add("key", "value2");- assertTrue(meta.isMultiValued("key"));+ Assert.assertTrue(meta.isMultiValued("key"));}/** Test for <code>names</code> method. */+ @Testpublic void testNames() {String[] names = null;SpellCheckedMetadata meta = new SpellCheckedMetadata();names = meta.names();- assertEquals(0, names.length);+ Assert.assertEquals(0, names.length);meta.add("name-one", "value");names = meta.names();- assertEquals(1, names.length);- assertEquals("name-one", names[0]);+ Assert.assertEquals(1, names.length);+ Assert.assertEquals("name-one", names[0]);meta.add("name-two", "value");names = meta.names();- assertEquals(2, names.length);+ Assert.assertEquals(2, names.length);}/** Test for <code>remove(String)</code> method. */+ @Testpublic void testRemove() {SpellCheckedMetadata meta = new SpellCheckedMetadata();meta.remove("name-one");- assertEquals(0, meta.size());+ Assert.assertEquals(0, meta.size());meta.add("name-one", "value-1.1");meta.add("name-one", "value-1.2");meta.add("name-two", "value-2.2");- assertEquals(2, meta.size());- assertNotNull(meta.get("name-one"));- assertNotNull(meta.get("name-two"));+ Assert.assertEquals(2, meta.size());+ Assert.assertNotNull(meta.get("name-one"));+ Assert.assertNotNull(meta.get("name-two"));meta.remove("name-one");- assertEquals(1, meta.size());- assertNull(meta.get("name-one"));- assertNotNull(meta.get("name-two"));+ Assert.assertEquals(1, meta.size());+ Assert.assertNull(meta.get("name-one"));+ Assert.assertNotNull(meta.get("name-two"));meta.remove("name-two");- assertEquals(0, meta.size());- assertNull(meta.get("name-one"));- assertNull(meta.get("name-two"));+ Assert.assertEquals(0, meta.size());+ Assert.assertNull(meta.get("name-one"));+ Assert.assertNull(meta.get("name-two"));}/** Test for <code>equals(Object)</code> method. */+ @Testpublic void testObject() {SpellCheckedMetadata meta1 = new SpellCheckedMetadata();SpellCheckedMetadata meta2 = new SpellCheckedMetadata();- assertFalse(meta1.equals(null));- assertFalse(meta1.equals("String"));- assertTrue(meta1.equals(meta2));+ Assert.assertFalse(meta1.equals(null));+ Assert.assertFalse(meta1.equals("String"));+ Assert.assertTrue(meta1.equals(meta2));meta1.add("name-one", "value-1.1");- assertFalse(meta1.equals(meta2));+ Assert.assertFalse(meta1.equals(meta2));meta2.add("name-one", "value-1.1");- assertTrue(meta1.equals(meta2));+ Assert.assertTrue(meta1.equals(meta2));meta1.add("name-one", "value-1.2");- assertFalse(meta1.equals(meta2));+ Assert.assertFalse(meta1.equals(meta2));meta2.add("name-one", "value-1.2");- assertTrue(meta1.equals(meta2));+ Assert.assertTrue(meta1.equals(meta2));meta1.add("name-two", "value-2.1");- assertFalse(meta1.equals(meta2));+ Assert.assertFalse(meta1.equals(meta2));meta2.add("name-two", "value-2.1");- assertTrue(meta1.equals(meta2));+ Assert.assertTrue(meta1.equals(meta2));meta1.add("name-two", "value-2.2");- assertFalse(meta1.equals(meta2));+ Assert.assertFalse(meta1.equals(meta2));meta2.add("name-two", "value-2.x");- assertFalse(meta1.equals(meta2));+ Assert.assertFalse(meta1.equals(meta2));}/** Test for <code>Writable</code> implementation. */+ @Testpublic void testWritable() {SpellCheckedMetadata result = null;SpellCheckedMetadata meta = new SpellCheckedMetadata();result = writeRead(meta);- assertEquals(0, result.size());+ Assert.assertEquals(0, result.size());meta.add("name-one", "value-1.1");result = writeRead(meta);meta.add("Contenttype", "text/html");- assertEquals(1, result.size());- assertEquals(1, result.getValues("name-one").length);- assertEquals("value-1.1", result.get("name-one"));+ Assert.assertEquals(1, result.size());+ Assert.assertEquals(1, result.getValues("name-one").length);+ Assert.assertEquals("value-1.1", result.get("name-one"));meta.add("name-two", "value-2.1");meta.add("name-two", "value-2.2");result = writeRead(meta);- assertEquals(3, result.size());- assertEquals(1, result.getValues("name-one").length);- assertEquals("value-1.1", result.getValues("name-one")[0]);- assertEquals(2, result.getValues("name-two").length);- assertEquals("value-2.1", result.getValues("name-two")[0]);- assertEquals("value-2.2", result.getValues("name-two")[1]);- assertEquals("text/html", result.get(Metadata.CONTENT_TYPE));+ Assert.assertEquals(3, result.size());+ Assert.assertEquals(1, result.getValues("name-one").length);+ Assert.assertEquals("value-1.1", result.getValues("name-one")[0]);+ Assert.assertEquals(2, result.getValues("name-two").length);+ Assert.assertEquals("value-2.1", result.getValues("name-two")[0]);+ Assert.assertEquals("value-2.2", result.getValues("name-two")[1]);+ Assert.assertEquals("text/html", result.get(Metadata.CONTENT_TYPE));}/*** IO Test method, usable only when you plan to do changes in metadata* to measure relative performance impact.*/+ @Testpublic final void testHandlingSpeed() {+ @SuppressWarnings("unused")SpellCheckedMetadata result;long start = System.currentTimeMillis();for (int i = 0; i < NUM_ITERATIONS; i++) {@@ -278,7 +277,7 @@ public class TestSpellCheckedMetadata extends TestCase {readed.readFields(new DataInputStream(new ByteArrayInputStream(out.toByteArray())));} catch (IOException ioe) {- fail(ioe.toString());+ Assert.fail(ioe.toString());}return readed;}diff --git a/src/test/org/apache/nutch/net/TestURLFilters.java b/src/test/org/apache/nutch/net/TestURLFilters.javaindex 66d9d560c..3cb556ef5 100644--- a/src/test/org/apache/nutch/net/TestURLFilters.java+++ b/src/test/org/apache/nutch/net/TestURLFilters.java@@ -18,15 +18,15 @@ package org.apache.nutch.net;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;+import org.junit.Test;-import junit.framework.TestCase;--public class TestURLFilters extends TestCase {+public class TestURLFilters {/*** Testcase for NUTCH-325.* @throws URLFilterException*/+ @Testpublic void testNonExistingUrlFilter() throws URLFilterException {Configuration conf = NutchConfiguration.create();String class1 = "NonExistingFilter";diff --git a/src/test/org/apache/nutch/net/TestURLNormalizers.java b/src/test/org/apache/nutch/net/TestURLNormalizers.javaindex 1d4b3f89b..bd2e73361 100644--- a/src/test/org/apache/nutch/net/TestURLNormalizers.java+++ b/src/test/org/apache/nutch/net/TestURLNormalizers.java@@ -20,11 +20,12 @@ import java.net.MalformedURLException;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;+import org.junit.Assert;+import org.junit.Test;-import junit.framework.TestCase;--public class TestURLNormalizers extends TestCase {+public class TestURLNormalizers {+ @Testpublic void testURLNormalizers() {Configuration conf = NutchConfiguration.create();String clazz1 = "org.apache.nutch.net.urlnormalizer.regex.RegexURLNormalizer";@@ -33,27 +34,27 @@ public class TestURLNormalizers extends TestCase {URLNormalizers normalizers = new URLNormalizers(conf, URLNormalizers.SCOPE_DEFAULT);- assertNotNull(normalizers);+ Assert.assertNotNull(normalizers);try {normalizers.normalize("http://www.example.com/", URLNormalizers.SCOPE_DEFAULT);} catch (MalformedURLException mue) {- fail(mue.toString());+ Assert.fail(mue.toString());}// NUTCH-1011 - Get rid of superfluous slashestry {String normalizedSlashes = normalizers.normalize("http://www.example.com//path/to//somewhere.html", URLNormalizers.SCOPE_DEFAULT);- assertEquals(normalizedSlashes, "http://www.example.com/path/to/somewhere.html");+ Assert.assertEquals(normalizedSlashes, "http://www.example.com/path/to/somewhere.html");} catch (MalformedURLException mue) {- fail(mue.toString());+ Assert.fail(mue.toString());}// HostNormalizer NUTCH-1319try {String normalizedHost = normalizers.normalize("http://www.example.org//path/to//somewhere.html", URLNormalizers.SCOPE_DEFAULT);- assertEquals(normalizedHost, "http://example.org/path/to/somewhere.html");+ Assert.assertEquals(normalizedHost, "http://example.org/path/to/somewhere.html");} catch (MalformedURLException mue) {- fail(mue.toString());+ Assert.fail(mue.toString());}// check the order@@ -64,7 +65,7 @@ public class TestURLNormalizers extends TestCase {if (impls[i].getClass().getName().equals(clazz2)) pos2 = i;}if (pos1 != -1 && pos2 != -1) {- assertTrue("RegexURLNormalizer before BasicURLNormalizer", pos1 < pos2);+ Assert.assertTrue("RegexURLNormalizer before BasicURLNormalizer", pos1 < pos2);}}}diff --git a/src/test/org/apache/nutch/parse/TestOutlinkExtractor.java b/src/test/org/apache/nutch/parse/TestOutlinkExtractor.javaindex 354f9b630..ede0ce804 100644--- a/src/test/org/apache/nutch/parse/TestOutlinkExtractor.java+++ b/src/test/org/apache/nutch/parse/TestOutlinkExtractor.java@@ -21,8 +21,8 @@ import org.apache.nutch.parse.Outlink;import org.apache.nutch.parse.OutlinkExtractor;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;--import junit.framework.TestCase;+import org.junit.Assert;+import org.junit.Test;/*** TestCase to check regExp extraction of URLs.@@ -31,51 +31,57 @@ import junit.framework.TestCase;** @version 1.0*/-public class TestOutlinkExtractor extends TestCase {+public class TestOutlinkExtractor {private static Configuration conf = NutchConfiguration.create();++ @Testpublic void testGetNoOutlinks() {Outlink[] outlinks = null;outlinks = OutlinkExtractor.getOutlinks(null, conf);- assertNotNull(outlinks);- assertEquals(0, outlinks.length);+ Assert.assertNotNull(outlinks);+ Assert.assertEquals(0, outlinks.length);outlinks = OutlinkExtractor.getOutlinks("", conf);- assertNotNull(outlinks);- assertEquals(0, outlinks.length);+ Assert.assertNotNull(outlinks);+ Assert.assertEquals(0, outlinks.length);}+ @Testpublic void testGetOutlinksHttp() {Outlink[] outlinks = OutlinkExtractor.getOutlinks("Test with http://www.nutch.org/index.html is it found? " +"What about www.google.com at http://www.google.de " +"A longer URL could be http://www.sybit.com/solutions/portals.html", conf);- assertTrue("Url not found!", outlinks.length == 3);- assertEquals("Wrong URL", "http://www.nutch.org/index.html", outlinks[0].getToUrl());- assertEquals("Wrong URL", "http://www.google.de", outlinks[1].getToUrl());- assertEquals("Wrong URL", "http://www.sybit.com/solutions/portals.html", outlinks[2].getToUrl());+ Assert.assertTrue("Url not found!", outlinks.length == 3);+ Assert.assertEquals("Wrong URL", "http://www.nutch.org/index.html", outlinks[0].getToUrl());+ Assert.assertEquals("Wrong URL", "http://www.google.de", outlinks[1].getToUrl());+ Assert.assertEquals("Wrong URL", "http://www.sybit.com/solutions/portals.html", outlinks[2].getToUrl());}+ @Testpublic void testGetOutlinksHttp2() {Outlink[] outlinks = OutlinkExtractor.getOutlinks("Test with http://www.nutch.org/index.html is it found? " +"What about www.google.com at http://www.google.de " +"A longer URL could be http://www.sybit.com/solutions/portals.html", "http://www.sybit.de", conf);- assertTrue("Url not found!", outlinks.length == 3);- assertEquals("Wrong URL", "http://www.nutch.org/index.html", outlinks[0].getToUrl());- assertEquals("Wrong URL", "http://www.google.de", outlinks[1].getToUrl());- assertEquals("Wrong URL", "http://www.sybit.com/solutions/portals.html", outlinks[2].getToUrl());+ Assert.assertTrue("Url not found!", outlinks.length == 3);+ Assert.assertEquals("Wrong URL", "http://www.nutch.org/index.html", outlinks[0].getToUrl());+ Assert.assertEquals("Wrong URL", "http://www.google.de", outlinks[1].getToUrl());+ Assert.assertEquals("Wrong URL", "http://www.sybit.com/solutions/portals.html", outlinks[2].getToUrl());}++ @Testpublic void testGetOutlinksFtp() {Outlink[] outlinks = OutlinkExtractor.getOutlinks("Test with ftp://www.nutch.org is it found? " +"What about www.google.com at ftp://www.google.de", conf);- assertTrue("Url not found!", outlinks.length >1);- assertEquals("Wrong URL", "ftp://www.nutch.org", outlinks[0].getToUrl());- assertEquals("Wrong URL", "ftp://www.google.de", outlinks[1].getToUrl());+ Assert.assertTrue("Url not found!", outlinks.length >1);+ Assert.assertEquals("Wrong URL", "ftp://www.nutch.org", outlinks[0].getToUrl());+ Assert.assertEquals("Wrong URL", "ftp://www.google.de", outlinks[1].getToUrl());}}diff --git a/src/test/org/apache/nutch/parse/TestParseData.java b/src/test/org/apache/nutch/parse/TestParseData.javaindex 4cd20f0ef..9507306bf 100644--- a/src/test/org/apache/nutch/parse/TestParseData.java+++ b/src/test/org/apache/nutch/parse/TestParseData.java@@ -17,22 +17,16 @@package org.apache.nutch.parse;-import org.apache.hadoop.conf.Configuration;-import org.apache.nutch.util.NutchConfiguration;-import org.apache.nutch.util.WritableTestUtils;import org.apache.nutch.metadata.Metadata;--import junit.framework.TestCase;+import org.junit.Assert;+import org.junit.Test;/** Unit tests for ParseData. */-public class TestParseData extends TestCase {-- private Configuration conf = NutchConfiguration.create();-- public TestParseData(String name) { super(name); }+public class TestParseData {+ @Testpublic void testParseData() throws Exception {String title = "The Foo Page";@@ -50,7 +44,8 @@ public class TestParseData extends TestCase {WritableTestUtils.testWritable(r, null);}-++ @Testpublic void testMaxOutlinks() throws Exception {Outlink[] outlinks = new Outlink[128];for (int i=0; i<outlinks.length; i++) {@@ -61,6 +56,6 @@ public class TestParseData extends TestCase {outlinks,new Metadata());ParseData data = (ParseData) WritableTestUtils.writeRead(original, null);- assertEquals(outlinks.length, data.getOutlinks().length);+ Assert.assertEquals(outlinks.length, data.getOutlinks().length);}}diff --git a/src/test/org/apache/nutch/parse/TestParseText.java b/src/test/org/apache/nutch/parse/TestParseText.javaindex 7aa1cd8d9..edacb64c1 100644--- a/src/test/org/apache/nutch/parse/TestParseText.java+++ b/src/test/org/apache/nutch/parse/TestParseText.java@@ -18,21 +18,17 @@package org.apache.nutch.parse;import org.apache.nutch.util.WritableTestUtils;--import junit.framework.TestCase;+import org.junit.Test;/** Unit tests for ParseText. */-public class TestParseText extends TestCase {- public TestParseText(String name) { super(name); }+public class TestParseText {+ @Testpublic void testParseText() throws Exception {String page = "Hello World The Quick Brown Fox Jumped Over the Lazy Fox";-ParseText s = new ParseText(page);-WritableTestUtils.testWritable(s);}-}diff --git a/src/test/org/apache/nutch/parse/TestParserFactory.java b/src/test/org/apache/nutch/parse/TestParserFactory.javaindex 1a5e40407..7b6697302 100644--- a/src/test/org/apache/nutch/parse/TestParserFactory.java+++ b/src/test/org/apache/nutch/parse/TestParserFactory.java@@ -17,13 +17,13 @@package org.apache.nutch.parse;-// JUnit imports-import junit.framework.TestCase;-// Nutch importsimport org.apache.nutch.plugin.Extension;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;/*** Unit test for new parse plugin selection.@@ -31,15 +31,14 @@ import org.apache.nutch.util.NutchConfiguration;* @author Sebastien Le Callonnec* @version 1.0*/-public class TestParserFactory extends TestCase {+public class TestParserFactory {private Configuration conf;private ParserFactory parserFactory;-- public TestParserFactory(String name) { super(name); }/** Inits the Test Case with the test parse-plugin file */- protected void setUp() throws Exception {+ @Before+ public void setUp() throws Exception {conf = NutchConfiguration.create();conf.set("plugin.includes", ".*");conf.set("parse.plugin.file",@@ -48,54 +47,56 @@ public class TestParserFactory extends TestCase {}/** Unit test for <code>getExtensions(String)</code> method. */+ @Testpublic void testGetExtensions() throws Exception {Extension ext = parserFactory.getExtensions("text/html").get(0);- assertEquals("parse-tika", ext.getDescriptor().getPluginId());+ Assert.assertEquals("parse-tika", ext.getDescriptor().getPluginId());ext = parserFactory.getExtensions("text/html; charset=ISO-8859-1").get(0);- assertEquals("parse-tika", ext.getDescriptor().getPluginId());+ Assert.assertEquals("parse-tika", ext.getDescriptor().getPluginId());ext = parserFactory.getExtensions("foo/bar").get(0);- assertEquals("parse-tika", ext.getDescriptor().getPluginId());+ Assert.assertEquals("parse-tika", ext.getDescriptor().getPluginId());}/** Unit test to check <code>getParsers</code> method */+ @Testpublic void testGetParsers() throws Exception {Parser [] parsers = parserFactory.getParsers("text/html", "http://foo.com");- assertNotNull(parsers);- assertEquals(1, parsers.length);- assertEquals("org.apache.nutch.parse.tika.TikaParser",+ Assert.assertNotNull(parsers);+ Assert.assertEquals(1, parsers.length);+ Assert.assertEquals("org.apache.nutch.parse.tika.TikaParser",parsers[0].getClass().getName());parsers = parserFactory.getParsers("text/html; charset=ISO-8859-1","http://foo.com");- assertNotNull(parsers);- assertEquals(1, parsers.length);- assertEquals("org.apache.nutch.parse.tika.TikaParser",+ Assert.assertNotNull(parsers);+ Assert.assertEquals(1, parsers.length);+ Assert.assertEquals("org.apache.nutch.parse.tika.TikaParser",parsers[0].getClass().getName());parsers = parserFactory.getParsers("application/x-javascript","http://foo.com");- assertNotNull(parsers);- assertEquals(1, parsers.length);- assertEquals("org.apache.nutch.parse.js.JSParseFilter",+ Assert.assertNotNull(parsers);+ Assert.assertEquals(1, parsers.length);+ Assert.assertEquals("org.apache.nutch.parse.js.JSParseFilter",parsers[0].getClass().getName());parsers = parserFactory.getParsers("text/plain", "http://foo.com");- assertNotNull(parsers);- assertEquals(1, parsers.length);- assertEquals("org.apache.nutch.parse.tika.TikaParser",+ Assert.assertNotNull(parsers);+ Assert.assertEquals(1, parsers.length);+ Assert.assertEquals("org.apache.nutch.parse.tika.TikaParser",parsers[0].getClass().getName());Parser parser1 = parserFactory.getParsers("text/plain", "http://foo.com")[0];Parser parser2 = parserFactory.getParsers("*", "http://foo.com")[0];- assertEquals("Different instances!", parser1.hashCode(), parser2.hashCode());+ Assert.assertEquals("Different instances!", parser1.hashCode(), parser2.hashCode());//test and make sure that the rss parser is loaded even though its plugin.xml//doesn't claim to support text/rss, only application/rss+xmlparsers = parserFactory.getParsers("text/rss","http://foo.com");- assertNotNull(parsers);- assertEquals(1,parsers.length);- assertEquals("org.apache.nutch.parse.tika.TikaParser",+ Assert.assertNotNull(parsers);+ Assert.assertEquals(1,parsers.length);+ Assert.assertEquals("org.apache.nutch.parse.tika.TikaParser",parsers[0].getClass().getName());}diff --git a/src/test/org/apache/nutch/plugin/TestPluginSystem.java b/src/test/org/apache/nutch/plugin/TestPluginSystem.javaindex d5ecaedbc..e73af5513 100644--- a/src/test/org/apache/nutch/plugin/TestPluginSystem.java+++ b/src/test/org/apache/nutch/plugin/TestPluginSystem.java@@ -26,272 +26,283 @@ import java.util.LinkedList;import java.util.Locale;import java.util.Properties;-import junit.framework.TestCase;-import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.mapred.JobConf;import org.apache.nutch.util.NutchConfiguration;import org.apache.nutch.util.NutchJob;+import org.junit.After;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;/*** Unit tests for the plugin system*/-public class TestPluginSystem extends TestCase {- private int fPluginCount;+public class TestPluginSystem {+ private int fPluginCount;- private LinkedList<File> fFolders = new LinkedList<File>();- private Configuration conf ;- private PluginRepository repository;+ private LinkedList<File> fFolders = new LinkedList<File>();+ private Configuration conf ;+ private PluginRepository repository;- protected void setUp() throws Exception {- this.conf = NutchConfiguration.create();- conf.set("plugin.includes", ".*");-// String string = this.conf.get("plugin.includes", "");-// conf.set("plugin.includes", string + "|Dummy*");- fPluginCount = 5;- createDummyPlugins(fPluginCount);- this.repository = PluginRepository.get(conf);- }+ @Before+ public void setUp() throws Exception {+ this.conf = NutchConfiguration.create();+ conf.set("plugin.includes", ".*");+ // String string = this.conf.get("plugin.includes", "");+ // conf.set("plugin.includes", string + "|Dummy*");+ fPluginCount = 5;+ createDummyPlugins(fPluginCount);+ this.repository = PluginRepository.get(conf);+ }- /*- * (non-Javadoc)- *- * @see junit.framework.TestCase#tearDown()- */- protected void tearDown() throws Exception {- for (int i = 0; i < fFolders.size(); i++) {- File folder = fFolders.get(i);- delete(folder);- folder.delete();- }+ /*+ * (non-Javadoc)+ *+ * @see junit.framework.TestCase#tearDown()+ */+ @After+ public void tearDown() throws Exception {+ for (int i = 0; i < fFolders.size(); i++) {+ File folder = fFolders.get(i);+ delete(folder);+ folder.delete();}+ }- /**- */- public void testPluginConfiguration() {- String string = getPluginFolder();- File file = new File(string);- if (!file.exists()) {- file.mkdir();- }- assertTrue(file.exists());+ /**+ */+ @Test+ public void testPluginConfiguration() {+ String string = getPluginFolder();+ File file = new File(string);+ if (!file.exists()) {+ file.mkdir();}+ Assert.assertTrue(file.exists());+ }- /**- */- public void testLoadPlugins() {- PluginDescriptor[] descriptors = repository- .getPluginDescriptors();- int k = descriptors.length;- assertTrue(fPluginCount <= k);- for (int i = 0; i < descriptors.length; i++) {- PluginDescriptor descriptor = descriptors[i];- if (!descriptor.getPluginId().startsWith("getPluginFolder()")) {- continue;- }- assertEquals(1, descriptor.getExportedLibUrls().length);- assertEquals(1, descriptor.getNotExportedLibUrls().length);- }+ /**+ */+ @Test+ public void testLoadPlugins() {+ PluginDescriptor[] descriptors = repository+ .getPluginDescriptors();+ int k = descriptors.length;+ Assert.assertTrue(fPluginCount <= k);+ for (int i = 0; i < descriptors.length; i++) {+ PluginDescriptor descriptor = descriptors[i];+ if (!descriptor.getPluginId().startsWith("getPluginFolder()")) {+ continue;+ }+ Assert.assertEquals(1, descriptor.getExportedLibUrls().length);+ Assert.assertEquals(1, descriptor.getNotExportedLibUrls().length);}+ }- public void testRepositoryCache() {- Configuration config = NutchConfiguration.create();- PluginRepository repo = PluginRepository.get(config);- JobConf job = new NutchJob(config);- PluginRepository repo1 = PluginRepository.get(job);- assertTrue(repo == repo1);- // now construct a config without UUID- config = new Configuration();- config.addResource("nutch-default.xml");- config.addResource("nutch-site.xml");- repo = PluginRepository.get(config);- job = new NutchJob(config);- repo1 = PluginRepository.get(job);- assertTrue(repo1 != repo);- }+ @Test+ public void testRepositoryCache() {+ Configuration config = NutchConfiguration.create();+ PluginRepository repo = PluginRepository.get(config);+ JobConf job = new NutchJob(config);+ PluginRepository repo1 = PluginRepository.get(job);+ Assert.assertTrue(repo == repo1);+ // now construct a config without UUID+ config = new Configuration();+ config.addResource("nutch-default.xml");+ config.addResource("nutch-site.xml");+ repo = PluginRepository.get(config);+ job = new NutchJob(config);+ repo1 = PluginRepository.get(job);+ Assert.assertTrue(repo1 != repo);+ }- /**- *- */- public void testGetExtensionAndAttributes() {- String xpId = " sdsdsd";- ExtensionPoint extensionPoint =repository- .getExtensionPoint(xpId);- assertEquals(extensionPoint, null);- Extension[] extension1 = repository- .getExtensionPoint(getGetExtensionId()).getExtensions();- assertEquals(extension1.length, fPluginCount);- for (int i = 0; i < extension1.length; i++) {- Extension extension2 = extension1[i];- String string = extension2.getAttribute(getGetConfigElementName());- assertEquals(string, getParameterValue());- }+ /**+ *+ */+ @Test+ public void testGetExtensionAndAttributes() {+ String xpId = " sdsdsd";+ ExtensionPoint extensionPoint =repository+ .getExtensionPoint(xpId);+ Assert.assertEquals(extensionPoint, null);+ Extension[] extension1 = repository+ .getExtensionPoint(getGetExtensionId()).getExtensions();+ Assert.assertEquals(extension1.length, fPluginCount);+ for (int i = 0; i < extension1.length; i++) {+ Extension extension2 = extension1[i];+ String string = extension2.getAttribute(getGetConfigElementName());+ Assert.assertEquals(string, getParameterValue());}+ }- /**- * @throws PluginRuntimeException- */- public void testGetExtensionInstances() throws PluginRuntimeException {- Extension[] extensions = repository- .getExtensionPoint(getGetExtensionId()).getExtensions();- assertEquals(extensions.length, fPluginCount);- for (int i = 0; i < extensions.length; i++) {- Extension extension = extensions[i];- Object object = extension.getExtensionInstance();- if (!(object instanceof HelloWorldExtension))- fail(" object is not a instance of HelloWorldExtension");- ((ITestExtension) object).testGetExtension("Bla ");- String string = ((ITestExtension) object).testGetExtension("Hello");- assertEquals("Hello World", string);- }+ /**+ * @throws PluginRuntimeException+ */+ @Test+ public void testGetExtensionInstances() throws PluginRuntimeException {+ Extension[] extensions = repository+ .getExtensionPoint(getGetExtensionId()).getExtensions();+ Assert.assertEquals(extensions.length, fPluginCount);+ for (int i = 0; i < extensions.length; i++) {+ Extension extension = extensions[i];+ Object object = extension.getExtensionInstance();+ if (!(object instanceof HelloWorldExtension))+ Assert.fail(" object is not a instance of HelloWorldExtension");+ ((ITestExtension) object).testGetExtension("Bla ");+ String string = ((ITestExtension) object).testGetExtension("Hello");+ Assert.assertEquals("Hello World", string);}+ }- /**- *- *- */- public void testGetClassLoader() {- PluginDescriptor[] descriptors = repository- .getPluginDescriptors();- for (int i = 0; i < descriptors.length; i++) {- PluginDescriptor descriptor = descriptors[i];- assertNotNull(descriptor.getClassLoader());- }+ /**+ *+ *+ */+ @Test+ public void testGetClassLoader() {+ PluginDescriptor[] descriptors = repository+ .getPluginDescriptors();+ for (int i = 0; i < descriptors.length; i++) {+ PluginDescriptor descriptor = descriptors[i];+ Assert.assertNotNull(descriptor.getClassLoader());}+ }- /**- * @throws IOException- */- public void testGetResources() throws IOException {- PluginDescriptor[] descriptors = repository- .getPluginDescriptors();- for (int i = 0; i < descriptors.length; i++) {- PluginDescriptor descriptor = descriptors[i];- if (!descriptor.getPluginId().startsWith("getPluginFolder()")) {- continue;- }- String value = descriptor.getResourceString("key", Locale.UK);- assertEquals("value", value);- value = descriptor.getResourceString("key",- Locale.TRADITIONAL_CHINESE);- assertEquals("value", value);+ /**+ * @throws IOException+ */+ @Test+ public void testGetResources() throws IOException {+ PluginDescriptor[] descriptors = repository+ .getPluginDescriptors();+ for (int i = 0; i < descriptors.length; i++) {+ PluginDescriptor descriptor = descriptors[i];+ if (!descriptor.getPluginId().startsWith("getPluginFolder()")) {+ continue;+ }+ String value = descriptor.getResourceString("key", Locale.UK);+ Assert.assertEquals("value", value);+ value = descriptor.getResourceString("key",+ Locale.TRADITIONAL_CHINESE);+ Assert.assertEquals("value", value);- }}+ }- /**- * @return a PluginFolderPath- */- private String getPluginFolder() {- String[] strings = conf.getStrings("plugin.folders");- if (strings == null || strings.length == 0)- fail("no plugin directory setuped..");+ /**+ * @return a PluginFolderPath+ */+ private String getPluginFolder() {+ String[] strings = conf.getStrings("plugin.folders");+ if (strings == null || strings.length == 0)+ Assert.fail("no plugin directory setuped..");- String name = strings[0];- return new PluginManifestParser(conf, this.repository).getPluginFolder(name).toString();- }+ String name = strings[0];+ return new PluginManifestParser(conf, this.repository).getPluginFolder(name).toString();+ }- /**- * Creates some Dummy Plugins- *- * @param pCount- */- private void createDummyPlugins(int pCount) {- String string = getPluginFolder();- try {- File folder = new File(string);- folder.mkdir();- for (int i = 0; i < pCount; i++) {- String pluginFolder = string + File.separator + "DummyPlugin"- + i;- File file = new File(pluginFolder);- file.mkdir();- fFolders.add(file);- createPluginManifest(i, file.getAbsolutePath());- createResourceFile(file.getAbsolutePath());- }- } catch (IOException e) {- e.printStackTrace();- }+ /**+ * Creates some Dummy Plugins+ *+ * @param pCount+ */+ private void createDummyPlugins(int pCount) {+ String string = getPluginFolder();+ try {+ File folder = new File(string);+ folder.mkdir();+ for (int i = 0; i < pCount; i++) {+ String pluginFolder = string + File.separator + "DummyPlugin"+ + i;+ File file = new File(pluginFolder);+ file.mkdir();+ fFolders.add(file);+ createPluginManifest(i, file.getAbsolutePath());+ createResourceFile(file.getAbsolutePath());+ }+ } catch (IOException e) {+ e.printStackTrace();}+ }- /**- * Creates an ResourceFile- *- * @param pFolderPath- * @throws FileNotFoundException- * @throws IOException- */- private void createResourceFile(String pFolderPath)- throws FileNotFoundException, IOException {- Properties properties = new Properties();- properties.setProperty("key", "value");- properties.store(new FileOutputStream(pFolderPath + File.separator- + "messages" + ".properties"), "");- }+ /**+ * Creates an ResourceFile+ *+ * @param pFolderPath+ * @throws FileNotFoundException+ * @throws IOException+ */+ private void createResourceFile(String pFolderPath)+ throws FileNotFoundException, IOException {+ Properties properties = new Properties();+ properties.setProperty("key", "value");+ properties.store(new FileOutputStream(pFolderPath + File.separator+ + "messages" + ".properties"), "");+ }- /**- * Deletes files in path- *- * @param path- * @throws IOException- */- private void delete(File path) throws IOException {- File[] files = path.listFiles();- for (int i = 0; i < files.length; ++i) {- if (files[i].isDirectory())- delete(files[i]);- files[i].delete();- }+ /**+ * Deletes files in path+ *+ * @param path+ * @throws IOException+ */+ private void delete(File path) throws IOException {+ File[] files = path.listFiles();+ for (int i = 0; i < files.length; ++i) {+ if (files[i].isDirectory())+ delete(files[i]);+ files[i].delete();}+ }- /**- * Creates an Plugin Manifest File- *- * @param i- * @param pFolderPath- * @throws IOException- */- private void createPluginManifest(int i, String pFolderPath)- throws IOException {- FileWriter out = new FileWriter(pFolderPath + File.separator- + "plugin.xml");- String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"- + "<!--this is just a simple plugin for testing issues.-->"- + "<plugin id=\"org.apache.nutch.plugin."- + i- + "\" name=\""- + i- + "\" version=\"1.0\" provider-name=\"joa23\" "- + "class=\"org.apache.nutch.plugin.SimpleTestPlugin\">"- + "<extension-point id=\"aExtensioID\" "- + "name=\"simple Parser Extension\" "- + "schema=\"schema/testExtensionPoint.exsd\"/>"- + "<runtime><library name=\"libs/exported.jar\"><extport/></library>"- + "<library name=\"libs/not_exported.jar\"/></runtime>"- + "<extension point=\"aExtensioID\">"- + "<implementation name=\"simple Parser Extension\" "- + "id=\"aExtensionId.\" class=\"org.apache.nutch.plugin.HelloWorldExtension\">"- + "<parameter name=\"dummy-name\" value=\"a simple param value\"/>"- + "</implementation></extension></plugin>";- out.write(xml);- out.flush();- out.close();- }+ /**+ * Creates an Plugin Manifest File+ *+ * @param i+ * @param pFolderPath+ * @throws IOException+ */+ private void createPluginManifest(int i, String pFolderPath)+ throws IOException {+ FileWriter out = new FileWriter(pFolderPath + File.separator+ + "plugin.xml");+ String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ + "<!--this is just a simple plugin for testing issues.-->"+ + "<plugin id=\"org.apache.nutch.plugin."+ + i+ + "\" name=\""+ + i+ + "\" version=\"1.0\" provider-name=\"joa23\" "+ + "class=\"org.apache.nutch.plugin.SimpleTestPlugin\">"+ + "<extension-point id=\"aExtensioID\" "+ + "name=\"simple Parser Extension\" "+ + "schema=\"schema/testExtensionPoint.exsd\"/>"+ + "<runtime><library name=\"libs/exported.jar\"><extport/></library>"+ + "<library name=\"libs/not_exported.jar\"/></runtime>"+ + "<extension point=\"aExtensioID\">"+ + "<implementation name=\"simple Parser Extension\" "+ + "id=\"aExtensionId.\" class=\"org.apache.nutch.plugin.HelloWorldExtension\">"+ + "<parameter name=\"dummy-name\" value=\"a simple param value\"/>"+ + "</implementation></extension></plugin>";+ out.write(xml);+ out.flush();+ out.close();+ }- private String getParameterValue() {- return "a simple param value";- }+ private String getParameterValue() {+ return "a simple param value";+ }- private static String getGetExtensionId() {- return "aExtensioID";- }+ private static String getGetExtensionId() {+ return "aExtensioID";+ }- private static String getGetConfigElementName() {- return "dummy-name";- }+ private static String getGetConfigElementName() {+ return "dummy-name";+ }- public static void main(String[] args) throws IOException {- new TestPluginSystem().createPluginManifest(1, "/");- }+ public static void main(String[] args) throws IOException {+ new TestPluginSystem().createPluginManifest(1, "/");+ }}diff --git a/src/test/org/apache/nutch/protocol/TestContent.java b/src/test/org/apache/nutch/protocol/TestContent.javaindex d8cba56c9..acf07eb62 100644--- a/src/test/org/apache/nutch/protocol/TestContent.java+++ b/src/test/org/apache/nutch/protocol/TestContent.java@@ -23,18 +23,16 @@ import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;import org.apache.nutch.util.WritableTestUtils;import org.apache.tika.mime.MimeTypes;--import junit.framework.TestCase;-+import org.junit.Assert;+import org.junit.Test;/** Unit tests for Content. */-public class TestContent extends TestCase {+public class TestContent {private static Configuration conf = NutchConfiguration.create();- public TestContent(String name) { super(name); }-+ @Testpublic void testContent() throws Exception {String page = "<HTML><BODY><H1>Hello World</H1><P>The Quick Brown Fox Jumped Over the Lazy Fox.</BODY></HTML>";@@ -46,66 +44,67 @@ public class TestContent extends TestCase {metaData.add("Content-Type", "text/html");Content r = new Content(url, url, page.getBytes("UTF8"), "text/html",- metaData, conf);+ metaData, conf);WritableTestUtils.testWritable(r);- assertEquals("text/html", r.getMetadata().get("Content-Type"));- assertEquals("text/html", r.getMetadata().get("content-type"));- assertEquals("text/html", r.getMetadata().get("CONTENTYPE"));+ Assert.assertEquals("text/html", r.getMetadata().get("Content-Type"));+ Assert.assertEquals("text/html", r.getMetadata().get("content-type"));+ Assert.assertEquals("text/html", r.getMetadata().get("CONTENTYPE"));}/** Unit tests for getContentType(String, String, byte[]) method. */+ @Testpublic void testGetContentType() throws Exception {Content c = null;Metadata p = new Metadata();c = new Content("http://www.foo.com/",- "http://www.foo.com/",- "".getBytes("UTF8"),- "text/html; charset=UTF-8", p, conf);- assertEquals("text/html", c.getContentType());+ "http://www.foo.com/",+ "".getBytes("UTF8"),+ "text/html; charset=UTF-8", p, conf);+ Assert.assertEquals("text/html", c.getContentType());c = new Content("http://www.foo.com/foo.html",- "http://www.foo.com/",- "".getBytes("UTF8"),- "", p, conf);- assertEquals("text/html", c.getContentType());+ "http://www.foo.com/",+ "".getBytes("UTF8"),+ "", p, conf);+ Assert.assertEquals("text/html", c.getContentType());c = new Content("http://www.foo.com/foo.html",- "http://www.foo.com/",- "".getBytes("UTF8"),- null, p, conf);- assertEquals("text/html", c.getContentType());+ "http://www.foo.com/",+ "".getBytes("UTF8"),+ null, p, conf);+ Assert.assertEquals("text/html", c.getContentType());c = new Content("http://www.foo.com/",- "http://www.foo.com/",- "<html></html>".getBytes("UTF8"),- "", p, conf);- assertEquals("text/html", c.getContentType());+ "http://www.foo.com/",+ "<html></html>".getBytes("UTF8"),+ "", p, conf);+ Assert.assertEquals("text/html", c.getContentType());c = new Content("http://www.foo.com/foo.html",- "http://www.foo.com/",- "<html></html>".getBytes("UTF8"),- "text/plain", p, conf);- assertEquals("text/html", c.getContentType());+ "http://www.foo.com/",+ "<html></html>".getBytes("UTF8"),+ "text/plain", p, conf);+ Assert.assertEquals("text/html", c.getContentType());c = new Content("http://www.foo.com/foo.png",- "http://www.foo.com/",- "<html></html>".getBytes("UTF8"),- "text/plain", p, conf);- assertEquals("text/html", c.getContentType());+ "http://www.foo.com/",+ "<html></html>".getBytes("UTF8"),+ "text/plain", p, conf);+ Assert.assertEquals("text/html", c.getContentType());c = new Content("http://www.foo.com/",- "http://www.foo.com/",- "".getBytes("UTF8"),- "", p, conf);- assertEquals(MimeTypes.OCTET_STREAM, c.getContentType());+ "http://www.foo.com/",+ "".getBytes("UTF8"),+ "", p, conf);+ Assert.assertEquals(MimeTypes.OCTET_STREAM, c.getContentType());c = new Content("http://www.foo.com/",- "http://www.foo.com/",- "".getBytes("UTF8"),- null, p, conf);- assertNotNull(c.getContentType());+ "http://www.foo.com/",+ "".getBytes("UTF8"),+ null, p, conf);+ Assert.assertNotNull(c.getContentType());}}diff --git a/src/test/org/apache/nutch/protocol/TestProtocolFactory.java b/src/test/org/apache/nutch/protocol/TestProtocolFactory.javaindex 45432704d..ae9d8b15a 100644--- a/src/test/org/apache/nutch/protocol/TestProtocolFactory.java+++ b/src/test/org/apache/nutch/protocol/TestProtocolFactory.java@@ -19,31 +19,34 @@ package org.apache.nutch.protocol;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.util.NutchConfiguration;import org.apache.nutch.util.ObjectCache;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;-import junit.framework.TestCase;--public class TestProtocolFactory extends TestCase {+public class TestProtocolFactory {Configuration conf;ProtocolFactory factory;- protected void setUp() throws Exception {+ @Before+ public void setUp() throws Exception {conf = NutchConfiguration.create();conf.set("plugin.includes", ".*");conf.set("http.agent.name", "test-bot");factory=new ProtocolFactory(conf);}+ @Testpublic void testGetProtocol(){//non existing protocoltry {factory.getProtocol("xyzxyz://somehost");- fail("Must throw ProtocolNotFound");+ Assert.fail("Must throw ProtocolNotFound");} catch (ProtocolNotFound e) {//all is ok} catch (Exception ex){- fail("Must not throw any other exception");+ Assert.fail("Must not throw any other exception");}Protocol httpProtocol=null;@@ -51,30 +54,31 @@ public class TestProtocolFactory extends TestCase {//existing protocoltry {httpProtocol=factory.getProtocol("http://somehost");- assertNotNull(httpProtocol);+ Assert.assertNotNull(httpProtocol);} catch (Exception ex){- fail("Must not throw any other exception");+ Assert.fail("Must not throw any other exception");}//cache keyObject protocol = ObjectCache.get(conf).getObject(Protocol.X_POINT_ID + "http");- assertNotNull(protocol);- assertEquals(httpProtocol, protocol);+ Assert.assertNotNull(protocol);+ Assert.assertEquals(httpProtocol, protocol);//test same object instancetry {- assertTrue(httpProtocol==factory.getProtocol("http://somehost"));+ Assert.assertTrue(httpProtocol==factory.getProtocol("http://somehost"));} catch (ProtocolNotFound e) {- fail("Must not throw any exception");+ Assert.fail("Must not throw any exception");}}+ @Testpublic void testContains(){- assertTrue(factory.contains("http", "http"));- assertTrue(factory.contains("http", "http,ftp"));- assertTrue(factory.contains("http", " http , ftp"));- assertTrue(factory.contains("smb", "ftp,smb,http"));- assertFalse(factory.contains("smb", "smbb"));+ Assert.assertTrue(factory.contains("http", "http"));+ Assert.assertTrue(factory.contains("http", "http,ftp"));+ Assert.assertTrue(factory.contains("http", " http , ftp"));+ Assert.assertTrue(factory.contains("smb", "ftp,smb,http"));+ Assert.assertFalse(factory.contains("smb", "smbb"));}}diff --git a/src/test/org/apache/nutch/segment/TestSegmentMerger.java b/src/test/org/apache/nutch/segment/TestSegmentMerger.javaindex 27b913146..d99bc006f 100644--- a/src/test/org/apache/nutch/segment/TestSegmentMerger.java+++ b/src/test/org/apache/nutch/segment/TestSegmentMerger.java@@ -27,10 +27,12 @@ import org.apache.hadoop.io.Text;import org.apache.hadoop.mapred.MapFileOutputFormat;import org.apache.nutch.parse.ParseText;import org.apache.nutch.util.NutchConfiguration;+import org.junit.After;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;-import junit.framework.TestCase;--public class TestSegmentMerger extends TestCase {+public class TestSegmentMerger {Configuration conf;FileSystem fs;Path testDir;@@ -39,6 +41,7 @@ public class TestSegmentMerger extends TestCase {Path out;int countSeg1, countSeg2;+ @Beforepublic void setUp() throws Exception {conf = NutchConfiguration.create();fs = FileSystem.get(conf);@@ -81,17 +84,19 @@ public class TestSegmentMerger extends TestCase {System.err.println(" - done: " + countSeg2 + " records.");}+ @Afterpublic void tearDown() throws Exception {fs.delete(testDir, true);}+ @Testpublic void testLargeMerge() throws Exception {SegmentMerger merger = new SegmentMerger(conf);merger.merge(out, new Path[]{seg1, seg2}, false, false, -1);// verify outputFileStatus[] stats = fs.listStatus(out);// there should be just one path- assertEquals(1, stats.length);+ Assert.assertEquals(1, stats.length);Path outSeg = stats[0].getPath();Text k = new Text();ParseText v = new ParseText();@@ -103,16 +108,16 @@ public class TestSegmentMerger extends TestCase {String vs = v.getText();if (ks.startsWith("seg1-")) {cnt1++;- assertTrue(vs.startsWith("seg1 "));+ Assert.assertTrue(vs.startsWith("seg1 "));} else if (ks.startsWith("seg2-")) {cnt2++;- assertTrue(vs.startsWith("seg2 "));+ Assert.assertTrue(vs.startsWith("seg2 "));}}r.close();}- assertEquals(countSeg1, cnt1);- assertEquals(countSeg2, cnt2);+ Assert.assertEquals(countSeg1, cnt1);+ Assert.assertEquals(countSeg2, cnt2);}}diff --git a/src/test/org/apache/nutch/segment/TestSegmentMergerCrawlDatums.java b/src/test/org/apache/nutch/segment/TestSegmentMergerCrawlDatums.javaindex 921dd7e7c..97e90d6d6 100644--- a/src/test/org/apache/nutch/segment/TestSegmentMergerCrawlDatums.java+++ b/src/test/org/apache/nutch/segment/TestSegmentMergerCrawlDatums.java@@ -28,13 +28,14 @@ import org.apache.hadoop.io.Text;import org.apache.hadoop.mapred.MapFileOutputFormat;import org.apache.nutch.crawl.CrawlDatum;import org.apache.nutch.util.NutchConfiguration;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;import org.slf4j.Logger;import org.slf4j.LoggerFactory;-import junit.framework.TestCase;-/**- * New SegmentMerger unit test focussing on several crappy issues with the segment+ * New SegmentMerger unit test focusing on several crappy issues with the segment* merger. The general problem is disappearing records and incorrect CrawlDatum* status values. This unit test performs random sequences of segment merging where* we're looking for an expected status.@@ -49,7 +50,7 @@ import junit.framework.TestCase;** Cheers!*/-public class TestSegmentMergerCrawlDatums extends TestCase {+public class TestSegmentMergerCrawlDatums {Configuration conf;FileSystem fs;Random rnd;@@ -57,6 +58,7 @@ public class TestSegmentMergerCrawlDatums extends TestCase {private static final Logger LOG = LoggerFactory.getLogger(TestSegmentMergerCrawlDatums.class);+ @Beforepublic void setUp() throws Exception {conf = NutchConfiguration.create();fs = FileSystem.get(conf);@@ -66,8 +68,9 @@ public class TestSegmentMergerCrawlDatums extends TestCase {/****/+ @Testpublic void testSingleRandomSequence() throws Exception {- assertEquals(+ Assert.assertEquals(new Byte(CrawlDatum.STATUS_FETCH_SUCCESS),new Byte(executeSequence(CrawlDatum.STATUS_FETCH_GONE,CrawlDatum.STATUS_FETCH_SUCCESS, 256, false)));@@ -76,6 +79,7 @@ public class TestSegmentMergerCrawlDatums extends TestCase {/****/+ @Testpublic void testMostlyRedirects() throws Exception {// Our test directoryPath testDir = new Path(conf.get("hadoop.tmp.dir"), "merge-" + System.currentTimeMillis());@@ -102,12 +106,13 @@ public class TestSegmentMergerCrawlDatums extends TestCase {Path mergedSegment = merge(testDir, new Path[]{segment1, segment2, segment3, segment4, segment5, segment6, segment7, segment8});Byte status = new Byte(status = checkMergedSegment(testDir, mergedSegment));- assertEquals(new Byte(CrawlDatum.STATUS_FETCH_SUCCESS), status);+ Assert.assertEquals(new Byte(CrawlDatum.STATUS_FETCH_SUCCESS), status);}/****/+ @Testpublic void testRandomizedSequences() throws Exception {for (int i = 0; i < rnd.nextInt(16) + 16; i++) {byte expectedStatus = (byte)(rnd.nextInt(6) + 0x21);@@ -122,7 +127,7 @@ public class TestSegmentMergerCrawlDatums extends TestCase {byte resultStatus = executeSequence(randomStatus, expectedStatus,rounds, withRedirects);- assertEquals(+ Assert.assertEquals("Expected status = " + CrawlDatum.getStatusName(expectedStatus)+ ", but got " + CrawlDatum.getStatusName(resultStatus)+ " when merging " + rounds + " segments"@@ -134,13 +139,15 @@ public class TestSegmentMergerCrawlDatums extends TestCase {/****/+ @Testpublic void testRandomTestSequenceWithRedirects() throws Exception {- assertEquals(new Byte(CrawlDatum.STATUS_FETCH_SUCCESS), new Byte(executeSequence(CrawlDatum.STATUS_FETCH_GONE, CrawlDatum.STATUS_FETCH_SUCCESS, 128, true)));+ Assert.assertEquals(new Byte(CrawlDatum.STATUS_FETCH_SUCCESS), new Byte(executeSequence(CrawlDatum.STATUS_FETCH_GONE, CrawlDatum.STATUS_FETCH_SUCCESS, 128, true)));}/*** Check a fixed sequence!*/+ @Testpublic void testFixedSequence() throws Exception {// Our test directoryPath testDir = new Path(conf.get("hadoop.tmp.dir"), "merge-" + System.currentTimeMillis());@@ -157,12 +164,13 @@ public class TestSegmentMergerCrawlDatums extends TestCase {Path mergedSegment = merge(testDir, new Path[]{segment1, segment2, segment3});Byte status = new Byte(status = checkMergedSegment(testDir, mergedSegment));- assertEquals(new Byte(CrawlDatum.STATUS_FETCH_SUCCESS), status);+ Assert.assertEquals(new Byte(CrawlDatum.STATUS_FETCH_SUCCESS), status);}/*** Check a fixed sequence!*/+ @Testpublic void testRedirFetchInOneSegment() throws Exception {// Our test directoryPath testDir = new Path(conf.get("hadoop.tmp.dir"), "merge-" + System.currentTimeMillis());@@ -175,12 +183,13 @@ public class TestSegmentMergerCrawlDatums extends TestCase {Path mergedSegment = merge(testDir, new Path[]{segment});Byte status = new Byte(status = checkMergedSegment(testDir, mergedSegment));- assertEquals(new Byte(CrawlDatum.STATUS_FETCH_SUCCESS), status);+ Assert.assertEquals(new Byte(CrawlDatum.STATUS_FETCH_SUCCESS), status);}/*** Check a fixed sequence!*/+ @Testpublic void testEndsWithRedirect() throws Exception {// Our test directoryPath testDir = new Path(conf.get("hadoop.tmp.dir"), "merge-" + System.currentTimeMillis());@@ -195,7 +204,7 @@ public class TestSegmentMergerCrawlDatums extends TestCase {Path mergedSegment = merge(testDir, new Path[]{segment1, segment2});Byte status = new Byte(status = checkMergedSegment(testDir, mergedSegment));- assertEquals(new Byte(CrawlDatum.STATUS_FETCH_SUCCESS), status);+ Assert.assertEquals(new Byte(CrawlDatum.STATUS_FETCH_SUCCESS), status);}/**@@ -303,7 +312,7 @@ public class TestSegmentMergerCrawlDatums extends TestCase {merger.merge(out, segments, false, false, -1);FileStatus[] stats = fs.listStatus(out);- assertEquals(1, stats.length);+ Assert.assertEquals(1, stats.length);return stats[0].getPath();}diff --git a/src/test/org/apache/nutch/util/TestEncodingDetector.java b/src/test/org/apache/nutch/util/TestEncodingDetector.javaindex d33d26da7..8697a62f0 100644--- a/src/test/org/apache/nutch/util/TestEncodingDetector.java+++ b/src/test/org/apache/nutch/util/TestEncodingDetector.java@@ -22,10 +22,10 @@ import org.apache.hadoop.conf.Configuration;import org.apache.nutch.metadata.Metadata;import org.apache.nutch.net.protocols.Response;import org.apache.nutch.protocol.Content;+import org.junit.Assert;+import org.junit.Test;-import junit.framework.TestCase;--public class TestEncodingDetector extends TestCase {+public class TestEncodingDetector {private static Configuration conf = NutchConfiguration.create();private static byte[] contentInOctets;@@ -38,10 +38,7 @@ public class TestEncodingDetector extends TestCase {}}- public TestEncodingDetector(String name) {- super(name);- }-+ @Testpublic void testGuessing() {// first disable auto detectionconf.setInt(EncodingDetector.MIN_CONFIDENCE_KEY, -1);@@ -57,7 +54,7 @@ public class TestEncodingDetector extends TestCase {detector.autoDetectClues(content, true);encoding = detector.guessEncoding(content, "windows-1252");// no information is available, so it should return default encoding- assertEquals("windows-1252", encoding.toLowerCase());+ Assert.assertEquals("windows-1252", encoding.toLowerCase());metadata.clear();metadata.set(Response.CONTENT_TYPE, "text/plain; charset=UTF-16");@@ -66,7 +63,7 @@ public class TestEncodingDetector extends TestCase {detector = new EncodingDetector(conf);detector.autoDetectClues(content, true);encoding = detector.guessEncoding(content, "windows-1252");- assertEquals("utf-16", encoding.toLowerCase());+ Assert.assertEquals("utf-16", encoding.toLowerCase());metadata.clear();content = new Content("http://www.example.com", "http://www.example.com/",@@ -75,7 +72,7 @@ public class TestEncodingDetector extends TestCase {detector.autoDetectClues(content, true);detector.addClue("windows-1254", "sniffed");encoding = detector.guessEncoding(content, "windows-1252");- assertEquals("windows-1254", encoding.toLowerCase());+ Assert.assertEquals("windows-1254", encoding.toLowerCase());// enable autodetectionconf.setInt(EncodingDetector.MIN_CONFIDENCE_KEY, 50);@@ -87,7 +84,7 @@ public class TestEncodingDetector extends TestCase {detector.autoDetectClues(content, true);detector.addClue("utf-32", "sniffed");encoding = detector.guessEncoding(content, "windows-1252");- assertEquals("utf-8", encoding.toLowerCase());+ Assert.assertEquals("utf-8", encoding.toLowerCase());}}diff --git a/src/test/org/apache/nutch/util/TestGZIPUtils.java b/src/test/org/apache/nutch/util/TestGZIPUtils.javaindex a72ae48ef..04dc00ee0 100644--- a/src/test/org/apache/nutch/util/TestGZIPUtils.java+++ b/src/test/org/apache/nutch/util/TestGZIPUtils.java@@ -17,106 +17,103 @@package org.apache.nutch.util;-import junit.framework.TestCase;-import java.io.IOException;+import org.junit.Assert;+import org.junit.Test;+/** Unit tests for GZIPUtils methods. */-public class TestGZIPUtils extends TestCase {- public TestGZIPUtils(String name) {- super(name);- }+public class TestGZIPUtils {/* a short, highly compressable, string */String SHORT_TEST_STRING=- "aaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbcccccccccccccccc";+ "aaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbcccccccccccccccc";/* a short, highly compressable, string */String LONGER_TEST_STRING=- SHORT_TEST_STRING + SHORT_TEST_STRING + SHORT_TEST_STRING- + SHORT_TEST_STRING + SHORT_TEST_STRING + SHORT_TEST_STRING- + SHORT_TEST_STRING + SHORT_TEST_STRING + SHORT_TEST_STRING- + SHORT_TEST_STRING + SHORT_TEST_STRING + SHORT_TEST_STRING;+ SHORT_TEST_STRING + SHORT_TEST_STRING + SHORT_TEST_STRING+ + SHORT_TEST_STRING + SHORT_TEST_STRING + SHORT_TEST_STRING+ + SHORT_TEST_STRING + SHORT_TEST_STRING + SHORT_TEST_STRING+ + SHORT_TEST_STRING + SHORT_TEST_STRING + SHORT_TEST_STRING;/* a snapshot of the nutch webpage */String WEBPAGE=- "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"- + "<html>\n"- + "<head>\n"- + " <meta http-equiv=\"content-type\"\n"- + " content=\"text/html; charset=ISO-8859-1\">\n"- + " <title>Nutch</title>\n"- + "</head>\n"- + "<body>\n"- + "<h1\n"- + " style=\"font-family: helvetica,arial,sans-serif; text-align: center; color: rgb(255, 153, 0);\"><a\n"- + " href=\"http://www.nutch.org/\"><font style=\"color: rgb(255, 153, 0);\">Nutch</font></a><br>\n"- + "<small>an open source web-search engine</small></h1>\n"- + "<hr style=\"width: 100%; height: 1px;\" noshade=\"noshade\">\n"- + "<table\n"- + " style=\"width: 100%; text-align: left; margin-left: auto; margin-right: auto;\"\n"- + " border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n"- + " <tbody>\n"- + " <tr>\n"- + " <td style=\"vertical-align: top; text-align: center;\"><a\n"- + " href=\"http://sourceforge.net/project/showfiles.php?group_id=59548\">Download</a><br>\n"- + " </td>\n"- + " <td style=\"vertical-align: top; text-align: center;\"><a\n"- + " href=\"tutorial.html\">Tutorial</a><br>\n"- + " </td>\n"- + " <td style=\"vertical-align: top; text-align: center;\"><a\n"- + " href=\"http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/nutch/nutch/\">CVS</a><br>\n"- + " </td>\n"- + " <td style=\"vertical-align: top; text-align: center;\"><a\n"- + " href=\"api/index.html\">Javadoc</a><br>\n"- + " </td>\n"- + " <td style=\"vertical-align: top; text-align: center;\"><a\n"- + " href=\"http://sourceforge.net/tracker/?atid=491356&group_id=59548&func=browse\">Bugs</a><br>\n"- + " </td>\n"- + " <td style=\"vertical-align: top; text-align: center;\"><a\n"- + " href=\"http://sourceforge.net/mail/?group_id=59548\">Lists</a></td>\n"- + " <td style=\"vertical-align: top; text-align: center;\"><a\n"- + " href=\"policies.html\">Policies</a><br>\n"- + " </td>\n"- + " </tr>\n"- + " </tbody>\n"- + "</table>\n"- + "<hr style=\"width: 100%; height: 1px;\" noshade=\"noshade\">\n"- + "<h2>Introduction</h2>\n"- + "Nutch is a nascent effort to implement an open-source web search\n"- + "engine. Web search is a basic requirement for internet navigation, yet\n"- + "the number of web search engines is decreasing. Today's oligopoly could\n"- + "soon be a monopoly, with a single company controlling nearly all web\n"- + "search for its commercial gain. That would not be good for the\n"- + "users of internet. Nutch aims to enable anyone to easily and\n"- + "cost-effectively deploy a world-class web search engine.<br>\n"- + "<br>\n"- + "To succeed, the Nutch software must be able to:<br>\n"- + "<ul>\n"- + " <li> crawl several billion pages per month</li>\n"- + " <li>maintain an index of these pages</li>\n"- + " <li>search that index up to 1000 times per second</li>\n"- + " <li>provide very high quality search results</li>\n"- + " <li>operate at minimal cost</li>\n"- + "</ul>\n"- + "<h2>Status</h2>\n"- + "Currently we're just a handful of developers working part-time to put\n"- + "together a demo. The demo is coded entirely in Java. However\n"- + "persistent data is written in well-documented formats so that modules\n"- + "may eventually be re-written in other languages (e.g., Perl, C++) as the\n"- + "project progresses.<br>\n"- + "<br>\n"- + "<hr style=\"width: 100%; height: 1px;\" noshade=\"noshade\"> <a\n"- + " href=\"http://sourceforge.net\"> </a>\n"- + "<div style=\"text-align: center;\"><a href=\"http://sourceforge.net\"><img\n"- + " src=\"http://sourceforge.net/sflogo.php?group_id=59548&type=1\"\n"- + " style=\"border: 0px solid ; width: 88px; height: 31px;\"\n"- + " alt=\"SourceForge.net Logo\" title=\"\"></a></div>\n"- + "</body>\n"- + "</html>\n";-- // tests-+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"+ + "<html>\n"+ + "<head>\n"+ + " <meta http-equiv=\"content-type\"\n"+ + " content=\"text/html; charset=ISO-8859-1\">\n"+ + " <title>Nutch</title>\n"+ + "</head>\n"+ + "<body>\n"+ + "<h1\n"+ + " style=\"font-family: helvetica,arial,sans-serif; text-align: center; color: rgb(255, 153, 0);\"><a\n"+ + " href=\"http://www.nutch.org/\"><font style=\"color: rgb(255, 153, 0);\">Nutch</font></a><br>\n"+ + "<small>an open source web-search engine</small></h1>\n"+ + "<hr style=\"width: 100%; height: 1px;\" noshade=\"noshade\">\n"+ + "<table\n"+ + " style=\"width: 100%; text-align: left; margin-left: auto; margin-right: auto;\"\n"+ + " border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n"+ + " <tbody>\n"+ + " <tr>\n"+ + " <td style=\"vertical-align: top; text-align: center;\"><a\n"+ + " href=\"http://sourceforge.net/project/showfiles.php?group_id=59548\">Download</a><br>\n"+ + " </td>\n"+ + " <td style=\"vertical-align: top; text-align: center;\"><a\n"+ + " href=\"tutorial.html\">Tutorial</a><br>\n"+ + " </td>\n"+ + " <td style=\"vertical-align: top; text-align: center;\"><a\n"+ + " href=\"http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/nutch/nutch/\">CVS</a><br>\n"+ + " </td>\n"+ + " <td style=\"vertical-align: top; text-align: center;\"><a\n"+ + " href=\"api/index.html\">Javadoc</a><br>\n"+ + " </td>\n"+ + " <td style=\"vertical-align: top; text-align: center;\"><a\n"+ + " href=\"http://sourceforge.net/tracker/?atid=491356&group_id=59548&func=browse\">Bugs</a><br>\n"+ + " </td>\n"+ + " <td style=\"vertical-align: top; text-align: center;\"><a\n"+ + " href=\"http://sourceforge.net/mail/?group_id=59548\">Lists</a></td>\n"+ + " <td style=\"vertical-align: top; text-align: center;\"><a\n"+ + " href=\"policies.html\">Policies</a><br>\n"+ + " </td>\n"+ + " </tr>\n"+ + " </tbody>\n"+ + "</table>\n"+ + "<hr style=\"width: 100%; height: 1px;\" noshade=\"noshade\">\n"+ + "<h2>Introduction</h2>\n"+ + "Nutch is a nascent effort to implement an open-source web search\n"+ + "engine. Web search is a basic requirement for internet navigation, yet\n"+ + "the number of web search engines is decreasing. Today's oligopoly could\n"+ + "soon be a monopoly, with a single company controlling nearly all web\n"+ + "search for its commercial gain. That would not be good for the\n"+ + "users of internet. Nutch aims to enable anyone to easily and\n"+ + "cost-effectively deploy a world-class web search engine.<br>\n"+ + "<br>\n"+ + "To succeed, the Nutch software must be able to:<br>\n"+ + "<ul>\n"+ + " <li> crawl several billion pages per month</li>\n"+ + " <li>maintain an index of these pages</li>\n"+ + " <li>search that index up to 1000 times per second</li>\n"+ + " <li>provide very high quality search results</li>\n"+ + " <li>operate at minimal cost</li>\n"+ + "</ul>\n"+ + "<h2>Status</h2>\n"+ + "Currently we're just a handful of developers working part-time to put\n"+ + "together a demo. The demo is coded entirely in Java. However\n"+ + "persistent data is written in well-documented formats so that modules\n"+ + "may eventually be re-written in other languages (e.g., Perl, C++) as the\n"+ + "project progresses.<br>\n"+ + "<br>\n"+ + "<hr style=\"width: 100%; height: 1px;\" noshade=\"noshade\"> <a\n"+ + " href=\"http://sourceforge.net\"> </a>\n"+ + "<div style=\"text-align: center;\"><a href=\"http://sourceforge.net\"><img\n"+ + " src=\"http://sourceforge.net/sflogo.php?group_id=59548&type=1\"\n"+ + " style=\"border: 0px solid ; width: 88px; height: 31px;\"\n"+ + " alt=\"SourceForge.net Logo\" title=\"\"></a></div>\n"+ + "</body>\n"+ + "</html>\n";++ @Testpublic void testZipUnzip() {byte[] testBytes= SHORT_TEST_STRING.getBytes();testZipUnzip(testBytes);@@ -126,6 +123,7 @@ public class TestGZIPUtils extends TestCase {testZipUnzip(testBytes);}+ @Testpublic void testZipUnzipBestEffort() {byte[] testBytes= SHORT_TEST_STRING.getBytes();testZipUnzipBestEffort(testBytes);@@ -134,7 +132,7 @@ public class TestGZIPUtils extends TestCase {testBytes= WEBPAGE.getBytes();testZipUnzipBestEffort(testBytes);}-+public void testTruncation() {byte[] testBytes= SHORT_TEST_STRING.getBytes();testTruncation(testBytes);@@ -144,6 +142,7 @@ public class TestGZIPUtils extends TestCase {testTruncation(testBytes);}+ @Testpublic void testLimit() {byte[] testBytes= SHORT_TEST_STRING.getBytes();testLimit(testBytes);@@ -158,38 +157,38 @@ public class TestGZIPUtils extends TestCase {public void testZipUnzip(byte[] origBytes) {byte[] compressedBytes= GZIPUtils.zip(origBytes);- assertTrue("compressed array is not smaller!",- compressedBytes.length < origBytes.length);+ Assert.assertTrue("compressed array is not smaller!",+ compressedBytes.length < origBytes.length);byte[] uncompressedBytes= null;try {uncompressedBytes= GZIPUtils.unzip(compressedBytes);} catch (IOException e) {e.printStackTrace();- assertTrue("caught exception '" + e + "' during unzip()",- false);+ Assert.assertTrue("caught exception '" + e + "' during unzip()",+ false);}- assertTrue("uncompressedBytes is wrong size",- uncompressedBytes.length == origBytes.length);+ Assert.assertTrue("uncompressedBytes is wrong size",+ uncompressedBytes.length == origBytes.length);for (int i= 0; i < origBytes.length; i++)if (origBytes[i] != uncompressedBytes[i])- assertTrue("uncompressedBytes does not match origBytes", false);+ Assert.assertTrue("uncompressedBytes does not match origBytes", false);}public void testZipUnzipBestEffort(byte[] origBytes) {byte[] compressedBytes= GZIPUtils.zip(origBytes);- assertTrue("compressed array is not smaller!",- compressedBytes.length < origBytes.length);+ Assert.assertTrue("compressed array is not smaller!",+ compressedBytes.length < origBytes.length);byte[] uncompressedBytes= GZIPUtils.unzipBestEffort(compressedBytes);- assertTrue("uncompressedBytes is wrong size",- uncompressedBytes.length == origBytes.length);+ Assert.assertTrue("uncompressedBytes is wrong size",+ uncompressedBytes.length == origBytes.length);for (int i= 0; i < origBytes.length; i++)if (origBytes[i] != uncompressedBytes[i])- assertTrue("uncompressedBytes does not match origBytes", false);+ Assert.assertTrue("uncompressedBytes does not match origBytes", false);}public void testTruncation(byte[] origBytes) {@@ -197,30 +196,30 @@ public class TestGZIPUtils extends TestCase {System.out.println("original data has len " + origBytes.length);System.out.println("compressed data has len "- + compressedBytes.length);+ + compressedBytes.length);for (int i= compressedBytes.length; i >= 0; i--) {byte[] truncCompressed= new byte[i];for (int j= 0; j < i; j++)- truncCompressed[j]= compressedBytes[j];+ truncCompressed[j]= compressedBytes[j];byte[] trunc= GZIPUtils.unzipBestEffort(truncCompressed);if (trunc == null) {- System.out.println("truncated to len "- + i + ", trunc is null");+ System.out.println("truncated to len "+ + i + ", trunc is null");} else {- System.out.println("truncated to len "- + i + ", trunc.length= "- + trunc.length);-- for (int j= 0; j < trunc.length; j++)- if (trunc[j] != origBytes[j])- assertTrue("truncated/uncompressed array differs at pos "- + j + " (compressed data had been truncated to len "- + i + ")", false);+ System.out.println("truncated to len "+ + i + ", trunc.length= "+ + trunc.length);++ for (int j= 0; j < trunc.length; j++)+ if (trunc[j] != origBytes[j])+ Assert.assertTrue("truncated/uncompressed array differs at pos "+ + j + " (compressed data had been truncated to len "+ + i + ")", false);}}}@@ -228,20 +227,20 @@ public class TestGZIPUtils extends TestCase {public void testLimit(byte[] origBytes) {byte[] compressedBytes= GZIPUtils.zip(origBytes);- assertTrue("compressed array is not smaller!",- compressedBytes.length < origBytes.length);+ Assert.assertTrue("compressed array is not smaller!",+ compressedBytes.length < origBytes.length);for (int i= 0; i < origBytes.length; i++) {byte[] uncompressedBytes=- GZIPUtils.unzipBestEffort(compressedBytes, i);+ GZIPUtils.unzipBestEffort(compressedBytes, i);- assertTrue("uncompressedBytes is wrong size",- uncompressedBytes.length == i);+ Assert.assertTrue("uncompressedBytes is wrong size",+ uncompressedBytes.length == i);for (int j= 0; j < i; j++)if (origBytes[j] != uncompressedBytes[j])- assertTrue("uncompressedBytes does not match origBytes", false);+ Assert.assertTrue("uncompressedBytes does not match origBytes", false);}}diff --git a/src/test/org/apache/nutch/util/TestNodeWalker.java b/src/test/org/apache/nutch/util/TestNodeWalker.javaindex fc4862d3f..1d0224d35 100644--- a/src/test/org/apache/nutch/util/TestNodeWalker.java+++ b/src/test/org/apache/nutch/util/TestNodeWalker.java@@ -18,20 +18,16 @@package org.apache.nutch.util;import java.io.ByteArrayInputStream;-import junit.framework.TestCase;import org.apache.xerces.parsers.DOMParser;+import org.junit.Assert;+import org.junit.Before;+import org.junit.Test;import org.w3c.dom.Node;import org.xml.sax.InputSource;---/** Unit tests for NodeWalker methods. */-public class TestNodeWalker extends TestCase {- public TestNodeWalker(String name) {- super(name);- }+public class TestNodeWalker {/* a snapshot of the nutch webpage */private final static String WEBPAGE=@@ -49,13 +45,15 @@ public class TestNodeWalker extends TestCase {private final static String[] ULCONTENT = new String[4];- protected void setUp() throws Exception{+ @Before+ public void setUp() throws Exception{ULCONTENT[0]="crawl several billion pages per month" ;ULCONTENT[1]="maintain an index of these pages" ;ULCONTENT[2]="search that index up to 1000 times per second" ;ULCONTENT[3]="operate at minimal cost" ;}+ @Testpublic void testSkipChildren() {DOMParser parser= new DOMParser();@@ -78,7 +76,7 @@ public class TestNodeWalker extends TestCase {sb.append(text);}}- assertTrue("UL Content can NOT be found in the node", findSomeUlContent(sb.toString()));+ Assert.assertTrue("UL Content can NOT be found in the node", findSomeUlContent(sb.toString()));StringBuffer sbSkip = new StringBuffer();NodeWalker walkerSkip = new NodeWalker(parser.getDocument());@@ -95,7 +93,7 @@ public class TestNodeWalker extends TestCase {sbSkip.append(text);}}- assertFalse("UL Content can be found in the node", findSomeUlContent(sbSkip.toString()));+ Assert.assertFalse("UL Content can be found in the node", findSomeUlContent(sbSkip.toString()));}public boolean findSomeUlContent(String str) {diff --git a/src/test/org/apache/nutch/util/TestPrefixStringMatcher.java b/src/test/org/apache/nutch/util/TestPrefixStringMatcher.javaindex 539513893..fc97c2e44 100644--- a/src/test/org/apache/nutch/util/TestPrefixStringMatcher.java+++ b/src/test/org/apache/nutch/util/TestPrefixStringMatcher.java@@ -17,13 +17,12 @@package org.apache.nutch.util;-import junit.framework.TestCase;+import org.junit.Assert;+import org.junit.Test;/** Unit tests for PrefixStringMatcher. */-public class TestPrefixStringMatcher extends TestCase {- public TestPrefixStringMatcher(String name) {- super(name);- }+public class TestPrefixStringMatcher {+private final static int NUM_TEST_ROUNDS= 20;private final static int MAX_TEST_PREFIXES= 100;@@ -51,6 +50,7 @@ public class TestPrefixStringMatcher extends TestCase {return new String(chars);}+ @Testpublic void testPrefixMatcher() {int numMatches= 0;int numInputsTested= 0;@@ -96,18 +96,18 @@ public class TestPrefixStringMatcher extends TestCase {numInputsTested++;- assertTrue( "'" + input + "' should " + (matches ? "" : "not ")+ Assert.assertTrue( "'" + input + "' should " + (matches ? "" : "not ")+ "match!",matches == prematcher.matches(input) );if (matches) {- assertTrue( shortestMatch+ Assert.assertTrue( shortestMatch== prematcher.shortestMatch(input).length());- assertTrue( input.substring(0, shortestMatch).equals(+ Assert.assertTrue( input.substring(0, shortestMatch).equals(prematcher.shortestMatch(input)) );- assertTrue( longestMatch+ Assert.assertTrue( longestMatch== prematcher.longestMatch(input).length());- assertTrue( input.substring(0, longestMatch).equals(+ Assert.assertTrue( input.substring(0, longestMatch).equals(prematcher.longestMatch(input)) );}diff --git a/src/test/org/apache/nutch/util/TestStringUtil.java b/src/test/org/apache/nutch/util/TestStringUtil.javaindex 4f8f039b9..44ca2a2c0 100644--- a/src/test/org/apache/nutch/util/TestStringUtil.java+++ b/src/test/org/apache/nutch/util/TestStringUtil.java@@ -17,45 +17,44 @@package org.apache.nutch.util;-import junit.framework.TestCase;+import org.junit.Assert;+import org.junit.Test;/** Unit tests for StringUtil methods. */-public class TestStringUtil extends TestCase {- public TestStringUtil(String name) {- super(name);- }+public class TestStringUtil {public void testRightPad() {String s= "my string";String ps= StringUtil.rightPad(s, 0);- assertTrue(s.equals(ps));+ Assert.assertTrue(s.equals(ps));ps= StringUtil.rightPad(s, 9);- assertTrue(s.equals(ps));+ Assert.assertTrue(s.equals(ps));ps= StringUtil.rightPad(s, 10);- assertTrue( (s+" ").equals(ps) );+ Assert.assertTrue( (s+" ").equals(ps) );ps= StringUtil.rightPad(s, 15);- assertTrue( (s+" ").equals(ps) );+ Assert.assertTrue( (s+" ").equals(ps) );}+ @Testpublic void testLeftPad() {String s= "my string";String ps= StringUtil.leftPad(s, 0);- assertTrue(s.equals(ps));+ Assert.assertTrue(s.equals(ps));ps= StringUtil.leftPad(s, 9);- assertTrue(s.equals(ps));+ Assert.assertTrue(s.equals(ps));ps= StringUtil.leftPad(s, 10);- assertTrue( (" "+s).equals(ps) );+ Assert.assertTrue( (" "+s).equals(ps) );ps= StringUtil.leftPad(s, 15);- assertTrue( (" "+s).equals(ps) );+ Assert.assertTrue( (" "+s).equals(ps) );}diff --git a/src/test/org/apache/nutch/util/TestSuffixStringMatcher.java b/src/test/org/apache/nutch/util/TestSuffixStringMatcher.javaindex 95392bd1c..e4c33275a 100644--- a/src/test/org/apache/nutch/util/TestSuffixStringMatcher.java+++ b/src/test/org/apache/nutch/util/TestSuffixStringMatcher.java@@ -17,13 +17,11 @@package org.apache.nutch.util;-import junit.framework.TestCase;+import org.junit.Assert;+import org.junit.Test;/** Unit tests for SuffixStringMatcher. */-public class TestSuffixStringMatcher extends TestCase {- public TestSuffixStringMatcher(String name) {- super(name);- }+public class TestSuffixStringMatcher {private final static int NUM_TEST_ROUNDS= 20;private final static int MAX_TEST_SUFFIXES= 100;@@ -51,6 +49,7 @@ public class TestSuffixStringMatcher extends TestCase {return new String(chars);}+ @Testpublic void testSuffixMatcher() {int numMatches= 0;int numInputsTested= 0;@@ -96,20 +95,19 @@ public class TestSuffixStringMatcher extends TestCase {numInputsTested++;- assertTrue( "'" + input + "' should " + (matches ? "" : "not ")+ Assert.assertTrue( "'" + input + "' should " + (matches ? "" : "not ")+ "match!",matches == sufmatcher.matches(input) );if (matches) {- assertTrue( shortestMatch+ Assert.assertTrue( shortestMatch== sufmatcher.shortestMatch(input).length());- assertTrue( input.substring(input.length() - shortestMatch).equals(+ Assert.assertTrue( input.substring(input.length() - shortestMatch).equals(sufmatcher.shortestMatch(input)) );- assertTrue( longestMatch+ Assert.assertTrue( longestMatch== sufmatcher.longestMatch(input).length());- assertTrue( input.substring(input.length() - longestMatch).equals(+ Assert.assertTrue( input.substring(input.length() - longestMatch).equals(sufmatcher.longestMatch(input)) );-}}}diff --git a/src/test/org/apache/nutch/util/TestURLUtil.java b/src/test/org/apache/nutch/util/TestURLUtil.javaindex a5b3f55e2..5307dedd7 100644--- a/src/test/org/apache/nutch/util/TestURLUtil.java+++ b/src/test/org/apache/nutch/util/TestURLUtil.java@@ -19,120 +19,115 @@ package org.apache.nutch.util;import java.net.URL;-import junit.framework.TestCase;+import org.junit.Assert;+import org.junit.Test;/** Test class for URLUtil */-public class TestURLUtil- extends TestCase {-- @Override- protected void setUp()- throws Exception {- super.setUp();- }+public class TestURLUtil {+ @Testpublic void testGetDomainName()throws Exception {URL url = null;url = new URL("http://lucene.apache.org/nutch");- assertEquals("apache.org", URLUtil.getDomainName(url));+ Assert.assertEquals("apache.org", URLUtil.getDomainName(url));url = new URL("http://en.wikipedia.org/wiki/Java_coffee");- assertEquals("wikipedia.org", URLUtil.getDomainName(url));+ Assert.assertEquals("wikipedia.org", URLUtil.getDomainName(url));url = new URL("http://140.211.11.130/foundation/contributing.html");- assertEquals("140.211.11.130", URLUtil.getDomainName(url));+ Assert.assertEquals("140.211.11.130", URLUtil.getDomainName(url));url = new URL("http://www.example.co.uk:8080/index.html");- assertEquals("example.co.uk", URLUtil.getDomainName(url));+ Assert.assertEquals("example.co.uk", URLUtil.getDomainName(url));url = new URL("http://com");- assertEquals("com", URLUtil.getDomainName(url));+ Assert.assertEquals("com", URLUtil.getDomainName(url));url = new URL("http://www.example.co.uk.com");- assertEquals("uk.com", URLUtil.getDomainName(url));+ Assert.assertEquals("uk.com", URLUtil.getDomainName(url));// "nn" is not a tldurl = new URL("http://example.com.nn");- assertEquals("nn", URLUtil.getDomainName(url));+ Assert.assertEquals("nn", URLUtil.getDomainName(url));url = new URL("http://");- assertEquals("", URLUtil.getDomainName(url));+ Assert.assertEquals("", URLUtil.getDomainName(url));url = new URL("http://www.edu.tr.xyz");- assertEquals("xyz", URLUtil.getDomainName(url));+ Assert.assertEquals("xyz", URLUtil.getDomainName(url));url = new URL("http://www.example.c.se");- assertEquals("example.c.se", URLUtil.getDomainName(url));+ Assert.assertEquals("example.c.se", URLUtil.getDomainName(url));// plc.co.im is listed as a domain suffixurl = new URL("http://www.example.plc.co.im");- assertEquals("example.plc.co.im", URLUtil.getDomainName(url));+ Assert.assertEquals("example.plc.co.im", URLUtil.getDomainName(url));// 2000.hu is listed as a domain suffixurl = new URL("http://www.example.2000.hu");- assertEquals("example.2000.hu", URLUtil.getDomainName(url));+ Assert.assertEquals("example.2000.hu", URLUtil.getDomainName(url));// test non-asciiurl = new URL("http://www.example.商業.tw");- assertEquals("example.商業.tw", URLUtil.getDomainName(url));-+ Assert.assertEquals("example.商業.tw", URLUtil.getDomainName(url));}+ @Testpublic void testGetDomainSuffix()throws Exception {URL url = null;url = new URL("http://lucene.apache.org/nutch");- assertEquals("org", URLUtil.getDomainSuffix(url).getDomain());+ Assert.assertEquals("org", URLUtil.getDomainSuffix(url).getDomain());url = new URL("http://140.211.11.130/foundation/contributing.html");- assertNull(URLUtil.getDomainSuffix(url));+ Assert.assertNull(URLUtil.getDomainSuffix(url));url = new URL("http://www.example.co.uk:8080/index.html");- assertEquals("co.uk", URLUtil.getDomainSuffix(url).getDomain());+ Assert.assertEquals("co.uk", URLUtil.getDomainSuffix(url).getDomain());url = new URL("http://com");- assertEquals("com", URLUtil.getDomainSuffix(url).getDomain());+ Assert.assertEquals("com", URLUtil.getDomainSuffix(url).getDomain());url = new URL("http://www.example.co.uk.com");- assertEquals("com", URLUtil.getDomainSuffix(url).getDomain());+ Assert.assertEquals("com", URLUtil.getDomainSuffix(url).getDomain());// "nn" is not a tldurl = new URL("http://example.com.nn");- assertNull(URLUtil.getDomainSuffix(url));+ Assert.assertNull(URLUtil.getDomainSuffix(url));url = new URL("http://");- assertNull(URLUtil.getDomainSuffix(url));+ Assert.assertNull(URLUtil.getDomainSuffix(url));url = new URL("http://www.edu.tr.xyz");- assertNull(URLUtil.getDomainSuffix(url));+ Assert.assertNull(URLUtil.getDomainSuffix(url));url = new URL("http://subdomain.example.edu.tr");- assertEquals("edu.tr", URLUtil.getDomainSuffix(url).getDomain());+ Assert.assertEquals("edu.tr", URLUtil.getDomainSuffix(url).getDomain());url = new URL("http://subdomain.example.presse.fr");- assertEquals("presse.fr", URLUtil.getDomainSuffix(url).getDomain());+ Assert.assertEquals("presse.fr", URLUtil.getDomainSuffix(url).getDomain());url = new URL("http://subdomain.example.presse.tr");- assertEquals("tr", URLUtil.getDomainSuffix(url).getDomain());+ Assert.assertEquals("tr", URLUtil.getDomainSuffix(url).getDomain());// plc.co.im is listed as a domain suffixurl = new URL("http://www.example.plc.co.im");- assertEquals("plc.co.im", URLUtil.getDomainSuffix(url).getDomain());+ Assert.assertEquals("plc.co.im", URLUtil.getDomainSuffix(url).getDomain());// 2000.hu is listed as a domain suffixurl = new URL("http://www.example.2000.hu");- assertEquals("2000.hu", URLUtil.getDomainSuffix(url).getDomain());+ Assert.assertEquals("2000.hu", URLUtil.getDomainSuffix(url).getDomain());// test non-asciiurl = new URL("http://www.example.商業.tw");- assertEquals("商業.tw", URLUtil.getDomainSuffix(url).getDomain());-+ Assert.assertEquals("商業.tw", URLUtil.getDomainSuffix(url).getDomain());}+ @Testpublic void testGetHostSegments()throws Exception {URL url;@@ -140,31 +135,32 @@ public class TestURLUtilurl = new URL("http://subdomain.example.edu.tr");segments = URLUtil.getHostSegments(url);- assertEquals("subdomain", segments[0]);- assertEquals("example", segments[1]);- assertEquals("edu", segments[2]);- assertEquals("tr", segments[3]);+ Assert.assertEquals("subdomain", segments[0]);+ Assert.assertEquals("example", segments[1]);+ Assert.assertEquals("edu", segments[2]);+ Assert.assertEquals("tr", segments[3]);url = new URL("http://");segments = URLUtil.getHostSegments(url);- assertEquals(1, segments.length);- assertEquals("", segments[0]);+ Assert.assertEquals(1, segments.length);+ Assert.assertEquals("", segments[0]);url = new URL("http://140.211.11.130/foundation/contributing.html");segments = URLUtil.getHostSegments(url);- assertEquals(1, segments.length);- assertEquals("140.211.11.130", segments[0]);+ Assert.assertEquals(1, segments.length);+ Assert.assertEquals("140.211.11.130", segments[0]);// test non-asciiurl = new URL("http://www.example.商業.tw");segments = URLUtil.getHostSegments(url);- assertEquals("www", segments[0]);- assertEquals("example", segments[1]);- assertEquals("商業", segments[2]);- assertEquals("tw", segments[3]);+ Assert.assertEquals("www", segments[0]);+ Assert.assertEquals("example", segments[1]);+ Assert.assertEquals("商業", segments[2]);+ Assert.assertEquals("tw", segments[3]);}+ @Testpublic void testChooseRepr()throws Exception {@@ -178,39 +174,39 @@ public class TestURLUtil// 1) different domain them keep dest, temp or perm// a.com -> b.com*- assertEquals(bDotCom, URLUtil.chooseRepr(aDotCom, bDotCom, true));- assertEquals(bDotCom, URLUtil.chooseRepr(aDotCom, bDotCom, false));+ Assert.assertEquals(bDotCom, URLUtil.chooseRepr(aDotCom, bDotCom, true));+ Assert.assertEquals(bDotCom, URLUtil.chooseRepr(aDotCom, bDotCom, false));// 2) permanent and root, keep src// *a.com -> a.com?y=1 || *a.com -> a.com/xyz/index.html- assertEquals(aDotCom, URLUtil.chooseRepr(aDotCom, aQStr, false));- assertEquals(aDotCom, URLUtil.chooseRepr(aDotCom, aPath, false));+ Assert.assertEquals(aDotCom, URLUtil.chooseRepr(aDotCom, aQStr, false));+ Assert.assertEquals(aDotCom, URLUtil.chooseRepr(aDotCom, aPath, false));//3) permanent and not root and dest root, keep dest//a.com/xyz/index.html -> a.com*- assertEquals(aDotCom, URLUtil.chooseRepr(aPath, aDotCom, false));+ Assert.assertEquals(aDotCom, URLUtil.chooseRepr(aPath, aDotCom, false));//4) permanent and neither root keep dest// a.com/xyz/index.html -> a.com/abc/page.html*- assertEquals(aPath2, URLUtil.chooseRepr(aPath, aPath2, false));+ Assert.assertEquals(aPath2, URLUtil.chooseRepr(aPath, aPath2, false));//5) temp and root and dest not root keep src//*a.com -> a.com/xyz/index.html- assertEquals(aDotCom, URLUtil.chooseRepr(aDotCom, aPath, true));+ Assert.assertEquals(aDotCom, URLUtil.chooseRepr(aDotCom, aPath, true));//6) temp and not root and dest root keep dest// a.com/xyz/index.html -> a.com*- assertEquals(aDotCom, URLUtil.chooseRepr(aPath, aDotCom, true));+ Assert.assertEquals(aDotCom, URLUtil.chooseRepr(aPath, aDotCom, true));//7) temp and neither root, keep shortest, if hosts equal by path else by hosts// a.com/xyz/index.html -> a.com/abc/page.html*// *www.a.com/xyz/index.html -> www.news.a.com/xyz/index.html- assertEquals(aPath2, URLUtil.chooseRepr(aPath, aPath2, true));- assertEquals(aPath, URLUtil.chooseRepr(aPath, aPath3, true));+ Assert.assertEquals(aPath2, URLUtil.chooseRepr(aPath, aPath2, true));+ Assert.assertEquals(aPath, URLUtil.chooseRepr(aPath, aPath3, true));//8) temp and both root keep shortest sub domain// *www.a.com -> www.news.a.com- assertEquals(aDotCom, URLUtil.chooseRepr(aDotCom, aSubDotCom, true));+ Assert.assertEquals(aDotCom, URLUtil.chooseRepr(aDotCom, aSubDotCom, true));}// from RFC3986 section 5.4.1@@ -241,37 +237,40 @@ public class TestURLUtil{ "../../g" , "http://a/g"}};+ @Testpublic void testResolveURL() throws Exception {// test NUTCH-436URL u436 = new URL("http://a/b/c/d;p?q#f");- assertEquals("http://a/b/c/d;p?q#f", u436.toString());+ Assert.assertEquals("http://a/b/c/d;p?q#f", u436.toString());URL abs = URLUtil.resolveURL(u436, "?y");- assertEquals("http://a/b/c/d;p?y", abs.toString());+ Assert.assertEquals("http://a/b/c/d;p?y", abs.toString());// test NUTCH-566URL u566 = new URL("http://www.fleurie.org/entreprise.asp");abs = URLUtil.resolveURL(u566, "?id_entrep=111");- assertEquals("http://www.fleurie.org/entreprise.asp?id_entrep=111", abs.toString());+ Assert.assertEquals("http://www.fleurie.org/entreprise.asp?id_entrep=111", abs.toString());URL base = new URL(baseString);- assertEquals("base url parsing", baseString, base.toString());+ Assert.assertEquals("base url parsing", baseString, base.toString());for (int i = 0; i < targets.length; i++) {URL u = URLUtil.resolveURL(base, targets[i][0]);- assertEquals(targets[i][1], targets[i][1], u.toString());+ Assert.assertEquals(targets[i][1], targets[i][1], u.toString());}}+ @Testpublic void testToUNICODE() throws Exception {- assertEquals("http://www.çevir.com", URLUtil.toUNICODE("http://www.xn--evir-zoa.com"));- assertEquals("http://uni-tübingen.de/", URLUtil.toUNICODE("http://xn--uni-tbingen-xhb.de/"));- assertEquals(+ Assert.assertEquals("http://www.çevir.com", URLUtil.toUNICODE("http://www.xn--evir-zoa.com"));+ Assert.assertEquals("http://uni-tübingen.de/", URLUtil.toUNICODE("http://xn--uni-tbingen-xhb.de/"));+ Assert.assertEquals("http://www.medizin.uni-tübingen.de:8080/search.php?q=abc#p1",URLUtil.toUNICODE("http://www.medizin.xn--uni-tbingen-xhb.de:8080/search.php?q=abc#p1"));}+ @Testpublic void testToASCII() throws Exception {- assertEquals("http://www.xn--evir-zoa.com", URLUtil.toASCII("http://www.çevir.com"));- assertEquals("http://xn--uni-tbingen-xhb.de/", URLUtil.toASCII("http://uni-tübingen.de/"));- assertEquals(+ Assert.assertEquals("http://www.xn--evir-zoa.com", URLUtil.toASCII("http://www.çevir.com"));+ Assert.assertEquals("http://xn--uni-tbingen-xhb.de/", URLUtil.toASCII("http://uni-tübingen.de/"));+ Assert.assertEquals("http://www.medizin.xn--uni-tbingen-xhb.de:8080/search.php?q=abc#p1",URLUtil.toASCII("http://www.medizin.uni-tübingen.de:8080/search.php?q=abc#p1"));}diff --git a/src/test/org/apache/nutch/util/WritableTestUtils.java b/src/test/org/apache/nutch/util/WritableTestUtils.javaindex 4d5b55dcc..6c07f2e86 100644--- a/src/test/org/apache/nutch/util/WritableTestUtils.java+++ b/src/test/org/apache/nutch/util/WritableTestUtils.java@@ -19,8 +19,7 @@ package org.apache.nutch.util;import org.apache.hadoop.io.*;import org.apache.hadoop.conf.*;--import junit.framework.TestCase;+import org.junit.Assert;public class WritableTestUtils {@@ -32,7 +31,7 @@ public class WritableTestUtils {/** Utility method for testing writables. */public static void testWritable(Writable before, Configuration conf)throws Exception {- TestCase.assertEquals(before, writeRead(before, conf));+ Assert.assertEquals(before, writeRead(before, conf));}