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