diametric 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +6 -14
  2. data/Gemfile +3 -3
  3. data/Jarfile +13 -6
  4. data/LICENSE.txt +2 -2
  5. data/README.md +57 -26
  6. data/Rakefile +1 -0
  7. data/bin/datomic-rest +1 -1
  8. data/bin/download-datomic +1 -1
  9. data/datomic_version.yml +2 -2
  10. data/diametric.gemspec +8 -7
  11. data/ext/diametric/DiametricCollection.java +45 -38
  12. data/ext/diametric/DiametricConnection.java +16 -15
  13. data/ext/diametric/DiametricDatabase.java +9 -8
  14. data/ext/diametric/DiametricEntity.java +104 -21
  15. data/ext/diametric/DiametricObject.java +12 -1
  16. data/ext/diametric/DiametricPeer.java +52 -31
  17. data/ext/diametric/DiametricService.java +2 -0
  18. data/ext/diametric/DiametricSet.java +11 -4
  19. data/ext/diametric/DiametricUUID.java +8 -1
  20. data/ext/diametric/DiametricUtils.java +90 -62
  21. data/lib/diametric.rb +1 -0
  22. data/lib/diametric/associations/collection.rb +103 -0
  23. data/lib/diametric/entity.rb +166 -103
  24. data/lib/diametric/persistence/common.rb +0 -44
  25. data/lib/diametric/persistence/peer.rb +53 -2
  26. data/lib/diametric/persistence/rest.rb +27 -1
  27. data/lib/diametric/query.rb +49 -31
  28. data/lib/diametric/rest_service.rb +8 -9
  29. data/lib/diametric/service_base.rb +7 -7
  30. data/lib/diametric/transactor.rb +6 -5
  31. data/lib/diametric/version.rb +1 -1
  32. data/lib/diametric_service.jar +0 -0
  33. data/spec/config/free-transactor-template.properties +6 -6
  34. data/spec/developer_query_spec.rb +17 -6
  35. data/spec/diametric/entity_spec.rb +62 -139
  36. data/spec/diametric/peer_api_spec.rb +23 -23
  37. data/spec/diametric/persistence/peer_spec.rb +73 -11
  38. data/spec/diametric/persistence/rest_spec.rb +108 -16
  39. data/spec/diametric/query_spec.rb +3 -3
  40. data/spec/diametric/rest_service_spec.rb +4 -4
  41. data/spec/diametric/schema_spec.rb +526 -0
  42. data/spec/diametric/transactor_spec.rb +5 -6
  43. data/spec/integration_spec.rb +7 -7
  44. data/spec/peer_integration_spec.rb +25 -1
  45. data/spec/peer_seattle_spec.rb +1 -2
  46. data/spec/spec_helper.rb +31 -4
  47. data/spec/support/cardinarity_many_example.rb +37 -0
  48. data/spec/support/entities.rb +127 -0
  49. data/spec/support/has_a_example.rb +31 -0
  50. data/spec/support/has_many_example.rb +79 -0
  51. data/spec/support/persistence_examples.rb +13 -5
  52. data/spec/support/various_types_examples.rb +163 -0
  53. data/spec/test_version_file.yml +2 -2
  54. metadata +66 -15
@@ -3,28 +3,120 @@ require 'diametric/persistence/rest'
3
3
  require 'securerandom'
4
4
 
5
5
  describe Diametric::Persistence::REST, :integration do
6
- before do
7
- @db_uri = ENV['DATOMIC_URI'] || 'http://localhost:46291'
8
- @storage = ENV['DATOMIC_STORAGE'] || 'free'
9
- @dbname = ENV['DATOMIC_NAME'] || "test-#{SecureRandom.uuid}"
10
- @connection_options = {
11
- :uri => @db_uri,
12
- :storage => @storage,
13
- :database => @dbname
14
- }
6
+ context "simple queries for a simple schema" do
7
+ before do
8
+ @db_uri = ENV['DATOMIC_URI'] || 'http://localhost:46291'
9
+ @storage = ENV['DATOMIC_STORAGE'] || 'free'
10
+ @dbname = ENV['DATOMIC_NAME'] || "mouse-#{SecureRandom.uuid}"
11
+ @connection_options = {
12
+ :uri => @db_uri,
13
+ :storage => @storage,
14
+ :database => @dbname
15
+ }
16
+ end
17
+
18
+ it "can connect to a Datomic database" do
19
+ subject.connect(@connection_options)
20
+ subject.connection.should be_a(Datomic::Client)
21
+ end
22
+
23
+ it_behaves_like "persistence API" do
24
+ let(:model_class) { Mouse }
25
+
26
+ before do
27
+ Diametric::Persistence::REST.connect(@connection_options)
28
+ Diametric::Persistence::REST.create_schemas
29
+ end
30
+ end
31
+ end
32
+
33
+ context "simple queries for various types" do
34
+ before do
35
+ @db_uri = ENV['DATOMIC_URI'] || 'http://localhost:46291'
36
+ @storage = ENV['DATOMIC_STORAGE'] || 'free'
37
+ @dbname = ENV['DATOMIC_NAME'] || "peacock-#{SecureRandom.uuid}"
38
+ @connection_options = {
39
+ :uri => @db_uri,
40
+ :storage => @storage,
41
+ :database => @dbname
42
+ }
43
+ end
44
+
45
+ it_behaves_like "supports various types" do
46
+ let(:model_class) { Peacock }
47
+
48
+ before do
49
+ Diametric::Persistence::REST.connect(@connection_options)
50
+ Diametric::Persistence::REST.create_schemas
51
+ end
52
+ end
15
53
  end
16
54
 
17
- it "can connect to a Datomic database" do
18
- subject.connect(@connection_options)
19
- subject.connection.should be_a(Datomic::Client)
55
+ context "simple queries for carinality many" do
56
+ before do
57
+ @db_uri = ENV['DATOMIC_URI'] || 'http://localhost:46291'
58
+ @storage = ENV['DATOMIC_STORAGE'] || 'free'
59
+ @dbname = ENV['DATOMIC_NAME'] || "your-words-#{SecureRandom.uuid}"
60
+ @connection_options = {
61
+ :uri => @db_uri,
62
+ :storage => @storage,
63
+ :database => @dbname
64
+ }
65
+ end
66
+
67
+ it_behaves_like "supports cardinality many" do
68
+ let(:model_class) { YourWords }
69
+
70
+ before do
71
+ Diametric::Persistence::REST.connect(@connection_options)
72
+ Diametric::Persistence::REST.create_schemas
73
+ end
74
+ end
20
75
  end
21
76
 
22
- it_behaves_like "persistence API" do
23
- let(:model_class) { Mouse }
77
+ context "simple queries for has_one association" do
78
+ before do
79
+ @db_uri = ENV['DATOMIC_URI'] || 'http://localhost:46291'
80
+ @storage = ENV['DATOMIC_STORAGE'] || 'free'
81
+ @dbname = ENV['DATOMIC_NAME'] || "box-#{SecureRandom.uuid}"
82
+ @connection_options = {
83
+ :uri => @db_uri,
84
+ :storage => @storage,
85
+ :database => @dbname
86
+ }
87
+ end
88
+
89
+ it_behaves_like "supports has_one association" do
90
+ let(:parent_class) { Box }
91
+ let(:child_class) { Mouse }
92
+
93
+ before do
94
+ Diametric::Persistence::REST.connect(@connection_options)
95
+ Diametric::Persistence::REST.create_schemas
96
+ end
97
+ end
98
+ end
24
99
 
100
+ context "simple queries for has_many association" do
25
101
  before do
26
- Diametric::Persistence::REST.connect(@connection_options)
27
- Diametric::Persistence::REST.create_schemas
102
+ @db_uri = ENV['DATOMIC_URI'] || 'http://localhost:46291'
103
+ @storage = ENV['DATOMIC_STORAGE'] || 'free'
104
+ @dbname = ENV['DATOMIC_NAME'] || "big-box-#{SecureRandom.uuid}"
105
+ @connection_options = {
106
+ :uri => @db_uri,
107
+ :storage => @storage,
108
+ :database => @dbname
109
+ }
110
+ end
111
+
112
+ it_behaves_like "supporting has_many association" do
113
+ let(:parent_class) { BigBox }
114
+ let(:child_class) { Mouse }
115
+
116
+ before do
117
+ Diametric::Persistence::REST.connect(@connection_options)
118
+ Diametric::Persistence::REST.create_schemas
119
+ end
28
120
  end
29
121
  end
30
122
  end
@@ -26,8 +26,8 @@ describe Diametric::Query do
26
26
  attribute :likes, String, :cardinality => :many
27
27
  end
28
28
  model.stub(:q => [[1, "Stu", "chocolate"], [1, "Stu", "vanilla"]])
29
- model.should_receive(:from_query).with([1, "Stu", ["chocolate", "vanilla"]], nil, true)
30
- Diametric::Query.new(model, nil, true).each {|x| x}
29
+ model.should_receive(:from_query).with([1, "Stu", ["chocolate", "vanilla"]], nil, false)
30
+ Diametric::Query.new(model, nil, false).each {|x| x}
31
31
  end
32
32
  end
33
33
 
@@ -64,7 +64,7 @@ describe Diametric::Query do
64
64
  attribute :likes, String, :cardinality => :many
65
65
  end
66
66
  model.stub(:q => [[1, "Stu", "chocolate"], [1, "Stu", "vanilla"]])
67
- Diametric::Query.new(model, nil, true).all.each do |e|
67
+ Diametric::Query.new(model, nil, false).all.each do |e|
68
68
  e.name.should == "Stu"
69
69
  e.likes.class.should == Set
70
70
  e.likes.should include "chocolate"
@@ -27,18 +27,18 @@ describe Diametric::RestService, :service =>true do
27
27
  end
28
28
 
29
29
  it "should know datomic version specified" do
30
- service.datomic_version("spec/test_version_file.yml").should == "datomic-free-0.8.4122"
31
- service.datomic_version("datomic-free-0.8.4122").should == "datomic-free-0.8.4122"
30
+ service.datomic_version("spec/test_version_file.yml").should == ["free", "0.9.4497"]
31
+ service.datomic_version("0.9.4497").should == ["free", "0.9.4497"]
32
32
  end
33
33
 
34
34
  it "should know the specified version of datomic has been downloaded" do
35
35
  service.downloaded?("spec/test_version_file.yml", "tmp/datomic").should be_false
36
- service.downloaded?("datomic-free-0.8.4122", "tmp/datomic").should be_false
36
+ service.downloaded?("0.9.4497", "tmp/datomic").should be_false
37
37
 
38
38
  service.download("spec/test_version_file.yml", "tmp/datomic")
39
39
 
40
40
  service.downloaded?("spec/test_version_file.yml", "tmp/datomic").should be_true
41
- service.downloaded?("datomic-free-0.8.4122", "tmp/datomic").should be_true
41
+ service.downloaded?("0.9.4497", "tmp/datomic").should be_true
42
42
  end
43
43
 
44
44
  context Diametric::RestService do
@@ -0,0 +1,526 @@
1
+ require 'spec_helper'
2
+
3
+ describe Diametric::Entity, :integration => true, :jruby => true do
4
+ context Rat do # Peer
5
+ let(:expected) {
6
+ [{:"db/id"=>"#db/id [:db.part/db]",
7
+ :"db/cardinality"=>:"db.cardinality/one",
8
+ :"db.install/_attribute"=>:"db.part/db",
9
+ :"db/ident"=>:"rat/name",
10
+ :"db/valueType"=>:"db.type/string",
11
+ :"db/index"=>true},
12
+ {:"db/id"=>"#db/id [:db.part/db]",
13
+ :"db/cardinality"=>:"db.cardinality/one",
14
+ :"db.install/_attribute"=>:"db.part/db",
15
+ :"db/ident"=>:"rat/age",
16
+ :"db/valueType"=>:"db.type/long"}]
17
+ }
18
+
19
+ before do
20
+ datomic_uri = "datomic:mem://rat-#{SecureRandom.uuid}"
21
+ @conn = Diametric::Persistence::Peer.connect(datomic_uri)
22
+ end
23
+
24
+ after do
25
+ @conn.release
26
+ end
27
+
28
+ it "should generate a schema" do
29
+ Rat.schema.each do |e|
30
+ e.should be_an_equivalent_hash(expected.shift)
31
+ end
32
+ end
33
+
34
+ it "should create schema" do
35
+ expect { Rat.create_schema(@conn).get }.
36
+ not_to raise_exception
37
+ end
38
+ end
39
+
40
+ context Mouse do # REST
41
+ let(:expected) {
42
+ [{:"db/id"=>"#db/id [:db.part/db]",
43
+ :"db/cardinality"=>:"db.cardinality/one",
44
+ :"db.install/_attribute"=>:"db.part/db",
45
+ :"db/ident"=>:"mouse/name",
46
+ :"db/valueType"=>:"db.type/string",
47
+ :"db/index"=>true},
48
+ {:"db/id"=>"#db/id [:db.part/db]",
49
+ :"db/cardinality"=>:"db.cardinality/one",
50
+ :"db.install/_attribute"=>:"db.part/db",
51
+ :"db/ident"=>:"mouse/age",
52
+ :"db/valueType"=>:"db.type/long"}]
53
+ }
54
+
55
+ before do
56
+ @db_uri = ENV['DATOMIC_URI'] || 'http://localhost:46291'
57
+ @storage = ENV['DATOMIC_STORAGE'] || 'free'
58
+ @dbname = ENV['DATOMIC_NAME'] || "mouse-#{SecureRandom.uuid}"
59
+ @connection_options = {
60
+ :uri => @db_uri,
61
+ :storage => @storage,
62
+ :database => @dbname
63
+ }
64
+ Diametric::Persistence::REST.connect(@connection_options)
65
+ end
66
+
67
+ it "it should generate a schema" do
68
+ Mouse.schema.each do |e|
69
+ e.should be_an_equivalent_hash(expected.shift)
70
+ end
71
+ end
72
+
73
+ it "should create schema" do
74
+ expect { Diametric::Persistence::REST.create_schemas }.
75
+ not_to raise_exception
76
+ end
77
+ end
78
+
79
+ context ScarletMacaw do # Peer
80
+ let (:expected) {
81
+ [{:"db/id"=>"#db/id [:db.part/db]",
82
+ :"db/cardinality"=>:"db.cardinality/one",
83
+ :"db.install/_attribute"=>:"db.part/db",
84
+ :"db/ident"=>:"scarlet_macaw/name",
85
+ :"db/valueType"=>:"db.type/string"},
86
+ {:"db/id"=>"#db/id [:db.part/db]",
87
+ :"db/cardinality"=>:"db.cardinality/one",
88
+ :"db.install/_attribute"=>:"db.part/db",
89
+ :"db/ident"=>:"scarlet_macaw/description",
90
+ :"db/valueType"=>:"db.type/string",
91
+ :"db/fulltext"=>true},
92
+ {:"db/id"=>"#db/id [:db.part/db]",
93
+ :"db/cardinality"=>:"db.cardinality/one",
94
+ :"db.install/_attribute"=>:"db.part/db",
95
+ :"db/ident"=>:"scarlet_macaw/talkative",
96
+ :"db/valueType"=>:"db.type/boolean"},
97
+ {:"db/id"=>"#db/id [:db.part/db]",
98
+ :"db/cardinality"=>:"db.cardinality/one",
99
+ :"db.install/_attribute"=>:"db.part/db",
100
+ :"db/ident"=>:"scarlet_macaw/colors",
101
+ :"db/valueType"=>:"db.type/long"},
102
+ {:"db/id"=>"#db/id [:db.part/db]",
103
+ :"db/cardinality"=>:"db.cardinality/one",
104
+ :"db.install/_attribute"=>:"db.part/db",
105
+ :"db/ident"=>:"scarlet_macaw/average_speed",
106
+ :"db/valueType"=>:"db.type/double"},
107
+ {:"db/id"=>"#db/id [:db.part/db]",
108
+ :"db/cardinality"=>:"db.cardinality/one",
109
+ :"db.install/_attribute"=>:"db.part/db",
110
+ :"db/ident"=>:"scarlet_macaw/observed",
111
+ :"db/valueType"=>:"db.type/instant"},
112
+ {:"db/id"=>"#db/id [:db.part/db]",
113
+ :"db/cardinality"=>:"db.cardinality/one",
114
+ :"db.install/_attribute"=>:"db.part/db",
115
+ :"db/ident"=>:"scarlet_macaw/case_no",
116
+ :"db/valueType"=>:"db.type/uuid",
117
+ :"db/index"=>true},
118
+ {:"db/id"=>"#db/id [:db.part/db]",
119
+ :"db/cardinality"=>:"db.cardinality/one",
120
+ :"db.install/_attribute"=>:"db.part/db",
121
+ :"db/ident"=>:"scarlet_macaw/serial",
122
+ :"db/valueType"=>:"db.type/uuid",
123
+ :"db/unique"=>:"db.unique/value"}]
124
+ }
125
+
126
+ before do
127
+ datomic_uri = "datomic:mem://scarlet-macaw-#{SecureRandom.uuid}"
128
+ @conn = Diametric::Persistence::Peer.connect(datomic_uri)
129
+ end
130
+
131
+ after do
132
+ @conn.release
133
+ end
134
+
135
+ it "should generate a schema" do
136
+ ScarletMacaw.schema.each do |e|
137
+ e.should be_an_equivalent_hash(expected.shift)
138
+ end
139
+ end
140
+
141
+ it "should create schema" do
142
+ expect { ScarletMacaw.create_schema(@conn).get }.
143
+ not_to raise_exception
144
+ dbid = Diametric::Persistence::Peer.q("[:find ?e :in $ [?value ...] :where [?e :db/ident ?value]]", @conn.db, ":scarlet_macaw/serial").first.first
145
+ entity_fn = Java::ClojureLang::RT.var("datomic.api", "entity")
146
+ emap = entity_fn.invoke(@conn.db.to_java, dbid)
147
+ emap.get(":db/ident").to_s.should == ":scarlet_macaw/serial"
148
+ emap.get(":db/cardinality").to_s.should == ":db.cardinality/one"
149
+ emap.get(":db/valueType").to_s.should == ":db.type/uuid"
150
+ emap.get(":db/unique").to_s.should == ":db.unique/value"
151
+ end
152
+ end
153
+
154
+ context Peacock do # REST
155
+ let(:expected) {
156
+ [{:"db/id"=>"#db/id [:db.part/db]",
157
+ :"db/cardinality"=>:"db.cardinality/one",
158
+ :"db.install/_attribute"=>:"db.part/db",
159
+ :"db/ident"=>:"peacock/name",
160
+ :"db/valueType"=>:"db.type/string"},
161
+ {:"db/id"=>"#db/id [:db.part/db]",
162
+ :"db/cardinality"=>:"db.cardinality/one",
163
+ :"db.install/_attribute"=>:"db.part/db",
164
+ :"db/ident"=>:"peacock/description",
165
+ :"db/valueType"=>:"db.type/string",
166
+ :"db/fulltext"=>true},
167
+ {:"db/id"=>"#db/id [:db.part/db]",
168
+ :"db/cardinality"=>:"db.cardinality/one",
169
+ :"db.install/_attribute"=>:"db.part/db",
170
+ :"db/ident"=>:"peacock/talkative",
171
+ :"db/valueType"=>:"db.type/boolean"},
172
+ {:"db/id"=>"#db/id [:db.part/db]",
173
+ :"db/cardinality"=>:"db.cardinality/one",
174
+ :"db.install/_attribute"=>:"db.part/db",
175
+ :"db/ident"=>:"peacock/colors",
176
+ :"db/valueType"=>:"db.type/long"},
177
+ {:"db/id"=>"#db/id [:db.part/db]",
178
+ :"db/cardinality"=>:"db.cardinality/one",
179
+ :"db.install/_attribute"=>:"db.part/db",
180
+ :"db/ident"=>:"peacock/average_speed",
181
+ :"db/valueType"=>:"db.type/double"},
182
+ {:"db/id"=>"#db/id [:db.part/db]",
183
+ :"db/cardinality"=>:"db.cardinality/one",
184
+ :"db.install/_attribute"=>:"db.part/db",
185
+ :"db/ident"=>:"peacock/observed",
186
+ :"db/valueType"=>:"db.type/instant"},
187
+ {:"db/id"=>"#db/id [:db.part/db]",
188
+ :"db/cardinality"=>:"db.cardinality/one",
189
+ :"db.install/_attribute"=>:"db.part/db",
190
+ :"db/ident"=>:"peacock/case_no",
191
+ :"db/valueType"=>:"db.type/uuid",
192
+ :"db/index"=>true},
193
+ {:"db/id"=>"#db/id [:db.part/db]",
194
+ :"db/cardinality"=>:"db.cardinality/one",
195
+ :"db.install/_attribute"=>:"db.part/db",
196
+ :"db/ident"=>:"peacock/serial",
197
+ :"db/valueType"=>:"db.type/uuid",
198
+ :"db/unique"=>:"db.unique/value"}]
199
+ }
200
+
201
+ before do
202
+ @db_uri = ENV['DATOMIC_URI'] || 'http://localhost:46291'
203
+ @storage = ENV['DATOMIC_STORAGE'] || 'free'
204
+ @dbname = ENV['DATOMIC_NAME'] || "peacock-#{SecureRandom.uuid}"
205
+ @connection_options = {
206
+ :uri => @db_uri,
207
+ :storage => @storage,
208
+ :database => @dbname
209
+ }
210
+ Diametric::Persistence::REST.connect(@connection_options)
211
+ end
212
+
213
+ it "it should generate a schema" do
214
+ Peacock.schema.each do |e|
215
+ e.should be_an_equivalent_hash(expected.shift)
216
+ end
217
+ end
218
+
219
+ it "should create schema" do
220
+ expect { Diametric::Persistence::REST.create_schemas }.
221
+ not_to raise_exception
222
+ end
223
+ end
224
+
225
+ context MyWords do # Peer
226
+ let(:expected) {
227
+ [{:"db/id"=>"#db/id [:db.part/db]",
228
+ :"db/cardinality"=>:"db.cardinality/many",
229
+ :"db.install/_attribute"=>:"db.part/db",
230
+ :"db/ident"=>:"my_words/words",
231
+ :"db/valueType"=>:"db.type/string"}]
232
+ }
233
+
234
+ before do
235
+ datomic_uri = "datomic:mem://my-words-#{SecureRandom.uuid}"
236
+ @conn = Diametric::Persistence::Peer.connect(datomic_uri)
237
+ end
238
+
239
+ after do
240
+ @conn.release
241
+ end
242
+
243
+ it "should genemywordse a schema" do
244
+ MyWords.schema.each do |e|
245
+ e.should be_an_equivalent_hash(expected.shift)
246
+ end
247
+ end
248
+
249
+ it "should create schema" do
250
+ expect { MyWords.create_schema(@conn).get }.
251
+ not_to raise_exception
252
+ dbid = Diametric::Persistence::Peer.q("[:find ?e :in $ [?value ...] :where [?e :db/ident ?value]]", @conn.db, ":my_words/words").first.first
253
+ entity_fn = Java::ClojureLang::RT.var("datomic.api", "entity")
254
+ emap = entity_fn.invoke(@conn.db.to_java, dbid)
255
+ emap.get(":db/ident").to_s.should == ":my_words/words"
256
+ emap.get(":db/cardinality").to_s.should == ":db.cardinality/many"
257
+ emap.get(":db/valueType").to_s.should == ":db.type/string"
258
+ end
259
+ end
260
+
261
+ context YourWords do # REST
262
+ let(:expected) {
263
+ [{:"db/id"=>"#db/id [:db.part/db]",
264
+ :"db/cardinality"=>:"db.cardinality/many",
265
+ :"db.install/_attribute"=>:"db.part/db",
266
+ :"db/ident"=>:"your_words/words",
267
+ :"db/valueType"=>:"db.type/string"}]
268
+ }
269
+
270
+ before do
271
+ @db_uri = ENV['DATOMIC_URI'] || 'http://localhost:46291'
272
+ @storage = ENV['DATOMIC_STORAGE'] || 'free'
273
+ @dbname = ENV['DATOMIC_NAME'] || "your-words-#{SecureRandom.uuid}"
274
+ @connection_options = {
275
+ :uri => @db_uri,
276
+ :storage => @storage,
277
+ :database => @dbname
278
+ }
279
+ Diametric::Persistence::REST.connect(@connection_options)
280
+ end
281
+
282
+ it "it should generate a schema" do
283
+ YourWords.schema.each do |e|
284
+ e.should be_an_equivalent_hash(expected.shift)
285
+ end
286
+ end
287
+
288
+ it "should create schema" do
289
+ expect { Diametric::Persistence::REST.create_schemas }.
290
+ not_to raise_exception
291
+ end
292
+ end
293
+
294
+ context Cage do # Peer
295
+ let(:expected) {
296
+ [{:"db/id"=>"#db/id [:db.part/db]",
297
+ :"db/cardinality"=>:"db.cardinality/one",
298
+ :"db.install/_attribute"=>:"db.part/db",
299
+ :"db/ident"=>:"cage/pet",
300
+ :"db/valueType"=>:"db.type/ref"}]
301
+ }
302
+
303
+ before do
304
+ datomic_uri = "datomic:mem://cage-#{SecureRandom.uuid}"
305
+ @conn = Diametric::Persistence::Peer.connect(datomic_uri)
306
+ end
307
+
308
+ after do
309
+ @conn.release
310
+ end
311
+
312
+ it "should genemywordse a schema" do
313
+ Cage.schema.each do |e|
314
+ e.should be_an_equivalent_hash(expected.shift)
315
+ end
316
+ end
317
+
318
+ it "should create schema" do
319
+ expect { Cage.create_schema(@conn).get }.
320
+ not_to raise_exception
321
+ dbid = Diametric::Persistence::Peer.q("[:find ?e :in $ [?value ...] :where [?e :db/ident ?value]]", @conn.db, ":cage/pet").first.first
322
+ entity_fn = Java::ClojureLang::RT.var("datomic.api", "entity")
323
+ emap = entity_fn.invoke(@conn.db.to_java, dbid)
324
+ emap.get(":db/ident").to_s.should == ":cage/pet"
325
+ emap.get(":db/cardinality").to_s.should == ":db.cardinality/one"
326
+ emap.get(":db/valueType").to_s.should == ":db.type/ref"
327
+ end
328
+ end
329
+
330
+ context Box do # REST
331
+ let(:expected) {
332
+ [{:"db/id"=>"#db/id [:db.part/db]",
333
+ :"db/cardinality"=>:"db.cardinality/one",
334
+ :"db.install/_attribute"=>:"db.part/db",
335
+ :"db/ident"=>:"box/pet",
336
+ :"db/valueType"=>:"db.type/ref"}]
337
+ }
338
+
339
+ before do
340
+ @db_uri = ENV['DATOMIC_URI'] || 'http://localhost:46291'
341
+ @storage = ENV['DATOMIC_STORAGE'] || 'free'
342
+ @dbname = ENV['DATOMIC_NAME'] || "box-#{SecureRandom.uuid}"
343
+ @connection_options = {
344
+ :uri => @db_uri,
345
+ :storage => @storage,
346
+ :database => @dbname
347
+ }
348
+ Diametric::Persistence::REST.connect(@connection_options)
349
+ end
350
+
351
+ it "it should generate a schema" do
352
+ Box.schema.each do |e|
353
+ e.should be_an_equivalent_hash(expected.shift)
354
+ end
355
+ end
356
+
357
+ it "should create schema" do
358
+ expect { Diametric::Persistence::REST.create_schemas }.
359
+ not_to raise_exception
360
+ end
361
+ end
362
+
363
+ context Author do # Peer
364
+ let(:expected) {
365
+ [{:"db/id"=>"#db/id [:db.part/db]",
366
+ :"db/cardinality"=>:"db.cardinality/one",
367
+ :"db.install/_attribute"=>:"db.part/db",
368
+ :"db/ident"=>:"author/name",
369
+ :"db/valueType"=>:"db.type/string"},
370
+ {:"db/id"=>"#db/id [:db.part/db]",
371
+ :"db/cardinality"=>:"db.cardinality/many",
372
+ :"db.install/_attribute"=>:"db.part/db",
373
+ :"db/ident"=>:"author/books",
374
+ :"db/valueType"=>:"db.type/ref"}]
375
+ }
376
+
377
+ before do
378
+ datomic_uri = "datomic:mem://author-#{SecureRandom.uuid}"
379
+ @conn = Diametric::Persistence::Peer.connect(datomic_uri)
380
+ end
381
+
382
+ after do
383
+ @conn.release
384
+ end
385
+
386
+ it "should genemywordse a schema" do
387
+ Author.schema.each do |e|
388
+ e.should be_an_equivalent_hash(expected.shift)
389
+ end
390
+ end
391
+
392
+ it "should create schema" do
393
+ expect { Author.create_schema(@conn).get }.
394
+ not_to raise_exception
395
+ dbid = Diametric::Persistence::Peer.q("[:find ?e :in $ [?value ...] :where [?e :db/ident ?value]]", @conn.db, ":author/books").first.first
396
+ entity_fn = Java::ClojureLang::RT.var("datomic.api", "entity")
397
+ emap = entity_fn.invoke(@conn.db.to_java, dbid)
398
+ emap.get(":db/ident").to_s.should == ":author/books"
399
+ emap.get(":db/cardinality").to_s.should == ":db.cardinality/many"
400
+ emap.get(":db/valueType").to_s.should == ":db.type/ref"
401
+ end
402
+ end
403
+
404
+ context Writer do # REST
405
+ let(:expected) {
406
+ [{:"db/id"=>"#db/id [:db.part/db]",
407
+ :"db/cardinality"=>:"db.cardinality/one",
408
+ :"db.install/_attribute"=>:"db.part/db",
409
+ :"db/ident"=>:"writer/name",
410
+ :"db/valueType"=>:"db.type/string"},
411
+ {:"db/id"=>"#db/id [:db.part/db]",
412
+ :"db/cardinality"=>:"db.cardinality/many",
413
+ :"db.install/_attribute"=>:"db.part/db",
414
+ :"db/ident"=>:"writer/books",
415
+ :"db/valueType"=>:"db.type/ref"}]
416
+ }
417
+
418
+ before do
419
+ @db_uri = ENV['DATOMIC_URI'] || 'http://localhost:46291'
420
+ @storage = ENV['DATOMIC_STORAGE'] || 'free'
421
+ @dbname = ENV['DATOMIC_NAME'] || "writer-#{SecureRandom.uuid}"
422
+ @connection_options = {
423
+ :uri => @db_uri,
424
+ :storage => @storage,
425
+ :database => @dbname
426
+ }
427
+ Diametric::Persistence::REST.connect(@connection_options)
428
+ end
429
+
430
+ it "it should generate a schema" do
431
+ Writer.schema.each do |e|
432
+ e.should be_an_equivalent_hash(expected.shift)
433
+ end
434
+ end
435
+
436
+ it "should create schema" do
437
+ expect { Diametric::Persistence::REST.create_schemas }.
438
+ not_to raise_exception
439
+ end
440
+ end
441
+
442
+ context Role do # Peer
443
+ let(:expected) {
444
+ [
445
+ {:"db/id"=>"#db/id [:db.part/db]",
446
+ :"db/cardinality"=>:"db.cardinality/one",
447
+ :"db.install/_attribute"=>:"db.part/db",
448
+ :"db/ident"=>:"role/type",
449
+ :"db/valueType"=>:"db.type/ref"},
450
+ [:"db/add", "#db/id [:db.part/user]", :"db/ident", :"role.type/accountant"],
451
+ [:"db/add", "#db/id [:db.part/user]", :"db/ident", :"role.type/manager"],
452
+ [:"db/add", "#db/id [:db.part/user]", :"db/ident", :"role.type/developer"]
453
+ ]
454
+ }
455
+
456
+ before do
457
+ datomic_uri = "datomic:mem://role-#{SecureRandom.uuid}"
458
+ @conn = Diametric::Persistence::Peer.connect(datomic_uri)
459
+ end
460
+
461
+ after do
462
+ @conn.release
463
+ end
464
+
465
+ it "should genemywordse a schema" do
466
+ Role.schema.each do |e|
467
+ if e.kind_of? Hash
468
+ e.should be_an_equivalent_hash(expected.shift)
469
+ elsif e.kind_of? Array
470
+ e.should be_an_equivalent_array(expected.shift)
471
+ end
472
+ end
473
+ end
474
+
475
+ it "should create schema" do
476
+ expect { Role.create_schema(@conn).get }.
477
+ not_to raise_exception
478
+ dbid = Diametric::Persistence::Peer.q("[:find ?e :in $ [?value ...] :where [?e :db/ident ?value]]", @conn.db, ":role.type/accountant").first.first
479
+ entity_fn = Java::ClojureLang::RT.var("datomic.api", "entity")
480
+ emap = entity_fn.invoke(@conn.db.to_java, dbid)
481
+ emap.get(":db/ident").to_s.should == ":role.type/accountant"
482
+ end
483
+ end
484
+
485
+ context Position do # REST
486
+ let(:expected) {
487
+ [
488
+ {:"db/id"=>"#db/id [:db.part/db]",
489
+ :"db/cardinality"=>:"db.cardinality/one",
490
+ :"db.install/_attribute"=>:"db.part/db",
491
+ :"db/ident"=>:"position/type",
492
+ :"db/valueType"=>:"db.type/ref"},
493
+ [:"db/add", "#db/id [:db.part/user]", :"db/ident", :"position.type/accountant"],
494
+ [:"db/add", "#db/id [:db.part/user]", :"db/ident", :"position.type/manager"],
495
+ [:"db/add", "#db/id [:db.part/user]", :"db/ident", :"position.type/developer"]
496
+ ]
497
+ }
498
+
499
+ before do
500
+ @db_uri = ENV['DATOMIC_URI'] || 'http://localhost:46291'
501
+ @storage = ENV['DATOMIC_STORAGE'] || 'free'
502
+ @dbname = ENV['DATOMIC_NAME'] || "position-#{SecureRandom.uuid}"
503
+ @connection_options = {
504
+ :uri => @db_uri,
505
+ :storage => @storage,
506
+ :database => @dbname
507
+ }
508
+ Diametric::Persistence::REST.connect(@connection_options)
509
+ end
510
+
511
+ it "it should generate a schema" do
512
+ Position.schema.each do |e|
513
+ if e.kind_of? Hash
514
+ e.should be_an_equivalent_hash(expected.shift)
515
+ elsif e.kind_of? Array
516
+ e.should be_an_equivalent_array(expected.shift)
517
+ end
518
+ end
519
+ end
520
+
521
+ it "should create schema" do
522
+ expect { Diametric::Persistence::REST.create_schemas }.
523
+ not_to raise_exception
524
+ end
525
+ end
526
+ end