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