Apache Nutch is an extensible and scalable web crawler
add some unit test for different factories
Sami Sirene156a5625ed0
diff --git a/src/test/org/apache/nutch/analysis/TestAnalyzerFactory.java b/src/test/org/apache/nutch/analysis/TestAnalyzerFactory.javanew file mode 100644index 000000000..a42b82347--- /dev/null+++ b/src/test/org/apache/nutch/analysis/TestAnalyzerFactory.java@@ -0,0 +1,58 @@+/*+ * Copyright 2006 The Apache Software Foundation+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package org.apache.nutch.analysis;++import org.apache.hadoop.conf.Configuration;+import org.apache.nutch.util.NutchConfiguration;++import junit.framework.TestCase;++/**+ * Simple test case to verify AnalyzerFactory functionality+ */+public class TestAnalyzerFactory extends TestCase {++ private Configuration conf;+ private AnalyzerFactory factory;++ protected void setUp() throws Exception {+ conf = NutchConfiguration.create();+ conf.set("plugin.includes", ".*");+ factory=AnalyzerFactory.get(conf);+ }++ public void testGetNull() {+ NutchAnalyzer analyzer=factory.get((String)null);+ assertSame(analyzer, factory.getDefault());+ }++ public void testGetExisting() {+ NutchAnalyzer analyzer=factory.get("en");+ assertNotNull(analyzer);+ }++ public void testGetNonExisting() {+ NutchAnalyzer analyzer=factory.get("imaginary-non-existing-language");+ assertSame(analyzer, factory.getDefault());+ }++ public void testCaching() {+ NutchAnalyzer analyzer1=factory.get("en");+ NutchAnalyzer analyzer2=factory.get("en");+ assertEquals(analyzer1, analyzer2);+ }++}diff --git a/src/test/org/apache/nutch/clustering/TestOnlineClustererFactory.java b/src/test/org/apache/nutch/clustering/TestOnlineClustererFactory.javanew file mode 100644index 000000000..370c85cf1--- /dev/null+++ b/src/test/org/apache/nutch/clustering/TestOnlineClustererFactory.java@@ -0,0 +1,49 @@+/*+ * Copyright 2006 The Apache Software Foundation+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package org.apache.nutch.clustering;++import org.apache.hadoop.conf.Configuration;+import org.apache.nutch.plugin.PluginRuntimeException;+import org.apache.nutch.util.NutchConfiguration;++import junit.framework.TestCase;++public class TestOnlineClustererFactory extends TestCase {++ private Configuration conf;++ protected void setUp() throws Exception {+ conf = NutchConfiguration.create();+ conf.set("plugin.includes", ".*");+ }++ public void testFacotyr(){+ OnlineClustererFactory factory = new OnlineClustererFactory(conf);++ try{+ OnlineClusterer clusterer1=factory.getOnlineClusterer();+ OnlineClusterer clusterer2=factory.getOnlineClusterer();+ assertNotNull(clusterer1);+ assertNotNull(clusterer2);++ //Current implementation creates new object instance in every call+ //TODO: check if this is required+ assertNotSame(clusterer1, clusterer2);+ } catch (PluginRuntimeException pre) {+ fail("Should not throw Exception:" + pre);+ }+ }+}diff --git a/src/test/org/apache/nutch/crawl/TestSignatureFactory.java b/src/test/org/apache/nutch/crawl/TestSignatureFactory.javanew file mode 100644index 000000000..d9ed9b91d--- /dev/null+++ b/src/test/org/apache/nutch/crawl/TestSignatureFactory.java@@ -0,0 +1,33 @@+/*+ * Copyright 2006 The Apache Software Foundation+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package org.apache.nutch.crawl;++import org.apache.hadoop.conf.Configuration;+import org.apache.nutch.util.NutchConfiguration;++import junit.framework.TestCase;++public class TestSignatureFactory extends TestCase {++ public void testGetSignature() {+ Configuration conf=NutchConfiguration.create();+ Signature signature1=SignatureFactory.getSignature(conf);+ Signature signature2=SignatureFactory.getSignature(conf);+ assertNotNull(signature1);+ assertNotNull(signature2);+ assertEquals(signature1, signature2);+ }+}diff --git a/src/test/org/apache/nutch/net/TestUrlNormalizerFactory.java b/src/test/org/apache/nutch/net/TestUrlNormalizerFactory.javanew file mode 100644index 000000000..606036d67--- /dev/null+++ b/src/test/org/apache/nutch/net/TestUrlNormalizerFactory.java@@ -0,0 +1,35 @@+/*+ * Copyright 2006 The Apache Software Foundation+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package org.apache.nutch.net;++import org.apache.hadoop.conf.Configuration;+import org.apache.nutch.util.NutchConfiguration;++import junit.framework.TestCase;++public class TestUrlNormalizerFactory extends TestCase {++ public void testGetNormalizer() {+ Configuration conf=NutchConfiguration.create();++ UrlNormalizerFactory factory=new UrlNormalizerFactory(conf);++ UrlNormalizer normalizer1=factory.getNormalizer();+ UrlNormalizer normalizer2=factory.getNormalizer();+ assertNotNull(normalizer1);+ assertEquals(normalizer1, normalizer2);+ }+}diff --git a/src/test/org/apache/nutch/ontology/TestOntologyFactory.java b/src/test/org/apache/nutch/ontology/TestOntologyFactory.javanew file mode 100644index 000000000..e9610764c--- /dev/null+++ b/src/test/org/apache/nutch/ontology/TestOntologyFactory.java@@ -0,0 +1,48 @@+/*+ * Copyright 2006 The Apache Software Foundation+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package org.apache.nutch.ontology;++import org.apache.hadoop.conf.Configuration;+import org.apache.nutch.plugin.PluginRuntimeException;+import org.apache.nutch.util.NutchConfiguration;++import junit.framework.TestCase;++public class TestOntologyFactory extends TestCase {++ private Configuration conf;++ protected void setUp() throws Exception {+ conf = NutchConfiguration.create();+ conf.set("plugin.includes", ".*");+ }++ public void testGetOntology() {+ OntologyFactory factory=new OntologyFactory(conf);++ try {+ Ontology ontology1=factory.getOntology();+ Ontology ontology2=factory.getOntology();+ assertNotNull(ontology1);+ assertNotNull(ontology2);+ //Current implementation creates new object instance in every call+ //TODO: check if this is required+ assertNotSame(ontology1, ontology2);+ } catch (PluginRuntimeException e) {+ fail("should not trow:" + e);+ }+ }+}diff --git a/src/test/org/apache/nutch/protocol/TestProtocolFactory.java b/src/test/org/apache/nutch/protocol/TestProtocolFactory.javaindex c15ee917c..c330d106f 100644--- a/src/test/org/apache/nutch/protocol/TestProtocolFactory.java+++ b/src/test/org/apache/nutch/protocol/TestProtocolFactory.java@@ -22,10 +22,15 @@ import junit.framework.TestCase;public class TestProtocolFactory extends TestCase {- public void testGetProtocol(){- Configuration conf=NutchConfiguration.create();+ Configuration conf;++ protected void setUp() throws Exception {+ conf = NutchConfiguration.create();+ conf.set("plugin.includes", ".*");conf.set("http.agent.name", "test-bot");-+ }++ public void testGetProtocol(){ProtocolFactory factory=new ProtocolFactory(conf);//non existing protocoldiff --git a/src/test/org/apache/nutch/searcher/TestSummarizerFactory.java b/src/test/org/apache/nutch/searcher/TestSummarizerFactory.javanew file mode 100644index 000000000..1006375fc--- /dev/null+++ b/src/test/org/apache/nutch/searcher/TestSummarizerFactory.java@@ -0,0 +1,40 @@+/*+ * Copyright 2006 The Apache Software Foundation+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package org.apache.nutch.searcher;++import org.apache.hadoop.conf.Configuration;+import org.apache.nutch.util.NutchConfiguration;++import junit.framework.TestCase;++public class TestSummarizerFactory extends TestCase {++ private Configuration conf;++ protected void setUp() throws Exception {+ conf = NutchConfiguration.create();+ conf.set("plugin.includes", ".*");+ }++ public void testGetSummarizer(){+ SummarizerFactory factory=new SummarizerFactory(conf);+ Summarizer summarizer1=factory.getSummarizer();+ Summarizer summarizer2=factory.getSummarizer();++ assertNotNull(summarizer1);+ assertEquals(summarizer1, summarizer2);+ }+}