                 :transaction-timeout 56
                 :transaction-mode :query}]
       (testing "with standard database map"
-        (as-expected-session-config? (session->map
-                                      (create-session db opts))
-                                     opts))
+        (with-open [sess (create-session db opts)]
+          (as-expected-session-config? (session->map sess) opts)))
       (testing "with uri content source"
-        (as-expected-session-config? (session->map
-                                      (create-session db
-                                                      (make-uri-content-source "xdbc://localhost:8383/")
-                                                      opts))
-                                     opts))
+        (with-open [sess (create-session
+                          db (make-uri-content-source "xdbc://localhost:8383/")
+                          opts)]
+          (as-expected-session-config? (session->map sess) opts)))
       (testing "with uri content source using options"
-        (as-expected-session-config? (session->map
-                                      (create-session
-                                       db (make-uri-content-source "xdbc://localhost:8383/"
-                                                                   {:preemptive-auth false})
-                                       opts))
-                                     opts))
+        (with-open [sess (create-session
+                          db (make-uri-content-source "xdbc://localhost:8383/"
+                                                      {:preemptive-auth false})
+                          opts)]
+          (as-expected-session-config? (session->map sess) opts)))
+
       (testing "with hosted content source"
-        (as-expected-session-config? (session->map
-                                      (create-session
-                                       db (make-hosted-content-source "localhost" 8383)
-                                       opts))
-                                     opts))
+        (with-open [sess (create-session
+                          db (make-hosted-content-source "localhost" 8383)
+                          opts)]
+          (as-expected-session-config? (session->map sess) opts)))
       (testing "with hosted content source using content base"
-        (as-expected-session-config? (session->map
-                                      (create-session
-                                       db (make-hosted-content-source "localhost" 8383
-                                                                      {:content-base "TutorialDB"})
-                                       opts))
-                                     opts))
+        (with-open [sess (create-session
+                          db (make-hosted-content-source "localhost" 8383
+                                                         {:content-base "TutorialDB"})
+                          opts)]
+          (as-expected-session-config? (session->map sess) opts)))
       (testing "with hosted content source using user, password, content-base"
-        (as-expected-session-config? (session->map
-                                      (create-session
-                                       db (make-hosted-content-source "localhost" 8383
-                                                                      {:user "rest-admin"
-                                                                       :password "x"
-                                                                       :content-base "TutorialDB"})
-                                       opts))
-                                     opts))
+        (with-open [sess (create-session
+                          db (make-hosted-content-source "localhost" 8383
+                                                         {:user "rest-admin"
+                                                          :password "x"
+                                                          :content-base "TutorialDB"})
+                          opts)]
+          (as-expected-session-config? (session->map sess) opts)))
       (testing "with hosted content source using user and password"
-        (as-expected-session-config? (session->map
-                                      (create-session
-                                       db (make-hosted-content-source "localhost" 8383
-                                                                      {:user "rest-admin"
-                                                                       :password "x"})
-                                       opts))
-                                     opts))
+        (with-open [sess (create-session
+                          db (make-hosted-content-source "localhost" 8383
+                                                         {:user "rest-admin"
+                                                          :password "x"})
+                          opts)]
+          (as-expected-session-config? (session->map sess) opts)))
       ;; TODO once we want to delve into extreme complexity of ConnectionProvider
       ;; (as-expected-session-config? (session->map
       ;;                                (create-session

  (testing "Creating sessions with a variety of parameters"
    (testing "...with just URI"
      (is (thrown? IllegalStateException
                   (let [session (create-session {:uri "xdbc://localhost:8383/"})]
                     (.submitRequest session (.newAdhocQuery session "\"Hello world\""))))))

    (testing "...with URI and content-base"
      (is (thrown? IllegalStateException
                   (let [session (create-session {:uri "xdbc://localhost:8383/"
                                                  :content-base "TutorialDB"})]
                     (.submitRequest session (.newAdhocQuery session "\"Hello world\""))))))

    (testing "...with URI, user, password"
      (is (= "Hello world"
             (let [session (create-session {:uri "xdbc://localhost:8383/"
                                            :user "rest-admin" :password "x"})]
               (-> session
                   (.submitRequest (.newAdhocQuery session
                                                   "\"Hello world\""))

(deftest default-session-config
  (testing "A session with no explicitly-set configuration must have default configuration"
    (testing "basic session creation with full database specified"
      (with-open [sess (create-session db)]
        (is-default-session-config? (session->map sess))))
    (testing "session creation with URI content source"
      (with-open [sess (create-session
                        db (make-uri-content-source "xdbc://localhost:8383/") {})]
        (is-default-session-config? (session->map sess))))
    (testing "session creation with URI content source using options"
      (with-open [sess (create-session
                        db (make-uri-content-source
                            "xdbc://localhost:8383/"
                            {:preemptive-auth false
                             :default-logger (Logger/getLogger "foobar")}))]
        (is-default-session-config? (session->map sess))))
    (testing "session creation with hosted content source"
      (with-open [sess (create-session
                        db (make-hosted-content-source "localhost" 8383) {})]
        (is-default-session-config? (session->map sess))))
    (testing "session creation with hosted content source using options"
      (with-open [sess (create-session
                        db (make-hosted-content-source "localhost" 8383
                                                       {:content-base "TutorialDB"})
                        {})]
        (is-default-session-config? (session->map sess))))
    ;; TODO once we want to delve into extreme complexity of ConnectionProvider
    ;; (testing "session creation with connectionProvider content source"
    ;;   (with-open [sess (create-session
    ;;                     db (make-cp-content-source ...)
    ;;                     {})]
    ;;     (is-default-session-config? (session->map sess))))
    ;; TODO once we want to delve into extreme complexity of ConnectionProvider
    ;; (testing "session creation with connectionProvider content source with options"
    ;;   (with-open [sess (create-session
    ;;                     db (make-cp-content-source ...) {})])
    ;;   (is-default-session-config? (session->map sess)))
    ))

;; (deftest accept-only-valid-session-options
