2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
package org.apache.solr.client.solrj.embedded;
22
import java.util.Random;
24
import org.apache.lucene.util.LuceneTestCase;
26
import org.apache.commons.io.IOUtils;
27
import org.apache.solr.SolrTestCaseJ4;
28
import org.apache.solr.util.ExternalPaths;
29
import org.mortbay.jetty.Connector;
30
import org.mortbay.jetty.Server;
31
import org.mortbay.jetty.bio.SocketConnector;
32
import org.mortbay.jetty.servlet.HashSessionIdManager;
33
import org.mortbay.jetty.webapp.WebAppContext;
36
* @version $Id: JettyWebappTest.java 1189490 2011-10-26 21:39:54Z sarowe $
39
public class JettyWebappTest extends LuceneTestCase
42
static final String context = "/test";
47
public void setUp() throws Exception
50
System.setProperty("solr.solr.home", ExternalPaths.EXAMPLE_HOME);
52
File dataDir = new File(SolrTestCaseJ4.TEMP_DIR,
53
getClass().getName() + "-" + System.currentTimeMillis());
55
System.setProperty("solr.data.dir", dataDir.getCanonicalPath());
56
String path = ExternalPaths.WEBAPP_HOME;
58
// disable VelocityResponseWriter from example configuration
59
System.setProperty("solr.velocity.enabled", "false");
61
server = new Server(port);
62
// insecure: only use for tests!!!!
63
server.setSessionIdManager(new HashSessionIdManager(new Random(random.nextLong())));
64
new WebAppContext(server, path, context );
66
SocketConnector connector = new SocketConnector();
67
connector.setMaxIdleTime(1000 * 60 * 60);
68
connector.setSoLingerTime(-1);
70
server.setConnectors(new Connector[]{connector});
71
server.setStopAtShutdown( true );
74
port = connector.getLocalPort();
78
public void tearDown() throws Exception
82
} catch( Exception ex ) {}
83
SolrTestCaseJ4.closeDirectories();
87
public void testJSP() throws Exception
89
// Currently not an extensive test, but it does fire up the JSP pages and make
90
// sure they compile ok
92
String adminPath = "http://localhost:"+port+context+"/";
93
byte[] bytes = IOUtils.toByteArray( new URL(adminPath).openStream() );
94
assertNotNull( bytes ); // real error will be an exception
96
adminPath += "admin/";
97
bytes = IOUtils.toByteArray( new URL(adminPath).openStream() );
98
assertNotNull( bytes ); // real error will be an exception
101
bytes = IOUtils.toByteArray( new URL(adminPath+"analysis.jsp").openStream() );
102
assertNotNull( bytes ); // real error will be an exception
105
bytes = IOUtils.toByteArray( new URL(adminPath+"schema.jsp").openStream() );
106
assertNotNull( bytes ); // real error will be an exception
109
bytes = IOUtils.toByteArray( new URL(adminPath+"threaddump.jsp").openStream() );
110
assertNotNull( bytes ); // real error will be an exception