tests: convert jetty/examples to junit4

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@927660 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2010-03-26 01:23:08 +00:00
parent cf05c92057
commit aedd12fea2
1 changed files with 18 additions and 50 deletions

View File

@ -17,54 +17,39 @@ package org.apache.solr.client.solrj.response;
*/ */
import junit.framework.Assert; import junit.framework.Assert;
import org.apache.solr.client.solrj.SolrExampleTestBase; import org.apache.solr.client.solrj.SolrJettyTestBase;
import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrQuery;
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.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.SpellingParams; import org.apache.solr.common.params.SpellingParams;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/** /**
* Test for SpellCheckComponent's response in Solrj * Test for SpellCheckComponent's response in Solrj
* *
* @version $Id$ * @version $Id$
* @since solr 1.3 * @since solr 1.3
*/ */
public class TestSpellCheckResponse extends SolrExampleTestBase { public class TestSpellCheckResponse extends SolrJettyTestBase {
@Override public String getSchemaFile() { return null; } @BeforeClass
@Override public String getSolrConfigFile() { return null; } public static void beforeTest() throws Exception {
// createJetty(EXAMPLE_HOME, null, null);
SolrServer server; initCore(EXAMPLE_CONFIG, EXAMPLE_SCHEMA, EXAMPLE_HOME);
JettySolrRunner jetty; // initCore("solrconfig.xml", "schema.xml", null);
}
int port = 0;
static final String context = "/example";
static String field = "name"; static String field = "name";
@Override @Test
public void setUp() throws Exception {
super.setUp();
jetty = new JettySolrRunner(context, 0);
jetty.start();
port = jetty.getLocalPort();
log.info("Assigned Port: " + port);
server = this.createNewSolrServer();
}
@Override
public void tearDown() throws Exception {
jetty.stop();
super.tearDown();
}
public void testSpellCheckResponse() throws Exception { public void testSpellCheckResponse() throws Exception {
getSolrServer();
SolrInputDocument doc = new SolrInputDocument(); SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "111"); doc.setField("id", "111");
doc.setField(field, "Samsung"); doc.setField(field, "Samsung");
@ -81,7 +66,9 @@ public class TestSpellCheckResponse extends SolrExampleTestBase {
Assert.assertEquals("samsung", response.getFirstSuggestion("samsang")); Assert.assertEquals("samsung", response.getFirstSuggestion("samsang"));
} }
@Test
public void testSpellCheckResponse_Extended() throws Exception { public void testSpellCheckResponse_Extended() throws Exception {
getSolrServer();
SolrInputDocument doc = new SolrInputDocument(); SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "111"); doc.setField("id", "111");
doc.setField(field, "Samsung"); doc.setField(field, "Samsung");
@ -116,23 +103,4 @@ public class TestSpellCheckResponse extends SolrExampleTestBase {
// Hmmm... the API for SpellCheckResponse could be nicer: // Hmmm... the API for SpellCheckResponse could be nicer:
response.getSuggestions().get(0).getAlternatives().get(0); response.getSuggestions().get(0).getAlternatives().get(0);
} }
protected SolrServer getSolrServer() {
return server;
}
protected SolrServer createNewSolrServer() {
try {
// setup the server...
String url = "http://localhost:" + port + context;
CommonsHttpSolrServer s = new CommonsHttpSolrServer(url);
s.setConnectionTimeout(100); // 1/10th sec
s.setDefaultMaxConnectionsPerHost(100);
s.setMaxTotalConnections(100);
return s;
}
catch (Exception ex) {
throw new RuntimeException(ex);
}
}
} }