Source Code Cross Referenced for SolrRequestParserTest.java in  » Search-Engine » apache-solr-1.2.0 » org » apache » solr » servlet » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Search Engine » apache solr 1.2.0 » org.apache.solr.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */package org.apache.solr.servlet;
017:
018:        import static org.easymock.EasyMock.createMock;
019:        import static org.easymock.EasyMock.expect;
020:        import static org.easymock.EasyMock.replay;
021:
022:        import java.net.URL;
023:        import java.util.ArrayList;
024:        import java.util.Collections;
025:        import java.util.HashMap;
026:        import java.util.List;
027:        import java.util.Map;
028:
029:        import javax.servlet.http.HttpServletRequest;
030:
031:        import org.apache.commons.io.IOUtils;
032:        import org.apache.solr.core.SolrConfig;
033:        import org.apache.solr.core.SolrCore;
034:        import org.apache.solr.request.MultiMapSolrParams;
035:        import org.apache.solr.request.SolrParams;
036:        import org.apache.solr.util.AbstractSolrTestCase;
037:        import org.apache.solr.util.ContentStream;
038:
039:        public class SolrRequestParserTest extends AbstractSolrTestCase {
040:
041:            public String getSchemaFile() {
042:                return "schema.xml";
043:            }
044:
045:            public String getSolrConfigFile() {
046:                return "solrconfig.xml";
047:            }
048:
049:            SolrRequestParsers parser;
050:
051:            public void setUp() throws Exception {
052:                super .setUp();
053:                parser = new SolrRequestParsers(SolrCore.getSolrCore(),
054:                        SolrConfig.config);
055:            }
056:
057:            public void testStreamBody() throws Exception {
058:                String body1 = "AMANAPLANPANAMA";
059:                String body2 = "qwertasdfgzxcvb";
060:                String body3 = "1234567890";
061:
062:                Map<String, String[]> args = new HashMap<String, String[]>();
063:                args.put(SolrParams.STREAM_BODY, new String[] { body1 });
064:
065:                // Make sure it got a single stream in and out ok
066:                List<ContentStream> streams = new ArrayList<ContentStream>();
067:                parser.buildRequestFrom(new MultiMapSolrParams(args), streams);
068:                assertEquals(1, streams.size());
069:                assertEquals(body1, IOUtils
070:                        .toString(streams.get(0).getStream()));
071:
072:                // Now add three and make sure they come out ok
073:                streams = new ArrayList<ContentStream>();
074:                args.put(SolrParams.STREAM_BODY, new String[] { body1, body2,
075:                        body3 });
076:                parser.buildRequestFrom(new MultiMapSolrParams(args), streams);
077:                assertEquals(3, streams.size());
078:                ArrayList<String> input = new ArrayList<String>();
079:                ArrayList<String> output = new ArrayList<String>();
080:                input.add(body1);
081:                input.add(body2);
082:                input.add(body3);
083:                output.add(IOUtils.toString(streams.get(0).getStream()));
084:                output.add(IOUtils.toString(streams.get(1).getStream()));
085:                output.add(IOUtils.toString(streams.get(2).getStream()));
086:                // sort them so the output is consistent
087:                Collections.sort(input);
088:                Collections.sort(output);
089:                assertEquals(input.toString(), output.toString());
090:
091:                // set the contentType and make sure tat gets set
092:                String ctype = "text/xxx";
093:                streams = new ArrayList<ContentStream>();
094:                args.put(SolrParams.STREAM_CONTENTTYPE, new String[] { ctype });
095:                parser.buildRequestFrom(new MultiMapSolrParams(args), streams);
096:                for (ContentStream s : streams) {
097:                    assertEquals(ctype, s.getContentType());
098:                }
099:            }
100:
101:            public void testStreamURL() throws Exception {
102:                boolean ok = false;
103:                String url = "http://svn.apache.org/repos/asf/lucene/solr/trunk/";
104:                String txt = null;
105:                try {
106:                    txt = IOUtils.toString(new URL(url).openStream());
107:                } catch (Exception ex) {
108:                    // TODO - should it fail/skip?
109:                    fail("this test only works if you have a network connection.");
110:                    return;
111:                }
112:
113:                Map<String, String[]> args = new HashMap<String, String[]>();
114:                args.put(SolrParams.STREAM_URL, new String[] { url });
115:
116:                // Make sure it got a single stream in and out ok
117:                List<ContentStream> streams = new ArrayList<ContentStream>();
118:                parser.buildRequestFrom(new MultiMapSolrParams(args), streams);
119:                assertEquals(1, streams.size());
120:                assertEquals(txt, IOUtils.toString(streams.get(0).getStream()));
121:            }
122:
123:            public void testUrlParamParsing() {
124:                String[][] teststr = new String[][] {
125:                        { "this is simple", "this%20is%20simple" },
126:                        { "this is simple", "this+is+simple" },
127:                        { "\u00FC", "%C3%BC" }, // lower-case "u" with diaeresis/umlaut
128:                        { "\u0026", "%26" }, // &
129:                        { "\u20AC", "%E2%82%AC" } // euro
130:                };
131:
132:                for (String[] tst : teststr) {
133:                    MultiMapSolrParams params = SolrRequestParsers
134:                            .parseQueryString("val=" + tst[1]);
135:                    assertEquals(tst[0], params.get("val"));
136:                }
137:            }
138:
139:            public void testStandardParseParamsAndFillStreams()
140:                    throws Exception {
141:                ArrayList<ContentStream> streams = new ArrayList<ContentStream>();
142:                Map<String, String[]> params = new HashMap<String, String[]>();
143:                params.put("q", new String[] { "hello" });
144:
145:                // Set up the expected behavior
146:                String[] ct = new String[] {
147:                        "application/x-www-form-urlencoded",
148:                        "Application/x-www-form-urlencoded",
149:                        "application/x-www-form-urlencoded; charset=utf-8",
150:                        "application/x-www-form-urlencoded;" };
151:
152:                for (String contentType : ct) {
153:                    HttpServletRequest request = createMock(HttpServletRequest.class);
154:                    expect(request.getMethod()).andReturn("POST").anyTimes();
155:                    expect(request.getContentType()).andReturn(contentType)
156:                            .anyTimes();
157:                    expect(request.getParameterMap()).andReturn(params)
158:                            .anyTimes();
159:                    replay(request);
160:
161:                    MultipartRequestParser multipart = new MultipartRequestParser(
162:                            1000000);
163:                    RawRequestParser raw = new RawRequestParser();
164:                    StandardRequestParser standard = new StandardRequestParser(
165:                            multipart, raw);
166:
167:                    SolrParams p = standard.parseParamsAndFillStreams(request,
168:                            streams);
169:
170:                    assertEquals("contentType: " + contentType, "hello", p
171:                            .get("q"));
172:                }
173:            }
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.