     ))
 
 
-
-
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; Type tests
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-;; (def session
-;;   (create-session {:uri "xdbc://localhost:8383/"
-;;                    :user "rest-admin" :password "x"
-;;                    :content-base "TutorialDB"}))
-
-(deftest types
-  (with-open [session (create-session {:uri "xdbc://localhost:8383/"
-                                       :user "rest-admin" :password "x"
-                                       :content-base "TutorialDB"})]
-    (testing "Types roundtrip through XQuery with expected conversions"
-      (testing "...JSON interface types"
-        (testing "......array-node type"
+(deftest type-conversion
+  (testing "Types roundtrip through XQuery with expected conversions"
+    (testing "...JSON interface types"
+      (testing "......array-node type"
+        (with-open [session (create-session db)]
           (is (= "array-node()"
                  (result->type (execute-xquery session "array-node {1,2,3}"
-                                               {:types :raw}))))
+                                               {:types :raw})))))
+
+        (with-open [session (create-session db)]
           (is (= [1 2 3]
                  (execute-xquery session "array-node {1,2,3}"
-                                 {:shape :single!}))))
-
-        (testing "......boolean-node type"
+                                 {:shape :single!})))))
+
+      (testing "......boolean-node type"
+        (with-open [session (create-session db)]
           (is (= "boolean-node()"
                  (result->type (execute-xquery session "boolean-node{false()}"
-                                               {:types :raw}))))
+                                               {:types :raw})))))
+        (with-open [session (create-session db)]
           (is (false? (execute-xquery session "boolean-node{false()}"
-                                      {:shape :single!}))))
-
-        ;; TODO produce and test JsonItem
-
-        (testing "......null-node type"
+                                      {:shape :single!})))))
+
+      ;; TODO produce and test JsonItem
+
+      (testing "......null-node type"
+        (with-open [session (create-session db)]
           (is (= "null-node()"
                  (result->type (execute-xquery session "null-node {}"
-                                               {:types :raw}))))
+                                               {:types :raw})))))
+        (with-open [session (create-session db)]
           (is (nil? (execute-xquery session "null-node {}"
-                                    {:shape :single!}))))
-
-        (testing "......number-node type"
+                                     {:shape :single!})))))
+
+      (testing "......number-node type"
+        (with-open [session (create-session db)]
           (is (= "number-node()"
                  (result->type (execute-xquery session "number-node {1}"
-                                               {:types :raw}))))
-          (is (= 1 (execute-xquery session "number-node {1}"
-                                   {:shape :single!}))))
-
-        (testing "......object-node type"
+                                               {:types :raw})))))
+          (with-open [session (create-session db)]
+            (is (= 1 (execute-xquery session "number-node {1}"
+                                    {:shape :single!})))))
+
+      (testing "......object-node type"
+        (with-open [session (create-session db)]
           (is (= "object-node()"
                  (result->type (execute-xquery session "xquery version \"1.0-ml\";
                                       let $object := json:object()
                                       let $_ := map:put($object,\"a\",111)
-                                      return xdmp:to-json($object)" {:types :raw}))))
-          (is (= {"a" 111}
-                 (execute-xquery session "xquery version \"1.0-ml\";
+                                      return xdmp:to-json($object)" {:types :raw})))))
+        (with-open [session (create-session db)]
+            (is (= {"a" 111}
+                  (execute-xquery session "xquery version \"1.0-ml\";
                                       let $object := json:object()
                                       let $_ := map:put($object,\"a\",111)
                                       return xdmp:to-json($object)"
-                                 {:shape :single!})))))
-
-      
-      (testing "...JSON types"
-        (testing "......JSON array type"
+                                  {:shape :single!}))))))
+
+
+    (testing "...JSON types"
+      (testing "......JSON array type"
+        (with-open [session (create-session db)]
           (is (= "json:array"
                  (result->type (execute-xquery session "xquery version \"1.0-ml\";
                             json:array(

                             <json:value xsi:type=\"xs:string\">two</json:value>
                             </json:array>
                             </json:array>
                            )" {:types :raw}))))
          (is (= ["hello" "world" ["one" "two"]]
                 (execute-xquery session
                                 "xquery version \"1.0-ml\";

(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
