View Javadoc

1   /*
2    * $Id: AbstractMockHttpServerTestCase.java 19817 2010-10-04 18:10:39Z dzapata $
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  import org.mule.tck.FunctionalTestCase;
15  
16  import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
17  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
18  
19  public abstract class AbstractMockHttpServerTestCase extends DynamicPortTestCase
20  {
21      private static final long MOCK_HTTP_SERVER_STARTUP_TIMEOUT = 30000;
22      private CountDownLatch serverStartLatch = new CountDownLatch(1);
23  
24      @Override
25      protected void doSetUp() throws Exception
26      {
27          super.doSetUp();
28  
29          MockHttpServer httpServer = getHttpServer(serverStartLatch);
30          new Thread(httpServer).start();
31  
32          // wait for the simple server thread to come up
33          assertTrue("MockHttpServer start failed", 
34              serverStartLatch.await(MOCK_HTTP_SERVER_STARTUP_TIMEOUT, TimeUnit.MILLISECONDS));
35      }
36  
37      /**
38       * Subclasses must implement this method to return their Subclass of {@link MockHttpServer}.
39       */
40      protected abstract MockHttpServer getHttpServer(CountDownLatch latch);
41  }