Author: siren
Date: Thu Jul 27 06:27:42 2006
New Revision: 426065

URL: http://svn.apache.org/viewvc?rev=426065&view=rev
Log:
add some unit test for different factories

Added:
    
lucene/nutch/trunk/src/test/org/apache/nutch/analysis/TestAnalyzerFactory.java
    
lucene/nutch/trunk/src/test/org/apache/nutch/clustering/TestOnlineClustererFactory.java
    lucene/nutch/trunk/src/test/org/apache/nutch/crawl/TestSignatureFactory.java
    
lucene/nutch/trunk/src/test/org/apache/nutch/net/TestUrlNormalizerFactory.java
    
lucene/nutch/trunk/src/test/org/apache/nutch/ontology/TestOntologyFactory.java
    
lucene/nutch/trunk/src/test/org/apache/nutch/searcher/TestSummarizerFactory.java
Modified:
    
lucene/nutch/trunk/src/test/org/apache/nutch/protocol/TestProtocolFactory.java

Added: 
lucene/nutch/trunk/src/test/org/apache/nutch/analysis/TestAnalyzerFactory.java
URL: 
http://svn.apache.org/viewvc/lucene/nutch/trunk/src/test/org/apache/nutch/analysis/TestAnalyzerFactory.java?rev=426065&view=auto
==============================================================================
--- 
lucene/nutch/trunk/src/test/org/apache/nutch/analysis/TestAnalyzerFactory.java 
(added)
+++ 
lucene/nutch/trunk/src/test/org/apache/nutch/analysis/TestAnalyzerFactory.java 
Thu Jul 27 06:27:42 2006
@@ -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);
+  }
+
+}

Added: 
lucene/nutch/trunk/src/test/org/apache/nutch/clustering/TestOnlineClustererFactory.java
URL: 
http://svn.apache.org/viewvc/lucene/nutch/trunk/src/test/org/apache/nutch/clustering/TestOnlineClustererFactory.java?rev=426065&view=auto
==============================================================================
--- 
lucene/nutch/trunk/src/test/org/apache/nutch/clustering/TestOnlineClustererFactory.java
 (added)
+++ 
lucene/nutch/trunk/src/test/org/apache/nutch/clustering/TestOnlineClustererFactory.java
 Thu Jul 27 06:27:42 2006
@@ -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);
+    }
+  }
+}

Added: 
lucene/nutch/trunk/src/test/org/apache/nutch/crawl/TestSignatureFactory.java
URL: 
http://svn.apache.org/viewvc/lucene/nutch/trunk/src/test/org/apache/nutch/crawl/TestSignatureFactory.java?rev=426065&view=auto
==============================================================================
--- 
lucene/nutch/trunk/src/test/org/apache/nutch/crawl/TestSignatureFactory.java 
(added)
+++ 
lucene/nutch/trunk/src/test/org/apache/nutch/crawl/TestSignatureFactory.java 
Thu Jul 27 06:27:42 2006
@@ -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);
+  }
+}

Added: 
lucene/nutch/trunk/src/test/org/apache/nutch/net/TestUrlNormalizerFactory.java
URL: 
http://svn.apache.org/viewvc/lucene/nutch/trunk/src/test/org/apache/nutch/net/TestUrlNormalizerFactory.java?rev=426065&view=auto
==============================================================================
--- 
lucene/nutch/trunk/src/test/org/apache/nutch/net/TestUrlNormalizerFactory.java 
(added)
+++ 
lucene/nutch/trunk/src/test/org/apache/nutch/net/TestUrlNormalizerFactory.java 
Thu Jul 27 06:27:42 2006
@@ -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);
+  }
+}

Added: 
lucene/nutch/trunk/src/test/org/apache/nutch/ontology/TestOntologyFactory.java
URL: 
http://svn.apache.org/viewvc/lucene/nutch/trunk/src/test/org/apache/nutch/ontology/TestOntologyFactory.java?rev=426065&view=auto
==============================================================================
--- 
lucene/nutch/trunk/src/test/org/apache/nutch/ontology/TestOntologyFactory.java 
(added)
+++ 
lucene/nutch/trunk/src/test/org/apache/nutch/ontology/TestOntologyFactory.java 
Thu Jul 27 06:27:42 2006
@@ -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);
+    }
+  }
+}

Modified: 
lucene/nutch/trunk/src/test/org/apache/nutch/protocol/TestProtocolFactory.java
URL: 
http://svn.apache.org/viewvc/lucene/nutch/trunk/src/test/org/apache/nutch/protocol/TestProtocolFactory.java?rev=426065&r1=426064&r2=426065&view=diff
==============================================================================
--- 
lucene/nutch/trunk/src/test/org/apache/nutch/protocol/TestProtocolFactory.java 
(original)
+++ 
lucene/nutch/trunk/src/test/org/apache/nutch/protocol/TestProtocolFactory.java 
Thu Jul 27 06:27:42 2006
@@ -22,10 +22,15 @@
 
 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 protocol

Added: 
lucene/nutch/trunk/src/test/org/apache/nutch/searcher/TestSummarizerFactory.java
URL: 
http://svn.apache.org/viewvc/lucene/nutch/trunk/src/test/org/apache/nutch/searcher/TestSummarizerFactory.java?rev=426065&view=auto
==============================================================================
--- 
lucene/nutch/trunk/src/test/org/apache/nutch/searcher/TestSummarizerFactory.java
 (added)
+++ 
lucene/nutch/trunk/src/test/org/apache/nutch/searcher/TestSummarizerFactory.java
 Thu Jul 27 06:27:42 2006
@@ -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);
+  }
+}


Reply via email to