1
|
package edu.ucsb.nceas.metacat.common.query;
|
2
|
|
3
|
import static org.junit.Assert.assertTrue;
|
4
|
|
5
|
import java.io.IOException;
|
6
|
import java.io.InputStream;
|
7
|
import java.util.Map;
|
8
|
|
9
|
import javax.xml.parsers.ParserConfigurationException;
|
10
|
|
11
|
import org.apache.solr.common.params.SolrParams;
|
12
|
import org.apache.solr.schema.SchemaField;
|
13
|
import org.apache.solr.servlet.SolrRequestParsers;
|
14
|
import org.dataone.service.exceptions.NotFound;
|
15
|
import org.dataone.service.exceptions.UnsupportedType;
|
16
|
import org.junit.Test;
|
17
|
import org.xml.sax.SAXException;
|
18
|
|
19
|
import edu.ucsb.nceas.metacat.common.MetacatCommonTestBase;
|
20
|
|
21
|
public class SolrQueryServiceControllerTest extends MetacatCommonTestBase {
|
22
|
/**
|
23
|
* Test get the solr version
|
24
|
* @throws SAXException
|
25
|
* @throws IOException
|
26
|
* @throws ParserConfigurationException
|
27
|
* @throws NotFound
|
28
|
* @throws UnsupportedType
|
29
|
*/
|
30
|
@Test
|
31
|
public void testGetSolrSpecVersion() throws UnsupportedType, NotFound, ParserConfigurationException, IOException, SAXException {
|
32
|
String version = SolrQueryServiceController.getInstance().getSolrSpecVersion();
|
33
|
//System.out.println("version is ======================== "+version);
|
34
|
assertTrue(version != null);
|
35
|
assertTrue("The version should be 3.4.0.2011.09.09.09.06.42 rather than "+version, version.equals("3.4.0.2011.09.09.09.06.42"));
|
36
|
}
|
37
|
|
38
|
|
39
|
/**
|
40
|
* Test get get valid schema fields.
|
41
|
* @throws SAXException
|
42
|
* @throws IOException
|
43
|
* @throws ParserConfigurationException
|
44
|
* @throws NotFound
|
45
|
* @throws UnsupportedType
|
46
|
*/
|
47
|
@Test
|
48
|
public void testgetIndexSchemaFields() throws Exception {
|
49
|
Map<String, SchemaField> fields = SolrQueryServiceController.getInstance().getIndexSchemaFields();
|
50
|
assertTrue(fields != null);
|
51
|
assertTrue("The number of index schema fields should be 142 rather than "+fields.size(), fields.size() == 142);
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* Test the query method
|
56
|
*/
|
57
|
@Test
|
58
|
public void testQuery() throws Exception {
|
59
|
String query = "q=*:*";
|
60
|
SolrParams solrParams = SolrRequestParsers.parseQueryString(query);
|
61
|
InputStream input = SolrQueryServiceController.getInstance().query(solrParams, null);
|
62
|
assertTrue(input != null);
|
63
|
}
|
64
|
}
|