View Javadoc

1   /*
2    * $Id: RestServiceComponentDeleteTestCase.java 19840 2010-10-05 18:32:45Z 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.components;
12  
13  import org.mule.module.client.MuleClient;
14  import org.mule.transport.http.HttpConstants;
15  import org.mule.transport.http.functional.AbstractMockHttpServerTestCase;
16  import org.mule.transport.http.functional.MockHttpServer;
17  
18  import java.io.BufferedReader;
19  import java.util.StringTokenizer;
20  
21  import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
22  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
23  
24  public class RestServiceComponentDeleteTestCase extends AbstractMockHttpServerTestCase
25  {
26      //private static final int LISTEN_PORT = 60205;
27      
28      private CountDownLatch serverRequestCompleteLatch = new CountDownLatch(1);
29      private boolean deleteRequestFound = false;
30      
31      @Override
32      protected String getConfigResources()
33      {
34          return "rest-service-component-delete-test.xml";
35      }
36      
37      protected MockHttpServer getHttpServer(CountDownLatch serverStartLatch)
38      {
39          return new SimpleHttpServer(getPorts().get(0), serverStartLatch, serverRequestCompleteLatch);
40      }
41  
42      public void testRestServiceComponentDelete() throws Exception
43      {
44          MuleClient client = new MuleClient(muleContext);
45          client.send("vm://fromTest", TEST_MESSAGE, null);
46          
47          assertTrue(serverRequestCompleteLatch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));
48          assertTrue(deleteRequestFound);
49      }
50      
51      private class SimpleHttpServer extends MockHttpServer
52      {
53          public SimpleHttpServer(int listenPort, CountDownLatch startupLatch, CountDownLatch testCompleteLatch)
54          {
55              super(listenPort, startupLatch, testCompleteLatch);
56          }
57  
58          @Override
59          protected void readHttpRequest(BufferedReader reader) throws Exception
60          {
61              String requestLine = reader.readLine();
62              String httpMethod = new StringTokenizer(requestLine).nextToken();
63              
64              deleteRequestFound = httpMethod.equals(HttpConstants.METHOD_DELETE);
65          }
66      }
67  
68      @Override
69      protected int getNumPortsToFind()
70      {
71          return 1;
72      }
73  }