Query DSL work preparation

This commit is contained in:
Michael S. Klishin 2011-11-06 23:03:36 +04:00
parent 6dd3491d39
commit 88fa9f07bb

View file

@ -1,6 +1,7 @@
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)
(ns monger.test.querying (ns monger.test.querying
(:refer-clojure :exclude [select find])
(:import [com.mongodb WriteResult WriteConcern DBCursor DBObject CommandResult$CommandFailure] (:import [com.mongodb WriteResult WriteConcern DBCursor DBObject CommandResult$CommandFailure]
[org.bson.types ObjectId] [org.bson.types ObjectId]
[java.util Date]) [java.util Date])
@ -9,6 +10,7 @@
[monger.result :as mgres]) [monger.result :as mgres])
(:use [clojure.test] (:use [clojure.test]
[monger.test.fixtures] [monger.test.fixtures]
;; [monger.query]
[monger.conversion])) [monger.conversion]))
@ -76,7 +78,18 @@
;; < ($lt), <= ($lte), > ($gt), >= ($gte) ;; < ($lt), <= ($lte), > ($gt), >= ($gte)
(deftest query-with-find-maps-using-$lt-operator ;; (deftest query-using-dsl-and-$lt-operator
;; (let [coll "docs"
;; doc1 { :language "Clojure" :_id (ObjectId.) :inception_year 2006 }
;; doc2 { :language "Java" :_id (ObjectId.) :inception_year 1992 }
;; doc3 { :language "Scala" :_id (ObjectId.) :inception_year 2003 }
;; _ (mgcol/insert-batch coll [doc1 doc2])
;; lt-result (in-collection "docs"
;; (find { :inception_year { "$lt" 2000 } })]
;; (is (= [doc2] lt-result))))
(deftest query-with-find-maps-using-$lt-operator
(let [coll "docs" (let [coll "docs"
doc1 { :language "Clojure" :_id (ObjectId.) :inception_year 2006 } doc1 { :language "Clojure" :_id (ObjectId.) :inception_year 2006 }
doc2 { :language "Java" :_id (ObjectId.) :inception_year 1992 } doc2 { :language "Java" :_id (ObjectId.) :inception_year 1992 }
@ -92,9 +105,9 @@
(is (= [doc1] gte-result)))) (is (= [doc1] gte-result))))
;; $all ;; $all
(deftest query-with-find-maps-using-$all (deftest query-with-find-maps-using-$all
(let [coll "docs" (let [coll "docs"
doc1 { :_id (ObjectId.) :title "Clojure" :tags ["functional" "homoiconic" "syntax-oriented" "dsls" "concurrency features" "jvm"] } doc1 { :_id (ObjectId.) :title "Clojure" :tags ["functional" "homoiconic" "syntax-oriented" "dsls" "concurrency features" "jvm"] }
doc2 { :_id (ObjectId.) :title "Java" :tags ["object-oriented" "jvm"] } doc2 { :_id (ObjectId.) :title "Java" :tags ["object-oriented" "jvm"] }
@ -108,9 +121,9 @@
(is (= 2 (count result3))))) (is (= 2 (count result3)))))
;; $exists ;; $exists
(deftest query-with-find-one-as-map-using-$exists (deftest query-with-find-one-as-map-using-$exists
(let [coll "docs" (let [coll "docs"
doc1 { :_id (ObjectId.) :published-by "Jill The Blogger" :draft false :title "X announces another Y" } doc1 { :_id (ObjectId.) :published-by "Jill The Blogger" :draft false :title "X announces another Y" }
doc2 { :_id (ObjectId.) :draft true :title "Z announces a Y competitor" } doc2 { :_id (ObjectId.) :draft true :title "Z announces a Y competitor" }
@ -120,9 +133,9 @@
(is (= doc1 result1)) (is (= doc1 result1))
(is (= doc2 result2)))) (is (= doc2 result2))))
;; $mod ;; $mod
(deftest query-with-find-one-as-map-using-$mod (deftest query-with-find-one-as-map-using-$mod
(let [coll "docs" (let [coll "docs"
doc1 { :_id (ObjectId.) :counter 25 } doc1 { :_id (ObjectId.) :counter 25 }
doc2 { :_id (ObjectId.) :counter 32 } doc2 { :_id (ObjectId.) :counter 32 }
@ -136,9 +149,9 @@
(is (empty? result3)))) (is (empty? result3))))
;; $ne ;; $ne
(deftest query-with-find-one-as-map-using-$ne (deftest query-with-find-one-as-map-using-$ne
(let [coll "docs" (let [coll "docs"
doc1 { :_id (ObjectId.) :counter 25 } doc1 { :_id (ObjectId.) :counter 25 }
doc2 { :_id (ObjectId.) :counter 32 } doc2 { :_id (ObjectId.) :counter 32 }