Project

General

Profile

« Previous | Next » 

Revision 8122

Added by Jing Tao over 11 years ago

Add a junit test.

View differences:

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

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

  
5

  
6
import org.apache.solr.response.JSONResponseWriter;
7

  
8
import org.apache.solr.response.QueryResponseWriter;
9

  
10
import org.apache.solr.response.XMLResponseWriter;
11
import org.junit.Test;
12

  
13
import edu.ucsb.nceas.metacat.common.MetacatCommonTestBase;
14

  
15
public class SolrQueryResponseWriterFactoryTest extends MetacatCommonTestBase {
16
    
17
    /**
18
     * Test the generate method
19
     * @throws Exception
20
     */
21
    @Test
22
    public void testGenerateResponseWriter() throws Exception {
23
        QueryResponseWriter writer = SolrQueryResponseWriterFactory.generateResponseWriter(null);
24
        assertTrue(writer instanceof XMLResponseWriter);
25
        writer = SolrQueryResponseWriterFactory.generateResponseWriter(SolrQueryResponseWriterFactory.XML);
26
        assertTrue(writer instanceof XMLResponseWriter);
27
        
28
        writer = SolrQueryResponseWriterFactory.generateResponseWriter(SolrQueryResponseWriterFactory.JSON);
29
        assertTrue(writer instanceof JSONResponseWriter);
30
        
31
        try {
32
            writer = SolrQueryResponseWriterFactory.generateResponseWriter("other");
33
            assertTrue("There is not wirter for name - other", false);
34
        } catch (Exception e ) {
35
            assertTrue("There is not wirter for name - other", true);
36
        }
37
    }
38
    /**
39
     * Test the get content type method
40
     */
41
    @Test
42
    public void testGetContentType() throws Exception {
43
        String contentType = SolrQueryResponseWriterFactory.getContentType(SolrQueryResponseWriterFactory.XML);
44
        assertTrue(contentType.equals("text/xml"));
45
        contentType = SolrQueryResponseWriterFactory.getContentType(SolrQueryResponseWriterFactory.JSON);
46
        assertTrue(contentType.equals("text/json"));
47
        contentType = SolrQueryResponseWriterFactory.getContentType("other");
48
        assertTrue(contentType == null);
49

  
50
    }
51
}

Also available in: Unified diff