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());
}
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);
}
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());
}
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));
}
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
}
}
Aggregations