01: // ========================================================================
02: // Copyright 2006 Mort Bay Consulting Pty. Ltd.
03: // ------------------------------------------------------------------------
04: // Licensed under the Apache License, Version 2.0 (the "License");
05: // you may not use this file except in compliance with the License.
06: // You may obtain a copy of the License at
07: // http://www.apache.org/licenses/LICENSE-2.0
08: // Unless required by applicable law or agreed to in writing, software
09: // distributed under the License is distributed on an "AS IS" BASIS,
10: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11: // See the License for the specific language governing permissions and
12: // limitations under the License.
13: // ========================================================================
14:
15: package org.mortbay.jetty;
16:
17: import java.io.IOException;
18: import java.io.PrintWriter;
19: import java.net.URL;
20: import java.util.Random;
21:
22: import javax.servlet.ServletException;
23: import javax.servlet.http.HttpServlet;
24: import javax.servlet.http.HttpServletRequest;
25: import javax.servlet.http.HttpServletResponse;
26:
27: import junit.framework.TestCase;
28:
29: import org.mortbay.jetty.handler.ContextHandler;
30: import org.mortbay.jetty.handler.DefaultHandler;
31: import org.mortbay.jetty.nio.SelectChannelConnector;
32: import org.mortbay.jetty.servlet.ServletHandler;
33: import org.mortbay.jetty.servlet.ServletHolder;
34: import org.mortbay.jetty.servlet.ServletMapping;
35: import org.mortbay.util.IO;
36:
37: /**
38: * @version $Revision$
39: */
40: public class ServerTest extends TestCase {
41: /**
42: * JETTY-87, adding a handler to a server without any handlers should not
43: * throw an exception
44: */
45: public void testAddHandlerToEmptyServer() {
46: Server server = new Server();
47: DefaultHandler handler = new DefaultHandler();
48: try {
49: server.addHandler(handler);
50: } catch (Exception e) {
51: fail("Adding handler " + handler + " to server " + server
52: + " threw exception " + e);
53: }
54: }
55:
56: public void testServerWithPort() {
57: int port = new Random().nextInt(20000) + 10000;
58: Server server = new Server(port);
59: assertEquals(port, server.getConnectors()[0].getPort());
60: }
61: }
|