1   /*
2    * $Id: HttpMethodTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.providers.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      public HttpMethodTestCase()
30      {
31          setDisposeManagerPerSuite(true);
32      }
33  
34      protected String getConfigResources()
35      {
36          return "http-method-test.xml";
37      }
38  
39      protected void doFunctionalTearDown () throws Exception
40      {
41          if (method != null)
42          {
43              method.releaseConnection();
44          }
45      }
46  
47      public void testHead() throws Exception
48      {
49          HttpClient client = new HttpClient();
50          method = new HeadMethod("http://localhost:60200");
51          int statusCode = client.executeMethod(method);
52          assertEquals(Integer.toString(HttpStatus.SC_OK), Integer.toString(statusCode));
53  
54      }
55  
56      public void testOptions() throws Exception
57      {
58          HttpClient client = new HttpClient();
59          method = new OptionsMethod("http://localhost:60200");
60          int statusCode = client.executeMethod(method);
61          assertEquals(Integer.toString(HttpStatus.SC_METHOD_NOT_ALLOWED), Integer.toString(statusCode));
62      }
63  
64      public void testPut() throws Exception
65      {
66          HttpClient client = new HttpClient();
67          method = new PutMethod("http://localhost:60200");
68          int statusCode = client.executeMethod(method);
69          assertEquals(Integer.toString(HttpStatus.SC_METHOD_NOT_ALLOWED), Integer.toString(statusCode));
70      }
71  
72      public void testDelete() throws Exception
73      {
74          HttpClient client = new HttpClient();
75          method = new DeleteMethod("http://localhost:60200");
76          int statusCode = client.executeMethod(method);
77          assertEquals(Integer.toString(HttpStatus.SC_METHOD_NOT_ALLOWED), Integer.toString(statusCode));
78      }
79  
80      public void testTrace() throws Exception
81      {
82          HttpClient client = new HttpClient();
83          method = new TraceMethod("http://localhost:60200");
84          int statusCode = client.executeMethod(method);
85          assertEquals(Integer.toString(HttpStatus.SC_METHOD_NOT_ALLOWED), Integer.toString(statusCode));
86      }
87  
88      public void testConnect() throws Exception
89      {
90          HttpClient client = new HttpClient();
91          method = new HttpMethodBase("http://localhost:60200")
92          {
93              public String getName()
94              {
95                  return "CONNECT";
96              }
97          };
98          int statusCode = client.executeMethod(method);
99          assertEquals(Integer.toString(HttpStatus.SC_METHOD_NOT_ALLOWED), Integer.toString(statusCode));
100     }
101 
102     public void testFoo() throws Exception
103     {
104         HttpClient client = new HttpClient();
105         method = new HttpMethodBase("http://localhost:60200")
106         {
107             public String getName()
108             {
109                 return "FOO";
110             }
111         };
112         int statusCode = client.executeMethod(method);
113         assertEquals(Integer.toString(HttpStatus.SC_BAD_REQUEST), Integer.toString(statusCode));
114     }
115 }
116 
117