Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(ns document-storage.protocol-test
(:require [document-storage.protocol :as sut]
[clojure.test :refer :all]
[clj-helper.string :refer [get-unique-id]]
[clojure.data :refer [diff]]))
(defn test-save-document [ds-atom]
(testing "save basic structure and load it"
(let [structure {:a 7 :c [1 2 3 4 99 5 -4] :v 3}
id "simple-test1"
repo :testrepo]
(.save-document @ds-atom id structure repo)
(is (some #{id} (.list-documents @ds-atom :testrepo)))
(is (= structure
(.load-document @ds-atom id repo))))))
(defn test-versioning [ds-atom]
(testing "update document and check if changes are versioned"
(let [structure-v1 {:a 7 :c [1 2 3 4 99 5 -4] :v 3}
structure-v2 (-> structure-v1
(assoc :a 1 :v -3)
(assoc-in [:c 2] 1258))
structure-v3 (-> structure-v2
(assoc :a -5 :v -6)
(assoc-in [:c 0] 121))
id (get-unique-id "tdoc")
repo :testrepo]
(.save-document @ds-atom id structure-v1 repo)
(.save-document @ds-atom id structure-v2 repo)
(.save-document @ds-atom id structure-v3 repo)
(let [versions (reverse (.list-versions @ds-atom id repo))]
(is (= (count versions) 3) "Check if there are the 3 expected versions")
(let [v1 (:version (nth versions 2))
v2 (:version (nth versions 1))
v3 (:version (nth versions 0))
storage-doc-v1 (.load-version @ds-atom id v1 repo)
storage-doc-v2 (.load-version @ds-atom id v2 repo)
storage-doc-v3 (.load-version @ds-atom id v3 repo)]
(is (= storage-doc-v1 structure-v1) "check if temporary and stored data is equal")
(is (= storage-doc-v2 structure-v2))
(is (= storage-doc-v3 structure-v3))
(is (= (diff structure-v1 structure-v2)
(diff storage-doc-v1 storage-doc-v2)))
(is (= (diff structure-v2 structure-v3)
(diff storage-doc-v2 storage-doc-v3))))))))