net.officefloor.plugin.socket.server.http.server
Class MockHttpServer

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by net.officefloor.frame.test.OfficeFrameTestCase
              extended by net.officefloor.frame.test.AbstractOfficeConstructTestCase
                  extended by net.officefloor.plugin.socket.server.http.server.MockHttpServer
All Implemented Interfaces:
junit.framework.Test, EscalationHandler, HttpServicerBuilder

public abstract class MockHttpServer
extends AbstractOfficeConstructTestCase
implements HttpServicerBuilder

Provides functionality to run a HTTP server for testing.

This should NEVER be used for Production as its focus is only to simplify writing tests for HTTP server functionality.

Author:
Daniel Sagenschneider

Nested Class Summary
static class MockHttpServer.TestSslEngineConfigurator
          SslEngineConfigurator to setup MockHttpServer to work with TestProtocolSocketFactory.
 
Nested classes/interfaces inherited from class net.officefloor.frame.test.OfficeFrameTestCase
OfficeFrameTestCase.FailOperation, OfficeFrameTestCase.StressTest
 
Constructor Summary
MockHttpServer()
           
 
Method Summary
 HttpServicerTask buildServicer(String managedObjectName, MockHttpServer server)
          Builds the ServerHttpConnection servicer Task.
 org.apache.http.client.HttpClient createHttpClient()
          Creates a HttpClient to connect to this MockHttpServer.
static int getAvailablePort()
          Obtains the next port number for testing.
static String getEntityBody(org.apache.http.HttpResponse response)
          Obtains the HttpEntity content.
static String getEntityBody(org.apache.http.HttpResponse response, Charset charset)
          Obtains the HttpEntity content.
 InetSocketAddress getLocalAddress()
          Obtains the local InetSocketAddress for this server.
 String getServerUrl()
          Obtains the URL of the server.
 boolean isServerSecure()
          Flags if MockHttpServer is running with secure connections.
protected  void setUp()
           
 void setupSecure()
          Flags to setup the MockHttpServer with secure connections.
 void shutdown()
          Shuts down this MockHttpServer.
 void startup(HttpServicerBuilder servicerBuilder)
          Starts up this MockHttpServer.
protected  void tearDown()
           
 
Methods inherited from class net.officefloor.frame.test.AbstractOfficeConstructTestCase
constructAdministrator, constructAdministrator, constructManagedObject, constructManagedObject, constructManagedObject, constructManagedObject, constructManagedObject, constructOfficeFloor, constructTask, constructTask, constructTask, constructTeam, constructTeam, constructWork, constructWork, constructWork, getOfficeBuilder, getOfficeFloorBuilder, getOfficeFloorName, getOfficeName, handleEscalation, invokeWork, invokeWork, recordReflectiveTaskMethodInvoked, setRecordReflectiveTaskMethodsInvoked, validateNoTopLevelEscalation, validateReflectiveMethodOrder
 
Methods inherited from class net.officefloor.frame.test.OfficeFrameTestCase
assertContents, assertContents, assertFail, assertFail, assertFail, assertGraph, assertGraph, assertList, assertList, assertList, assertList, assertList, assertProperties, assertTextEquals, assertXmlEquals, clearDirectory, control, copyDirectory, createFile, createMock, createPlatformIndependentText, createSynchronizedMock, deleteDirectory, displayGraph, displayGraph, fail, findFile, findFile, findInputStream, getDisplayRunTime, getFileContents, getFileLocation, getItem, getPackageRelativePath, getProperty, printHeapMemoryDiagnostics, printMessage, printMessage, printMessage, recordReturn, recordReturn, registerMockObject, removeXmlWhiteSpacing, replayMockObjects, runBare, setVerbose, sleep, throwException, timeout, timeout, verifyMockObjects
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MockHttpServer

public MockHttpServer()
Method Detail

getAvailablePort

public static int getAvailablePort()
Obtains the next port number for testing.

Returns:
Next port number for testing.

getEntityBody

public static String getEntityBody(org.apache.http.HttpResponse response)
                            throws IOException
Obtains the HttpEntity content.

Parameters:
response - HttpResponse.
Returns:
Content of HttpEntity.
Throws:
IOException - If fails to obtain content.

getEntityBody

public static String getEntityBody(org.apache.http.HttpResponse response,
                                   Charset charset)
                            throws IOException
Obtains the HttpEntity content.

Parameters:
response - HttpResponse.
charset - Charset.
Returns:
Content of HttpEntity.
Throws:
IOException - If fails to obtain content.

setupSecure

public void setupSecure()
Flags to setup the MockHttpServer with secure connections.


startup

public void startup(HttpServicerBuilder servicerBuilder)
             throws Exception
Starts up this MockHttpServer.

Throws:
Exception

isServerSecure

public boolean isServerSecure()
Flags if MockHttpServer is running with secure connections.

Returns:
true if secure connections.

getServerUrl

public String getServerUrl()
Obtains the URL of the server.

Returns:
URL of the server.

createHttpClient

public org.apache.http.client.HttpClient createHttpClient()
Creates a HttpClient to connect to this MockHttpServer.

Returns:
HttpClient to connect to this MockHttpServer.

getLocalAddress

public InetSocketAddress getLocalAddress()
Obtains the local InetSocketAddress for this server.

Returns:
Local InetSocketAddress for this server.

shutdown

public void shutdown()
              throws Exception
Shuts down this MockHttpServer.

Throws:
Exception

setUp

protected void setUp()
              throws Exception
Overrides:
setUp in class AbstractOfficeConstructTestCase
Throws:
Exception

tearDown

protected void tearDown()
                 throws Exception
Overrides:
tearDown in class AbstractOfficeConstructTestCase
Throws:
Exception

buildServicer

public HttpServicerTask buildServicer(String managedObjectName,
                                      MockHttpServer server)
                               throws Exception
Description copied from interface: HttpServicerBuilder
Builds the ServerHttpConnection servicer Task.

Specified by:
buildServicer in interface HttpServicerBuilder
Parameters:
managedObjectName - Name that the ManagedObject for the ServerHttpConnection is registered under.
server - MockHttpServer to construct the servicer Task instances.
Returns:
HttpServicerTask to link the ManagedObjectSource to service the ServerHttpConnection.
Throws:
Exception - If fails to build the servicer Task.


Copyright © 2005-2011. All Rights Reserved.