Skip to content

Commit

Permalink
Add repository methods: descriptor descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
jukka committed Feb 25, 2010
1 parent 101650c commit 81e3838
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/cljcr.clj
Expand Up @@ -58,6 +58,22 @@
{(var *repo*) (get-repository ~repo-params)}
~@body))

(defn descriptor
#^{ :doc "Returns the string value(s) of a repository descriptor." }
([key]
(descriptor (repository) key))
([repository key]
(if (. repository isSingleValueDescriptor key)
(. (. repository getDescriptorValue key) getString)
(map #(. %1 getString) (. repository getDescriptorValues key)))))

(defn descriptors
#^{ :doc "Returns a map of the repository descriptors." }
([] (descriptors (repository)))
([repository]
(let [keys (. repository getDescriptorKeys)]
(reduce #(assoc %1 %2 (descriptor repository %2)) {} keys))))

(defmacro with-session
[session-params & body]
`(with-bindings
Expand Down
8 changes: 6 additions & 2 deletions test/test_cljcr.clj
Expand Up @@ -39,6 +39,10 @@
:once
(fn [test] (with-repository jackrabbit-repo (with-guest-session (test)))))

(deftest test-descriptors
(testing "descriptors"
(is (= (get (descriptors) "jcr.repository.name") "Jackrabbit"))))

(deftest test-has-changes?
(is (not (has-changes?)) "there should be no unsaved changes"))

Expand All @@ -56,10 +60,10 @@
(testing "node-at"
(let [path "/jcr:system"]
(is (= (. (node-at path) getPath) path)
"the path of (node-at \"/jcr:system\") /jcr:system?")))
"the path of (node-at \"/jcr:system\") /jcr:system?"))))

(deftest test-property-at
(testing "property-at"
(let [path "/jcr:primaryType"]
(is (= (. (property-at path) getPath) path)
"the path of (property-at \"/jcr:primaryType\") /jcr:primaryType?")))
"the path of (property-at \"/jcr:primaryType\") /jcr:primaryType?"))))

0 comments on commit 81e3838

Please sign in to comment.