View Javadoc

1   /*
2    * $Id: AbstractMockHttpServerTestCase.java 20297 2010-11-22 18:49:18Z aperepel $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.http.functional;
12  
13  import org.mule.tck.DynamicPortTestCase;
14  
15  import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
16  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
17  
18  public abstract class AbstractMockHttpServerTestCase extends DynamicPortTestCase
19  {
20      private static final long MOCK_HTTP_SERVER_STARTUP_TIMEOUT = 30000;
21      private CountDownLatch serverStartLatch = new CountDownLatch(1);
22  
23      @Override
24      protected void doSetUp() throws Exception
25      {
26          super.doSetUp();
27  
28          MockHttpServer httpServer = getHttpServer(serverStartLatch);
29          new Thread(httpServer).start();
30  
31          // wait for the simple server thread to come up
32          assertTrue("MockHttpServer start failed", 
33              serverStartLatch.await(MOCK_HTTP_SERVER_STARTUP_TIMEOUT, TimeUnit.MILLISECONDS));
34      }
35  
36      /**
37       * Subclasses must implement this method to return their Subclass of {@link MockHttpServer}.
38       */
39      protected abstract MockHttpServer getHttpServer(CountDownLatch latch);
40  }