Project

General

Profile

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.net.MalformedURLException;
8
import java.util.List;
9
import java.util.Map;
10

    
11
import javax.xml.parsers.ParserConfigurationException;
12

    
13
import org.apache.solr.common.params.SolrParams;
14
import org.apache.solr.schema.SchemaField;
15
import org.apache.solr.servlet.SolrRequestParsers;
16
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
        assertTrue(version != null);
34
        assertTrue(!version.equals(""));
35
    }
36
    
37
    
38
    /**
39
     * Test get get valid schema fields.
40
     * @throws SAXException 
41
     * @throws IOException 
42
     * @throws ParserConfigurationException 
43
     * @throws NotFound 
44
     * @throws UnsupportedType 
45
     */
46
    @Test
47
    public void testGetValidSchemaFields() throws Exception {
48
       List<String> fields = SolrQueryServiceController.getInstance().getValidSchemaFields();
49
       assertTrue(fields != null);
50
       assertTrue(!fields.isEmpty());
51
    }
52
    
53
    /**
54
     * Test get get valid schema fields.
55
     * @throws SAXException 
56
     * @throws IOException 
57
     * @throws ParserConfigurationException 
58
     * @throws NotFound 
59
     * @throws UnsupportedType 
60
     */
61
    @Test
62
    public void testgetIndexSchemaFields() throws Exception {
63
       Map<String, SchemaField> fields = SolrQueryServiceController.getInstance().getIndexSchemaFields();
64
       assertTrue(fields != null);
65
       assertTrue(!fields.isEmpty());
66
    }
67
    
68
    /**
69
     * Test the query method
70
     */
71
    @Test
72
    public void testQuery() throws Exception {
73
        String query = "q=*:*";
74
        SolrParams solrParams = SolrRequestParsers.parseQueryString(query);
75
        InputStream input = SolrQueryServiceController.getInstance().query(solrParams, null);
76
        assertTrue(input != null);
77
    }
78
}
(2-2/2)