          (finally
            (shutdown))))))
 
-(defservice hello-test-service
-  [[:WebserverService add-war-handler]]
-  (init [this context]
-        (add-war-handler "test-resources/helloWorld.war" "/test")
-        context)
-  (stop [this context]
-        context))
-
 (deftest jetty-jetty9-service
+  (testing "static content context"
+    (let [app                 (bootstrap-services-with-cli-data [jetty9-service]
+                                {:config
+                                  (str
+                                    test-resources-config-dir
+                                    "jetty-plaintext-http.ini")})
+          s                   (get-service app :WebserverService)
+          add-context-handler (partial add-context-handler s)
+          shutdown            (partial stop s (service-context s))
+          path                "/resources"
+          resource            "logback.xml"]
+      (try
+        (add-context-handler test-resources-dir path)
+        (let [response (http-client/get (str "http://localhost:8080" path "/" resource))]
+          (is (= (:status response) 200))
+          (is (= (:body response) (slurp (str test-resources-dir resource)))))
+        (finally
+          (shutdown)))))
+
+  (testing "customization of static content context"
+    (let [app                 (bootstrap-services-with-cli-data [jetty9-service]
+                                {:config
+                                  (str
+                                    test-resources-config-dir
+                                    "jetty-plaintext-http.ini")})
+          s                   (get-service app :WebserverService)
+          add-context-handler (partial add-context-handler s)
+          shutdown            (partial stop s (service-context s))
+          path                "/resources"
+          body                "Hey there"
+          servlet-path        "/hey"
+          servlet             (SimpleServlet. body)]
+      (try
+        (add-context-handler test-resources-dir path
+                             [(reify ServletContextListener
+                                (contextInitialized [this event]
+                                  (doto (.addServlet (.getServletContext event) "simple" servlet)
+                                    (.addMapping (into-array [servlet-path]))))
+                                (contextDestroyed [this event]))])
+        (let [response (http-client/get (str "http://localhost:8080" path servlet-path))]
+          (is (= (:status response) 200))
+          (is (= (:body response) body)))
+        (finally
+          (shutdown)))))
+
   (testing "ring request over http succeeds")
     (bootstrap-and-validate-ring-handler
       "http://localhost:8080"

          (shutdown)))))

  (testing "WAR support"
    (let [app (bootstrap-services-with-cli-data [jetty9-service hello-test-service]
                {:config
                  (str
                    test-resources-config-dir
                    "jetty-plaintext-http.ini")})]
      (try
        (let [response (http-client/get "http://localhost:8080/test/hello")]
          (is (= (:status response) 200))
          (is (= (:body response)
                 "<html>\n<head><title>Hello World Servlet</title></head>\n<body>Hello World!!</body>\n</html>\n")))
        (finally
          (app/stop app)))))

  (testing "webserver bootstrap throws IllegalArgumentException when neither
            port nor ssl-port specified in the config"

(ns puppetlabs.trapperkeeper.services.webserver.jetty9-service-test
  (:import  (java.net ConnectException)
            (javax.net.ssl SSLPeerUnverifiedException)
            (javax.servlet ServletContextListener)
            [servlet SimpleServlet])
  (:require [clojure.test :refer :all]
            [clj-http.client :as http-client]
            [puppetlabs.trapperkeeper.app :refer [get-service]]
            [puppetlabs.trapperkeeper.services :refer [stop service-context]]
            [puppetlabs.trapperkeeper.services.webserver.jetty9-service
               :refer :all]
