01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.solr.servlet;
17:
18: import org.apache.solr.request.SolrParams;
19: import org.apache.solr.util.AbstractSolrTestCase;
20:
21: public class DirectSolrConnectionTest extends AbstractSolrTestCase {
22: public String getSchemaFile() {
23: return "solr/crazy-path-to-schema.xml";
24: }
25:
26: public String getSolrConfigFile() {
27: return "solr/crazy-path-to-config.xml";
28: }
29:
30: DirectSolrConnection direct;
31:
32: @Override
33: public void setUp() throws Exception {
34: super .setUp();
35: direct = new DirectSolrConnection();
36: }
37:
38: // Check that a request gets back the echoParams call
39: public void testSimpleRequest() throws Exception {
40: String pathAndParams = "/select?wt=xml&version=2.2&echoParams=explicit&q=*:*";
41:
42: String got = direct.request(pathAndParams, null);
43:
44: assertTrue(got
45: .indexOf("<str name=\"echoParams\">explicit</str>") > 5);
46:
47: // It should throw an exception for unknown handler
48: try {
49: direct.request("/path to nonexistang thingy!!", null);
50: fail("should throw an exception");
51: } catch (Exception ex) {
52: }
53: }
54:
55: // Check that a request gets back the echoParams call
56: public void testInsertThenSelect() throws Exception {
57: String value = "Kittens!!! \u20AC";
58: String[] cmds = new String[] {
59: "<delete><id>42</id></delete>",
60: "<add><doc><field name=\"id\">42</field><field name=\"subject\">"
61: + value + "</field></doc></add>", "<commit/>" };
62: String getIt = "/select?wt=xml&q=id:42";
63:
64: // Test using the Stream body parameter
65: for (String cmd : cmds) {
66: direct.request("/update?" + SolrParams.STREAM_BODY + "="
67: + cmd, null);
68: }
69: String got = direct.request(getIt, null);
70: assertTrue(got.indexOf(value) > 0);
71:
72: // Same thing using the posted body
73: for (String cmd : cmds) {
74: direct.request("/update", cmd);
75: }
76: got = direct.request(getIt, null);
77: assertTrue(got.indexOf(value) > 0);
78: }
79: }
|