Project

General

Profile

« Previous | Next » 

Revision 8123

Added by Jing Tao over 11 years ago

Add a junit test class.

View differences:

metacat-common/src/test/java/edu/ucsb/nceas/metacat/common/query/SolrQueryResponseTransformerTest.java
1
package edu.ucsb.nceas.metacat.common.query;
2

  
3
import static org.junit.Assert.assertTrue;
4

  
5
import java.io.InputStream;
6

  
7
import org.apache.solr.client.solrj.SolrServer;
8
import org.apache.solr.client.solrj.response.QueryResponse;
9
import org.apache.solr.common.params.SolrParams;
10
import org.apache.solr.core.CoreContainer;
11
import org.apache.solr.servlet.SolrRequestParsers;
12
import org.junit.Test;
13

  
14
import edu.ucsb.nceas.metacat.common.MetacatCommonTestBase;
15
import edu.ucsb.nceas.metacat.common.SolrServerFactory;
16

  
17
public class SolrQueryResponseTransformerTest extends MetacatCommonTestBase {
18
    
19
    /**
20
     * Test the transformResults method
21
     */
22
    @Test
23
    public void testTransformResults() throws Exception {
24
        
25
        SolrServer solrServer = SolrServerFactory.createSolrServer();
26
        CoreContainer coreContainer = SolrServerFactory.getCoreContainer();
27
        String collectionName = SolrServerFactory.getCollectionName();
28
        SolrQueryResponseTransformer solrTransformer = new SolrQueryResponseTransformer(coreContainer.getCore(collectionName));
29
        InputStream inputStream = null;
30
        String wt = "xml";
31
        String queryStr = "q=*:*";
32
        SolrParams query = SolrRequestParsers.parseQueryString(queryStr);
33
        QueryResponse response = solrServer.query(query);
34
        inputStream = solrTransformer.transformResults(query, response, wt);
35
        assertTrue(inputStream != null);
36
    }
37
}

Also available in: Unified diff