title: Integration Test to webDav client using apache httpclient LocalTestServer
body: <p>I am trying to write Integrations tests for WebDavClient (based on jackrabbit) using apache httpclient LocalTestServer.
  I was inspired from the following <a href="https://thecarlhall.wordpress.com/2010/03/25/unit-testing-with-httpclients-localtestserver/" rel="nofollow">blog</a> and written the test below:</p>
  
  <pre><code>public class WebDAVClientIT {
  
      private LocalTestServer server;
  
      @Before
      public void setup() throws Exception{
          server = new LocalTestServer(null, null);
          server.start();
          //direct all requests to my handelr
          server.register("/*", new WebDavHandler());
      }
  
      @Test
      public void testUploadFileStringInputStreamString() throws Exception {
  
          WebDAVClient webDavClient = new WebDAVClient();
          //set the client user/pass etc
          webDavClient.init();
  
          byte[] data = "123,456,789,123,456,789".getBytes();
          InputStream input = new ByteArrayInputStream(data);
          Status uploadFileStatus = webDavClient.uploadFile("test/file.csv", input, "text/csv");
          assertThat(uploadFileStatus.getStatusCode(), is(HttpStatus.SC_CREATED));
  
      }
  
      @After
      public void distory() throws Exception {
          server.stop();
      }
  }
  </code></pre>
  
  <p>I created a request handler that will make the server feel like a WebDav server.</p>
  
  <pre><code>public class WebDavHandler implements HttpRequestHandler {
          private Map&lt;String, String&gt; resources;
          public WebDavHandler() {
              //map existing resources 
              resources = new HashMap&lt;&gt;();
          }
  
          @Override
          public void handle(HttpRequest request, HttpResponse response,
                  HttpContext context) throws HttpException, IOException {
              RequestLine requestLine = request.getRequestLine();
              String method = requestLine.getMethod();
              String uri = request.getRequestLine().getUri();
  
              switch (method) {
              case "GET":
                  if (resources.containsKey(uri)) {
                      response.setStatusCode(HttpStatus.SC_OK);
                  } else {
                      response.setStatusCode(HttpStatus.SC_NOT_FOUND);
                  }
                  break;
              case "MKCOL":
                  if (resources.containsKey(uri)) {
                      response.setStatusCode(HttpStatus.SC_OK);
                  } else {
                      response.setStatusCode(HttpStatus.SC_CREATED);
                      resources.put(uri, uri);
                  }
                  break;
              }
              logger.info("Executing " + request);
          }
  
      }
  </code></pre>
  
  <p>Now my problem is that LocalTestServer is not a real WebDav server and some of the methods supported by WebDav will not be supported by LocalTestServer e.g. MkColMethod </p>
  
  <pre><code>[statusCode=501, statusText=Internal Server Error, responseString=MKCOL method not supported]
  </code></pre>
  
  <p>How do I extend the LocalTestServer to emulate webdav missing methods.</p>