Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[maven-release-plugin] copy for tag jetty-7.0.0.RC6
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/tags/jetty-7.0.0.RC6@944 7e9141cc-0065-0410-87d8-b60c137991c4
- Loading branch information
Showing
5 changed files
with
117 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/StatisticsServletTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// ======================================================================== | ||
// Copyright (c) 2009 Mort Bay Consulting Pty. Ltd. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
package org.eclipse.jetty.servlet; | ||
|
||
import org.eclipse.jetty.server.Handler; | ||
import org.eclipse.jetty.server.LocalConnector; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.server.handler.StatisticsHandler; | ||
|
||
import junit.framework.AssertionFailedError; | ||
import junit.framework.TestCase; | ||
|
||
public class StatisticsServletTest extends TestCase | ||
{ | ||
Server server; | ||
LocalConnector connector; | ||
ServletContextHandler context; | ||
|
||
protected void setUp() throws Exception | ||
{ | ||
super.setUp(); | ||
|
||
server = new Server(); | ||
server.setSendServerVersion(false); | ||
context = new ServletContextHandler(); | ||
context.setContextPath("/"); | ||
ServletHolder holder = new ServletHolder(); | ||
holder.setServlet(new org.eclipse.jetty.servlet.StatisticsServlet()); | ||
holder.setInitParameter("restrictToLocalhost", "false"); | ||
context.addServlet(holder, "/stats"); | ||
|
||
server.setHandler(context); | ||
connector = new LocalConnector(); | ||
server.addConnector(connector); | ||
} | ||
|
||
protected void tearDown() throws Exception | ||
{ | ||
super.tearDown(); | ||
|
||
if (server != null) | ||
{ | ||
server.stop(); | ||
} | ||
} | ||
|
||
|
||
public void testNoHandler () throws Exception | ||
{ | ||
server.start(); | ||
|
||
StringBuffer req1 = new StringBuffer(); | ||
req1.append("GET /stats HTTP/1.1\n"); | ||
req1.append("Host: localhost\n"); | ||
req1.append("\n"); | ||
|
||
String response = connector.getResponses(req1.toString()); | ||
assertResponseContains("503", response); | ||
} | ||
|
||
public void testWithHandler () throws Exception | ||
{ | ||
StatisticsHandler statsHandler = new StatisticsHandler(); | ||
statsHandler.setHandler(context); | ||
server.setHandler(statsHandler); | ||
server.start(); | ||
|
||
StringBuffer req1 = new StringBuffer(); | ||
req1.append("GET /stats HTTP/1.1\n"); | ||
req1.append("Host: localhost\n"); | ||
req1.append("\n"); | ||
|
||
String response = connector.getResponses(req1.toString()); | ||
assertResponseContains("Statistics gathering started ", response); | ||
} | ||
|
||
|
||
private void assertResponseContains(String expected, String response) | ||
{ | ||
int idx = response.indexOf(expected); | ||
if (idx == (-1)) | ||
{ | ||
// Not found | ||
StringBuffer err = new StringBuffer(); | ||
err.append("Response does not contain expected string \"").append(expected).append("\""); | ||
err.append("\n").append(response); | ||
|
||
System.err.println(err); | ||
throw new AssertionFailedError(err.toString()); | ||
} | ||
} | ||
} |