Project

General

Profile

1 8119 tao
package edu.ucsb.nceas.metacat.common.query;
2
3
import static org.junit.Assert.assertTrue;
4
5
import java.io.IOException;
6 8120 tao
import java.io.InputStream;
7 8119 tao
import java.net.MalformedURLException;
8
import java.util.List;
9
import java.util.Map;
10
11
import javax.xml.parsers.ParserConfigurationException;
12
13 8120 tao
import org.apache.solr.common.params.SolrParams;
14 8119 tao
import org.apache.solr.schema.SchemaField;
15 8120 tao
import org.apache.solr.servlet.SolrRequestParsers;
16 8119 tao
import org.dataone.service.exceptions.NotFound;
17
import org.dataone.service.exceptions.UnsupportedType;
18
import org.junit.Test;
19
import org.xml.sax.SAXException;
20
21
public class SolrQueryServiceControllerTest {
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 8139 tao
        //System.out.println("version is ======================== "+version);
34 8119 tao
        assertTrue(version != null);
35 8139 tao
        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 8119 tao
    }
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 testGetValidSchemaFields() throws Exception {
49
       List<String> fields = SolrQueryServiceController.getInstance().getValidSchemaFields();
50
       assertTrue(fields != null);
51 8139 tao
       assertTrue("The number of valid schema fields should be 76 rather than "+fields.size(), fields.size() ==76);
52 8119 tao
    }
53
54
    /**
55
     * Test get get valid schema fields.
56
     * @throws SAXException
57
     * @throws IOException
58
     * @throws ParserConfigurationException
59
     * @throws NotFound
60
     * @throws UnsupportedType
61
     */
62
    @Test
63
    public void testgetIndexSchemaFields() throws Exception {
64
       Map<String, SchemaField> fields = SolrQueryServiceController.getInstance().getIndexSchemaFields();
65
       assertTrue(fields != null);
66 8139 tao
       assertTrue("The number of index schema fields should be 93 rather than "+fields.size(), fields.size() == 93);
67 8119 tao
    }
68 8120 tao
69
    /**
70
     * Test the query method
71
     */
72
    @Test
73
    public void testQuery() throws Exception {
74
        String query = "q=*:*";
75
        SolrParams solrParams = SolrRequestParsers.parseQueryString(query);
76
        InputStream input = SolrQueryServiceController.getInstance().query(solrParams, null);
77
        assertTrue(input != null);
78
    }
79 8119 tao
}