Revision 7590
Added by ben leinfelder almost 11 years ago
SolrIndexIT.java | ||
---|---|---|
13 | 13 |
|
14 | 14 |
|
15 | 15 |
|
16 |
import org.apache.commons.io.FileUtils; |
|
17 | 16 |
import org.apache.solr.client.solrj.SolrServer; |
18 | 17 |
import org.apache.solr.client.solrj.SolrServerException; |
19 | 18 |
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; |
20 | 19 |
import org.apache.solr.client.solrj.response.QueryResponse; |
21 |
import org.apache.solr.common.SolrDocument; |
|
22 |
import org.apache.solr.common.SolrDocumentList; |
|
23 | 20 |
import org.apache.solr.common.params.SolrParams; |
24 | 21 |
import org.apache.solr.core.CoreContainer; |
25 | 22 |
import org.apache.solr.servlet.SolrRequestParsers; |
23 |
import org.dataone.configuration.Settings; |
|
26 | 24 |
import org.dataone.service.types.v1.SystemMetadata; |
27 | 25 |
import org.dataone.service.util.TypeMarshaller; |
26 |
import org.junit.Before; |
|
28 | 27 |
import org.junit.Test; |
29 | 28 |
import org.xml.sax.SAXException; |
30 | 29 |
|
... | ... | |
36 | 35 |
private static final String EMLUPDATEFILEPATH = "src/test/resources/eml-updating-example.xml"; |
37 | 36 |
private static final String id = "urn:uuid:606a19dd-b531-4bf4-b5a5-6d06c3d39098"; |
38 | 37 |
private static final String newId = "urn:uuid:606a19dd-b531-4bf4-b5a5-6d06c3d39099"; |
39 |
private static final String SOLRHOME = "solr-home"; |
|
40 |
private static final String SOLRTESTHOMEPATH = "target/"+SOLRHOME; |
|
38 |
private static String SOLRTESTHOMEPATH = null; |
|
41 | 39 |
|
40 |
/** |
|
41 |
* |
|
42 |
*/ |
|
43 |
@Before |
|
44 |
public void setUp() { |
|
45 |
SOLRTESTHOMEPATH = Settings.getConfiguration().getString("solr.homeDir"); |
|
46 |
} |
|
42 | 47 |
|
43 | 48 |
/** |
44 | 49 |
* Test building index for an insert. |
45 | 50 |
*/ |
46 | 51 |
@Test |
47 | 52 |
public void testInsert() throws Exception { |
53 |
try { |
|
48 | 54 |
SolrIndex solrIndex = generateSolrIndex(); |
55 |
|
|
49 | 56 |
//InputStream systemInputStream = new FileInputStream(new File(SYSTEMMETAFILEPATH)); |
50 | 57 |
SystemMetadata systemMetadata = TypeMarshaller.unmarshalTypeFromFile(SystemMetadata.class, SYSTEMMETAFILEPATH); |
51 | 58 |
InputStream emlInputStream = new FileInputStream(new File(EMLFILEPATH)); |
52 | 59 |
solrIndex.insert(id, systemMetadata, emlInputStream); |
53 | 60 |
String result = doQuery(solrIndex.getSolrServer()); |
54 | 61 |
assertTrue(result.contains("version1")); |
62 |
} catch (Exception e) { |
|
63 |
e.printStackTrace(); |
|
64 |
} |
|
55 | 65 |
} |
56 | 66 |
|
57 | 67 |
/** |
... | ... | |
128 | 138 |
* Generate a test solr server |
129 | 139 |
*/ |
130 | 140 |
private SolrServer generateSolrServer() throws IOException, ParserConfigurationException, SAXException { |
131 |
createSolrHome(); |
|
132 |
System.setProperty(SolrIndex.SOLRHOME, SOLRTESTHOMEPATH); |
|
133 |
//System.out.println("====="+"/Users/tao/projects/metacat-index/"+SOLRTESTHOMEPATH); |
|
134 |
CoreContainer.Initializer init = new CoreContainer.Initializer(); |
|
135 |
CoreContainer c = init.initialize(); |
|
141 |
//createSolrHome(); |
|
142 |
File configFile = new File(SOLRTESTHOMEPATH, "solr.xml"); |
|
143 |
CoreContainer c = new CoreContainer(SOLRTESTHOMEPATH, configFile); |
|
144 |
c.load(SOLRTESTHOMEPATH, configFile); |
|
136 | 145 |
SolrServer solrServer = new EmbeddedSolrServer(c, "collection1"); |
137 | 146 |
return solrServer; |
138 | 147 |
} |
139 | 148 |
|
140 |
/* |
|
141 |
* Create a solr home directory |
|
142 |
*/ |
|
143 |
private void createSolrHome() throws IOException { |
|
144 |
File solrHomeTestDir = new File(SOLRTESTHOMEPATH); |
|
145 |
solrHomeTestDir.mkdir(); |
|
146 |
File solrData = new File(SOLRTESTHOMEPATH+"/data"); |
|
147 |
solrData.mkdir(); |
|
148 |
File solr_home_source_dir = new File("src/main/resources/"+SOLRHOME); |
|
149 |
FileUtils.copyDirectory(solr_home_source_dir, solrHomeTestDir); |
|
150 |
} |
|
151 | 149 |
} |
152 | 150 |
|
Also available in: Unified diff
simplify testing with embedded solr server locations -- no need to copy solr-home or set system properties. Still more to do (factory method) but this is getting cleaner.