SOLR-2299: improve test-running from eclipse

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1053405 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2010-12-28 18:54:06 +00:00
parent 1b671cfba3
commit 3ae880e7df
5 changed files with 32 additions and 14 deletions

View File

@ -278,6 +278,8 @@ public class SolrResourceLoader implements ResourceLoader
} }
// delegate to the class loader (looking into $INSTANCE_DIR/lib jars) // delegate to the class loader (looking into $INSTANCE_DIR/lib jars)
is = classLoader.getResourceAsStream(resource); is = classLoader.getResourceAsStream(resource);
if (is == null)
is = classLoader.getResourceAsStream(getConfigDir() + resource);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Error opening " + resource, e); throw new RuntimeException("Error opening " + resource, e);
} }

View File

@ -18,12 +18,16 @@
package org.apache.solr.client.solrj.response; package org.apache.solr.client.solrj.response;
import java.io.FileReader; import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import junit.framework.Assert; import junit.framework.Assert;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.client.solrj.impl.XMLResponseParser; import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrResourceLoader;
import org.junit.Test; import org.junit.Test;
/** /**
@ -35,8 +39,9 @@ public class QueryResponseTest extends LuceneTestCase {
@Test @Test
public void testDateFacets() throws Exception { public void testDateFacets() throws Exception {
XMLResponseParser parser = new XMLResponseParser(); XMLResponseParser parser = new XMLResponseParser();
FileReader in = new FileReader("sampleDateFacetResponse.xml"); InputStream is = new SolrResourceLoader(null, null).openResource("sampleDateFacetResponse.xml");
assertTrue("in is null and it shouldn't be", in != null); assertNotNull(is);
Reader in = new InputStreamReader(is, "UTF-8");
NamedList<Object> response = parser.processResponse(in); NamedList<Object> response = parser.processResponse(in);
in.close(); in.close();

View File

@ -20,6 +20,7 @@ package org.apache.solr.common.util;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -29,6 +30,7 @@ import java.net.URL;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.common.util.ContentStreamBase; import org.apache.solr.common.util.ContentStreamBase;
import org.apache.solr.core.SolrResourceLoader;
/** /**
*/ */
@ -45,8 +47,12 @@ public class ContentStreamTest extends LuceneTestCase
public void testFileStream() throws IOException public void testFileStream() throws IOException
{ {
File file = new File( "README" ); InputStream is = new SolrResourceLoader(null, null).openResource( "README" );
assertTrue( file.exists() ); // "make sure you are running from: solr\src\test\test-files" assertNotNull( is );
File file = new File(TEMP_DIR, "README");
FileOutputStream os = new FileOutputStream(file);
IOUtils.copy(is, os);
os.close();
ContentStreamBase stream = new ContentStreamBase.FileStream( file ); ContentStreamBase stream = new ContentStreamBase.FileStream( file );
assertEquals( file.length(), stream.getSize().intValue() ); assertEquals( file.length(), stream.getSize().intValue() );

View File

@ -25,10 +25,13 @@ import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.util.List; import java.util.List;
public class TestBinaryField extends LuceneTestCase { public class TestBinaryField extends LuceneTestCase {
@ -53,12 +56,17 @@ public class TestBinaryField extends LuceneTestCase {
dataDir.mkdirs(); dataDir.mkdirs();
confDir.mkdirs(); confDir.mkdirs();
SolrResourceLoader loader = new SolrResourceLoader(null, null);
File f = new File(confDir, "solrconfig.xml"); File f = new File(confDir, "solrconfig.xml");
String fname = "." + File.separator + "solr" + File.separator + "conf" + File.separator + "solrconfig-slave1.xml"; String fname = "solr/conf/solrconfig-slave1.xml";
FileUtils.copyFile(new File(fname), f); FileOutputStream out = new FileOutputStream(f);
IOUtils.copy(loader.openResource(fname), out);
out.close();
f = new File(confDir, "schema.xml"); f = new File(confDir, "schema.xml");
fname = "." + File.separator + "solr" + File.separator + "conf" + File.separator + "schema-binaryfield.xml"; fname = "solr/conf/schema-binaryfield.xml";
FileUtils.copyFile(new File(fname), f); out = new FileOutputStream(f);
IOUtils.copy(loader.openResource(fname), out);
out.close();
System.setProperty("solr.solr.home", homeDir.getAbsolutePath()); System.setProperty("solr.solr.home", homeDir.getAbsolutePath());
System.setProperty("solr.data.dir", dataDir.getAbsolutePath()); System.setProperty("solr.data.dir", dataDir.getAbsolutePath());
System.setProperty("solr.test.sys.prop1", "propone"); System.setProperty("solr.test.sys.prop1", "propone");

View File

@ -65,8 +65,7 @@ public class FileBasedSpellCheckerTest extends SolrTestCaseJ4 {
spellchecker.add("classname", FileBasedSpellChecker.class.getName()); spellchecker.add("classname", FileBasedSpellChecker.class.getName());
spellchecker.add(SolrSpellChecker.DICTIONARY_NAME, "external"); spellchecker.add(SolrSpellChecker.DICTIONARY_NAME, "external");
File spelling = new File("spellings.txt"); spellchecker.add(AbstractLuceneSpellChecker.LOCATION, "spellings.txt");
spellchecker.add(AbstractLuceneSpellChecker.LOCATION, spelling.getAbsolutePath());
spellchecker.add(IndexBasedSpellChecker.FIELD, "teststop"); spellchecker.add(IndexBasedSpellChecker.FIELD, "teststop");
spellchecker.add(FileBasedSpellChecker.SOURCE_FILE_CHAR_ENCODING, "UTF-8"); spellchecker.add(FileBasedSpellChecker.SOURCE_FILE_CHAR_ENCODING, "UTF-8");
File indexDir = new File(TEMP_DIR, "spellingIdx" + new Date().getTime()); File indexDir = new File(TEMP_DIR, "spellingIdx" + new Date().getTime());
@ -102,8 +101,7 @@ public class FileBasedSpellCheckerTest extends SolrTestCaseJ4 {
NamedList spellchecker = new NamedList(); NamedList spellchecker = new NamedList();
spellchecker.add("classname", FileBasedSpellChecker.class.getName()); spellchecker.add("classname", FileBasedSpellChecker.class.getName());
spellchecker.add(SolrSpellChecker.DICTIONARY_NAME, "external"); spellchecker.add(SolrSpellChecker.DICTIONARY_NAME, "external");
File spelling = new File("spellings.txt"); spellchecker.add(AbstractLuceneSpellChecker.LOCATION, "spellings.txt");
spellchecker.add(AbstractLuceneSpellChecker.LOCATION, spelling.getAbsolutePath());
spellchecker.add(IndexBasedSpellChecker.FIELD, "teststop"); spellchecker.add(IndexBasedSpellChecker.FIELD, "teststop");
spellchecker.add(FileBasedSpellChecker.SOURCE_FILE_CHAR_ENCODING, "UTF-8"); spellchecker.add(FileBasedSpellChecker.SOURCE_FILE_CHAR_ENCODING, "UTF-8");
File indexDir = new File(TEMP_DIR, "spellingIdx" + new Date().getTime()); File indexDir = new File(TEMP_DIR, "spellingIdx" + new Date().getTime());
@ -149,8 +147,7 @@ public class FileBasedSpellCheckerTest extends SolrTestCaseJ4 {
spellchecker.add("classname", FileBasedSpellChecker.class.getName()); spellchecker.add("classname", FileBasedSpellChecker.class.getName());
spellchecker.add(SolrSpellChecker.DICTIONARY_NAME, "external"); spellchecker.add(SolrSpellChecker.DICTIONARY_NAME, "external");
File spelling = new File("spellings.txt"); spellchecker.add(AbstractLuceneSpellChecker.LOCATION, "spellings.txt");
spellchecker.add(AbstractLuceneSpellChecker.LOCATION, spelling.getAbsolutePath());
spellchecker.add(FileBasedSpellChecker.SOURCE_FILE_CHAR_ENCODING, "UTF-8"); spellchecker.add(FileBasedSpellChecker.SOURCE_FILE_CHAR_ENCODING, "UTF-8");
spellchecker.add(IndexBasedSpellChecker.FIELD, "teststop"); spellchecker.add(IndexBasedSpellChecker.FIELD, "teststop");
spellchecker.add(FileBasedSpellChecker.FIELD_TYPE, "teststop"); spellchecker.add(FileBasedSpellChecker.FIELD_TYPE, "teststop");