rincon_client 0.1.1

A typesafe client for the ArangoDB Rest API
Documentation
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535

#[macro_use] extern crate serde_derive;
extern crate tokio_core;

extern crate rincon_core;
extern crate rincon_connector;
extern crate rincon_client;
extern crate rincon_test_helper;

use rincon_core::api::connector::Execute;
use rincon_core::api::types::EMPTY;
use rincon_client::document::types::NewDocument;
use rincon_client::graph::methods::*;
use rincon_client::graph::types::*;

use rincon_test_helper::*;


#[test]
fn create_graph() {
    arango_test_with_user_db("test_graph_user10", "test_graph_db10", |conn, ref mut core| {

        let edge_defs = vec![
            EdgeDefinition::new("UsersInGroups",
                vec!["Users".to_owned()],
                vec!["Groups".to_owned()]
            ),
        ];

        #[cfg(not(feature = "enterprise"))]
        let new_graph = NewGraph::new("test_graph1", edge_defs.clone());
        #[cfg(feature = "enterprise")]
        let new_graph = NewGraph::new("test_graph1", edge_defs.clone(), false);

        let method = CreateGraph::new(new_graph);
        let graph = core.run(conn.execute(method)).unwrap();

        assert_eq!("_graphs", graph.id().collection_name());
        assert_eq!("test_graph1", graph.id().document_key());
        assert_eq!("test_graph1", graph.key().as_str());
        assert!(!graph.revision().as_str().is_empty());
        assert_eq!("test_graph1", graph.name());
        assert_eq!(edge_defs, graph.edge_definitions());
        assert_eq!(0, graph.orphan_collections().len());

        #[cfg(feature = "enterprise")]
        assert_eq!(false, graph.is_smart());
        #[cfg(feature = "enterprise")]
        assert_eq!("", graph.smart_graph_attribute());
    });
}

#[cfg(feature = "enterprise")]
#[test]
fn create_smart_graph() {
    arango_test_with_user_db("test_graph_user11", "test_graph_db11", |conn, ref mut core| {

        let edge_defs = vec![
            EdgeDefinition::new("UsersInGroups",
                vec!["Users".to_owned()],
                vec!["Groups".to_owned()]
            ),
        ];

        let mut new_graph = NewGraph::new("test_graph1", edge_defs.clone(), true);
        new_graph.options_mut().set_smart_graph_attribute("knows".to_owned());
        let new_graph = new_graph;

        let method = CreateGraph::new(new_graph);
        let graph = core.run(conn.execute(method)).unwrap();

        assert_eq!("_graphs", graph.id().collection_name());
        assert_eq!("test_graph1", graph.id().document_key());
        assert_eq!("test_graph1", graph.key().as_str());
        assert!(!graph.revision().as_str().is_empty());
        assert_eq!("test_graph1", graph.name());
        assert_eq!(edge_defs, graph.edge_definitions());
        assert_eq!(0, graph.orphan_collections().len());

        assert_eq!(true, graph.is_smart());
        assert_eq!("knows", graph.smart_graph_attribute());
    });
}

#[test]
fn create_graph_with_2_edge_definitions() {
    arango_test_with_user_db("test_graph_user12", "test_graph_db12", |conn, ref mut core| {

        let edge_defs = vec![
            EdgeDefinition::new("UsersInGroups",
                vec!["Users".to_owned()],
                vec!["Groups".to_owned()]
            ),
            EdgeDefinition::new("UsersKnowsUsers",
                vec!["Users".to_owned()],
                vec!["Users".to_owned()]
            ),
        ];

        #[cfg(not(feature = "enterprise"))]
        let new_graph = NewGraph::new("test_graph1", edge_defs.clone());
        #[cfg(feature = "enterprise")]
        let new_graph = NewGraph::new("test_graph1", edge_defs.clone(), false);

        let method = CreateGraph::new(new_graph);
        let graph = core.run(conn.execute(method)).unwrap();

        assert_eq!("_graphs", graph.id().collection_name());
        assert_eq!("test_graph1", graph.id().document_key());
        assert_eq!("test_graph1", graph.key().as_str());
        assert!(!graph.revision().as_str().is_empty());
        assert_eq!("test_graph1", graph.name());
        assert_eq!(edge_defs, graph.edge_definitions());
        assert_eq!(0, graph.orphan_collections().len());

        #[cfg(feature = "enterprise")]
            assert_eq!(false, graph.is_smart());
        #[cfg(feature = "enterprise")]
            assert_eq!("", graph.smart_graph_attribute());
    });
}

#[test]
fn drop_graph() {
    arango_test_with_user_db("test_graph_user20", "test_graph_db20", |conn, ref mut core| {

        let edge_defs = vec![
            EdgeDefinition::new("UsersInGroups",
                vec!["Users".to_owned()],
                vec!["Groups".to_owned()]
            ),
        ];
        #[cfg(not(feature = "enterprise"))]
        let new_graph = NewGraph::new("test_graph1", edge_defs);
        #[cfg(feature = "enterprise")]
        let new_graph = NewGraph::new("test_graph1", edge_defs, false);
        let graph = core.run(conn.execute(CreateGraph::new(new_graph))).unwrap();
        assert_eq!("_graphs/test_graph1".to_owned(), graph.id().to_string());

        let method = DropGraph::with_name("test_graph1");
        let deleted = core.run(conn.execute(method)).unwrap();

        assert_eq!(true, deleted);
    });
}

#[test]
fn get_graph() {
    arango_test_with_user_db("test_graph_user30", "test_graph_db30", |conn, ref mut core| {

        let edge_defs = vec![
            EdgeDefinition::new("UsersInGroups",
                vec!["Users".to_owned()],
                vec!["Groups".to_owned()]
            ),
        ];
        #[cfg(not(feature = "enterprise"))]
        let new_graph = NewGraph::new("test_graph1", edge_defs);
        #[cfg(feature = "enterprise")]
        let new_graph = NewGraph::new("test_graph1", edge_defs, false);
        let created = core.run(conn.execute(CreateGraph::new(new_graph))).unwrap();
        assert_eq!("_graphs/test_graph1".to_owned(), created.id().to_string());

        let method = GetGraph::with_name("test_graph1");
        let graph = core.run(conn.execute(method)).unwrap();

        assert_eq!(created, graph);
    });
}

#[test]
fn list_graphs() {
    arango_test_with_user_db("test_graph_user40", "test_graph_db40", |conn, ref mut core| {

        let edge_defs1 = vec![
            EdgeDefinition::new("UsersInGroups",
                vec!["Users".to_owned()],
                vec!["Groups".to_owned()]
            ),
        ];
        #[cfg(not(feature = "enterprise"))]
        let new_graph1 = NewGraph::new("test_graph1", edge_defs1);
        #[cfg(feature = "enterprise")]
        let new_graph1 = NewGraph::new("test_graph1", edge_defs1, false);
        let created1 = core.run(conn.execute(CreateGraph::new(new_graph1))).unwrap();
        assert_eq!("_graphs/test_graph1".to_owned(), created1.id().to_string());

        let edge_defs2 = vec![
            EdgeDefinition::new("UsersKnowsUsers",
                vec!["Users".to_owned()],
                vec!["Users".to_owned()]
            ),
        ];
        #[cfg(not(feature = "enterprise"))]
        let new_graph2 = NewGraph::new("test_graph2", edge_defs2);
        #[cfg(feature = "enterprise")]
        let new_graph2 = NewGraph::new("test_graph2", edge_defs2, false);
        let created2 = core.run(conn.execute(CreateGraph::new(new_graph2))).unwrap();
        assert_eq!("_graphs/test_graph2".to_owned(), created2.id().to_string());

        let method = ListGraphs::new();
        let graphs = core.run(conn.execute(method)).unwrap();

        let graph1 = graphs.iter().find(|g| g.name() == "test_graph1").unwrap();
        let graph2 = graphs.iter().find(|g| g.name() == "test_graph2").unwrap();
        assert_eq!(&created1, graph1);
        assert_eq!(&created2, graph2);
    });
}

#[test]
fn add_vertex_collection() {
    arango_test_with_user_db("test_graph_user50", "test_graph_db50", |conn, ref mut core| {

        let edge_defs = vec![
            EdgeDefinition::new("UsersInGroups",
                vec!["Users".to_owned()],
                vec!["Groups".to_owned()]
            ),
        ];
        #[cfg(not(feature = "enterprise"))]
        let new_graph = NewGraph::new("test_graph1", edge_defs);
        #[cfg(feature = "enterprise")]
        let new_graph = NewGraph::new("test_graph1", edge_defs, false);
        let created = core.run(conn.execute(CreateGraph::new(new_graph))).unwrap();
        assert_eq!("_graphs/test_graph1".to_owned(), created.id().to_string());
        assert_eq!(0, created.orphan_collections().len());

        let vertex_collection = VertexCollection::new("other_vertices");
        let method = AddVertexCollection::new("test_graph1", vertex_collection);
        let graph = core.run(conn.execute(method)).unwrap();

        assert_eq!("_graphs", graph.id().collection_name());
        assert_eq!("test_graph1", graph.id().document_key());
        assert_eq!(1, graph.orphan_collections().len());
        assert!(graph.orphan_collections().contains(&"other_vertices".to_owned()));
    });
}

#[test]
fn remove_vertex_collection() {
    arango_test_with_user_db("test_graph_user60", "test_graph_db60", |conn, ref mut core| {

        let edge_defs = vec![
            EdgeDefinition::new("UsersInGroups",
                vec!["Users".to_owned()],
                vec!["Groups".to_owned()]
            ),
        ];
        #[cfg(not(feature = "enterprise"))]
        let new_graph = NewGraph::new("test_graph1", edge_defs)
            .with_orphan_collections(vec![
                "add_ons".to_owned(),
                "spare".to_owned()
            ]);
        #[cfg(feature = "enterprise")]
        let new_graph = NewGraph::new("test_graph1", edge_defs, false)
            .with_orphan_collections(vec![
                "add_ons".to_owned(),
                "spare".to_owned()
            ]);
        let created = core.run(conn.execute(CreateGraph::new(new_graph))).unwrap();
        assert_eq!("_graphs/test_graph1".to_owned(), created.id().to_string());
        assert_eq!(2, created.orphan_collections().len());

        let method = RemoveVertexCollection::new("test_graph1", "add_ons");
        let graph = core.run(conn.execute(method)).unwrap();

        assert_eq!("_graphs", graph.id().collection_name());
        assert_eq!("test_graph1", graph.id().document_key());
        assert_eq!(1, graph.orphan_collections().len());
        assert!(graph.orphan_collections().contains(&"spare".to_owned()));
    });
}

#[test]
fn list_vertex_collections() {
    arango_test_with_user_db("test_graph_user70", "test_graph_db70", |conn, ref mut core| {

        let edge_defs = vec![
            EdgeDefinition::new("UsersInGroups",
                vec!["Users".to_owned()],
                vec!["Groups".to_owned()]
            ),
        ];
        #[cfg(not(feature = "enterprise"))]
        let new_graph = NewGraph::new("test_graph1", edge_defs)
            .with_orphan_collections(vec![
                "add_ons".to_owned(),
                "spare".to_owned()
            ]);
        #[cfg(feature = "enterprise")]
        let new_graph = NewGraph::new("test_graph1", edge_defs, false)
            .with_orphan_collections(vec![
                "add_ons".to_owned(),
                "spare".to_owned()
            ]);
        let created = core.run(conn.execute(CreateGraph::new(new_graph))).unwrap();
        assert_eq!("_graphs/test_graph1".to_owned(), created.id().to_string());

        let method = ListVertexCollections::new("test_graph1");
        let vertices = core.run(conn.execute(method)).unwrap();

        assert!(vertices.contains(&"Users".to_owned()));
        assert!(vertices.contains(&"Groups".to_owned()));
        assert!(vertices.contains(&"add_ons".to_owned()));
        assert!(vertices.contains(&"spare".to_owned()));
        assert_eq!(4, vertices.len());
    });
}

#[test]
fn insert_vertex() {
    arango_test_with_user_db("test_graph_user120", "test_graph_db120", |conn, ref mut core| {

        let edge_defs = vec![
            EdgeDefinition::new("works_in",
                vec!["female".to_owned(), "male".to_owned()],
                vec!["city".to_owned()],
            ),
        ];
        #[cfg(not(feature = "enterprise"))]
        let new_graph = NewGraph::new("social", edge_defs);
        #[cfg(feature = "enterprise")]
        let new_graph = NewGraph::new("social", edge_defs, false);
        let created = core.run(conn.execute(CreateGraph::new(new_graph))).unwrap();
        assert_eq!("_graphs/social".to_owned(), created.id().to_string());

        #[derive(Debug, Serialize)]
        struct City {
            name: String,
        }

        let city_doc = NewDocument::from(City { name: "New Orleans".to_owned() });
        let method = InsertVertex::new("social", "city", city_doc);
        let doc_header = core.run(conn.execute(method)).unwrap();

        assert_eq!("city".to_owned(), doc_header.id().collection_name());
        assert!(!doc_header.key().as_str().is_empty());
        assert!(!doc_header.revision().as_str().is_empty());
    });
}

#[test]
fn add_edge_definition() {
    arango_test_with_user_db("test_graph_user80", "test_graph_db80", |conn, ref mut core| {

        let edge_defs = vec![
            EdgeDefinition::new("relation",
                vec!["female".to_owned(), "male".to_owned()],
                vec!["male".to_owned(), "female".to_owned()],
            ),
        ];
        #[cfg(not(feature = "enterprise"))]
        let new_graph = NewGraph::new("social", edge_defs);
        #[cfg(feature = "enterprise")]
        let new_graph = NewGraph::new("social", edge_defs, false);
        let created = core.run(conn.execute(CreateGraph::new(new_graph))).unwrap();
        assert_eq!("_graphs/social".to_owned(), created.id().to_string());

        let works_in = EdgeDefinition::new("works_in",
            vec!["female".to_owned(), "male".to_owned()],
            vec!["city".to_owned()],
        );
        let method = AddEdgeDefinition::new("social", works_in);
        let graph = core.run(conn.execute(method)).unwrap();

        assert_eq!("_graphs", graph.id().collection_name());
        assert_eq!("social", graph.id().document_key());
        assert_eq!("social", graph.name());
        let expected_edge_defs = vec![
            EdgeDefinition::new("relation",
                vec!["female".to_owned(), "male".to_owned()],
                vec!["female".to_owned(), "male".to_owned()],
            ),
            EdgeDefinition::new("works_in",
                vec!["female".to_owned(), "male".to_owned()],
                vec!["city".to_owned()],
            ),
        ];
        assert_eq!(&expected_edge_defs[..], graph.edge_definitions());
        assert!(graph.orphan_collections().is_empty());
    });
}

#[test]
fn remove_edge_definition() {
    arango_test_with_user_db("test_graph_user90", "test_graph_db90", |conn, ref mut core| {

        let edge_defs = vec![
            EdgeDefinition::new("relation",
                vec!["female".to_owned(), "male".to_owned()],
                vec!["male".to_owned(), "female".to_owned()],
            ),
            EdgeDefinition::new("works_in",
                vec!["female".to_owned(), "male".to_owned()],
                vec!["city".to_owned()],
            ),
        ];
        #[cfg(not(feature = "enterprise"))]
        let new_graph = NewGraph::new("social", edge_defs);
        #[cfg(feature = "enterprise")]
        let new_graph = NewGraph::new("social", edge_defs, false);
        let created = core.run(conn.execute(CreateGraph::new(new_graph))).unwrap();
        assert_eq!("_graphs/social".to_owned(), created.id().to_string());

        let method = RemoveEdgeDefinition::new("social", "works_in");
        let graph = core.run(conn.execute(method)).unwrap();

        assert_eq!("_graphs", graph.id().collection_name());
        assert_eq!("social", graph.id().document_key());
        assert_eq!("social", graph.name());
        let expected_edge_defs = vec![
            EdgeDefinition::new("relation",
                vec!["female".to_owned(), "male".to_owned()],
                vec!["female".to_owned(), "male".to_owned()],
            ),
        ];
        assert_eq!(&expected_edge_defs[..], graph.edge_definitions());
        assert_eq!(&vec!["city".to_owned()][..], graph.orphan_collections());
    });
}

#[test]
fn replace_edge_definition() {
    arango_test_with_user_db("test_graph_user100", "test_graph_db100", |conn, ref mut core| {

        let edge_defs = vec![
            EdgeDefinition::new("relation",
                vec!["female".to_owned(), "male".to_owned()],
                vec!["male".to_owned(), "female".to_owned()],
            ),
        ];
        #[cfg(not(feature = "enterprise"))]
        let new_graph = NewGraph::new("social", edge_defs);
        #[cfg(feature = "enterprise")]
        let new_graph = NewGraph::new("social", edge_defs, false);
        let created = core.run(conn.execute(CreateGraph::new(new_graph))).unwrap();
        assert_eq!("_graphs/social".to_owned(), created.id().to_string());

        let replacement_edge_def = EdgeDefinition::new("relation",
            vec!["female".to_owned(), "male".to_owned(), "animal".to_owned()],
            vec!["male".to_owned(), "female".to_owned(), "animal".to_owned()],
        );
        let method = ReplaceEdgeDefinition::new("social", "relation", replacement_edge_def);
        let graph = core.run(conn.execute(method)).unwrap();

        assert_eq!("_graphs", graph.id().collection_name());
        assert_eq!("social", graph.id().document_key());
        assert_eq!("social", graph.name());
        let expected_edge_defs = vec![
            EdgeDefinition::new("relation",
                vec!["animal".to_owned(), "female".to_owned(), "male".to_owned()],
                vec!["animal".to_owned(), "female".to_owned(), "male".to_owned()],
            ),
        ];
        assert_eq!(&expected_edge_defs[..], graph.edge_definitions());
        assert!(graph.orphan_collections().is_empty());
    });
}

#[test]
fn list_edge_collections() {
    arango_test_with_user_db("test_graph_user110", "test_graph_db110", |conn, ref mut core| {

        let edge_defs = vec![
            EdgeDefinition::new("relation",
                vec!["female".to_owned(), "male".to_owned()],
                vec!["male".to_owned(), "female".to_owned()],
            ),
            EdgeDefinition::new("works_in",
                vec!["female".to_owned(), "male".to_owned()],
                vec!["city".to_owned()],
            ),
        ];
        #[cfg(not(feature = "enterprise"))]
        let new_graph = NewGraph::new("social", edge_defs);
        #[cfg(feature = "enterprise")]
        let new_graph = NewGraph::new("social", edge_defs, false);
        let created = core.run(conn.execute(CreateGraph::new(new_graph))).unwrap();
        assert_eq!("_graphs/social".to_owned(), created.id().to_string());

        let method = ListEdgeCollections::new("social");
        let edges = core.run(conn.execute(method)).unwrap();

        assert!(edges.contains(&"relation".to_owned()));
        assert!(edges.contains(&"works_in".to_owned()));
        assert_eq!(2, edges.len());
    });
}

#[test]
fn insert_edge() {
    arango_test_with_user_db("test_graph_user130", "test_graph_db130", |conn, ref mut core| {

        let edge_defs = vec![
            EdgeDefinition::new("works_in",
                vec!["female".to_owned(), "male".to_owned()],
                vec!["city".to_owned()],
            ),
        ];
        #[cfg(not(feature = "enterprise"))]
        let new_graph = NewGraph::new("social", edge_defs);
        #[cfg(feature = "enterprise")]
        let new_graph = NewGraph::new("social", edge_defs, false);
        let created = core.run(conn.execute(CreateGraph::new(new_graph))).unwrap();
        assert_eq!("_graphs/social".to_owned(), created.id().to_string());

        #[derive(Debug, Serialize)]
        struct Person {
            name: String,
        }

        let person_doc = NewDocument::from(Person { name: "Jane Doe".to_owned() });
        let method = InsertVertex::new("social", "female", person_doc);
        let (person_id, _, _) = core.run(conn.execute(method)).unwrap().deconstruct();

        #[derive(Debug, Serialize)]
        struct City {
            name: String,
        }

        let city_doc = NewDocument::from(City { name: "New Orleans".to_owned() });
        let method = InsertVertex::new("social", "city", city_doc);
        let (city_id, _, _) = core.run(conn.execute(method)).unwrap().deconstruct();

        let works_in = NewEdge::new(person_id, city_id, EMPTY);
        let method = InsertEdge::new("social", "works_in", works_in);
        let edge_header = core.run(conn.execute(method)).unwrap();

        assert_eq!("works_in".to_owned(), edge_header.id().collection_name());
        assert!(!edge_header.key().as_str().is_empty());
        assert!(!edge_header.revision().as_str().is_empty());
    });
}