lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r927644 - in /lucene/dev/trunk/solr/src/test/org/apache/solr/servlet: CacheHeaderTest.java CacheHeaderTestBase.java NoCacheHeaderTest.java
Date Thu, 25 Mar 2010 23:55:14 GMT
Author: yonik
Date: Thu Mar 25 23:55:14 2010
New Revision: 927644

URL: http://svn.apache.org/viewvc?rev=927644&view=rev
Log:
tests: convert more jetty/example tests to junit4

Modified:
    lucene/dev/trunk/solr/src/test/org/apache/solr/servlet/CacheHeaderTest.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/servlet/NoCacheHeaderTest.java

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/servlet/CacheHeaderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/servlet/CacheHeaderTest.java?rev=927644&r1=927643&r2=927644&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/servlet/CacheHeaderTest.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/servlet/CacheHeaderTest.java Thu Mar 25
23:55:14 2010
@@ -26,20 +26,26 @@ import org.apache.commons.httpclient.Hea
 import org.apache.commons.httpclient.HttpMethodBase;
 import org.apache.commons.httpclient.NameValuePair;
 import org.apache.commons.httpclient.util.DateUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static junit.framework.Assert.*;
 
 /**
  * A test case for the several HTTP cache headers emitted by Solr
  */
 public class CacheHeaderTest extends CacheHeaderTestBase {
-  @Override
-  public String getSolrConfigFilename() {
-    return "solrconfig.xml";
+
+  @BeforeClass
+  public static void beforeTest() throws Exception {
+    createJetty("solr/", null, null);
   }
 
   protected static final String CHARSET = "UTF-8";
 
   protected static final String CONTENTS = "id\n100\n101\n102";
 
+  @Test
   public void testCacheVetoHandler() throws Exception {
     File f=makeFile(CONTENTS);
     HttpMethodBase m=getUpdateMethod("GET");
@@ -49,6 +55,7 @@ public class CacheHeaderTest extends Cac
     checkVetoHeaders(m, true);
   }
   
+  @Test
   public void testCacheVetoException() throws Exception {
     HttpMethodBase m = getSelectMethod("GET");
     // We force an exception from Solr. This should emit "no-cache" HTTP headers
@@ -59,6 +66,7 @@ public class CacheHeaderTest extends Cac
     checkVetoHeaders(m, false);
   }
 
+
   protected void checkVetoHeaders(HttpMethodBase m, boolean checkExpires) throws Exception
{
     Header head = m.getResponseHeader("Cache-Control");
     assertNotNull("We got no Cache-Control header", head);

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java?rev=927644&r1=927643&r2=927644&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java Thu Mar
25 23:55:14 2010
@@ -23,47 +23,16 @@ import org.apache.commons.httpclient.met
 import org.apache.commons.httpclient.methods.HeadMethod;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.solr.client.solrj.SolrExampleTestBase;
+import org.apache.solr.client.solrj.SolrJettyTestBase;
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.embedded.JettySolrRunner;
 import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
+import org.junit.Test;
 
-public abstract class CacheHeaderTestBase extends SolrExampleTestBase {
-  @Override public String getSolrHome() {  return "solr/"; }
-  
-  abstract public String getSolrConfigFilename();
-  
-  public String getSolrConfigFile() { return getSolrHome()+"conf/"+getSolrConfigFilename();
}
-  
-  CommonsHttpSolrServer server;
-
-  JettySolrRunner jetty;
-
-  int port = 0;
-
-  static final String context = "/example";
-
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
-    
-    jetty = new JettySolrRunner(context, 0, getSolrConfigFilename());
-    jetty.start();
-    port = jetty.getLocalPort();
-
-    server = this.createNewSolrServer();
-  }
-
-  @Override
-  public void tearDown() throws Exception {
-    super.tearDown();
-    jetty.stop(); // stop the server
-  }
-  
-  @Override
-  protected SolrServer getSolrServer() {
-    return server;
-  }
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
+public abstract class CacheHeaderTestBase extends SolrJettyTestBase {
   @Override
   protected CommonsHttpSolrServer createNewSolrServer() {
     try {
@@ -80,13 +49,14 @@ public abstract class CacheHeaderTestBas
   }
 
   protected HttpMethodBase getSelectMethod(String method) {
+    CommonsHttpSolrServer httpserver = (CommonsHttpSolrServer)getSolrServer();
     HttpMethodBase m = null;
     if ("GET".equals(method)) {
-      m = new GetMethod(server.getBaseURL() + "/select");
+      m = new GetMethod(httpserver.getBaseURL() + "/select");
     } else if ("HEAD".equals(method)) {
-      m = new HeadMethod(server.getBaseURL() + "/select");
+      m = new HeadMethod(httpserver.getBaseURL() + "/select");
     } else if ("POST".equals(method)) {
-      m = new PostMethod(server.getBaseURL() + "/select");
+      m = new PostMethod(httpserver.getBaseURL() + "/select");
     }
     m.setQueryString(new NameValuePair[] { new NameValuePair("q", "solr"),
           new NameValuePair("qt", "standard") });
@@ -94,21 +64,23 @@ public abstract class CacheHeaderTestBas
   }
 
   protected HttpMethodBase getUpdateMethod(String method) {
+    CommonsHttpSolrServer httpserver = (CommonsHttpSolrServer)getSolrServer();
     HttpMethodBase m = null;
     
     if ("GET".equals(method)) {
-      m=new GetMethod(server.getBaseURL()+"/update/csv");
+      m=new GetMethod(httpserver.getBaseURL()+"/update/csv");
     } else if ("POST".equals(method)) {
-      m=new PostMethod(server.getBaseURL()+"/update/csv");      
+      m=new PostMethod(httpserver.getBaseURL()+"/update/csv");
     } else if ("HEAD".equals(method)) {
-      m=new HeadMethod(server.getBaseURL()+"/update/csv");      
+      m=new HeadMethod(httpserver.getBaseURL()+"/update/csv");
     }
     
     return m;
   }
   
   protected HttpClient getClient() {
-    return server.getHttpClient();
+    CommonsHttpSolrServer httpserver = (CommonsHttpSolrServer)getSolrServer();
+    return httpserver.getHttpClient();
   }
 
   protected void checkResponseBody(String method, HttpMethodBase resp)
@@ -140,16 +112,19 @@ public abstract class CacheHeaderTestBas
   }
 
   // The tests
+  @Test
   public void testLastModified() throws Exception {
     doLastModified("GET");
     doLastModified("HEAD");
   }
 
+  @Test
   public void testEtag() throws Exception {
     doETag("GET");
     doETag("HEAD");
   }
 
+  @Test
   public void testCacheControl() throws Exception {
     doCacheControl("GET");
     doCacheControl("HEAD");

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/servlet/NoCacheHeaderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/servlet/NoCacheHeaderTest.java?rev=927644&r1=927643&r2=927644&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/servlet/NoCacheHeaderTest.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/servlet/NoCacheHeaderTest.java Thu Mar
25 23:55:14 2010
@@ -21,24 +21,35 @@ import java.util.Date;
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HttpMethodBase;
 import org.apache.commons.httpclient.util.DateUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static junit.framework.Assert.*;
+
 
 /**
  * A test case for the several HTTP cache headers emitted by Solr
  */
 public class NoCacheHeaderTest extends CacheHeaderTestBase {
-  @Override public String getSolrConfigFilename() { return "solrconfig-nocache.xml";  }
+  @BeforeClass
+  public static void beforeTest() throws Exception {
+    createJetty("solr/", "solr/conf/solrconfig-nocache.xml", null);
+  }
 
   // The tests
+  @Test
   public void testLastModified() throws Exception {
     doLastModified("GET");
     doLastModified("HEAD");
   }
 
+  @Test
   public void testEtag() throws Exception {
     doETag("GET");
     doETag("HEAD");
   }
 
+  @Test
   public void testCacheControl() throws Exception {
     doCacheControl("GET");
     doCacheControl("HEAD");



Mime
View raw message