View Javadoc

1   /*
2    * $Id: AbstractMockHttpServerTestCase.java 22488 2011-07-21 09:23:32Z justin.calleja $
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 static org.junit.Assert.assertTrue;
14  
15  import java.util.concurrent.CountDownLatch;
16  import java.util.concurrent.TimeUnit;
17  
18  import org.mule.tck.AbstractServiceAndFlowTestCase;
19  
20  public abstract class AbstractMockHttpServerTestCase extends AbstractServiceAndFlowTestCase
21  {
22  
23      private static final long MOCK_HTTP_SERVER_STARTUP_TIMEOUT = 30000;
24      private CountDownLatch serverStartLatch = new CountDownLatch(1);
25  
26      public AbstractMockHttpServerTestCase(ConfigVariant variant, String configResources)
27      {
28          super(variant, configResources);
29      }
30  
31      @Override
32      protected void doSetUp() throws Exception
33      {
34          super.doSetUp();
35  
36          MockHttpServer httpServer = getHttpServer(serverStartLatch);
37          new Thread(httpServer).start();
38  
39          // wait for the simple server thread to come up
40          assertTrue("MockHttpServer start failed",
41              serverStartLatch.await(MOCK_HTTP_SERVER_STARTUP_TIMEOUT, TimeUnit.MILLISECONDS));
42      }
43  
44      /**
45       * Subclasses must implement this method to return their Subclass of
46       * {@link MockHttpServer}.
47       */
48      protected abstract MockHttpServer getHttpServer(CountDownLatch latch);
49  }