/
integration_test.clj
84 lines (82 loc) · 3.84 KB
/
integration_test.clj
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
(ns clojurewerkz.titanium.integration-test
(:require [clojurewerkz.titanium.graph :as tg]
[clojurewerkz.titanium.vertices :as tv]
[clojurewerkz.titanium.edges :as ted]
[clojurewerkz.ogre.core :as g])
(:use clojure.test
[clojurewerkz.titanium.test.support :only (*graph* graph-fixture)]))
(use-fixtures :once graph-fixture)
;; The Graph of the Gods example from the Titan wiki
(deftest test-integration-example1
(tg/with-transaction [tx *graph*]
(let [saturn (tv/create! tx {:name "Saturn" :type "titan"})
jupiter (tv/create! tx {:name "Jupiter" :type "god"})
hercules (tv/create! tx {:name "Hercules" :type "demigod"})
alcmene (tv/create! tx {:name "Alcmene" :type "human"})
neptune (tv/create! tx {:name "Neptune" :type "god"})
pluto (tv/create! tx {:name "Pluto" :type "god"})
sea (tv/create! tx {:name "Sea" :type "location"})
sky (tv/create! tx {:name "Sky" :type "location"})
tartarus (tv/create! tx {:name "Tartarus" :type "location"})
nemean (tv/create! tx {:name "Nemean" :type "monster"})
hydra (tv/create! tx {:name "Hydra" :type "monster"})
cerberus (tv/create! tx {:name "Cerberus" :type "monster"})]
(ted/connect! tx neptune :lives sea)
(ted/connect! tx jupiter :lives sky)
(ted/connect! tx pluto :lives tartarus)
(ted/connect! tx jupiter :father saturn)
(ted/connect! tx hercules :father jupiter)
(ted/connect! tx hercules :mother alcmene)
(ted/connect! tx jupiter :brother pluto)
(ted/connect! tx pluto :brother jupiter)
(ted/connect! tx neptune :brother pluto)
(ted/connect! tx pluto :brother neptune)
(ted/connect! tx jupiter :brother neptune)
(ted/connect! tx neptune :brother jupiter)
(ted/connect! tx cerberus :lives tartarus)
(ted/connect! tx pluto :pet cerberus)
(ted/connect! tx hercules :battled nemean {:times 1})
(ted/connect! tx hercules :battled hydra {:times 2})
(ted/connect! tx hercules :battled cerberus {:times 12})
(let [r1 (g/query saturn
(g/<-- [:father])
(g/<-- [:father])
g/first-of!)
r2 (g/query hercules
(g/out [:father :mother])
(g/property :name)
g/into-set!)
r3 (g/query hercules
(g/-E> [:battled])
(g/has :times > 1)
(g/in-vertex)
(g/property :name)
g/into-set!)
c3 (g/query hercules
(g/-E> [:battled])
(g/has :times > 1)
(g/in-vertex)
g/count!)
r4 (g/query pluto
(g/--> [:lives])
(g/<-- [:lives])
(g/except [pluto])
(g/property :name)
g/into-set!)
r5 (g/query pluto
(g/--> [:brother])
(g/as "god")
(g/--> [:lives])
(g/as "place")
(g/select (g/prop :name))
g/all-into-maps!)]
(is (= r1 hercules))
(is (= r2 #{"Alcmene" "Jupiter"}))
(is (= r3 #{"Cerberus" "Hydra"}))
(is (= c3 2))
(is (= r4 #{"Cerberus"}))
;; when https://github.com/tinkerpop/pipes/issues/75 is fixed,
;; we will be able to turn tables into vectors of maps, as they
;; should be represented (Neocons does it for Cypher responses). MK.
(is (= #{{:god "Neptune" :place "Sea"} {:god "Jupiter" :place "Sky"}}
(set r5)))))))