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.servlet.jetty.functional;
8   
9   import static org.junit.Assert.assertEquals;
10  
11  import org.mule.api.MuleEventContext;
12  import org.mule.api.MuleMessage;
13  import org.mule.tck.functional.EventCallback;
14  import org.mule.tck.functional.FunctionalTestComponent;
15  import org.mule.tck.junit4.FunctionalTestCase;
16  import org.mule.tck.junit4.rule.DynamicPort;
17  import org.mule.transport.http.HttpConstants;
18  import org.mule.transport.http.PatchMethod;
19  
20  import org.apache.commons.httpclient.HttpClient;
21  import org.apache.commons.httpclient.HttpStatus;
22  import org.junit.ClassRule;
23  import org.junit.Test;
24  
25  public class JettyPatchMethodTestCase extends FunctionalTestCase
26  {
27      @ClassRule
28      public static DynamicPort port1 = new DynamicPort("port1");
29  
30      public JettyPatchMethodTestCase()
31      {
32          super();
33          setDisposeContextPerClass(true);
34      }
35  
36      @Override
37      protected String getConfigResources()
38      {
39          return "jetty-patch-method.xml";
40      }
41  
42      @Override
43      protected void doSetUp() throws Exception
44      {
45          super.doSetUp();
46          setupTestComponent();
47      }
48  
49      private void setupTestComponent() throws Exception
50      {
51          FunctionalTestComponent ftc = (FunctionalTestComponent) getComponent("PatchWithCustomComponent");
52          ftc.setEventCallback(new CheckMessageCallback());
53      }
54  
55      @Test
56      public void testPatch() throws Exception
57      {
58          String url = String.format("http://localhost:%d/component", port1.getNumber());
59          PatchMethod method = new PatchMethod(url);
60          int status = new HttpClient().executeMethod(method);
61          assertEquals(HttpStatus.SC_OK, status);
62      }
63  
64      private static class CheckMessageCallback implements EventCallback
65      {
66          public void eventReceived(MuleEventContext context, Object component) throws Exception
67          {
68              MuleMessage message = context.getMessage();
69              assertEquals(HttpConstants.METHOD_PATCH, message.getInboundProperty("http.method"));
70          }
71      }
72  }