Search in sources :

Example 1 with VelocityResponseWriter

use of org.apache.solr.response.VelocityResponseWriter in project lucene-solr by apache.

the class VelocityResponseWriterTest method testFileResourceLoader.

@Test
public void testFileResourceLoader() throws Exception {
    VelocityResponseWriter vrw = new VelocityResponseWriter();
    NamedList<String> nl = new NamedList<String>();
    nl.add("template.base.dir", getFile("velocity").getAbsolutePath());
    vrw.init(nl);
    SolrQueryRequest req = req(VelocityResponseWriter.TEMPLATE, "file");
    SolrQueryResponse rsp = new SolrQueryResponse();
    StringWriter buf = new StringWriter();
    vrw.write(buf, req, rsp);
    assertEquals("testing", buf.toString());
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) VelocityResponseWriter(org.apache.solr.response.VelocityResponseWriter) StringWriter(java.io.StringWriter) NamedList(org.apache.solr.common.util.NamedList) Test(org.junit.Test)

Example 2 with VelocityResponseWriter

use of org.apache.solr.response.VelocityResponseWriter in project lucene-solr by apache.

the class VelocityResponseWriterTest method testVelocityResponseWriterRegistered.

@Test
public void testVelocityResponseWriterRegistered() {
    QueryResponseWriter writer = h.getCore().getQueryResponseWriter("velocity");
    assertTrue("VrW registered check", writer instanceof VelocityResponseWriter);
}
Also used : VelocityResponseWriter(org.apache.solr.response.VelocityResponseWriter) QueryResponseWriter(org.apache.solr.response.QueryResponseWriter) Test(org.junit.Test)

Example 3 with VelocityResponseWriter

use of org.apache.solr.response.VelocityResponseWriter in project lucene-solr by apache.

the class VelocityResponseWriterTest method testCustomParamTemplate.

@Test
public void testCustomParamTemplate() throws Exception {
    org.apache.solr.response.VelocityResponseWriter vrw = new VelocityResponseWriter();
    NamedList<String> nl = new NamedList<String>();
    nl.add(VelocityResponseWriter.PARAMS_RESOURCE_LOADER_ENABLED, "true");
    vrw.init(nl);
    SolrQueryRequest req = req(VelocityResponseWriter.TEMPLATE, "custom", SolrParamResourceLoader.TEMPLATE_PARAM_PREFIX + "custom", "$response.response.response_data");
    SolrQueryResponse rsp = new SolrQueryResponse();
    StringWriter buf = new StringWriter();
    rsp.add("response_data", "testing");
    vrw.write(buf, req, rsp);
    assertEquals("testing", buf.toString());
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) VelocityResponseWriter(org.apache.solr.response.VelocityResponseWriter) StringWriter(java.io.StringWriter) NamedList(org.apache.solr.common.util.NamedList) VelocityResponseWriter(org.apache.solr.response.VelocityResponseWriter) Test(org.junit.Test)

Example 4 with VelocityResponseWriter

use of org.apache.solr.response.VelocityResponseWriter in project lucene-solr by apache.

the class VelocityResponseWriterTest method testContentType.

@Test
public void testContentType() throws Exception {
    VelocityResponseWriter vrw = new VelocityResponseWriter();
    NamedList<String> nl = new NamedList<String>();
    vrw.init(nl);
    SolrQueryResponse rsp = new SolrQueryResponse();
    // with v.json=wrf, content type should default to application/json
    assertEquals("application/json;charset=UTF-8", vrw.getContentType(req(VelocityResponseWriter.TEMPLATE, "numFound", VelocityResponseWriter.JSON, "wrf"), rsp));
    // with no v.json specified, the default text/html should be returned
    assertEquals("text/html;charset=UTF-8", vrw.getContentType(req(VelocityResponseWriter.TEMPLATE, "numFound"), rsp));
    // if v.contentType is specified, that should be used, even if v.json is specified
    assertEquals("text/plain", vrw.getContentType(req(VelocityResponseWriter.TEMPLATE, "numFound", VelocityResponseWriter.CONTENT_TYPE, "text/plain"), rsp));
    assertEquals("text/plain", vrw.getContentType(req(VelocityResponseWriter.TEMPLATE, "numFound", VelocityResponseWriter.JSON, "wrf", VelocityResponseWriter.CONTENT_TYPE, "text/plain"), rsp));
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) VelocityResponseWriter(org.apache.solr.response.VelocityResponseWriter) NamedList(org.apache.solr.common.util.NamedList) Test(org.junit.Test)

Example 5 with VelocityResponseWriter

use of org.apache.solr.response.VelocityResponseWriter in project lucene-solr by apache.

the class VelocityResponseWriterTest method testParamResourceLoaderDisabled.

@Test
public void testParamResourceLoaderDisabled() throws Exception {
    VelocityResponseWriter vrw = new VelocityResponseWriter();
    // by default param resource loader is disabled, no need to set it here
    SolrQueryRequest req = req(VelocityResponseWriter.TEMPLATE, "custom", SolrParamResourceLoader.TEMPLATE_PARAM_PREFIX + "custom", "$response.response.response_data");
    SolrQueryResponse rsp = new SolrQueryResponse();
    StringWriter buf = new StringWriter();
    try {
        vrw.write(buf, req, rsp);
        fail("Should have thrown exception due to missing template");
    } catch (IOException e) {
    // expected exception
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) VelocityResponseWriter(org.apache.solr.response.VelocityResponseWriter) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

VelocityResponseWriter (org.apache.solr.response.VelocityResponseWriter)5 Test (org.junit.Test)5 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)4 StringWriter (java.io.StringWriter)3 NamedList (org.apache.solr.common.util.NamedList)3 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)3 IOException (java.io.IOException)1 QueryResponseWriter (org.apache.solr.response.QueryResponseWriter)1