~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
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
8
 
 *
9
 
 *     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
 
 */
17
 
 
18
 
package org.apache.solr.client.solrj.embedded;
19
 
 
20
 
import java.io.File;
21
 
import java.net.URL;
22
 
import java.util.Random;
23
 
 
24
 
import org.apache.lucene.util.LuceneTestCase;
25
 
 
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;
34
 
 
35
 
/**
36
 
 * @version $Id: JettyWebappTest.java 1189490 2011-10-26 21:39:54Z sarowe $
37
 
 * @since solr 1.3
38
 
 */
39
 
public class JettyWebappTest extends LuceneTestCase 
40
 
{
41
 
  int port = 0;
42
 
  static final String context = "/test";
43
 
  
44
 
  Server server;
45
 
  
46
 
  @Override
47
 
  public void setUp() throws Exception 
48
 
  {
49
 
    super.setUp();
50
 
    System.setProperty("solr.solr.home", ExternalPaths.EXAMPLE_HOME);
51
 
    
52
 
    File dataDir = new File(SolrTestCaseJ4.TEMP_DIR,
53
 
        getClass().getName() + "-" + System.currentTimeMillis());
54
 
    dataDir.mkdirs();
55
 
    System.setProperty("solr.data.dir", dataDir.getCanonicalPath());
56
 
    String path = ExternalPaths.WEBAPP_HOME;
57
 
 
58
 
    // disable VelocityResponseWriter from example configuration
59
 
    System.setProperty("solr.velocity.enabled", "false");
60
 
 
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 );
65
 
 
66
 
    SocketConnector connector = new SocketConnector();
67
 
    connector.setMaxIdleTime(1000 * 60 * 60);
68
 
    connector.setSoLingerTime(-1);
69
 
    connector.setPort(0);
70
 
    server.setConnectors(new Connector[]{connector});
71
 
    server.setStopAtShutdown( true );
72
 
    
73
 
    server.start();
74
 
    port = connector.getLocalPort();
75
 
  }
76
 
 
77
 
  @Override
78
 
  public void tearDown() throws Exception 
79
 
  {
80
 
    try {
81
 
      server.stop();
82
 
    } catch( Exception ex ) {}
83
 
    SolrTestCaseJ4.closeDirectories();
84
 
    super.tearDown();
85
 
  }
86
 
  
87
 
  public void testJSP() throws Exception
88
 
  {
89
 
    // Currently not an extensive test, but it does fire up the JSP pages and make 
90
 
    // sure they compile ok
91
 
    
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
95
 
 
96
 
    adminPath += "admin/";
97
 
    bytes = IOUtils.toByteArray( new URL(adminPath).openStream() );
98
 
    assertNotNull( bytes ); // real error will be an exception
99
 
 
100
 
    // analysis
101
 
    bytes = IOUtils.toByteArray( new URL(adminPath+"analysis.jsp").openStream() );
102
 
    assertNotNull( bytes ); // real error will be an exception
103
 
 
104
 
    // schema browser
105
 
    bytes = IOUtils.toByteArray( new URL(adminPath+"schema.jsp").openStream() );
106
 
    assertNotNull( bytes ); // real error will be an exception
107
 
 
108
 
    // schema browser
109
 
    bytes = IOUtils.toByteArray( new URL(adminPath+"threaddump.jsp").openStream() );
110
 
    assertNotNull( bytes ); // real error will be an exception
111
 
  }
112
 
}