1   /*
2    * $Id: HttpMethodTestCase.java 11179 2008-03-05 13:46:23Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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 org.mule.tck.FunctionalTestCase;
14  
15  import org.apache.commons.httpclient.HttpClient;
16  import org.apache.commons.httpclient.HttpMethodBase;
17  import org.apache.commons.httpclient.HttpStatus;
18  import org.apache.commons.httpclient.methods.DeleteMethod;
19  import org.apache.commons.httpclient.methods.HeadMethod;
20  import org.apache.commons.httpclient.methods.OptionsMethod;
21  import org.apache.commons.httpclient.methods.PutMethod;
22  import org.apache.commons.httpclient.methods.TraceMethod;
23  
24  public class HttpMethodTestCase extends FunctionalTestCase
25  {
26  
27      private HttpMethodBase method;
28  
29      protected String getConfigResources()
30      {
31          return "http-method-test.xml";
32      }
33  
34      protected void doFunctionalTearDown () throws Exception
35      {
36          if (method != null)
37          {
38              method.releaseConnection();
39          }
40      }
41  
42      public void testHead() throws Exception
43      {
44          HttpClient client = new HttpClient();
45          method = new HeadMethod("http://localhost:60200");
46          int statusCode = client.executeMethod(method);
47          assertEquals(Integer.toString(HttpStatus.SC_OK), Integer.toString(statusCode));
48  
49      }
50  
51      public void testOptions() throws Exception
52      {
53          HttpClient client = new HttpClient();
54          method = new OptionsMethod("http://localhost:60200");
55          int statusCode = client.executeMethod(method);
56          assertEquals(Integer.toString(HttpStatus.SC_OK), Integer.toString(statusCode));
57      }
58  
59      public void testPut() throws Exception
60      {
61          HttpClient client = new HttpClient();
62          method = new PutMethod("http://localhost:60200");
63          int statusCode = client.executeMethod(method);
64          assertEquals(Integer.toString(HttpStatus.SC_OK), Integer.toString(statusCode));
65      }
66  
67      public void testDelete() throws Exception
68      {
69          HttpClient client = new HttpClient();
70          method = new DeleteMethod("http://localhost:60200");
71          int statusCode = client.executeMethod(method);
72          assertEquals(Integer.toString(HttpStatus.SC_OK), Integer.toString(statusCode));
73      }
74  
75      public void testTrace() throws Exception
76      {
77          HttpClient client = new HttpClient();
78          method = new TraceMethod("http://localhost:60200");
79          int statusCode = client.executeMethod(method);
80          assertEquals(Integer.toString(HttpStatus.SC_OK), Integer.toString(statusCode));
81      }
82  
83      public void testConnect() throws Exception
84      {
85          HttpClient client = new HttpClient();
86          method = new HttpMethodBase("http://localhost:60200")
87          {
88              public String getName()
89              {
90                  return "CONNECT";
91              }
92          };
93          int statusCode = client.executeMethod(method);
94          assertEquals(Integer.toString(HttpStatus.SC_OK), Integer.toString(statusCode));
95      }
96  
97      public void testFoo() throws Exception
98      {
99          HttpClient client = new HttpClient();
100         method = new HttpMethodBase("http://localhost:60200")
101         {
102             public String getName()
103             {
104                 return "FOO";
105             }
106         };
107         int statusCode = client.executeMethod(method);
108         assertEquals(Integer.toString(HttpStatus.SC_BAD_REQUEST), Integer.toString(statusCode));
109     }
110 }
111 
112