Add a ResourceHandler test, we seem to be missing even a basic one

This commit is contained in:
Jesse McConnell 2011-09-28 14:38:14 -05:00
parent 1e5b85a2cb
commit af698b0023
2 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,76 @@
package org.eclipse.jetty.server.handler;
//========================================================================
//Copyright (c) 1999-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.
//========================================================================
import java.net.URI;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.bio.SocketConnector;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.SimpleRequest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import junit.framework.Assert;
import junit.framework.TestCase;
/**
* Resource Handler test
*
* TODO: increase the testing going on here
*/
public class ResourceHandlerTest extends TestCase
{
private static Server _server;
private static Connector _connector;
private static ContextHandler _contextHandler;
private static ResourceHandler _resourceHandler;
@BeforeClass
public void setUp() throws Exception
{
_server = new Server();
_connector = new SocketConnector();
_server.setConnectors(new Connector[] { _connector });
_resourceHandler = new ResourceHandler();
_contextHandler = new ContextHandler("/resource");
_contextHandler.setHandler(_resourceHandler);
_server.setHandler(_contextHandler);
_server.start();
}
/* ------------------------------------------------------------ */
@AfterClass
public void tearDown() throws Exception
{
_server.stop();
}
@Test
public void testSimpleResourceHandler() throws Exception
{
_resourceHandler.setResourceBase(MavenTestingUtils.getTestResourceDir("simple").getAbsolutePath());
SimpleRequest sr = new SimpleRequest(new URI("http://localhost:" + _connector.getLocalPort()));
Assert.assertEquals("simple text", sr.getString("/resource/simple.txt"));
Assert.assertNotNull("missing jetty.css" , sr.getString("/resource/jetty-dir.css"));
}
}

View File

@ -0,0 +1 @@
simple text