001package org.apache.maven.wagon.providers.http;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.wagon.Wagon;
023import org.codehaus.plexus.PlexusTestCase;
024import org.eclipse.jetty.server.Server;
025import org.eclipse.jetty.server.ServerConnector;
026import org.eclipse.jetty.server.handler.ResourceHandler;
027import org.eclipse.jetty.servlet.ServletContextHandler;
028
029/**
030 * User: jdumay Date: 24/01/2008 Time: 18:15:53
031 */
032public abstract class HttpWagonHttpServerTestCase
033    extends PlexusTestCase
034{
035    private Server server;
036
037    protected ResourceHandler resourceHandler;
038
039    protected ServletContextHandler context;
040
041    protected void setUp()
042        throws Exception
043    {
044        super.setUp();
045        server = new Server( 0 );
046
047        context = new ServletContextHandler( ServletContextHandler.SESSIONS );
048        resourceHandler = new ResourceHandler();
049        context.setHandler( resourceHandler );
050        server.setHandler( context );
051    }
052
053    protected Wagon getWagon()
054        throws Exception
055    {
056        return (Wagon) lookup( HttpWagon.ROLE );
057    }
058
059    protected void startServer()
060        throws Exception
061    {
062        server.start();
063    }
064
065    protected void stopServer()
066        throws Exception
067    {
068        server.stop();
069    }
070    
071    protected final int getPort()
072    {
073        return ((ServerConnector) server.getConnectors()[0]).getLocalPort();
074    }
075    
076}