From 2083461192eaf88d66392f5d907d528868bb7417 Mon Sep 17 00:00:00 2001 From: Allan Clements Date: Fri, 8 Nov 2024 19:23:00 -0600 Subject: [PATCH] Supplanted integration_traversal tests into single parameterized test --- gremlin-client/tests/integration_traversal.rs | 654 ++-- .../tests/integration_traversal_omni.rs | 2803 ----------------- .../tests/integration_traversal_v2.rs | 1837 ----------- 3 files changed, 386 insertions(+), 4908 deletions(-) delete mode 100644 gremlin-client/tests/integration_traversal_omni.rs delete mode 100644 gremlin-client/tests/integration_traversal_v2.rs diff --git a/gremlin-client/tests/integration_traversal.rs b/gremlin-client/tests/integration_traversal.rs index 78c4725a..f3bf4fe4 100644 --- a/gremlin-client/tests/integration_traversal.rs +++ b/gremlin-client/tests/integration_traversal.rs @@ -1,3 +1,4 @@ +use core::panic; use std::collections::HashMap; use std::convert::TryInto; @@ -7,14 +8,37 @@ use gremlin_client::structure::{ Cardinality, Column, List, Map, Pop, TextP, Vertex, VertexProperty, P, T, }; -use gremlin_client::{utils, GKey, GValue}; +use gremlin_client::{ + utils, BorrowFromGValue, GKey, GValue, GremlinClient, GremlinError, IoProtocol, +}; mod common; +use rstest::rstest; +use rstest_reuse::{self, *}; + +use serial_test::serial; + use common::io::{ - create_edge, create_vertex, create_vertex_with_label, drop_edges, drop_vertices, graph, + create_edge, create_vertex, create_vertex_with_label, drop_edges, drop_vertices, + graph_serializer, }; +//GraphSONV2 doesn't appear to support merge steps, so ommit it from +//being one of the serializers tested for those tests +#[template] +#[rstest] +#[case::graphson_v3(graph_serializer(IoProtocol::GraphSONV3))] +#[case::graph_binary_v1(graph_serializer(IoProtocol::GraphBinaryV1))] +fn merge_capable_serializers(#[case] client: GremlinClient) {} + +#[template] +#[rstest] +#[case::graphson_v2(graph_serializer(IoProtocol::GraphSONV2))] +#[case::graphson_v3(graph_serializer(IoProtocol::GraphSONV3))] +#[case::graph_binary_v1(graph_serializer(IoProtocol::GraphBinaryV1))] +fn serializers(#[case] client: GremlinClient) {} + #[cfg(feature = "merge_tests")] mod merge_tests { use super::*; @@ -25,9 +49,9 @@ mod merge_tests { }; use std::collections::HashMap; - #[test] - fn test_merge_v_no_options() { - let client = graph(); + #[apply(merge_capable_serializers)] + #[serial(test_merge_v_no_options)] + fn test_merge_v_no_options(client: GremlinClient) { let test_vertex_label = "test_merge_v_no_options"; drop_vertices(&client, test_vertex_label) .expect("Failed to drop vertices in case of rerun"); @@ -60,9 +84,9 @@ mod merge_tests { assert_map_property(&vertex_properties, "propertyKey", "propertyValue"); } - #[test] - fn test_merge_v_options() { - let client = graph(); + #[apply(merge_capable_serializers)] + #[serial(test_merge_v_options)] + fn test_merge_v_options(client: GremlinClient) { let expected_label = "test_merge_v_options"; drop_vertices(&client, expected_label).expect("Failed to drop vertices"); let g = traversal().with_remote(client); @@ -111,9 +135,9 @@ mod merge_tests { assert_map_property(&on_match_vertex_map, prop_key, expected_on_match_prop_value); } - #[test] - fn test_merge_v_start_step() { - let client = graph(); + #[apply(merge_capable_serializers)] + #[serial(test_merge_v_start_step)] + fn test_merge_v_start_step(client: GremlinClient) { let expected_label = "test_merge_v_start_step"; drop_vertices(&client, &expected_label).expect("Failed to drop vertiecs"); let g = traversal().with_remote(client); @@ -128,9 +152,9 @@ mod merge_tests { assert_eq!(expected_label, actual_vertex.label()) } - #[test] - fn test_merge_v_anonymous_traversal() { - let client = graph(); + #[apply(merge_capable_serializers)] + #[serial(test_merge_v_anonymous_traversal)] + fn test_merge_v_anonymous_traversal(client: GremlinClient) { let expected_label = "test_merge_v_anonymous_traversal"; drop_vertices(&client, &expected_label).expect("Failed to drop vertiecs"); let g = traversal().with_remote(client); @@ -146,9 +170,9 @@ mod merge_tests { assert_eq!(expected_label, actual_vertex.label()) } - #[test] - fn test_merge_e_start_step() { - let client = graph(); + #[apply(merge_capable_serializers)] + #[serial(test_merge_e_start_step)] + fn test_merge_e_start_step(client: GremlinClient) { let expected_vertex_label = "test_merge_e_start_step_vertex"; let expected_edge_label = "test_merge_e_start_step_edge"; let expected_edge_property_key = "test_merge_e_start_step_edge_prop"; @@ -199,6 +223,7 @@ mod merge_tests { let incoming_vertex_id = incoming_vertex .get("id") + .or(incoming_vertex.get(T::Id)) .expect("Should have returned vertex id"); assert_eq!(incoming_vertex_id, &vertex_a.id().to_gvalue()); @@ -209,13 +234,14 @@ mod merge_tests { .unwrap(); let outgoing_vertex_id = outgoing_vertex .get("id") + .or(outgoing_vertex.get(T::Id)) .expect("Should have returned vertex id"); assert_eq!(outgoing_vertex_id, &vertex_b.id().to_gvalue()); } - #[test] - fn test_merge_e_no_options() { - let client = graph(); + #[apply(merge_capable_serializers)] + #[serial(test_merge_e_no_options)] + fn test_merge_e_no_options(client: GremlinClient) { let expected_vertex_label = "test_merge_e_no_options_vertex"; let expected_edge_label = "test_merge_e_no_options_edge"; let expected_edge_property_key = "test_merge_e_no_options_edge_prop"; @@ -268,6 +294,7 @@ mod merge_tests { .unwrap(); let incoming_vertex_id = incoming_vertex .get("id") + .or(incoming_vertex.get(T::Id)) .expect("Should have returned vertex id"); assert_eq!(incoming_vertex_id, &vertex_a.id().to_gvalue()); @@ -278,13 +305,14 @@ mod merge_tests { .unwrap(); let outgoing_vertex_id = outgoing_vertex .get("id") + .or(outgoing_vertex.get(T::Id)) .expect("Should have returned vertex id"); assert_eq!(outgoing_vertex_id, &vertex_b.id().to_gvalue()); } - #[test] - fn test_merge_e_options() { - let client = graph(); + #[apply(merge_capable_serializers)] + #[serial(test_merge_e_options)] + fn test_merge_e_options(client: GremlinClient) { let expected_vertex_label = "test_merge_e_options_vertex"; let expected_edge_label = "test_merge_e_options_edge"; let expected_edge_property_key = "test_merge_e_options_edge_prop"; @@ -352,9 +380,9 @@ mod merge_tests { ); } - #[test] - fn test_merge_e_anonymous_traversal() { - let client = graph(); + #[apply(merge_capable_serializers)] + #[serial(test_merge_e_anonymous_traversal)] + fn test_merge_e_anonymous_traversal(client: GremlinClient) { let expected_vertex_label = "test_merge_e_options_vertex"; let expected_edge_label = "test_merge_e_options_edge"; drop_vertices(&client, &expected_vertex_label).expect("Failed to drop vertiecs"); @@ -393,6 +421,7 @@ mod merge_tests { .unwrap(); let incoming_vertex_id = incoming_vertex .get("id") + .or(incoming_vertex.get(T::Id)) .expect("Should have returned vertex id"); assert_eq!(incoming_vertex_id, &vertex_a.id().to_gvalue()); @@ -403,14 +432,16 @@ mod merge_tests { .unwrap(); let outgoing_vertex_id = outgoing_vertex .get("id") + .or(outgoing_vertex.get(T::Id)) .expect("Should have returned vertex id"); assert_eq!(outgoing_vertex_id, &vertex_b.id().to_gvalue()); } - #[test] - fn test_merge_v_into_merge_e() { + #[apply(merge_capable_serializers)] + #[serial(test_merge_v_into_merge_e)] + fn test_merge_v_into_merge_e(client: GremlinClient) { //Based on the reference doc's combo example - let client = graph(); + let expected_vertex_label = "test_merge_v_into_merge_e_vertex"; let expected_edge_label = "test_merge_v_into_merge_e_edge"; drop_vertices(&client, &expected_vertex_label).expect("Failed to drop vertiecs"); @@ -455,6 +486,7 @@ mod merge_tests { .unwrap(); let brandy_vertex_id = brandy_vertex .get("id") + .or(brandy_vertex.get(T::Id)) .expect("Should have returned vertex id"); assert_eq!(*brandy_vertex_id, GValue::Int64(expected_brandy_id)); @@ -465,6 +497,7 @@ mod merge_tests { .unwrap(); let toby_vertex_id = toby_vertex .get("id") + .or(toby_vertex.get(T::Id)) .expect("Should have returned vertex id"); assert_eq!(*toby_vertex_id, GValue::Int64(expected_toby_id)); @@ -472,18 +505,20 @@ mod merge_tests { } } -#[test] -fn test_simple_vertex_traversal() { - let g = traversal().with_remote(graph()); +#[apply(serializers)] +#[serial(test_simple_vertex_traversal)] +fn test_simple_vertex_traversal(client: GremlinClient) { + let g = traversal().with_remote(client); let results = g.v(()).to_list().unwrap(); assert!(results.len() > 0); } -#[test] -fn test_inject() { - let g = traversal().with_remote(graph()); +#[apply(serializers)] +#[serial(test_inject)] +fn test_inject(client: GremlinClient) { + let g = traversal().with_remote(client); let expected_value = "foo"; let response: String = g .inject(vec![expected_value.into()]) @@ -495,10 +530,9 @@ fn test_inject() { assert_eq!(expected_value, response); } -#[test] -fn test_simple_vertex_traversal_with_id() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_simple_vertex_traversal_with_id)] +fn test_simple_vertex_traversal_with_id(client: GremlinClient) { let vertex = create_vertex(&client, "Traversal"); let g = traversal().with_remote(client); @@ -510,9 +544,9 @@ fn test_simple_vertex_traversal_with_id() { assert_eq!(vertex.id(), results[0].id()); } -#[test] -fn test_simple_vertex_traversal_with_multiple_id() { - let client = graph(); +#[apply(serializers)] +#[serial(test_simple_vertex_traversal_with_multiple_id)] +fn test_simple_vertex_traversal_with_multiple_id(client: GremlinClient) { drop_vertices(&client, "test_simple_vertex_traversal").unwrap(); let vertex = create_vertex_with_label(&client, "test_simple_vertex_traversal", "Traversal"); @@ -528,10 +562,9 @@ fn test_simple_vertex_traversal_with_multiple_id() { assert_eq!(vertex2.id(), results[1].id()); } -#[test] -fn test_simple_vertex_traversal_with_label() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_simple_vertex_traversal_with_label)] +fn test_simple_vertex_traversal_with_label(client: GremlinClient) { drop_vertices(&client, "test_simple_vertex_traversal_with_label").unwrap(); let vertex = create_vertex_with_label( @@ -553,10 +586,9 @@ fn test_simple_vertex_traversal_with_label() { assert_eq!(vertex.id(), results[0].id()); } -#[test] -fn test_simple_vertex_traversal_with_label_and_has() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_simple_vertex_traversal_with_label_and_has)] +fn test_simple_vertex_traversal_with_label_and_has(client: GremlinClient) { drop_vertices(&client, "test_simple_vertex_traversal_with_label_and_has").unwrap(); let vertex = create_vertex_with_label( @@ -621,19 +653,19 @@ fn test_simple_vertex_traversal_with_label_and_has() { assert_eq!(vertex.id(), results[0].id()); } -#[test] -fn test_simple_edge_traversal() { - let g = traversal().with_remote(graph()); +#[apply(serializers)] +#[serial(test_simple_edge_traversal)] +fn test_simple_edge_traversal(client: GremlinClient) { + let g = traversal().with_remote(client); let results = g.e(()).to_list().unwrap(); assert!(results.len() > 0); } -#[test] -fn test_simple_edge_traversal_id() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_simple_edge_traversal_id)] +fn test_simple_edge_traversal_id(client: GremlinClient) { let v = create_vertex(&client, "Traversal"); let v1 = create_vertex(&client, "Traversal"); @@ -648,10 +680,9 @@ fn test_simple_edge_traversal_id() { assert_eq!(e.id(), results[0].id()); } -#[test] -fn test_simple_edge_traversal_with_label() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_simple_edge_traversal_with_label)] +fn test_simple_edge_traversal_with_label(client: GremlinClient) { drop_edges(&client, "test_simple_edge_traversal_with_label").unwrap(); let v = create_vertex(&client, "Traversal"); @@ -672,10 +703,9 @@ fn test_simple_edge_traversal_with_label() { assert_eq!(e.id(), results[0].id()); } -#[test] -fn test_traversal() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_traversal)] +fn test_traversal(client: GremlinClient) { drop_edges(&client, "test_vertex_out_traversal").unwrap(); let v = create_vertex(&client, "Traversal"); @@ -815,9 +845,10 @@ fn test_traversal() { assert_eq!(0, results.len()); } -#[test] -fn test_add_v() { - let g = traversal().with_remote(graph()); +#[apply(serializers)] +#[serial(test_add_v)] +fn test_add_v(client: GremlinClient) { + let g = traversal().with_remote(client); let results = g.add_v("person").to_list().unwrap(); @@ -833,9 +864,9 @@ fn test_add_v() { assert_eq!("vertex", results[0].label()); } -#[test] -fn test_add_v_with_properties() { - let client = graph(); +#[apply(serializers)] +#[serial(test_add_v_with_properties)] +fn test_add_v_with_properties(client: GremlinClient) { let g = traversal().with_remote(client.clone()); let results = g @@ -878,10 +909,9 @@ fn test_add_v_with_properties() { ); } -#[test] -fn test_add_v_with_property_many() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_add_v_with_property_many)] +fn test_add_v_with_property_many(client: GremlinClient) { drop_vertices(&client, "test_add_v_with_property_many").unwrap(); let g = traversal().with_remote(client.clone()); @@ -928,10 +958,9 @@ fn test_add_v_with_property_many() { ); } -#[test] -fn test_has_many() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_has_many)] +fn test_has_many(client: GremlinClient) { drop_vertices(&client, "test_has_many").unwrap(); let g = traversal().with_remote(client.clone()); @@ -961,9 +990,9 @@ fn test_has_many() { assert_eq!(results.len(), 1); } -#[test] -fn test_add_e() { - let client = graph(); +#[apply(serializers)] +#[serial(test_add_e)] +fn test_add_e(client: GremlinClient) { let g = traversal().with_remote(client.clone()); let v = g @@ -1024,10 +1053,9 @@ fn test_add_e() { assert_eq!("knows", edges[0].label()); } -#[test] -fn test_label_step() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_label_step)] +fn test_label_step(client: GremlinClient) { let vertex = create_vertex(&client, "Traversal"); let g = traversal().with_remote(client); @@ -1039,10 +1067,9 @@ fn test_label_step() { assert_eq!("person", results[0]); } -#[test] -fn test_properties_step() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_properties_step)] +fn test_properties_step(client: GremlinClient) { let vertex = create_vertex(&client, "Traversal"); let g = traversal().with_remote(client); @@ -1064,10 +1091,9 @@ fn test_properties_step() { assert_eq!(0, results.len()); } -#[test] -fn test_property_map() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_property_map)] +fn test_property_map(client: GremlinClient) { let vertex = create_vertex(&client, "Traversal"); let g = traversal().with_remote(client); @@ -1111,10 +1137,9 @@ fn test_property_map() { assert_eq!(0, properties.len()); } -#[test] -fn test_values() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_values)] +fn test_values(client: GremlinClient) { let vertex = create_vertex(&client, "Traversal"); let g = traversal().with_remote(client); @@ -1140,10 +1165,9 @@ fn test_values() { assert_eq!(0, results.len()); } -#[test] -fn test_value_map() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_value_map)] +fn test_value_map(client: GremlinClient) { let g = traversal().with_remote(client); let vertices = g @@ -1162,9 +1186,7 @@ fn test_value_map() { assert_eq!( "test", - value["name"].get::().unwrap()[0] - .get::() - .unwrap() + get_map::(value, "name").unwrap().unwrap() ); let results = g.v(vertex.id()).value_map("name").to_list().unwrap(); @@ -1175,9 +1197,7 @@ fn test_value_map() { assert_eq!( "test", - value["name"].get::().unwrap()[0] - .get::() - .unwrap() + get_map::(value, "name").unwrap().unwrap() ); let results = g.v(vertex.id()).value_map("fake").to_list().unwrap(); @@ -1185,16 +1205,29 @@ fn test_value_map() { assert_eq!(0, results[0].len()); let results = g.v(vertex.id()).value_map(true).to_list().unwrap(); + assert_eq!(1, results.len()); + let value = &results[0]; - assert_eq!(true, results[0].get("id").is_some()); - assert_eq!(true, results[0].get("label").is_some()); + assert_eq!( + Some(vertex.id().get().unwrap()), + get_map_id(&value).unwrap() + ); + assert_eq!(Some(vertex.label()), get_map_label(&value).unwrap()); + assert_eq!( + Some("test".to_owned()).as_ref(), + get_map(&value, "name").unwrap() + ); + assert!(results[0].get("id").or(results[0].get(T::Id)).is_some()); + assert!(results[0] + .get("label") + .or(results[0].get(T::Label)) + .is_some()); assert_eq!(true, results[0].get("name").is_some()); } -#[test] -fn test_unwrap_map() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_unwrap_map)] +fn test_unwrap_map(client: GremlinClient) { let g = traversal().with_remote(client); let vertices = g @@ -1208,23 +1241,17 @@ fn test_unwrap_map() { let results = g.v(vertex.id()).value_map(true).next().unwrap().unwrap(); let v_id = vertex.id().get::().unwrap(); - let id = utils::unwrap_map::(&results, "id", 0); - let property = utils::unwrap_map::(&results, "name", 0); - let label = utils::unwrap_map::(&results, "label", 0); - - assert_eq!(id.is_ok(), true); - assert_eq!(property.is_ok(), true); - assert_eq!(label.is_ok(), true); - - assert_eq!(id.unwrap(), v_id); + let id = get_map_id(&results).unwrap(); + let property = get_map::(&results, "name").unwrap(); + let label = get_map_label(&results).unwrap(); + assert_eq!(id, Some(v_id)); assert_eq!(property.unwrap(), "test"); - assert_eq!(label.unwrap(), "test_value_map"); + assert_eq!(label, Some(vertex.label())); } -#[test] -fn test_element_map() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_element_map)] +fn test_element_map(client: GremlinClient) { let g = traversal().with_remote(client); let vertices = g @@ -1252,22 +1279,44 @@ fn test_element_map() { assert_eq!("test", value["name"].get::().unwrap()); let results = g.v(vertex.id()).element_map("fake").to_list().unwrap(); + let value = &results[0]; + assert_eq!(2, value.len()); + assert_eq!( + Some(vertex.id().get().unwrap()), + get_map_id(&value).unwrap() + ); + assert_eq!(Some(vertex.label()), get_map_label(&value).unwrap()); assert_eq!(2, results[0].len()); - assert_eq!(true, results[0].get("id").is_some()); - assert_eq!(true, results[0].get("label").is_some()); + assert!(results[0].get("id").or(results[0].get(T::Id)).is_some()); + assert!(results[0] + .get("label") + .or(results[0].get(T::Label)) + .is_some()); let results = g.v(vertex.id()).element_map(()).to_list().unwrap(); + let value = &results[0]; - assert_eq!(true, results[0].get("id").is_some()); - assert_eq!(true, results[0].get("label").is_some()); + assert_eq!( + Some(vertex.id().get().unwrap()), + get_map_id(&value).unwrap() + ); + assert_eq!(Some(vertex.label()), get_map_label(&value).unwrap()); + assert_eq!( + Some("test".to_owned()).as_ref(), + get_map(&value, "name").unwrap() + ); + assert!(results[0].get("id").or(results[0].get(T::Id)).is_some()); + assert!(results[0] + .get("label") + .or(results[0].get(T::Label)) + .is_some()); assert_eq!(true, results[0].get("name").is_some()); } -#[test] -fn test_count() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_count)] +fn test_count(client: GremlinClient) { let vertex = create_vertex_with_label(&client, "test_count", "Count"); let g = traversal().with_remote(client); @@ -1281,10 +1330,9 @@ fn test_count() { assert_eq!(&1, value); } -#[test] -fn test_group_count_step() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_group_count_step)] +fn test_group_count_step(client: GremlinClient) { drop_vertices(&client, "test_group_count").unwrap(); let vertex = create_vertex_with_label(&client, "test_group_count", "Count"); @@ -1295,14 +1343,36 @@ fn test_group_count_step() { .v(()) .has_label("test_group_count") .group_count() - .to_list() + //Normalize the keys to a common type of Id across serializers + .by(T::Id) + .next() .unwrap(); - assert_eq!(1, results.len()); + let value = results.expect("Should have returned a map"); + assert_eq!(1, value.len(), "Should only have 1 entry in map"); + let (actual_key, actual_value) = value.into_iter().next().unwrap(); - let value = &results[0]; + //The actual key may come back as either an int or a string depending + //on the serializer, so normalize it and the vertex gid to a string + let normalized_actual_key = match actual_key { + GKey::String(v) => v, + GKey::Int64(v) => v.to_string(), + other => panic!("Unexpected key type: {:?}", other), + }; + + let normalized_vertex_id = match vertex.id() { + gremlin_client::GID::String(v) => v.clone(), + gremlin_client::GID::Int32(v) => v.to_string(), + gremlin_client::GID::Int64(v) => v.to_string(), + }; - assert_eq!(&1, value[&vertex].get::().unwrap()); + assert_eq!(normalized_actual_key, normalized_vertex_id); + + assert_eq!( + actual_value, + GValue::Int64(1), + "Group count should have been the single vertex" + ); let results = g .v(()) @@ -1333,10 +1403,9 @@ fn test_group_count_step() { assert_eq!(&1, value["test_group_count"].get::().unwrap()); } -#[test] -fn test_group_by_step() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_group_by_step)] +fn test_group_by_step(client: GremlinClient) { drop_vertices(&client, "test_group_by_step").unwrap(); create_vertex_with_label(&client, "test_group_by_step", "Count"); @@ -1389,10 +1458,9 @@ fn test_group_by_step() { assert_eq!(&1, value["test_group_by_step"].get::().unwrap()); } -#[test] -fn test_select_step() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_select_step)] +fn test_select_step(client: GremlinClient) { drop_vertices(&client, "test_select_step").unwrap(); create_vertex_with_label(&client, "test_select_step", "Count"); @@ -1415,10 +1483,9 @@ fn test_select_step() { assert_eq!(&1, value.get::().unwrap()); } -#[test] -fn test_fold_step() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_fold_step)] +fn test_fold_step(client: GremlinClient) { drop_vertices(&client, "test_fold_step").unwrap(); create_vertex_with_label(&client, "test_fold_step", "Count"); @@ -1440,10 +1507,9 @@ fn test_fold_step() { assert_eq!("Count", value[0].get::().unwrap()); } -#[test] -fn test_unfold_step() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_unfold_step)] +fn test_unfold_step(client: GremlinClient) { drop_vertices(&client, "test_unfold_step").unwrap(); let vertex = create_vertex_with_label(&client, "test_unfold_step", "Count"); @@ -1471,10 +1537,9 @@ fn test_unfold_step() { ); } -#[test] -fn test_path_step() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_path_step)] +fn test_path_step(client: GremlinClient) { drop_vertices(&client, "test_path_step").unwrap(); let v = create_vertex_with_label(&client, "test_path_step", "Count"); @@ -1495,10 +1560,9 @@ fn test_path_step() { assert_eq!(v.id(), value.objects()[0].get::().unwrap().id()); } -#[test] -fn test_limit_step() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_limit_step)] +fn test_limit_step(client: GremlinClient) { drop_vertices(&client, "test_limit_step").unwrap(); create_vertex_with_label(&client, "test_limit_step", "Count"); @@ -1516,10 +1580,9 @@ fn test_limit_step() { assert_eq!(1, results.len()); } -#[test] -fn test_dedup_step() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_dedup_step)] +fn test_dedup_step(client: GremlinClient) { drop_vertices(&client, "test_limit_step").unwrap(); create_vertex_with_label(&client, "test_limit_step", "Count"); @@ -1538,10 +1601,9 @@ fn test_dedup_step() { assert_eq!(1, results.len()); } -#[test] -fn test_numerical_steps() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_numerical_steps)] +fn test_numerical_steps(client: GremlinClient) { drop_vertices(&client, "test_numerical_steps").unwrap(); let g = traversal().with_remote(client); @@ -1610,10 +1672,9 @@ fn test_numerical_steps() { assert_eq!(&20, results[0].get::().unwrap()); } -#[test] -fn test_has_with_p_steps() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_has_with_p_steps)] +fn test_has_with_p_steps(client: GremlinClient) { drop_vertices(&client, "test_has_with_p_steps").unwrap(); let g = traversal().with_remote(client); @@ -1650,6 +1711,29 @@ fn test_has_with_p_steps() { assert_eq!(&20, results[0].get::().unwrap()); + let results = g + .v(()) + .has(("test_has_with_p_steps", "age", 20)) + .values("age") + .to_list() + .unwrap(); + + assert_eq!(1, results.len()); + + assert_eq!(&20, results[0].get::().unwrap()); + + let results = g + .v(()) + .has_label("test_has_with_p_steps") + .values("age") + .where_(__.is(P::eq(20))) + .to_list() + .unwrap(); + + assert_eq!(1, results.len()); + + assert_eq!(&20, results[0].get::().unwrap()); + let results = g .v(()) .has_label("test_has_with_p_steps") @@ -1663,10 +1747,9 @@ fn test_has_with_p_steps() { assert_eq!(&20, results[0].get::().unwrap()); } -#[test] -fn test_has_with_text_p_step() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_has_with_text_p_step)] +fn test_has_with_text_p_step(client: GremlinClient) { drop_vertices(&client, "test_has_with_text_p_step").unwrap(); let g = traversal().with_remote(client); @@ -1730,10 +1813,9 @@ fn test_has_with_text_p_step() { assert_eq!(2, results.len()); } -#[test] -fn where_step_test() { - let client = graph(); - +#[apply(serializers)] +#[serial(where_step_test)] +fn where_step_test(client: GremlinClient) { drop_vertices(&client, "where_step_test").unwrap(); let g = traversal().with_remote(client); @@ -1756,10 +1838,9 @@ fn where_step_test() { assert_eq!(v[0].id(), results[0].id()); } -#[test] -fn not_step_test() { - let client = graph(); - +#[apply(serializers)] +#[serial(not_step_test)] +fn not_step_test(client: GremlinClient) { drop_vertices(&client, "not_step_test").unwrap(); let g = traversal().with_remote(client); @@ -1779,10 +1860,9 @@ fn not_step_test() { assert_eq!(0, results.len()); } -#[test] -fn order_step_test() { - let client = graph(); - +#[apply(serializers)] +#[serial(order_step_test)] +fn order_step_test(client: GremlinClient) { drop_vertices(&client, "order_step_test").unwrap(); let g = traversal().with_remote(client); @@ -1823,10 +1903,9 @@ fn order_step_test() { assert_eq!("b", results[0].get::().unwrap()); } -#[test] -fn match_step_test() { - let client = graph(); - +#[apply(serializers)] +#[serial(match_step_test)] +fn match_step_test(client: GremlinClient) { drop_vertices(&client, "match_step_test").unwrap(); drop_edges(&client, "match_step_test_edge").unwrap(); @@ -1885,10 +1964,9 @@ fn match_step_test() { assert_eq!(&v3[0], first["c"].get::().unwrap()); } -#[test] -fn drop_step_test() { - let client = graph(); - +#[apply(serializers)] +#[serial(drop_step_test)] +fn drop_step_test(client: GremlinClient) { drop_vertices(&client, "drop_step_test").unwrap(); let g = traversal().with_remote(client); @@ -1918,10 +1996,9 @@ fn drop_step_test() { assert_eq!(false, results); } -#[test] -fn or_step_test() { - let client = graph(); - +#[apply(serializers)] +#[serial(or_step_test)] +fn or_step_test(client: GremlinClient) { drop_vertices(&client, "or_step_test").unwrap(); let g = traversal().with_remote(client); @@ -1959,10 +2036,9 @@ fn or_step_test() { assert_eq!(result.len(), 2); } -#[test] -fn iter_terminator_test() { - let client = graph(); - +#[apply(serializers)] +#[serial(iter_terminator_test)] +fn iter_terminator_test(client: GremlinClient) { drop_vertices(&client, "iter_terminator_test").unwrap(); let g = traversal().with_remote(client); @@ -1988,10 +2064,9 @@ fn iter_terminator_test() { assert_eq!(2, results.len()) } -#[test] -fn test_select_pop() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_select_pop)] +fn test_select_pop(client: GremlinClient) { drop_vertices(&client, "test_select_pop").unwrap(); drop_vertices(&client, "test_select_pop_child").unwrap(); @@ -2077,10 +2152,9 @@ fn test_select_pop() { assert_eq!(results.len(), 1); } -#[test] -fn test_repeat_until_loops_loops() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_repeat_until_loops_loops)] +fn test_repeat_until_loops_loops(client: GremlinClient) { drop_vertices(&client, "test_repeat_until_loops").unwrap(); drop_vertices(&client, "test_repeat_until_loops_child").unwrap(); @@ -2118,10 +2192,28 @@ fn test_repeat_until_loops_loops() { assert_eq!(results[0], e2[0]); } -#[test] -fn test_simple_path() { - let client = graph(); +#[apply(serializers)] +#[serial(test_simple_path)] +fn test_simple_vertex_property(client: GremlinClient) { + drop_vertices(&client, "test_simple_vertex_property").unwrap(); + + let g = traversal().with_remote(client); + + let v = g + .add_v("test_simple_vertex_property") + .property("name", "a") + .element_map(()) + .next() + .unwrap() + .unwrap(); + + let actual_property: &String = v.get("name").expect("Should have property").get().unwrap(); + assert_eq!(actual_property, "a"); +} +#[apply(serializers)] +#[serial(test_simple_path)] +fn test_simple_path(client: GremlinClient) { drop_vertices(&client, "test_simple_path").unwrap(); drop_vertices(&client, "test_simple_path_child").unwrap(); @@ -2160,10 +2252,9 @@ fn test_simple_path() { assert_eq!(results[0], e2[0]); } -#[test] -fn test_sample() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_sample)] +fn test_sample(client: GremlinClient) { drop_vertices(&client, "test_sample").unwrap(); drop_vertices(&client, "test_sample_child").unwrap(); @@ -2193,10 +2284,9 @@ fn test_sample() { assert_eq!(results.len(), 1); } -#[test] -fn test_local() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_local)] +fn test_local(client: GremlinClient) { drop_vertices(&client, "test_local").unwrap(); drop_vertices(&client, "test_local_child").unwrap(); drop_vertices(&client, "test_local_child_child").unwrap(); @@ -2269,9 +2359,9 @@ fn test_local() { assert_eq!(results.len(), 2); } -#[test] -fn test_side_effect() { - let client = graph(); +#[apply(serializers)] +#[serial(test_side_effect)] +fn test_side_effect(client: GremlinClient) { let test_vertex_label = "test_side_effect"; let expected_side_effect_key = "prop_key"; let expected_side_effect_value = "prop_val"; @@ -2298,9 +2388,9 @@ fn test_side_effect() { ); } -#[test] -fn test_anonymous_traversal_properties_drop() { - let client = graph(); +#[apply(serializers)] +#[serial(test_anonymous_traversal_properties_drop)] +fn test_anonymous_traversal_properties_drop(client: GremlinClient) { let test_vertex_label = "test_anonymous_traversal_properties_drop"; let pre_drop_prop_key = "pre_drop_prop_key"; let expected_prop_value = "prop_val"; @@ -2323,7 +2413,10 @@ fn test_anonymous_traversal_properties_drop() { //Make sure the property was assigned assert_map_property(&element_map, pre_drop_prop_key, expected_prop_value); - let created_vertex_id = element_map.get("id").expect("Should have id property"); + let created_vertex_id = element_map + .get("id") + .or(element_map.get(T::Id)) + .expect("Should have id property"); let GValue::Int64(id) = created_vertex_id else { panic!("Not expected id type"); }; @@ -2353,9 +2446,9 @@ fn test_anonymous_traversal_properties_drop() { ); } -#[test] -fn test_by_columns() { - let client = graph(); +#[apply(serializers)] +#[serial(test_by_columns)] +fn test_by_columns(client: GremlinClient) { let test_vertex_label = "test_by_columns"; let expected_side_effect_key_a = "prop_key_a"; let expected_side_effect_value_a = "prop_val_a"; @@ -2409,10 +2502,9 @@ fn test_by_columns() { ); } -#[test] -fn test_property_cardinality() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_property_cardinality)] +fn test_property_cardinality(client: GremlinClient) { drop_vertices(&client, "test_property_cardinality").unwrap(); let g = traversal().with_remote(client); @@ -2440,10 +2532,9 @@ fn test_property_cardinality() { assert_eq!(1, new_v["name"].get::().unwrap().len()); } -#[test] -fn test_choose() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_choose)] +fn test_choose(client: GremlinClient) { drop_vertices(&client, "test_choose").unwrap(); let g = traversal().with_remote(client); @@ -2482,9 +2573,9 @@ fn test_choose() { assert_eq!(success_vertices.is_some(), true); } -#[test] -fn test_choose_by_literal_options() { - let client = graph(); +#[apply(serializers)] +#[serial(test_choose_by_literal_options)] +fn test_choose_by_literal_options(client: GremlinClient) { let g = traversal().with_remote(client); let choosen_literal_a = g @@ -2510,10 +2601,9 @@ fn test_choose_by_literal_options() { assert_eq!(choosen_literal_b, Some("option-b".into())); } -#[test] -fn test_coalesce() { - let client = graph(); - +#[apply(serializers)] +#[serial()] +fn test_coalesce(client: GremlinClient) { use gremlin_client::GValue; drop_vertices(&client, "test_coalesce").unwrap(); @@ -2546,10 +2636,9 @@ fn test_coalesce() { assert!(values.contains(&String::from("b"))); } -#[test] -fn test_coalesce_unfold() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_coalesce_unfold)] +fn test_coalesce_unfold(client: GremlinClient) { drop_vertices(&client, "test_coalesce_unfold").unwrap(); let g = traversal().with_remote(client); @@ -2603,10 +2692,9 @@ fn test_coalesce_unfold() { ); } -#[test] -fn test_none_step() { - let client = graph(); - +#[apply(serializers)] +#[serial(test_none_step)] +fn test_none_step(client: GremlinClient) { drop_vertices(&client, "test_none_step").unwrap(); let g = traversal().with_remote(client); @@ -2631,15 +2719,45 @@ fn test_none_step() { assert_eq!(1, vertex_count); } -#[test] +fn get_map_id<'a>(map: &'a Map) -> Result, GremlinError> { + let string_keyed = get_map(map, "id")?; + if string_keyed.is_some() { + Ok(string_keyed) + } else { + get_map(map, T::Id) + } +} + +fn get_map_label<'a>(map: &'a Map) -> Result, GremlinError> { + let string_keyed = get_map(map, "label")?; + if string_keyed.is_some() { + Ok(string_keyed) + } else { + get_map(map, T::Label) + } +} + +fn get_map<'a, T, K>(map: &'a Map, key: K) -> Result, GremlinError> +where + T: BorrowFromGValue, + K: Into, +{ + map.get(key) + .map(|val| match val { + GValue::List(list) => list[0].get::(), + other => other.get::(), + }) + .transpose() +} + +#[apply(serializers)] +#[serial(test_traversal_vertex_mapping)] #[cfg(feature = "derive")] -fn test_traversal_vertex_mapping() { +fn test_traversal_vertex_mapping(client: GremlinClient) { use chrono::{DateTime, TimeZone, Utc}; use gremlin_client::derive::FromGMap; use std::convert::TryFrom; - let client = graph(); - drop_vertices(&client, "test_vertex_mapping").unwrap(); let g = traversal().with_remote(client); diff --git a/gremlin-client/tests/integration_traversal_omni.rs b/gremlin-client/tests/integration_traversal_omni.rs deleted file mode 100644 index f3bf4fe4..00000000 --- a/gremlin-client/tests/integration_traversal_omni.rs +++ /dev/null @@ -1,2803 +0,0 @@ -use core::panic; -use std::collections::HashMap; -use std::convert::TryInto; - -use common::assert_map_property; -use gremlin_client::process::traversal::{traversal, Order, __}; -use gremlin_client::structure::{ - Cardinality, Column, List, Map, Pop, TextP, Vertex, VertexProperty, P, T, -}; - -use gremlin_client::{ - utils, BorrowFromGValue, GKey, GValue, GremlinClient, GremlinError, IoProtocol, -}; - -mod common; - -use rstest::rstest; -use rstest_reuse::{self, *}; - -use serial_test::serial; - -use common::io::{ - create_edge, create_vertex, create_vertex_with_label, drop_edges, drop_vertices, - graph_serializer, -}; - -//GraphSONV2 doesn't appear to support merge steps, so ommit it from -//being one of the serializers tested for those tests -#[template] -#[rstest] -#[case::graphson_v3(graph_serializer(IoProtocol::GraphSONV3))] -#[case::graph_binary_v1(graph_serializer(IoProtocol::GraphBinaryV1))] -fn merge_capable_serializers(#[case] client: GremlinClient) {} - -#[template] -#[rstest] -#[case::graphson_v2(graph_serializer(IoProtocol::GraphSONV2))] -#[case::graphson_v3(graph_serializer(IoProtocol::GraphSONV3))] -#[case::graph_binary_v1(graph_serializer(IoProtocol::GraphBinaryV1))] -fn serializers(#[case] client: GremlinClient) {} - -#[cfg(feature = "merge_tests")] -mod merge_tests { - use super::*; - use gremlin_client::{ - process::traversal::{GraphTraversalSource, SyncTerminator}, - structure::{Direction, Merge}, - Edge, GValue, ToGValue, - }; - use std::collections::HashMap; - - #[apply(merge_capable_serializers)] - #[serial(test_merge_v_no_options)] - fn test_merge_v_no_options(client: GremlinClient) { - let test_vertex_label = "test_merge_v_no_options"; - drop_vertices(&client, test_vertex_label) - .expect("Failed to drop vertices in case of rerun"); - let g = traversal().with_remote(client); - - let mut injection_map: HashMap = HashMap::new(); - let mut lookup_map: HashMap = HashMap::new(); - lookup_map.insert(T::Label.into(), test_vertex_label.into()); - let mut property_map: HashMap = HashMap::new(); - property_map.insert("propertyKey".into(), "propertyValue".into()); - injection_map.insert("lookup".into(), lookup_map.into()); - injection_map.insert("properties".into(), property_map.into()); - - let vertex_properties = g - .inject(vec![injection_map.into()]) - .unfold() - .as_("payload") - .merge_v(__.select("lookup")) - .property( - "propertyKey", - __.select("payload") - .select("properties") - .select("propertyKey"), - ) - .element_map(()) - .next() - .expect("Should get response") - .expect("Should have returned a vertex"); - - assert_map_property(&vertex_properties, "propertyKey", "propertyValue"); - } - - #[apply(merge_capable_serializers)] - #[serial(test_merge_v_options)] - fn test_merge_v_options(client: GremlinClient) { - let expected_label = "test_merge_v_options"; - drop_vertices(&client, expected_label).expect("Failed to drop vertices"); - let g = traversal().with_remote(client); - let mut start_step_map: HashMap = HashMap::new(); - start_step_map.insert(T::Label.into(), expected_label.into()); - start_step_map.insert("identifing_prop".into(), "some_Value".into()); - - let prop_key = "some_prop"; - let mut on_create_map: HashMap = HashMap::new(); - let expected_on_create_prop_value = "on_create_value"; - on_create_map.insert(prop_key.into(), expected_on_create_prop_value.into()); - - let mut on_match_map: HashMap = HashMap::new(); - let expected_on_match_prop_value = "on_match_value"; - on_match_map.insert(prop_key.into(), expected_on_match_prop_value.into()); - - let on_create_vertex_map = g - .merge_v(start_step_map.clone()) - .option((Merge::OnCreate, on_create_map.clone())) - .option((Merge::OnMatch, on_match_map.clone())) - .element_map(()) - .next() - .expect("Should get a response") - .expect("Should return a vertex"); - - assert_map_property(&on_create_vertex_map, "label", expected_label); - - assert_map_property( - &on_create_vertex_map, - prop_key, - expected_on_create_prop_value, - ); - - //Now run the traversal again, and confirm the OnMatch applied this time - let on_match_vertex_map = g - .merge_v(start_step_map) - .option((Merge::OnCreate, on_create_map.clone())) - .option((Merge::OnMatch, on_match_map.clone())) - .element_map(()) - .next() - .expect("Should get a response") - .expect("Should return a vertex"); - - assert_map_property(&on_match_vertex_map, "label", expected_label); - - assert_map_property(&on_match_vertex_map, prop_key, expected_on_match_prop_value); - } - - #[apply(merge_capable_serializers)] - #[serial(test_merge_v_start_step)] - fn test_merge_v_start_step(client: GremlinClient) { - let expected_label = "test_merge_v_start_step"; - drop_vertices(&client, &expected_label).expect("Failed to drop vertiecs"); - let g = traversal().with_remote(client); - let mut start_step_map: HashMap = HashMap::new(); - start_step_map.insert(T::Label.into(), expected_label.into()); - let actual_vertex = g - .merge_v(start_step_map) - .next() - .expect("Should get a response") - .expect("Should return a vertex"); - - assert_eq!(expected_label, actual_vertex.label()) - } - - #[apply(merge_capable_serializers)] - #[serial(test_merge_v_anonymous_traversal)] - fn test_merge_v_anonymous_traversal(client: GremlinClient) { - let expected_label = "test_merge_v_anonymous_traversal"; - drop_vertices(&client, &expected_label).expect("Failed to drop vertiecs"); - let g = traversal().with_remote(client); - let mut start_step_map: HashMap = HashMap::new(); - start_step_map.insert(T::Label.into(), expected_label.into()); - let actual_vertex = g - .inject(1) - .unfold() - .coalesce::([__.merge_v(start_step_map)]) - .next() - .expect("Should get a response") - .expect("Should return a vertex"); - assert_eq!(expected_label, actual_vertex.label()) - } - - #[apply(merge_capable_serializers)] - #[serial(test_merge_e_start_step)] - fn test_merge_e_start_step(client: GremlinClient) { - let expected_vertex_label = "test_merge_e_start_step_vertex"; - let expected_edge_label = "test_merge_e_start_step_edge"; - let expected_edge_property_key = "test_merge_e_start_step_edge_prop"; - let expected_edge_property_value = "test_merge_e_start_step_edge_value"; - drop_vertices(&client, &expected_vertex_label).expect("Failed to drop vertiecs"); - let g = traversal().with_remote(client); - - let vertex_a = g - .add_v(expected_vertex_label) - .next() - .expect("Should get a response") - .expect("Should return a vertex"); - - let vertex_b = g - .add_v(expected_vertex_label) - .next() - .expect("Should get a response") - .expect("Should return a vertex"); - - let mut start_step_map: HashMap = HashMap::new(); - start_step_map.insert(Direction::In.into(), vertex_a.id().into()); - start_step_map.insert(Direction::Out.into(), vertex_b.id().into()); - start_step_map.insert(T::Label.into(), expected_edge_label.into()); - start_step_map.insert( - expected_edge_property_key.into(), - expected_edge_property_value.into(), - ); - let merged_edge_properties = g - .merge_e(start_step_map) - .element_map(()) - .next() - .expect("Should get a response") - .expect("Should return a edge properties"); - - assert_map_property(&merged_edge_properties, "label", expected_edge_label); - - assert_map_property( - &merged_edge_properties, - expected_edge_property_key, - expected_edge_property_value, - ); - - let incoming_vertex: &Map = merged_edge_properties - .get(Direction::In) - .expect("Should have returned incoming vertex info") - .get() - .unwrap(); - - let incoming_vertex_id = incoming_vertex - .get("id") - .or(incoming_vertex.get(T::Id)) - .expect("Should have returned vertex id"); - assert_eq!(incoming_vertex_id, &vertex_a.id().to_gvalue()); - - let outgoing_vertex: &Map = merged_edge_properties - .get(Direction::Out) - .expect("Should have returned outgoing vertex info") - .get() - .unwrap(); - let outgoing_vertex_id = outgoing_vertex - .get("id") - .or(outgoing_vertex.get(T::Id)) - .expect("Should have returned vertex id"); - assert_eq!(outgoing_vertex_id, &vertex_b.id().to_gvalue()); - } - - #[apply(merge_capable_serializers)] - #[serial(test_merge_e_no_options)] - fn test_merge_e_no_options(client: GremlinClient) { - let expected_vertex_label = "test_merge_e_no_options_vertex"; - let expected_edge_label = "test_merge_e_no_options_edge"; - let expected_edge_property_key = "test_merge_e_no_options_edge_prop"; - let expected_edge_property_value = "test_merge_e_no_options_edge_value"; - drop_vertices(&client, &expected_vertex_label).expect("Failed to drop vertiecs"); - let g = traversal().with_remote(client); - - let vertex_a = g - .add_v(expected_vertex_label) - .next() - .expect("Should get a response") - .expect("Should return a vertex"); - - let vertex_b = g - .add_v(expected_vertex_label) - .next() - .expect("Should get a response") - .expect("Should return a vertex"); - - let mut assignment_map: HashMap = HashMap::new(); - assignment_map.insert(Direction::In.into(), vertex_a.id().into()); - assignment_map.insert(Direction::Out.into(), vertex_b.id().into()); - assignment_map.insert(T::Label.into(), expected_edge_label.into()); - assignment_map.insert( - expected_edge_property_key.into(), - expected_edge_property_value.into(), - ); - - let merged_edge_properties = g - .inject(vec![assignment_map.into()]) - .unfold() - .as_("payload") - .merge_e(__.select("payload")) - .element_map(()) - .next() - .expect("Should get a response") - .expect("Should return edge properties"); - - assert_map_property(&merged_edge_properties, "label", expected_edge_label); - assert_map_property( - &merged_edge_properties, - expected_edge_property_key, - expected_edge_property_value, - ); - - let incoming_vertex: &Map = merged_edge_properties - .get(Direction::In) - .expect("Should have returned incoming vertex info") - .get() - .unwrap(); - let incoming_vertex_id = incoming_vertex - .get("id") - .or(incoming_vertex.get(T::Id)) - .expect("Should have returned vertex id"); - assert_eq!(incoming_vertex_id, &vertex_a.id().to_gvalue()); - - let outgoing_vertex: &Map = merged_edge_properties - .get(Direction::Out) - .expect("Should have returned outgoing vertex info") - .get() - .unwrap(); - let outgoing_vertex_id = outgoing_vertex - .get("id") - .or(outgoing_vertex.get(T::Id)) - .expect("Should have returned vertex id"); - assert_eq!(outgoing_vertex_id, &vertex_b.id().to_gvalue()); - } - - #[apply(merge_capable_serializers)] - #[serial(test_merge_e_options)] - fn test_merge_e_options(client: GremlinClient) { - let expected_vertex_label = "test_merge_e_options_vertex"; - let expected_edge_label = "test_merge_e_options_edge"; - let expected_edge_property_key = "test_merge_e_options_edge_prop"; - drop_vertices(&client, &expected_vertex_label).expect("Failed to drop vertiecs"); - let g = traversal().with_remote(client); - - let vertex_a = g - .add_v(expected_vertex_label) - .next() - .expect("Should get a response") - .expect("Should return a vertex"); - - let vertex_b = g - .add_v(expected_vertex_label) - .next() - .expect("Should get a response") - .expect("Should return a vertex"); - - let mut assignment_map: HashMap = HashMap::new(); - assignment_map.insert(Direction::In.into(), vertex_a.id().into()); - assignment_map.insert(Direction::Out.into(), vertex_b.id().into()); - assignment_map.insert(T::Label.into(), expected_edge_label.into()); - - let mut on_create_map: HashMap = HashMap::new(); - on_create_map.insert(expected_edge_property_key.into(), "on_create".into()); - - let mut on_match_map: HashMap = HashMap::new(); - on_match_map.insert(expected_edge_property_key.into(), "on_match".into()); - - let mut injection_map: HashMap = HashMap::new(); - injection_map.insert("merge_params".into(), assignment_map.into()); - injection_map.insert("create_params".into(), on_create_map.into()); - injection_map.insert("match_params".into(), on_match_map.into()); - - let do_merge_edge = |g: GraphTraversalSource| -> Map { - g.inject(vec![injection_map.clone().into()]) - .unfold() - .as_("payload") - .merge_e(__.select("payload").select("merge_params")) - .option(( - Merge::OnCreate, - __.select("payload").select("create_params"), - )) - .option((Merge::OnMatch, __.select("payload").select("match_params"))) - .element_map(()) - .next() - .expect("Should get a response") - .expect("Should return a edge properties") - }; - - let on_create_edge_properties = do_merge_edge(g.clone()); - - //Initially the edge should be the on create value - assert_map_property( - &on_create_edge_properties, - expected_edge_property_key, - "on_create", - ); - - let on_match_edge_properties = do_merge_edge(g); - assert_map_property( - &on_match_edge_properties, - expected_edge_property_key, - "on_match", - ); - } - - #[apply(merge_capable_serializers)] - #[serial(test_merge_e_anonymous_traversal)] - fn test_merge_e_anonymous_traversal(client: GremlinClient) { - let expected_vertex_label = "test_merge_e_options_vertex"; - let expected_edge_label = "test_merge_e_options_edge"; - drop_vertices(&client, &expected_vertex_label).expect("Failed to drop vertiecs"); - let g = traversal().with_remote(client); - - let vertex_a = g - .add_v(expected_vertex_label) - .next() - .expect("Should get a response") - .expect("Should return a vertex"); - - let vertex_b = g - .add_v(expected_vertex_label) - .next() - .expect("Should get a response") - .expect("Should return a vertex"); - - let mut assignment_map: HashMap = HashMap::new(); - assignment_map.insert(Direction::In.into(), vertex_a.id().into()); - assignment_map.insert(Direction::Out.into(), vertex_b.id().into()); - assignment_map.insert(T::Label.into(), expected_edge_label.into()); - - let anonymous_merge_e_properties = g - .inject(1) - .unfold() - .coalesce::([__.merge_e(assignment_map)]) - .element_map(()) - .next() - .expect("Should get a response") - .expect("Should return a edge properties"); - - let incoming_vertex: &Map = anonymous_merge_e_properties - .get(Direction::In) - .expect("Should have returned incoming vertex info") - .get() - .unwrap(); - let incoming_vertex_id = incoming_vertex - .get("id") - .or(incoming_vertex.get(T::Id)) - .expect("Should have returned vertex id"); - assert_eq!(incoming_vertex_id, &vertex_a.id().to_gvalue()); - - let outgoing_vertex: &Map = anonymous_merge_e_properties - .get(Direction::Out) - .expect("Should have returned outgoing vertex info") - .get() - .unwrap(); - let outgoing_vertex_id = outgoing_vertex - .get("id") - .or(outgoing_vertex.get(T::Id)) - .expect("Should have returned vertex id"); - assert_eq!(outgoing_vertex_id, &vertex_b.id().to_gvalue()); - } - - #[apply(merge_capable_serializers)] - #[serial(test_merge_v_into_merge_e)] - fn test_merge_v_into_merge_e(client: GremlinClient) { - //Based on the reference doc's combo example - - let expected_vertex_label = "test_merge_v_into_merge_e_vertex"; - let expected_edge_label = "test_merge_v_into_merge_e_edge"; - drop_vertices(&client, &expected_vertex_label).expect("Failed to drop vertiecs"); - let g = traversal().with_remote(client); - - let expected_toby_id = 100_001i64; - let expected_brandy_id = 200_001i64; - - let mut vertex_a_map: HashMap = HashMap::new(); - vertex_a_map.insert(T::Label.into(), expected_vertex_label.into()); - vertex_a_map.insert(T::Id.into(), expected_toby_id.into()); - vertex_a_map.insert("name".into(), "Toby".into()); - - let mut vertex_b_map: HashMap = HashMap::new(); - vertex_b_map.insert(T::Label.into(), expected_vertex_label.into()); - vertex_b_map.insert(T::Id.into(), expected_brandy_id.into()); - vertex_b_map.insert("name".into(), "Brandy".into()); - - let mut edge_map: HashMap = HashMap::new(); - edge_map.insert(T::Label.into(), expected_edge_label.into()); - edge_map.insert("some_key".into(), "some_value".into()); - edge_map.insert(Direction::From.into(), Merge::OutV.into()); - edge_map.insert(Direction::To.into(), Merge::InV.into()); - - let combo_merge_edge_properties = g - .merge_v(vertex_a_map) - .as_("Toby") - .merge_v(vertex_b_map) - .as_("Brandy") - .merge_e(edge_map) - .option((Merge::OutV, __.select("Toby"))) - .option((Merge::InV, __.select("Brandy"))) - .element_map(()) - .next() - .expect("Should get a response") - .expect("Should return a edge properties"); - - let brandy_vertex: &Map = combo_merge_edge_properties - .get(Direction::In) - .expect("Should have returned incoming vertex info") - .get() - .unwrap(); - let brandy_vertex_id = brandy_vertex - .get("id") - .or(brandy_vertex.get(T::Id)) - .expect("Should have returned vertex id"); - assert_eq!(*brandy_vertex_id, GValue::Int64(expected_brandy_id)); - - let toby_vertex: &Map = combo_merge_edge_properties - .get(Direction::Out) - .expect("Should have returned outgoing vertex info") - .get() - .unwrap(); - let toby_vertex_id = toby_vertex - .get("id") - .or(toby_vertex.get(T::Id)) - .expect("Should have returned vertex id"); - assert_eq!(*toby_vertex_id, GValue::Int64(expected_toby_id)); - - assert_map_property(&combo_merge_edge_properties, "label", expected_edge_label); - } -} - -#[apply(serializers)] -#[serial(test_simple_vertex_traversal)] -fn test_simple_vertex_traversal(client: GremlinClient) { - let g = traversal().with_remote(client); - - let results = g.v(()).to_list().unwrap(); - - assert!(results.len() > 0); -} - -#[apply(serializers)] -#[serial(test_inject)] -fn test_inject(client: GremlinClient) { - let g = traversal().with_remote(client); - let expected_value = "foo"; - let response: String = g - .inject(vec![expected_value.into()]) - .next() - .expect("Should get response") - .expect("Should have gotten a Some") - .try_into() - .expect("Should be parsable into a String"); - assert_eq!(expected_value, response); -} - -#[apply(serializers)] -#[serial(test_simple_vertex_traversal_with_id)] -fn test_simple_vertex_traversal_with_id(client: GremlinClient) { - let vertex = create_vertex(&client, "Traversal"); - - let g = traversal().with_remote(client); - - let results = g.v(vertex.id()).to_list().unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertex.id(), results[0].id()); -} - -#[apply(serializers)] -#[serial(test_simple_vertex_traversal_with_multiple_id)] -fn test_simple_vertex_traversal_with_multiple_id(client: GremlinClient) { - drop_vertices(&client, "test_simple_vertex_traversal").unwrap(); - - let vertex = create_vertex_with_label(&client, "test_simple_vertex_traversal", "Traversal"); - let vertex2 = create_vertex_with_label(&client, "test_simple_vertex_traversal", "Traversal"); - - let g = traversal().with_remote(client); - - let results = g.v(vec![vertex.id(), vertex2.id()]).to_list().unwrap(); - - assert_eq!(2, results.len()); - - assert_eq!(vertex.id(), results[0].id()); - assert_eq!(vertex2.id(), results[1].id()); -} - -#[apply(serializers)] -#[serial(test_simple_vertex_traversal_with_label)] -fn test_simple_vertex_traversal_with_label(client: GremlinClient) { - drop_vertices(&client, "test_simple_vertex_traversal_with_label").unwrap(); - - let vertex = create_vertex_with_label( - &client, - "test_simple_vertex_traversal_with_label", - "Traversal", - ); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_simple_vertex_traversal_with_label") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertex.id(), results[0].id()); -} - -#[apply(serializers)] -#[serial(test_simple_vertex_traversal_with_label_and_has)] -fn test_simple_vertex_traversal_with_label_and_has(client: GremlinClient) { - drop_vertices(&client, "test_simple_vertex_traversal_with_label_and_has").unwrap(); - - let vertex = create_vertex_with_label( - &client, - "test_simple_vertex_traversal_with_label_and_has", - "Traversal", - ); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_simple_vertex_traversal_with_label_and_has") - .has(("name", "Traversal")) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertex.id(), results[0].id()); - - // with 3 params - - let results = g - .v(()) - .has(( - "test_simple_vertex_traversal_with_label_and_has", - "name", - "Traversal", - )) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertex.id(), results[0].id()); - - // with 1 param - - let results = g - .v(()) - .has_label("test_simple_vertex_traversal_with_label_and_has") - .has("name") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertex.id(), results[0].id()); - - // hasNot - - let results = g - .v(()) - .has_label("test_simple_vertex_traversal_with_label_and_has") - .has_not("surname") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertex.id(), results[0].id()); -} - -#[apply(serializers)] -#[serial(test_simple_edge_traversal)] -fn test_simple_edge_traversal(client: GremlinClient) { - let g = traversal().with_remote(client); - - let results = g.e(()).to_list().unwrap(); - - assert!(results.len() > 0); -} - -#[apply(serializers)] -#[serial(test_simple_edge_traversal_id)] -fn test_simple_edge_traversal_id(client: GremlinClient) { - let v = create_vertex(&client, "Traversal"); - let v1 = create_vertex(&client, "Traversal"); - - let e = create_edge(&client, &v, &v1, "TraversalEdge"); - - let g = traversal().with_remote(client); - - let results = g.e(e.id()).to_list().unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(e.id(), results[0].id()); -} - -#[apply(serializers)] -#[serial(test_simple_edge_traversal_with_label)] -fn test_simple_edge_traversal_with_label(client: GremlinClient) { - drop_edges(&client, "test_simple_edge_traversal_with_label").unwrap(); - - let v = create_vertex(&client, "Traversal"); - let v1 = create_vertex(&client, "Traversal"); - - let e = create_edge(&client, &v, &v1, "test_simple_edge_traversal_with_label"); - - let g = traversal().with_remote(client); - - let results = g - .e(()) - .has_label("test_simple_edge_traversal_with_label") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(e.id(), results[0].id()); -} - -#[apply(serializers)] -#[serial(test_traversal)] -fn test_traversal(client: GremlinClient) { - drop_edges(&client, "test_vertex_out_traversal").unwrap(); - - let v = create_vertex(&client, "Traversal"); - let v1 = create_vertex(&client, "Traversal"); - let v2 = create_vertex(&client, "Traversal"); - - let _e = create_edge(&client, &v, &v1, "test_vertex_out_traversal"); - let _e2 = create_edge(&client, &v2, &v, "test_vertex_out_traversal"); - - let g = traversal().with_remote(client); - - // OUT - let results = g - .v(v.id()) - .out("test_vertex_out_traversal") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(v1.id(), results[0].id()); - - let results = g.v(v.id()).out("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); - - // OUT_E - - let results = g - .v(v.id()) - .out_e("test_vertex_out_traversal") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!("test_vertex_out_traversal", results[0].label()); - - assert_eq!(v.id(), results[0].out_v().id()); - assert_eq!(v1.id(), results[0].in_v().id()); - - // OUT_E -> IN_V - let results = g - .v(v.id()) - .out_e("test_vertex_out_traversal") - .in_v() - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(v1.id(), results[0].id()); - - let results = g.v(v.id()).out("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); - - // IN - let results = g - .v(v1.id()) - .in_("test_vertex_out_traversal") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(v.id(), results[0].id()); - - let results = g.v(v1.id()).in_("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); - - // IN_E - - let results = g - .v(v1.id()) - .in_e("test_vertex_out_traversal") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!("test_vertex_out_traversal", results[0].label()); - - assert_eq!(v.id(), results[0].out_v().id()); - assert_eq!(v1.id(), results[0].in_v().id()); - - // IN_E -> OUT_V - let results = g - .v(v1.id()) - .in_e("test_vertex_out_traversal") - .out_v() - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(v.id(), results[0].id()); - - let results = g.v(v1.id()).in_("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); - - // BOTH - - let results = g - .v(v.id()) - .both("test_vertex_out_traversal") - .to_list() - .unwrap(); - - assert_eq!(2, results.len()); - - assert_eq!(v1.id(), results[0].id()); - assert_eq!(v2.id(), results[1].id()); - - let results = g.v(v1.id()).in_("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); - - // BOTH_E -> OTHER_V - - let results = g - .v(v.id()) - .both_e("test_vertex_out_traversal") - .other_v() - .to_list() - .unwrap(); - - assert_eq!(2, results.len()); - - assert_eq!(v1.id(), results[0].id()); - assert_eq!(v2.id(), results[1].id()); - - let results = g.v(v1.id()).in_("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); -} - -#[apply(serializers)] -#[serial(test_add_v)] -fn test_add_v(client: GremlinClient) { - let g = traversal().with_remote(client); - - let results = g.add_v("person").to_list().unwrap(); - - assert!(results.len() > 0); - - assert_eq!("person", results[0].label()); - - let results = g.add_v("person").add_v(()).to_list().unwrap(); - - assert!(results.len() > 0); - - //default label - assert_eq!("vertex", results[0].label()); -} - -#[apply(serializers)] -#[serial(test_add_v_with_properties)] -fn test_add_v_with_properties(client: GremlinClient) { - let g = traversal().with_remote(client.clone()); - - let results = g - .add_v("person") - .property("name", "marko") - .property("age", 29) - .to_list() - .unwrap(); - - assert!(results.len() > 0); - - assert_eq!("person", results[0].label()); - - let results = client - .execute("g.V(_id).propertyMap()", &[("_id", results[0].id())]) - .expect("it should execute addV") - .filter_map(Result::ok) - .map(|f| f.take::()) - .collect::, _>>() - .expect("It should be ok"); - - let properties = &results[0]; - - assert_eq!( - &29, - properties["age"].get::().unwrap()[0] - .get::() - .unwrap() - .get::() - .unwrap() - ); - - assert_eq!( - &"marko", - properties["name"].get::().unwrap()[0] - .get::() - .unwrap() - .get::() - .unwrap() - ); -} - -#[apply(serializers)] -#[serial(test_add_v_with_property_many)] -fn test_add_v_with_property_many(client: GremlinClient) { - drop_vertices(&client, "test_add_v_with_property_many").unwrap(); - - let g = traversal().with_remote(client.clone()); - - let results = g - .add_v("test_add_v_with_property_many") - .property_many(vec![ - (String::from("name"), "marko"), - (String::from("age"), "29"), - ]) - .to_list() - .unwrap(); - - assert!(results.len() > 0); - - assert_eq!("test_add_v_with_property_many", results[0].label()); - - let results = client - .execute("g.V(_id).propertyMap()", &[("_id", results[0].id())]) - .expect("it should execute addV") - .filter_map(Result::ok) - .map(|f| f.take::()) - .collect::, _>>() - .expect("It should be ok"); - - let properties = &results[0]; - - assert_eq!( - &"29".to_string(), - properties["age"].get::().unwrap()[0] - .get::() - .unwrap() - .get::() - .unwrap() - ); - - assert_eq!( - &"marko", - properties["name"].get::().unwrap()[0] - .get::() - .unwrap() - .get::() - .unwrap() - ); -} - -#[apply(serializers)] -#[serial(test_has_many)] -fn test_has_many(client: GremlinClient) { - drop_vertices(&client, "test_has_many").unwrap(); - - let g = traversal().with_remote(client.clone()); - - let results = g - .add_v("test_has_many") - .property_many(vec![ - (String::from("name"), "josh"), - (String::from("age"), "21"), - ]) - .to_list() - .unwrap(); - - assert!(results.len() > 0); - - assert_eq!("test_has_many", results[0].label()); - - let results = g - .v(()) - .has_many(vec![ - (String::from("name"), "josh"), - (String::from("age"), "21"), - ]) - .to_list() - .unwrap(); - - assert_eq!(results.len(), 1); -} - -#[apply(serializers)] -#[serial(test_add_e)] -fn test_add_e(client: GremlinClient) { - let g = traversal().with_remote(client.clone()); - - let v = g - .add_v("person") - .property("name", "marko") - .property("age", 29) - .to_list() - .unwrap(); - - let v1 = g - .add_v("person") - .property("name", "jon") - .property("age", 29) - .to_list() - .unwrap(); - - let edges = g.add_e("knows").from(&v[0]).to(&v1[0]).to_list().unwrap(); - - assert!(edges.len() > 0); - - assert_eq!("knows", edges[0].label()); - - let edges = g - .v(v[0].id()) - .as_("a") - .out("knows") - .add_e("livesNear") - .from("a") - .property("year", 2009) - .to_list() - .unwrap(); - - assert!(edges.len() > 0); - - assert_eq!("livesNear", edges[0].label()); - - let edges = g - .v(()) - .as_("a") - .out("created") - .add_e("createdBy") - .to("a") - .property("acl", "public") - .to_list() - .unwrap(); - - assert_eq!("createdBy", edges[0].label()); - - let edges = g - .add_e("knows") - .from(__.v(()).has(("name", "marko"))) - .to(__.v(()).has(("name", "jon"))) - .to_list() - .unwrap(); - - assert!(edges.len() > 0); - - assert_eq!("knows", edges[0].label()); -} - -#[apply(serializers)] -#[serial(test_label_step)] -fn test_label_step(client: GremlinClient) { - let vertex = create_vertex(&client, "Traversal"); - - let g = traversal().with_remote(client); - - let results = g.v(vertex.id()).label().to_list().unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!("person", results[0]); -} - -#[apply(serializers)] -#[serial(test_properties_step)] -fn test_properties_step(client: GremlinClient) { - let vertex = create_vertex(&client, "Traversal"); - - let g = traversal().with_remote(client); - - let results = g.v(vertex.id()).properties(()).to_list().unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!("Traversal", results[0].get::().unwrap()); - - let results = g.v(vertex.id()).properties("name").to_list().unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!("Traversal", results[0].get::().unwrap()); - - let results = g.v(vertex.id()).properties("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); -} - -#[apply(serializers)] -#[serial(test_property_map)] -fn test_property_map(client: GremlinClient) { - let vertex = create_vertex(&client, "Traversal"); - - let g = traversal().with_remote(client); - - let results = g.v(vertex.id()).property_map(()).to_list().unwrap(); - - assert_eq!(1, results.len()); - - let properties = &results[0]; - - assert_eq!( - "Traversal", - properties["name"].get::().unwrap()[0] - .get::() - .unwrap() - .get::() - .unwrap() - ); - - let results = g.v(vertex.id()).property_map("name").to_list().unwrap(); - - assert_eq!(1, results.len()); - - let properties = &results[0]; - - assert_eq!( - "Traversal", - properties["name"].get::().unwrap()[0] - .get::() - .unwrap() - .get::() - .unwrap() - ); - - let results = g.v(vertex.id()).property_map("fake").to_list().unwrap(); - - assert_eq!(1, results.len()); - - let properties = &results[0]; - - assert_eq!(0, properties.len()); -} - -#[apply(serializers)] -#[serial(test_values)] -fn test_values(client: GremlinClient) { - let vertex = create_vertex(&client, "Traversal"); - - let g = traversal().with_remote(client); - - let results = g.v(vertex.id()).values(()).to_list().unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!("Traversal", value.get::().unwrap()); - - let results = g.v(vertex.id()).values("name").to_list().unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!("Traversal", value.get::().unwrap()); - - let results = g.v(vertex.id()).values("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); -} - -#[apply(serializers)] -#[serial(test_value_map)] -fn test_value_map(client: GremlinClient) { - let g = traversal().with_remote(client); - - let vertices = g - .add_v("test_value_map") - .property("name", "test") - .to_list() - .unwrap(); - - let vertex = &vertices[0]; - - let results = g.v(vertex.id()).value_map(()).to_list().unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!( - "test", - get_map::(value, "name").unwrap().unwrap() - ); - - let results = g.v(vertex.id()).value_map("name").to_list().unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!( - "test", - get_map::(value, "name").unwrap().unwrap() - ); - - let results = g.v(vertex.id()).value_map("fake").to_list().unwrap(); - - assert_eq!(0, results[0].len()); - - let results = g.v(vertex.id()).value_map(true).to_list().unwrap(); - assert_eq!(1, results.len()); - let value = &results[0]; - - assert_eq!( - Some(vertex.id().get().unwrap()), - get_map_id(&value).unwrap() - ); - assert_eq!(Some(vertex.label()), get_map_label(&value).unwrap()); - assert_eq!( - Some("test".to_owned()).as_ref(), - get_map(&value, "name").unwrap() - ); - assert!(results[0].get("id").or(results[0].get(T::Id)).is_some()); - assert!(results[0] - .get("label") - .or(results[0].get(T::Label)) - .is_some()); - assert_eq!(true, results[0].get("name").is_some()); -} - -#[apply(serializers)] -#[serial(test_unwrap_map)] -fn test_unwrap_map(client: GremlinClient) { - let g = traversal().with_remote(client); - - let vertices = g - .add_v("test_value_map") - .property("name", "test") - .to_list() - .unwrap(); - - let vertex = &vertices[0]; - - let results = g.v(vertex.id()).value_map(true).next().unwrap().unwrap(); - let v_id = vertex.id().get::().unwrap(); - - let id = get_map_id(&results).unwrap(); - let property = get_map::(&results, "name").unwrap(); - let label = get_map_label(&results).unwrap(); - assert_eq!(id, Some(v_id)); - assert_eq!(property.unwrap(), "test"); - assert_eq!(label, Some(vertex.label())); -} - -#[apply(serializers)] -#[serial(test_element_map)] -fn test_element_map(client: GremlinClient) { - let g = traversal().with_remote(client); - - let vertices = g - .add_v("test_element_map") - .property("name", "test") - .to_list() - .unwrap(); - - let vertex = &vertices[0]; - - let results = g.v(vertex.id()).element_map(()).to_list().unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!("test", value["name"].get::().unwrap()); - - let results = g.v(vertex.id()).element_map("name").to_list().unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!("test", value["name"].get::().unwrap()); - - let results = g.v(vertex.id()).element_map("fake").to_list().unwrap(); - let value = &results[0]; - - assert_eq!(2, value.len()); - assert_eq!( - Some(vertex.id().get().unwrap()), - get_map_id(&value).unwrap() - ); - assert_eq!(Some(vertex.label()), get_map_label(&value).unwrap()); - assert_eq!(2, results[0].len()); - assert!(results[0].get("id").or(results[0].get(T::Id)).is_some()); - assert!(results[0] - .get("label") - .or(results[0].get(T::Label)) - .is_some()); - - let results = g.v(vertex.id()).element_map(()).to_list().unwrap(); - let value = &results[0]; - - assert_eq!( - Some(vertex.id().get().unwrap()), - get_map_id(&value).unwrap() - ); - assert_eq!(Some(vertex.label()), get_map_label(&value).unwrap()); - assert_eq!( - Some("test".to_owned()).as_ref(), - get_map(&value, "name").unwrap() - ); - assert!(results[0].get("id").or(results[0].get(T::Id)).is_some()); - assert!(results[0] - .get("label") - .or(results[0].get(T::Label)) - .is_some()); - assert_eq!(true, results[0].get("name").is_some()); -} - -#[apply(serializers)] -#[serial(test_count)] -fn test_count(client: GremlinClient) { - let vertex = create_vertex_with_label(&client, "test_count", "Count"); - - let g = traversal().with_remote(client); - - let results = g.v(vertex.id()).count().to_list().unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(&1, value); -} - -#[apply(serializers)] -#[serial(test_group_count_step)] -fn test_group_count_step(client: GremlinClient) { - drop_vertices(&client, "test_group_count").unwrap(); - - let vertex = create_vertex_with_label(&client, "test_group_count", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_group_count") - .group_count() - //Normalize the keys to a common type of Id across serializers - .by(T::Id) - .next() - .unwrap(); - - let value = results.expect("Should have returned a map"); - assert_eq!(1, value.len(), "Should only have 1 entry in map"); - let (actual_key, actual_value) = value.into_iter().next().unwrap(); - - //The actual key may come back as either an int or a string depending - //on the serializer, so normalize it and the vertex gid to a string - let normalized_actual_key = match actual_key { - GKey::String(v) => v, - GKey::Int64(v) => v.to_string(), - other => panic!("Unexpected key type: {:?}", other), - }; - - let normalized_vertex_id = match vertex.id() { - gremlin_client::GID::String(v) => v.clone(), - gremlin_client::GID::Int32(v) => v.to_string(), - gremlin_client::GID::Int64(v) => v.to_string(), - }; - - assert_eq!(normalized_actual_key, normalized_vertex_id); - - assert_eq!( - actual_value, - GValue::Int64(1), - "Group count should have been the single vertex" - ); - - let results = g - .v(()) - .has_label("test_group_count") - .group_count() - .by("name") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(&1, value["Count"].get::().unwrap()); - - let results = g - .v(()) - .has_label("test_group_count") - .group_count() - .by(T::Label) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(&1, value["test_group_count"].get::().unwrap()); -} - -#[apply(serializers)] -#[serial(test_group_by_step)] -fn test_group_by_step(client: GremlinClient) { - drop_vertices(&client, "test_group_by_step").unwrap(); - - create_vertex_with_label(&client, "test_group_by_step", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_group_by_step") - .group() - .by("name") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(1, value["Count"].get::().unwrap().len()); - - let results = g - .v(()) - .has_label("test_group_by_step") - .group() - .by(T::Label) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(1, value["test_group_by_step"].get::().unwrap().len()); - - // - - let results = g - .v(()) - .has_label("test_group_by_step") - .group() - .by(T::Label) - .by(__.count()) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(&1, value["test_group_by_step"].get::().unwrap()); -} - -#[apply(serializers)] -#[serial(test_select_step)] -fn test_select_step(client: GremlinClient) { - drop_vertices(&client, "test_select_step").unwrap(); - - create_vertex_with_label(&client, "test_select_step", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_select_step") - .group_count() - .by("name") - .select("Count") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(&1, value.get::().unwrap()); -} - -#[apply(serializers)] -#[serial(test_fold_step)] -fn test_fold_step(client: GremlinClient) { - drop_vertices(&client, "test_fold_step").unwrap(); - - create_vertex_with_label(&client, "test_fold_step", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_fold_step") - .values("name") - .fold() - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!("Count", value[0].get::().unwrap()); -} - -#[apply(serializers)] -#[serial(test_unfold_step)] -fn test_unfold_step(client: GremlinClient) { - drop_vertices(&client, "test_unfold_step").unwrap(); - - let vertex = create_vertex_with_label(&client, "test_unfold_step", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(vertex.id()) - .property_map(()) - .unfold() - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!( - "Count", - value["name"].get::().unwrap()[0] - .get::() - .unwrap() - .get::() - .unwrap() - ); -} - -#[apply(serializers)] -#[serial(test_path_step)] -fn test_path_step(client: GremlinClient) { - drop_vertices(&client, "test_path_step").unwrap(); - - let v = create_vertex_with_label(&client, "test_path_step", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_path_step") - .path() - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(v.id(), value.objects()[0].get::().unwrap().id()); -} - -#[apply(serializers)] -#[serial(test_limit_step)] -fn test_limit_step(client: GremlinClient) { - drop_vertices(&client, "test_limit_step").unwrap(); - - create_vertex_with_label(&client, "test_limit_step", "Count"); - create_vertex_with_label(&client, "test_limit_step", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_limit_step") - .limit(1) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); -} - -#[apply(serializers)] -#[serial(test_dedup_step)] -fn test_dedup_step(client: GremlinClient) { - drop_vertices(&client, "test_limit_step").unwrap(); - - create_vertex_with_label(&client, "test_limit_step", "Count"); - create_vertex_with_label(&client, "test_limit_step", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_limit_step") - .dedup(()) - .by(T::Label) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); -} - -#[apply(serializers)] -#[serial(test_numerical_steps)] -fn test_numerical_steps(client: GremlinClient) { - drop_vertices(&client, "test_numerical_steps").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("test_numerical_steps") - .property("age", 26) - .to_list() - .unwrap(); - g.add_v("test_numerical_steps") - .property("age", 20) - .to_list() - .unwrap(); - - // sum - let results = g - .v(()) - .has_label("test_numerical_steps") - .values("age") - .sum(()) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(&46, results[0].get::().unwrap()); - - // max - let results = g - .v(()) - .has_label("test_numerical_steps") - .values("age") - .max(()) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(&26, results[0].get::().unwrap()); - - // mean - - let results = g - .v(()) - .has_label("test_numerical_steps") - .values("age") - .mean(()) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(&23.0, results[0].get::().unwrap()); - - // min - - let results = g - .v(()) - .has_label("test_numerical_steps") - .values("age") - .min(()) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(&20, results[0].get::().unwrap()); -} - -#[apply(serializers)] -#[serial(test_has_with_p_steps)] -fn test_has_with_p_steps(client: GremlinClient) { - drop_vertices(&client, "test_has_with_p_steps").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("test_has_with_p_steps") - .property("age", 26) - .to_list() - .unwrap(); - let vertices = g - .add_v("test_has_with_p_steps") - .property("age", 20) - .to_list() - .unwrap(); - - let results = g - .v(()) - .has(("test_has_with_p_steps", "age", P::within(vec![19, 20]))) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertices[0].id(), results[0].id()); - - let results = g - .v(()) - .has_label("test_has_with_p_steps") - .values("age") - .is(20) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(&20, results[0].get::().unwrap()); - - let results = g - .v(()) - .has(("test_has_with_p_steps", "age", 20)) - .values("age") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(&20, results[0].get::().unwrap()); - - let results = g - .v(()) - .has_label("test_has_with_p_steps") - .values("age") - .where_(__.is(P::eq(20))) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(&20, results[0].get::().unwrap()); - - let results = g - .v(()) - .has_label("test_has_with_p_steps") - .values("age") - .is(P::within(vec![19, 20])) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(&20, results[0].get::().unwrap()); -} - -#[apply(serializers)] -#[serial(test_has_with_text_p_step)] -fn test_has_with_text_p_step(client: GremlinClient) { - drop_vertices(&client, "test_has_with_text_p_step").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("test_has_with_text_p_step") - .property("name", "Jon") - .to_list() - .unwrap(); - - let vertices = g - .add_v("test_has_with_text_p_step") - .property("name", "Alice") - .to_list() - .unwrap(); - - let results = g - .v(()) - .has(("test_has_with_text_p_step", "name", TextP::containing("A"))) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertices[0].id(), results[0].id()); - - let results = g - .v(()) - .has_label("test_has_with_text_p_step") - .values("name") - .is("Alice") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!("Alice", results[0].get::().unwrap()); - - let results = g - .v(()) - .has_label("test_has_with_text_p_step") - .values("name") - .is(TextP::containing("Al")) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!("Alice", results[0].get::().unwrap()); - - g.add_v("test_has_with_text_p_step") - .property("name", "Alice2") - .to_list() - .unwrap(); - - let results = g - .v(()) - .has(("test_has_with_text_p_step", "name", TextP::containing("A"))) - .to_list() - .unwrap(); - - assert_eq!(2, results.len()); -} - -#[apply(serializers)] -#[serial(where_step_test)] -fn where_step_test(client: GremlinClient) { - drop_vertices(&client, "where_step_test").unwrap(); - - let g = traversal().with_remote(client); - - let v = g - .add_v("where_step_test") - .property("age", 26) - .to_list() - .unwrap(); - - let results = g - .v(()) - .has_label("where_step_test") - .where_(__.values("age").is(26)) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(v[0].id(), results[0].id()); -} - -#[apply(serializers)] -#[serial(not_step_test)] -fn not_step_test(client: GremlinClient) { - drop_vertices(&client, "not_step_test").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("not_step_test") - .property("age", 26) - .to_list() - .unwrap(); - - let results = g - .v(()) - .has_label("not_step_test") - .not(__.values("age").is(26)) - .to_list() - .unwrap(); - - assert_eq!(0, results.len()); -} - -#[apply(serializers)] -#[serial(order_step_test)] -fn order_step_test(client: GremlinClient) { - drop_vertices(&client, "order_step_test").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("order_step_test") - .property("name", "b") - .to_list() - .unwrap(); - - g.add_v("order_step_test") - .property("name", "a") - .to_list() - .unwrap(); - - let results = g - .v(()) - .has_label("order_step_test") - .values("name") - .order(()) - .to_list() - .unwrap(); - - assert_eq!(2, results.len()); - - assert_eq!("a", results[0].get::().unwrap()); - - let results = g - .v(()) - .has_label("order_step_test") - .values("name") - .order(()) - .by(Order::Desc) - .to_list() - .unwrap(); - - assert_eq!(2, results.len()); - - assert_eq!("b", results[0].get::().unwrap()); -} - -#[apply(serializers)] -#[serial(match_step_test)] -fn match_step_test(client: GremlinClient) { - drop_vertices(&client, "match_step_test").unwrap(); - - drop_edges(&client, "match_step_test_edge").unwrap(); - - let g = traversal().with_remote(client); - - let v1 = g - .add_v("match_step_test") - .property("name", "a") - .to_list() - .unwrap(); - - let v2 = g - .add_v("match_step_test") - .property("name", "b") - .to_list() - .unwrap(); - - let v3 = g - .add_v("match_step_test") - .property("name", "c") - .to_list() - .unwrap(); - - g.add_e("match_step_test_edge") - .from(&v1[0]) - .to(&v2[0]) - .to_list() - .unwrap(); - - g.add_e("match_step_test_edge") - .from(&v2[0]) - .to(&v3[0]) - .to_list() - .unwrap(); - - let results = g - .v(()) - .has_label("match_step_test") - .match_(vec![ - __.as_("a") - .has(("name", "a")) - .out("match_step_test_edge") - .as_("b"), - __.as_("b").out("match_step_test_edge").as_("c"), - ]) - .select(vec!["a", "c"]) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let first = &results[0].get::().unwrap(); - - assert_eq!(&v1[0], first["a"].get::().unwrap()); - assert_eq!(&v3[0], first["c"].get::().unwrap()); -} - -#[apply(serializers)] -#[serial(drop_step_test)] -fn drop_step_test(client: GremlinClient) { - drop_vertices(&client, "drop_step_test").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("drop_step_test") - .property("name", "a") - .next() - .unwrap(); - - g.add_v("drop_step_test") - .property("name", "b") - .next() - .unwrap(); - - let results = g.v(()).has_label("drop_step_test").count().next().unwrap(); - - assert_eq!(Some(2), results); - - g.v(()) - .has_label("drop_step_test") - .drop() - .to_list() - .unwrap(); - - let results = g.v(()).has_label("drop_step_test").has_next().unwrap(); - - assert_eq!(false, results); -} - -#[apply(serializers)] -#[serial(or_step_test)] -fn or_step_test(client: GremlinClient) { - drop_vertices(&client, "or_step_test").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("or_step_test") - .property("foo", "bar") - .property("bar", "foo") - .next() - .unwrap(); - - g.add_v("or_step_test") - .property("foo", "nobar") - .property("bar", "nofoo") - .next() - .unwrap(); - - let result = g - .v(()) - .has_label("or_step_test") - .has(("foo", "bar")) - .or(()) - .has(("bar", "foo")) - .to_list() - .unwrap(); - assert_eq!(result.len(), 1); - - let result = g - .v(()) - .has_label("or_step_test") - .has(("foo", "bar")) - .or(()) - .has(("bar", "nofoo")) - .to_list() - .unwrap(); - assert_eq!(result.len(), 2); -} - -#[apply(serializers)] -#[serial(iter_terminator_test)] -fn iter_terminator_test(client: GremlinClient) { - drop_vertices(&client, "iter_terminator_test").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("iter_terminator_test") - .property("name", "a") - .next() - .unwrap(); - - g.add_v("iter_terminator_test") - .property("name", "b") - .next() - .unwrap(); - - let results: Vec = g - .v(()) - .has_label("iter_terminator_test") - .iter() - .unwrap() - .filter_map(Result::ok) - .collect(); - - assert_eq!(2, results.len()) -} - -#[apply(serializers)] -#[serial(test_select_pop)] -fn test_select_pop(client: GremlinClient) { - drop_vertices(&client, "test_select_pop").unwrap(); - drop_vertices(&client, "test_select_pop_child").unwrap(); - - let g = traversal().with_remote(client); - - let v1 = g - .add_v("test_select_pop") - .property("name", "a") - .to_list() - .unwrap(); - - let v2 = g - .add_v("test_select_pop") - .property("name", "b") - .to_list() - .unwrap(); - - let e1 = g - .add_v("test_select_pop_child") - .property("name", "a") - .to_list() - .unwrap(); - - let e2 = g - .add_v("test_select_pop_child") - .property("name", "b") - .to_list() - .unwrap(); - - g.add_e("child").from(&v1[0]).to(&e1[0]).to_list().unwrap(); - - g.add_e("child").from(&v2[0]).to(&e2[0]).to_list().unwrap(); - - let results = g - .v(()) - .has_label("test_select_pop") - .has(("name", "a")) - .out("child") - .as_("v") - .v(()) - .has_label("test_select_pop") - .has(("name", "b")) - .out("child") - .as_("v") - .select((Pop::All, "v")) - .unfold() - .to_list() - .unwrap(); - assert_eq!(results.len(), 2); - - let results = g - .v(()) - .has_label("test_select_pop") - .has(("name", "a")) - .out("child") - .as_("v") - .v(()) - .has_label("test_select_pop") - .has(("name", "b")) - .out("child") - .as_("v") - .select((Pop::Last, "v")) - .unfold() - .to_list() - .unwrap(); - assert_eq!(results.len(), 1); - - let results = g - .v(()) - .has_label("test_select_pop") - .has(("name", "a")) - .out("child") - .as_("v") - .v(()) - .has_label("test_select_pop") - .has(("name", "b")) - .out("child") - .as_("v") - .select((Pop::First, "v")) - .unfold() - .to_list() - .unwrap(); - assert_eq!(results.len(), 1); -} - -#[apply(serializers)] -#[serial(test_repeat_until_loops_loops)] -fn test_repeat_until_loops_loops(client: GremlinClient) { - drop_vertices(&client, "test_repeat_until_loops").unwrap(); - drop_vertices(&client, "test_repeat_until_loops_child").unwrap(); - - let g = traversal().with_remote(client); - - let v1 = g - .add_v("test_repeat_until_loops") - .property("name", "a") - .to_list() - .unwrap(); - - let e1 = g - .add_v("test_repeat_until_loops_child") - .property("name", "b") - .to_list() - .unwrap(); - - let e2 = g - .add_v("test_repeat_until_loops_child") - .property("name", "c") - .to_list() - .unwrap(); - - g.add_e("child").from(&v1[0]).to(&e1[0]).to_list().unwrap(); - g.add_e("child").from(&e1[0]).to(&e2[0]).to_list().unwrap(); - - let results = g - .v(v1[0].id()) - .repeat(__.out("child")) - .until(__.loops(()).is(2)) - .to_list() - .unwrap(); - - assert_eq!(results.len(), 1); - assert_eq!(results[0], e2[0]); -} - -#[apply(serializers)] -#[serial(test_simple_path)] -fn test_simple_vertex_property(client: GremlinClient) { - drop_vertices(&client, "test_simple_vertex_property").unwrap(); - - let g = traversal().with_remote(client); - - let v = g - .add_v("test_simple_vertex_property") - .property("name", "a") - .element_map(()) - .next() - .unwrap() - .unwrap(); - - let actual_property: &String = v.get("name").expect("Should have property").get().unwrap(); - assert_eq!(actual_property, "a"); -} - -#[apply(serializers)] -#[serial(test_simple_path)] -fn test_simple_path(client: GremlinClient) { - drop_vertices(&client, "test_simple_path").unwrap(); - drop_vertices(&client, "test_simple_path_child").unwrap(); - - let g = traversal().with_remote(client); - - let v1 = g - .add_v("test_simple_path") - .property("name", "a") - .to_list() - .unwrap(); - - let e1 = g - .add_v("test_simple_path_child") - .property("name", "b") - .to_list() - .unwrap(); - - let e2 = g - .add_v("test_simple_path_child") - .property("name", "c") - .to_list() - .unwrap(); - - g.add_e("child").from(&v1[0]).to(&e1[0]).to_list().unwrap(); - g.add_e("child").from(&e1[0]).to(&e2[0]).to_list().unwrap(); - g.add_e("child").from(&e2[0]).to(&v1[0]).to_list().unwrap(); - - let results = g - .v(v1[0].id()) - .repeat(__.out("child").simple_path()) - .until(__.loops(()).is(2)) - .to_list() - .unwrap(); - - assert_eq!(results.len(), 1); - assert_eq!(results[0], e2[0]); -} - -#[apply(serializers)] -#[serial(test_sample)] -fn test_sample(client: GremlinClient) { - drop_vertices(&client, "test_sample").unwrap(); - drop_vertices(&client, "test_sample_child").unwrap(); - - let g = traversal().with_remote(client); - - let v1 = g - .add_v("test_sample") - .property("name", "a") - .to_list() - .unwrap(); - - let e1 = g - .add_v("test_sample_child") - .property("name", "b") - .to_list() - .unwrap(); - - let e2 = g - .add_v("test_sample_child") - .property("name", "b") - .to_list() - .unwrap(); - - g.add_e("child").from(&v1[0]).to(&e1[0]).to_list().unwrap(); - g.add_e("child").from(&v1[0]).to(&e2[0]).to_list().unwrap(); - let results = g.v(v1[0].id()).out("child").sample(1).to_list().unwrap(); - assert_eq!(results.len(), 1); -} - -#[apply(serializers)] -#[serial(test_local)] -fn test_local(client: GremlinClient) { - drop_vertices(&client, "test_local").unwrap(); - drop_vertices(&client, "test_local_child").unwrap(); - drop_vertices(&client, "test_local_child_child").unwrap(); - - let g = traversal().with_remote(client); - - let v1 = g - .add_v("test_local") - .property("name", "a") - .to_list() - .unwrap(); - - let e1 = g - .add_v("test_local_child") - .property("name", "b") - .to_list() - .unwrap(); - - let e2 = g - .add_v("test_local_child") - .property("name", "b") - .to_list() - .unwrap(); - - let e3 = g - .add_v("test_local_child_child") - .property("name", "c") - .to_list() - .unwrap(); - - let e4 = g - .add_v("test_local_child_child") - .property("name", "d") - .to_list() - .unwrap(); - - let e5 = g - .add_v("test_local_child_child") - .property("name", "e") - .to_list() - .unwrap(); - - g.add_e("child").from(&v1[0]).to(&e1[0]).to_list().unwrap(); - g.add_e("child").from(&v1[0]).to(&e2[0]).to_list().unwrap(); - - g.add_e("child_child") - .from(&e1[0]) - .to(&e3[0]) - .to_list() - .unwrap(); - g.add_e("child_child") - .from(&e1[0]) - .to(&e4[0]) - .to_list() - .unwrap(); - - g.add_e("child_child") - .from(&e2[0]) - .to(&e5[0]) - .to_list() - .unwrap(); - - let results = g - .v(v1[0].id()) - .out("child") - .local(__.out("child_child").sample(1)) //Local used here to only get one vertices from each child - .to_list() - .unwrap(); - - assert_eq!(results.len(), 2); -} - -#[apply(serializers)] -#[serial(test_side_effect)] -fn test_side_effect(client: GremlinClient) { - let test_vertex_label = "test_side_effect"; - let expected_side_effect_key = "prop_key"; - let expected_side_effect_value = "prop_val"; - - drop_vertices(&client, &test_vertex_label).unwrap(); - - let g = traversal().with_remote(client); - - let element_map = g - .add_v(test_vertex_label) - .side_effect(__.property( - gremlin_client::structure::Either2::A(expected_side_effect_key), - expected_side_effect_value, - )) - .element_map(()) - .next() - .expect("Should get response") - .expect("Should have returned an element map"); - - assert_map_property( - &element_map, - expected_side_effect_key, - expected_side_effect_value, - ); -} - -#[apply(serializers)] -#[serial(test_anonymous_traversal_properties_drop)] -fn test_anonymous_traversal_properties_drop(client: GremlinClient) { - let test_vertex_label = "test_anonymous_traversal_properties_drop"; - let pre_drop_prop_key = "pre_drop_prop_key"; - let expected_prop_value = "prop_val"; - - drop_vertices(&client, &test_vertex_label).unwrap(); - - let g = traversal().with_remote(client); - - let element_map = g - .add_v(test_vertex_label) - .side_effect(__.property( - gremlin_client::structure::Either2::A(pre_drop_prop_key), - expected_prop_value, - )) - .element_map(()) - .next() - .expect("Should get response") - .expect("Should have returned an element map"); - - //Make sure the property was assigned - assert_map_property(&element_map, pre_drop_prop_key, expected_prop_value); - - let created_vertex_id = element_map - .get("id") - .or(element_map.get(T::Id)) - .expect("Should have id property"); - let GValue::Int64(id) = created_vertex_id else { - panic!("Not expected id type"); - }; - - let post_drop_prop_key = "post_drop_prop_key"; - //Operate on the same vertex via id - let post_drop_map = g - .v(*id) - //Drop all properties first - .side_effect(__.properties(()).drop()) - //Then add a different property - .side_effect(__.property( - gremlin_client::structure::Either2::A(pre_drop_prop_key), - expected_prop_value, - )) - .element_map(()) - .next() - .expect("Should get response") - .expect("Should have returned an element map"); - - assert_map_property(&post_drop_map, pre_drop_prop_key, expected_prop_value); - - //Now make sure the pre drop property key is no longer present - assert!( - post_drop_map.get(post_drop_prop_key).is_none(), - "Pre drop key should have been dropped" - ); -} - -#[apply(serializers)] -#[serial(test_by_columns)] -fn test_by_columns(client: GremlinClient) { - let test_vertex_label = "test_by_columns"; - let expected_side_effect_key_a = "prop_key_a"; - let expected_side_effect_value_a = "prop_val_a"; - let expected_side_effect_key_b = "prop_key_b"; - let expected_side_effect_value_b = "prop_val_b"; - - drop_vertices(&client, &test_vertex_label).unwrap(); - - let g = traversal().with_remote(client); - let mut property_map: HashMap = HashMap::new(); - property_map.insert( - expected_side_effect_key_a.into(), - expected_side_effect_value_a.into(), - ); - property_map.insert( - expected_side_effect_key_b.into(), - expected_side_effect_value_b.into(), - ); - - let element_map = g - .inject(vec![property_map.into()]) - .unfold() - .as_("properties") - .add_v(test_vertex_label) - .as_("v") - .side_effect( - __.select("properties") - .unfold() - .as_("kv_pair") - .select("v") - .property( - __.select("kv_pair").by(Column::Keys), - __.select("kv_pair").by(Column::Values), - ), - ) - .element_map(()) - .next() - .expect("Should get response") - .expect("Should have returned an element map"); - - assert_map_property( - &element_map, - expected_side_effect_key_a, - expected_side_effect_value_a, - ); - - assert_map_property( - &element_map, - expected_side_effect_key_b, - expected_side_effect_value_b, - ); -} - -#[apply(serializers)] -#[serial(test_property_cardinality)] -fn test_property_cardinality(client: GremlinClient) { - drop_vertices(&client, "test_property_cardinality").unwrap(); - - let g = traversal().with_remote(client); - - let v1 = g - .add_v("test_property_cardinality") - .property("name", "a") - .to_list() - .unwrap(); - - assert!(v1.len() > 0); - - g.v(v1[0].id()) - .property_with_cardinality(Cardinality::List, "name", "b") - .next() - .unwrap(); - let new_v = g.v(v1[0].id()).property_map(()).next().unwrap().unwrap(); - assert_eq!(2, new_v["name"].get::().unwrap().len()); - - g.v(v1[0].id()) - .property_with_cardinality(Cardinality::Single, "name", "b") - .next() - .unwrap(); - let new_v = g.v(v1[0].id()).property_map(()).next().unwrap().unwrap(); - assert_eq!(1, new_v["name"].get::().unwrap().len()); -} - -#[apply(serializers)] -#[serial(test_choose)] -fn test_choose(client: GremlinClient) { - drop_vertices(&client, "test_choose").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("test_choose") - .property("name", "a") - .as_("source") - .choose(( - __.select("source").has("name"), - __.add_v("test_choose_success"), - __.add_v("test_choose_failure"), - )) - .next() - .unwrap(); - - let success_vertices = g.v(()).has_label("test_choose_success").next().unwrap(); - assert_eq!(success_vertices.is_some(), true); - - let success_vertices = g.v(()).has_label("test_choose_failure").next().unwrap(); - assert_eq!(success_vertices.is_some(), false); - - g.add_v("test_choose") - .property("name", "b") - .as_("source") - .choose(( - __.select("source").has("name"), - __.add_v("test_choose_success2"), - )) - .next() - .unwrap(); - - let success_vertices = g.v(()).has_label("test_choose_failure2").next().unwrap(); - assert_eq!(success_vertices.is_some(), false); - - let success_vertices = g.v(()).has_label("test_choose_success2").next().unwrap(); - assert_eq!(success_vertices.is_some(), true); -} - -#[apply(serializers)] -#[serial(test_choose_by_literal_options)] -fn test_choose_by_literal_options(client: GremlinClient) { - let g = traversal().with_remote(client); - - let choosen_literal_a = g - .inject(1) - .unfold() - .choose(__.identity()) - .option((GValue::Int64(1), __.constant("option-a"))) - .option((GValue::Int64(2), __.constant("option-b"))) - .next() - .unwrap(); - - assert_eq!(choosen_literal_a, Some("option-a".into())); - - let choosen_literal_b = g - .inject(2) - .unfold() - .choose(__.identity()) - .option((GValue::Int64(1), __.constant("option-a"))) - .option((GValue::Int64(2), __.constant("option-b"))) - .next() - .unwrap(); - - assert_eq!(choosen_literal_b, Some("option-b".into())); -} - -#[apply(serializers)] -#[serial()] -fn test_coalesce(client: GremlinClient) { - use gremlin_client::GValue; - - drop_vertices(&client, "test_coalesce").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("test_coalesce") - .property("name", "a") - .to_list() - .unwrap(); - - g.add_v("test_coalesce") - .property("nickname", "b") - .to_list() - .unwrap(); - - let v = g - .v(()) - .has_label("test_coalesce") - .coalesce::([__.values("nickname"), __.values("name")]) - .to_list() - .unwrap(); - - let values = v - .into_iter() - .map(|e| e.take::().unwrap()) - .collect::>(); - - assert!(values.contains(&String::from("a"))); - assert!(values.contains(&String::from("b"))); -} - -#[apply(serializers)] -#[serial(test_coalesce_unfold)] -fn test_coalesce_unfold(client: GremlinClient) { - drop_vertices(&client, "test_coalesce_unfold").unwrap(); - - let g = traversal().with_remote(client); - - g.v(()) - .has(("test_coalesce_unfold", "name", "unfold")) - .fold() - .coalesce::([__.unfold(), __.add_v("test_coalesce_unfold")]) - .property("name", "unfold") - .next() - .expect("It should create a vertex with coalesce"); - - let v = g - .v(()) - .has_label("test_coalesce_unfold") - .value_map(()) - .to_list() - .unwrap(); - - let values = v.into_iter().collect::>(); - - assert_eq!(1, values.len()); - - assert_eq!( - "unfold", - utils::unwrap_map::(&values[0], "name", 0).unwrap() - ); - - g.v(()) - .has(("test_coalesce_unfold", "name", "unfold")) - .fold() - .coalesce::([__.unfold(), __.add_v("test_coalesce_unfold")]) - .property("name", "unfold") - .next() - .expect("It should create a vertex with coalesce"); - - let v = g - .v(()) - .has_label("test_coalesce_unfold") - .value_map(()) - .to_list() - .unwrap(); - - let values = v.into_iter().collect::>(); - - assert_eq!(1, values.len()); - - assert_eq!( - "unfold", - utils::unwrap_map::(&values[0], "name", 0).unwrap() - ); -} - -#[apply(serializers)] -#[serial(test_none_step)] -fn test_none_step(client: GremlinClient) { - drop_vertices(&client, "test_none_step").unwrap(); - - let g = traversal().with_remote(client); - - //The addition of a None step however should not IO a vertex back - g.add_v("test_none_step") - .none() - .iter() - .expect("Should get a iter back") - .iterate() - .expect("Shouldn't error consuming iterator"); - - //Make sure the vertex is present in the graph - let vertex_count = g - .v(()) - .has_label("test_none_step") - .count() - .next() - .ok() - .flatten() - .expect("Should have gotten a response"); - assert_eq!(1, vertex_count); -} - -fn get_map_id<'a>(map: &'a Map) -> Result, GremlinError> { - let string_keyed = get_map(map, "id")?; - if string_keyed.is_some() { - Ok(string_keyed) - } else { - get_map(map, T::Id) - } -} - -fn get_map_label<'a>(map: &'a Map) -> Result, GremlinError> { - let string_keyed = get_map(map, "label")?; - if string_keyed.is_some() { - Ok(string_keyed) - } else { - get_map(map, T::Label) - } -} - -fn get_map<'a, T, K>(map: &'a Map, key: K) -> Result, GremlinError> -where - T: BorrowFromGValue, - K: Into, -{ - map.get(key) - .map(|val| match val { - GValue::List(list) => list[0].get::(), - other => other.get::(), - }) - .transpose() -} - -#[apply(serializers)] -#[serial(test_traversal_vertex_mapping)] -#[cfg(feature = "derive")] -fn test_traversal_vertex_mapping(client: GremlinClient) { - use chrono::{DateTime, TimeZone, Utc}; - use gremlin_client::derive::FromGMap; - use std::convert::TryFrom; - - drop_vertices(&client, "test_vertex_mapping").unwrap(); - - let g = traversal().with_remote(client); - - let uuid = uuid::Uuid::new_v4(); - let mark = g - .add_v("person") - .property("name", "Mark") - .property("age", 22) - .property("time", 22 as i64) - .property("score", 3.2) - .property("uuid", uuid.clone()) - .property("datetime", chrono::Utc.timestamp(1551825863, 0)) - .property("date", 1551825863 as i64) - .value_map(true) - .by(TraversalBuilder::new(Bytecode::new()).unfold()) - .next(); - assert_eq!(mark.is_ok(), true); - - #[derive(Debug, PartialEq, FromGMap)] - struct Person { - name: String, - age: i32, - time: i64, - datetime: DateTime, - uuid: uuid::Uuid, - optional: Option, - } - let person = Person::try_from(mark.unwrap().unwrap()); - assert_eq!(person.is_ok(), true); - - assert_eq!( - Person { - name: String::from("Mark"), - age: 22, - time: 22, - datetime: chrono::Utc.timestamp(1551825863, 0), - uuid: uuid, - optional: None - }, - person.unwrap() - ); -} diff --git a/gremlin-client/tests/integration_traversal_v2.rs b/gremlin-client/tests/integration_traversal_v2.rs deleted file mode 100644 index 2cae261a..00000000 --- a/gremlin-client/tests/integration_traversal_v2.rs +++ /dev/null @@ -1,1837 +0,0 @@ -use gremlin_client::process::traversal::{traversal, Order, __}; -use gremlin_client::structure::{ - Cardinality, GKey, GValue, List, Map, Pop, TextP, Vertex, VertexProperty, GID, P, T, -}; -use gremlin_client::{utils, IoProtocol}; - -mod common; - -use common::io::{ - create_edge, create_vertex, create_vertex_with_label, drop_edges, drop_vertices, - graph_serializer, -}; - -#[test] -fn test_simple_vertex_traversal_v2() { - let g = traversal().with_remote(graph_serializer(IoProtocol::GraphSONV2)); - - let results = g.v(()).to_list().unwrap(); - - assert!(results.len() > 0); -} - -#[test] -fn test_simple_vertex_traversal_with_id_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - let vertex = create_vertex(&client, "Traversal"); - - let g = traversal().with_remote(client); - - let results = g.v(vertex.id()).to_list().unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertex.id(), results[0].id()); -} - -#[test] -fn test_simple_vertex_traversal_with_multiple_id_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - drop_vertices(&client, "test_simple_vertex_traversal").unwrap(); - - let vertex = create_vertex_with_label(&client, "test_simple_vertex_traversal", "Traversal"); - let vertex2 = create_vertex_with_label(&client, "test_simple_vertex_traversal", "Traversal"); - - let g = traversal().with_remote(client); - - let results = g.v(vec![vertex.id(), vertex2.id()]).to_list().unwrap(); - - assert_eq!(2, results.len()); - - assert_eq!(vertex.id(), results[0].id()); - assert_eq!(vertex2.id(), results[1].id()); -} - -#[test] -fn test_simple_vertex_traversal_with_label_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_simple_vertex_traversal_with_label").unwrap(); - - let vertex = create_vertex_with_label( - &client, - "test_simple_vertex_traversal_with_label", - "Traversal", - ); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_simple_vertex_traversal_with_label") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertex.id(), results[0].id()); -} - -#[test] -fn test_simple_vertex_traversal_with_label_and_has_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_simple_vertex_traversal_with_label_and_has").unwrap(); - - let vertex = create_vertex_with_label( - &client, - "test_simple_vertex_traversal_with_label_and_has", - "Traversal", - ); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_simple_vertex_traversal_with_label_and_has") - .has(("name", "Traversal")) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertex.id(), results[0].id()); - - // with 3 params - - let results = g - .v(()) - .has(( - "test_simple_vertex_traversal_with_label_and_has", - "name", - "Traversal", - )) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertex.id(), results[0].id()); - - // with 1 param - - let results = g - .v(()) - .has_label("test_simple_vertex_traversal_with_label_and_has") - .has("name") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertex.id(), results[0].id()); - - // hasNot - - let results = g - .v(()) - .has_label("test_simple_vertex_traversal_with_label_and_has") - .has_not("surname") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertex.id(), results[0].id()); -} - -#[test] -fn test_simple_edge_traversal_v2() { - let g = traversal().with_remote(graph_serializer(IoProtocol::GraphSONV2)); - - let results = g.e(()).to_list().unwrap(); - - assert!(results.len() > 0); -} - -#[test] -fn test_simple_edge_traversal_id_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - let v = create_vertex(&client, "Traversal"); - let v1 = create_vertex(&client, "Traversal"); - - let e = create_edge(&client, &v, &v1, "TraversalEdge"); - - let g = traversal().with_remote(client); - - let results = g.e(e.id()).to_list().unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(e.id(), results[0].id()); -} - -#[test] -fn test_simple_edge_traversal_with_label_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_edges(&client, "test_simple_edge_traversal_with_label").unwrap(); - - let v = create_vertex(&client, "Traversal"); - let v1 = create_vertex(&client, "Traversal"); - - let e = create_edge(&client, &v, &v1, "test_simple_edge_traversal_with_label"); - - let g = traversal().with_remote(client); - - let results = g - .e(()) - .has_label("test_simple_edge_traversal_with_label") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(e.id(), results[0].id()); -} - -#[test] -fn test_traversal_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_edges(&client, "test_vertex_out_traversal").unwrap(); - - let v = create_vertex(&client, "Traversal"); - let v1 = create_vertex(&client, "Traversal"); - let v2 = create_vertex(&client, "Traversal"); - - let _e = create_edge(&client, &v, &v1, "test_vertex_out_traversal"); - let _e2 = create_edge(&client, &v2, &v, "test_vertex_out_traversal"); - - let g = traversal().with_remote(client); - - // OUT - let results = g - .v(v.id()) - .out("test_vertex_out_traversal") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(v1.id(), results[0].id()); - - let results = g.v(v.id()).out("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); - - // OUT_E - - let results = g - .v(v.id()) - .out_e("test_vertex_out_traversal") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!("test_vertex_out_traversal", results[0].label()); - - assert_eq!(v.id(), results[0].out_v().id()); - assert_eq!(v1.id(), results[0].in_v().id()); - - // OUT_E -> IN_V - let results = g - .v(v.id()) - .out_e("test_vertex_out_traversal") - .in_v() - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(v1.id(), results[0].id()); - - let results = g.v(v.id()).out("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); - - // IN - let results = g - .v(v1.id()) - .in_("test_vertex_out_traversal") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(v.id(), results[0].id()); - - let results = g.v(v1.id()).in_("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); - - // IN_E - - let results = g - .v(v1.id()) - .in_e("test_vertex_out_traversal") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!("test_vertex_out_traversal", results[0].label()); - - assert_eq!(v.id(), results[0].out_v().id()); - assert_eq!(v1.id(), results[0].in_v().id()); - - // IN_E -> OUT_V - let results = g - .v(v1.id()) - .in_e("test_vertex_out_traversal") - .out_v() - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(v.id(), results[0].id()); - - let results = g.v(v1.id()).in_("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); - - // BOTH - - let results = g - .v(v.id()) - .both("test_vertex_out_traversal") - .to_list() - .unwrap(); - - assert_eq!(2, results.len()); - - assert_eq!(v1.id(), results[0].id()); - assert_eq!(v2.id(), results[1].id()); - - let results = g.v(v1.id()).in_("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); - - // BOTH_E -> OTHER_V - - let results = g - .v(v.id()) - .both_e("test_vertex_out_traversal") - .other_v() - .to_list() - .unwrap(); - - assert_eq!(2, results.len()); - - assert_eq!(v1.id(), results[0].id()); - assert_eq!(v2.id(), results[1].id()); - - let results = g.v(v1.id()).in_("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); -} - -#[test] -fn test_add_v_v2() { - let g = traversal().with_remote(graph_serializer(IoProtocol::GraphSONV2)); - - let results = g.add_v("person").to_list().unwrap(); - - assert!(results.len() > 0); - - assert_eq!("person", results[0].label()); - - let results = g.add_v("person").add_v(()).to_list().unwrap(); - - assert!(results.len() > 0); - - //default label - assert_eq!("vertex", results[0].label()); -} - -#[test] -fn test_add_v_with_properties_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - let g = traversal().with_remote(client.clone()); - - let results = g - .add_v("person") - .property("name", "marko") - .property("age", 29) - .to_list() - .unwrap(); - - assert!(results.len() > 0); - - assert_eq!("person", results[0].label()); - - let results = client - .execute("g.V(_id).propertyMap()", &[("_id", results[0].id())]) - .expect("it should execute addV") - .filter_map(Result::ok) - .map(|f| f.take::()) - .collect::, _>>() - .expect("It should be ok"); - - let properties = &results[0]; - - assert_eq!( - &29, - properties["age"].get::().unwrap()[0] - .get::() - .unwrap() - .get::() - .unwrap() - ); - - assert_eq!( - &"marko", - properties["name"].get::().unwrap()[0] - .get::() - .unwrap() - .get::() - .unwrap() - ); -} - -#[test] -fn test_add_v_with_property_many_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_add_v_with_property_many").unwrap(); - - let g = traversal().with_remote(client.clone()); - - let results = g - .add_v("test_add_v_with_property_many") - .property_many(vec![ - (String::from("name"), "marko"), - (String::from("age"), "29"), - ]) - .to_list() - .unwrap(); - - assert!(results.len() > 0); - - assert_eq!("test_add_v_with_property_many", results[0].label()); - - let results = client - .execute("g.V(_id).propertyMap()", &[("_id", results[0].id())]) - .expect("it should execute addV") - .filter_map(Result::ok) - .map(|f| f.take::()) - .collect::, _>>() - .expect("It should be ok"); - - let properties = &results[0]; - - assert_eq!( - &"29".to_string(), - properties["age"].get::().unwrap()[0] - .get::() - .unwrap() - .get::() - .unwrap() - ); - - assert_eq!( - &"marko", - properties["name"].get::().unwrap()[0] - .get::() - .unwrap() - .get::() - .unwrap() - ); -} - -#[test] -fn test_has_many_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_has_many").unwrap(); - - let g = traversal().with_remote(client.clone()); - - let results = g - .add_v("test_has_many") - .property_many(vec![ - (String::from("name"), "josh"), - (String::from("age"), "21"), - ]) - .to_list() - .unwrap(); - - assert!(results.len() > 0); - - assert_eq!("test_has_many", results[0].label()); - - let results = g - .v(()) - .has_many(vec![ - (String::from("name"), "josh"), - (String::from("age"), "21"), - ]) - .to_list() - .unwrap(); - - assert_eq!(results.len(), 1); -} - -#[test] -fn test_add_e_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - let g = traversal().with_remote(client.clone()); - - let v = g - .add_v("person") - .property("name", "marko") - .property("age", 29) - .to_list() - .unwrap(); - - let v1 = g - .add_v("person") - .property("name", "jon") - .property("age", 29) - .to_list() - .unwrap(); - - let edges = g.add_e("knows").from(&v[0]).to(&v1[0]).to_list().unwrap(); - - assert!(edges.len() > 0); - - assert_eq!("knows", edges[0].label()); - - let edges = g - .v(v[0].id()) - .as_("a") - .out("knows") - .add_e("livesNear") - .from("a") - .property("year", 2009) - .to_list() - .unwrap(); - - assert!(edges.len() > 0); - - assert_eq!("livesNear", edges[0].label()); - - let edges = g - .v(()) - .as_("a") - .out("created") - .add_e("createdBy") - .to("a") - .property("acl", "public") - .to_list() - .unwrap(); - - assert_eq!("createdBy", edges[0].label()); - - let edges = g - .add_e("knows") - .from(__.v(()).has(("name", "marko"))) - .to(__.v(()).has(("name", "jon"))) - .to_list() - .unwrap(); - - assert!(edges.len() > 0); - - assert_eq!("knows", edges[0].label()); -} - -#[test] -fn test_label_step_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - let vertex = create_vertex(&client, "Traversal"); - - let g = traversal().with_remote(client); - - let results = g.v(vertex.id()).label().to_list().unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!("person", results[0]); -} - -#[test] -fn test_properties_step_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - let vertex = create_vertex(&client, "Traversal"); - - let g = traversal().with_remote(client); - - let results = g.v(vertex.id()).properties(()).to_list().unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!("Traversal", results[0].get::().unwrap()); - - let results = g.v(vertex.id()).properties("name").to_list().unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!("Traversal", results[0].get::().unwrap()); - - let results = g.v(vertex.id()).properties("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); -} - -#[test] -fn test_property_map_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - let vertex = create_vertex(&client, "Traversal"); - - let g = traversal().with_remote(client); - - let results = g.v(vertex.id()).property_map(()).to_list().unwrap(); - - assert_eq!(1, results.len()); - - let properties = &results[0]; - - assert_eq!( - "Traversal", - properties["name"].get::().unwrap()[0] - .get::() - .unwrap() - .get::() - .unwrap() - ); - - let results = g.v(vertex.id()).property_map("name").to_list().unwrap(); - - assert_eq!(1, results.len()); - - let properties = &results[0]; - - assert_eq!( - "Traversal", - properties["name"].get::().unwrap()[0] - .get::() - .unwrap() - .get::() - .unwrap() - ); - - let results = g.v(vertex.id()).property_map("fake").to_list().unwrap(); - - assert_eq!(1, results.len()); - - let properties = &results[0]; - - assert_eq!(0, properties.len()); -} - -#[test] -fn test_values_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - let vertex = create_vertex(&client, "Traversal"); - - let g = traversal().with_remote(client); - - let results = g.v(vertex.id()).values(()).to_list().unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!("Traversal", value.get::().unwrap()); - - let results = g.v(vertex.id()).values("name").to_list().unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!("Traversal", value.get::().unwrap()); - - let results = g.v(vertex.id()).values("fake").to_list().unwrap(); - - assert_eq!(0, results.len()); -} - -#[test] -fn test_value_map_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - let g = traversal().with_remote(client); - - let vertices = g - .add_v("test_value_map") - .property("name", "test") - .to_list() - .unwrap(); - - let vertex = &vertices[0]; - - let results = g.v(vertex.id()).value_map(()).to_list().unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!( - "test", - value["name"].get::().unwrap()[0] - .get::() - .unwrap() - ); - - let results = g.v(vertex.id()).value_map("name").to_list().unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!( - "test", - value["name"].get::().unwrap()[0] - .get::() - .unwrap() - ); - - let results = g.v(vertex.id()).value_map("fake").to_list().unwrap(); - - assert_eq!(0, results[0].len()); - - let results = g.v(vertex.id()).value_map(true).to_list().unwrap(); - - assert_eq!(true, results[0].get("id").is_some()); - assert_eq!(true, results[0].get("label").is_some()); - assert_eq!(true, results[0].get("name").is_some()); -} - -#[test] -fn test_unwrap_map_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - let g = traversal().with_remote(client); - - let vertices = g - .add_v("test_value_map") - .property("name", "test") - .to_list() - .unwrap(); - - let vertex = &vertices[0]; - - let results = g.v(vertex.id()).value_map(true).next().unwrap().unwrap(); - let v_id = vertex.id().get::().unwrap(); - - let id = utils::unwrap_map::(&results, "id", 0); - let property = utils::unwrap_map::(&results, "name", 0); - let label = utils::unwrap_map::(&results, "label", 0); - - assert_eq!(id.is_ok(), true); - assert_eq!(property.is_ok(), true); - assert_eq!(label.is_ok(), true); - - assert_eq!(id.unwrap(), v_id); - assert_eq!(property.unwrap(), "test"); - assert_eq!(label.unwrap(), "test_value_map"); -} - -#[test] -fn test_element_map_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - let g = traversal().with_remote(client); - - let vertices = g - .add_v("test_element_map") - .property("name", "test") - .to_list() - .unwrap(); - - let vertex = &vertices[0]; - - let results = g.v(vertex.id()).element_map(()).to_list().unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!("test", value["name"].get::().unwrap()); - - let results = g.v(vertex.id()).element_map("name").to_list().unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!("test", value["name"].get::().unwrap()); - - let results = g.v(vertex.id()).element_map("fake").to_list().unwrap(); - - assert_eq!(2, results[0].len()); - assert_eq!(true, results[0].get("id").is_some()); - assert_eq!(true, results[0].get("label").is_some()); - - let results = g.v(vertex.id()).element_map(()).to_list().unwrap(); - - assert_eq!(true, results[0].get("id").is_some()); - assert_eq!(true, results[0].get("label").is_some()); - assert_eq!(true, results[0].get("name").is_some()); -} - -#[test] -fn test_count_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - let vertex = create_vertex_with_label(&client, "test_count", "Count"); - - let g = traversal().with_remote(client); - - let results = g.v(vertex.id()).count().to_list().unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(&1, value); -} - -#[test] -fn test_group_count_step_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_group_count").unwrap(); - - let vertex = create_vertex_with_label(&client, "test_group_count", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_group_count") - .group_count() - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!( - &GValue::Int64(1), - value - .get(GKey::String(match vertex.id() { - GID::String(s) => s.to_string(), - GID::Int32(i) => i.to_string(), - GID::Int64(i) => i.to_string(), - })) - .unwrap() - ); - //println - //value[&vertex].get::().unwrap()); - - let results = g - .v(()) - .has_label("test_group_count") - .group_count() - .by("name") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(&1, value["Count"].get::().unwrap()); - - let results = g - .v(()) - .has_label("test_group_count") - .group_count() - .by(T::Label) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(&1, value["test_group_count"].get::().unwrap()); -} - -#[test] -fn test_group_by_step_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_group_by_step").unwrap(); - - create_vertex_with_label(&client, "test_group_by_step", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_group_by_step") - .group() - .by("name") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(1, value["Count"].get::().unwrap().len()); - - let results = g - .v(()) - .has_label("test_group_by_step") - .group() - .by(T::Label) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(1, value["test_group_by_step"].get::().unwrap().len()); - - // - - let results = g - .v(()) - .has_label("test_group_by_step") - .group() - .by(T::Label) - .by(__.count()) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(&1, value["test_group_by_step"].get::().unwrap()); -} - -#[test] -fn test_select_step_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_select_step").unwrap(); - - create_vertex_with_label(&client, "test_select_step", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_select_step") - .group_count() - .by("name") - .select("Count") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(&1, value.get::().unwrap()); -} - -#[test] -fn test_fold_step_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_fold_step").unwrap(); - - create_vertex_with_label(&client, "test_fold_step", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_fold_step") - .values("name") - .fold() - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!("Count", value[0].get::().unwrap()); -} - -#[test] -fn test_unfold_step_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_unfold_step").unwrap(); - - let vertex = create_vertex_with_label(&client, "test_unfold_step", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(vertex.id()) - .property_map(()) - .unfold() - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!( - "Count", - value["name"].get::().unwrap()[0] - .get::() - .unwrap() - .get::() - .unwrap() - ); -} - -#[test] -fn test_path_step_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_path_step").unwrap(); - - let v = create_vertex_with_label(&client, "test_path_step", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_path_step") - .path() - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let value = &results[0]; - - assert_eq!(v.id(), value.objects()[0].get::().unwrap().id()); -} - -#[test] -fn test_limit_step_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_limit_step").unwrap(); - - create_vertex_with_label(&client, "test_limit_step", "Count"); - create_vertex_with_label(&client, "test_limit_step", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_limit_step") - .limit(1) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); -} - -#[test] -fn test_dedup_step_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_limit_step").unwrap(); - - create_vertex_with_label(&client, "test_limit_step", "Count"); - create_vertex_with_label(&client, "test_limit_step", "Count"); - - let g = traversal().with_remote(client); - - let results = g - .v(()) - .has_label("test_limit_step") - .dedup(()) - .by(T::Label) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); -} - -#[test] -fn test_numerical_steps_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_numerical_steps").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("test_numerical_steps") - .property("age", 26) - .to_list() - .unwrap(); - g.add_v("test_numerical_steps") - .property("age", 20) - .to_list() - .unwrap(); - - // sum - let results = g - .v(()) - .has_label("test_numerical_steps") - .values("age") - .sum(()) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(&46, results[0].get::().unwrap()); - - // max - let results = g - .v(()) - .has_label("test_numerical_steps") - .values("age") - .max(()) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(&26, results[0].get::().unwrap()); - - // mean - - let results = g - .v(()) - .has_label("test_numerical_steps") - .values("age") - .mean(()) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(&23.0, results[0].get::().unwrap()); - - // min - - let results = g - .v(()) - .has_label("test_numerical_steps") - .values("age") - .min(()) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(&20, results[0].get::().unwrap()); -} - -#[test] -fn test_has_with_p_steps_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_has_with_p_steps").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("test_has_with_p_steps") - .property("age", 26) - .to_list() - .unwrap(); - let vertices = g - .add_v("test_has_with_p_steps") - .property("age", 20) - .to_list() - .unwrap(); - - let results = g - .v(()) - .has(("test_has_with_p_steps", "age", P::within(vec![19, 20]))) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertices[0].id(), results[0].id()); - - let results = g - .v(()) - .has_label("test_has_with_p_steps") - .values("age") - .is(20) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(&20, results[0].get::().unwrap()); - - let results = g - .v(()) - .has_label("test_has_with_p_steps") - .values("age") - .is(P::within(vec![19, 20])) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(&20, results[0].get::().unwrap()); -} - -#[test] -fn test_has_with_text_p_step_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_has_with_text_p_step").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("test_has_with_text_p_step") - .property("name", "Jon") - .to_list() - .unwrap(); - - let vertices = g - .add_v("test_has_with_text_p_step") - .property("name", "Alice") - .to_list() - .unwrap(); - - let results = g - .v(()) - .has(("test_has_with_text_p_step", "name", TextP::containing("A"))) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(vertices[0].id(), results[0].id()); - - let results = g - .v(()) - .has_label("test_has_with_text_p_step") - .values("name") - .is("Alice") - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!("Alice", results[0].get::().unwrap()); - - let results = g - .v(()) - .has_label("test_has_with_text_p_step") - .values("name") - .is(TextP::containing("Al")) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!("Alice", results[0].get::().unwrap()); - - g.add_v("test_has_with_text_p_step") - .property("name", "Alice2") - .to_list() - .unwrap(); - - let results = g - .v(()) - .has(("test_has_with_text_p_step", "name", TextP::containing("A"))) - .to_list() - .unwrap(); - - assert_eq!(2, results.len()); -} - -#[test] -fn where_step_test_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "where_step_test").unwrap(); - - let g = traversal().with_remote(client); - - let v = g - .add_v("where_step_test") - .property("age", 26) - .to_list() - .unwrap(); - - let results = g - .v(()) - .has_label("where_step_test") - .where_(__.values("age").is(26)) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - assert_eq!(v[0].id(), results[0].id()); -} - -#[test] -fn not_step_test_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "not_step_test").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("not_step_test") - .property("age", 26) - .to_list() - .unwrap(); - - let results = g - .v(()) - .has_label("not_step_test") - .not(__.values("age").is(26)) - .to_list() - .unwrap(); - - assert_eq!(0, results.len()); -} - -#[test] -fn order_step_test_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "order_step_test").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("order_step_test") - .property("name", "b") - .to_list() - .unwrap(); - - g.add_v("order_step_test") - .property("name", "a") - .to_list() - .unwrap(); - - let results = g - .v(()) - .has_label("order_step_test") - .values("name") - .order(()) - .to_list() - .unwrap(); - - assert_eq!(2, results.len()); - - assert_eq!("a", results[0].get::().unwrap()); - - let results = g - .v(()) - .has_label("order_step_test") - .values("name") - .order(()) - .by(Order::Desc) - .to_list() - .unwrap(); - - assert_eq!(2, results.len()); - - assert_eq!("b", results[0].get::().unwrap()); -} - -#[test] -fn match_step_test_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "match_step_test").unwrap(); - - drop_edges(&client, "match_step_test_edge").unwrap(); - - let g = traversal().with_remote(client); - - let v1 = g - .add_v("match_step_test") - .property("name", "a") - .to_list() - .unwrap(); - - let v2 = g - .add_v("match_step_test") - .property("name", "b") - .to_list() - .unwrap(); - - let v3 = g - .add_v("match_step_test") - .property("name", "c") - .to_list() - .unwrap(); - - g.add_e("match_step_test_edge") - .from(&v1[0]) - .to(&v2[0]) - .to_list() - .unwrap(); - - g.add_e("match_step_test_edge") - .from(&v2[0]) - .to(&v3[0]) - .to_list() - .unwrap(); - - let results = g - .v(()) - .has_label("match_step_test") - .match_(vec![ - __.as_("a") - .has(("name", "a")) - .out("match_step_test_edge") - .as_("b"), - __.as_("b").out("match_step_test_edge").as_("c"), - ]) - .select(vec!["a", "c"]) - .to_list() - .unwrap(); - - assert_eq!(1, results.len()); - - let first = &results[0].get::().unwrap(); - - assert_eq!(&v1[0], first["a"].get::().unwrap()); - assert_eq!(&v3[0], first["c"].get::().unwrap()); -} - -#[test] -fn drop_step_test_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "drop_step_test").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("drop_step_test") - .property("name", "a") - .next() - .unwrap(); - - g.add_v("drop_step_test") - .property("name", "b") - .next() - .unwrap(); - - let results = g.v(()).has_label("drop_step_test").count().next().unwrap(); - - assert_eq!(Some(2), results); - - g.v(()) - .has_label("drop_step_test") - .drop() - .to_list() - .unwrap(); - - let results = g.v(()).has_label("drop_step_test").has_next().unwrap(); - - assert_eq!(false, results); -} - -#[test] -fn or_step_test_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "or_step_test").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("or_step_test") - .property("foo", "bar") - .property("bar", "foo") - .next() - .unwrap(); - - g.add_v("or_step_test") - .property("foo", "nobar") - .property("bar", "nofoo") - .next() - .unwrap(); - - let result = g - .v(()) - .has_label("or_step_test") - .has(("foo", "bar")) - .or(()) - .has(("bar", "foo")) - .to_list() - .unwrap(); - assert_eq!(result.len(), 1); - - let result = g - .v(()) - .has_label("or_step_test") - .has(("foo", "bar")) - .or(()) - .has(("bar", "nofoo")) - .to_list() - .unwrap(); - assert_eq!(result.len(), 2); -} - -#[test] -fn iter_terminator_test_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "iter_terminator_test").unwrap(); - - let g = traversal().with_remote(client); - - g.add_v("iter_terminator_test") - .property("name", "a") - .next() - .unwrap(); - - g.add_v("iter_terminator_test") - .property("name", "b") - .next() - .unwrap(); - - let results: Vec = g - .v(()) - .has_label("iter_terminator_test") - .iter() - .unwrap() - .filter_map(Result::ok) - .collect(); - - assert_eq!(2, results.len()) -} - -#[test] -fn test_select_pop_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_select_pop").unwrap(); - drop_vertices(&client, "test_select_pop_child").unwrap(); - - let g = traversal().with_remote(client); - - let v1 = g - .add_v("test_select_pop") - .property("name", "a") - .to_list() - .unwrap(); - - let v2 = g - .add_v("test_select_pop") - .property("name", "b") - .to_list() - .unwrap(); - - let e1 = g - .add_v("test_select_pop_child") - .property("name", "a") - .to_list() - .unwrap(); - - let e2 = g - .add_v("test_select_pop_child") - .property("name", "b") - .to_list() - .unwrap(); - - g.add_e("child").from(&v1[0]).to(&e1[0]).to_list().unwrap(); - - g.add_e("child").from(&v2[0]).to(&e2[0]).to_list().unwrap(); - - let results = g - .v(()) - .has_label("test_select_pop") - .has(("name", "a")) - .out("child") - .as_("v") - .v(()) - .has_label("test_select_pop") - .has(("name", "b")) - .out("child") - .as_("v") - .select((Pop::All, "v")) - .unfold() - .to_list() - .unwrap(); - assert_eq!(results.len(), 2); - - let results = g - .v(()) - .has_label("test_select_pop") - .has(("name", "a")) - .out("child") - .as_("v") - .v(()) - .has_label("test_select_pop") - .has(("name", "b")) - .out("child") - .as_("v") - .select((Pop::Last, "v")) - .unfold() - .to_list() - .unwrap(); - assert_eq!(results.len(), 1); - - let results = g - .v(()) - .has_label("test_select_pop") - .has(("name", "a")) - .out("child") - .as_("v") - .v(()) - .has_label("test_select_pop") - .has(("name", "b")) - .out("child") - .as_("v") - .select((Pop::First, "v")) - .unfold() - .to_list() - .unwrap(); - assert_eq!(results.len(), 1); -} - -#[test] -fn test_repeat_until_loops_loops_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_repeat_until_loops").unwrap(); - drop_vertices(&client, "test_repeat_until_loops_child").unwrap(); - - let g = traversal().with_remote(client); - - let v1 = g - .add_v("test_repeat_until_loops") - .property("name", "a") - .to_list() - .unwrap(); - - let e1 = g - .add_v("test_repeat_until_loops_child") - .property("name", "b") - .to_list() - .unwrap(); - - let e2 = g - .add_v("test_repeat_until_loops_child") - .property("name", "c") - .to_list() - .unwrap(); - - g.add_e("child").from(&v1[0]).to(&e1[0]).to_list().unwrap(); - g.add_e("child").from(&e1[0]).to(&e2[0]).to_list().unwrap(); - - let results = g - .v(v1[0].id()) - .repeat(__.out("child")) - .until(__.loops(()).is(2)) - .to_list() - .unwrap(); - - assert_eq!(results.len(), 1); - assert_eq!(results[0], e2[0]); -} - -#[test] -fn test_simple_path_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_simple_path").unwrap(); - drop_vertices(&client, "test_simple_path_child").unwrap(); - - let g = traversal().with_remote(client); - - let v1 = g - .add_v("test_simple_path") - .property("name", "a") - .to_list() - .unwrap(); - - let e1 = g - .add_v("test_simple_path_child") - .property("name", "b") - .to_list() - .unwrap(); - - let e2 = g - .add_v("test_simple_path_child") - .property("name", "c") - .to_list() - .unwrap(); - - g.add_e("child").from(&v1[0]).to(&e1[0]).to_list().unwrap(); - g.add_e("child").from(&e1[0]).to(&e2[0]).to_list().unwrap(); - g.add_e("child").from(&e2[0]).to(&v1[0]).to_list().unwrap(); - - let results = g - .v(v1[0].id()) - .repeat(__.out("child").simple_path()) - .until(__.loops(()).is(2)) - .to_list() - .unwrap(); - - assert_eq!(results.len(), 1); - assert_eq!(results[0], e2[0]); -} - -#[test] -fn test_sample_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_sample").unwrap(); - drop_vertices(&client, "test_sample_child").unwrap(); - - let g = traversal().with_remote(client); - - let v1 = g - .add_v("test_sample") - .property("name", "a") - .to_list() - .unwrap(); - - let e1 = g - .add_v("test_sample_child") - .property("name", "b") - .to_list() - .unwrap(); - - let e2 = g - .add_v("test_sample_child") - .property("name", "b") - .to_list() - .unwrap(); - - g.add_e("child").from(&v1[0]).to(&e1[0]).to_list().unwrap(); - g.add_e("child").from(&v1[0]).to(&e2[0]).to_list().unwrap(); - let results = g.v(v1[0].id()).out("child").sample(1).to_list().unwrap(); - assert_eq!(results.len(), 1); -} - -#[test] -fn test_local_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_local").unwrap(); - drop_vertices(&client, "test_local_child").unwrap(); - drop_vertices(&client, "test_local_child_child").unwrap(); - - let g = traversal().with_remote(client); - - let v1 = g - .add_v("test_local") - .property("name", "a") - .to_list() - .unwrap(); - - let e1 = g - .add_v("test_local_child") - .property("name", "b") - .to_list() - .unwrap(); - - let e2 = g - .add_v("test_local_child") - .property("name", "b") - .to_list() - .unwrap(); - - let e3 = g - .add_v("test_local_child_child") - .property("name", "c") - .to_list() - .unwrap(); - - let e4 = g - .add_v("test_local_child_child") - .property("name", "d") - .to_list() - .unwrap(); - - let e5 = g - .add_v("test_local_child_child") - .property("name", "e") - .to_list() - .unwrap(); - - g.add_e("child").from(&v1[0]).to(&e1[0]).to_list().unwrap(); - g.add_e("child").from(&v1[0]).to(&e2[0]).to_list().unwrap(); - - g.add_e("child_child") - .from(&e1[0]) - .to(&e3[0]) - .to_list() - .unwrap(); - g.add_e("child_child") - .from(&e1[0]) - .to(&e4[0]) - .to_list() - .unwrap(); - - g.add_e("child_child") - .from(&e2[0]) - .to(&e5[0]) - .to_list() - .unwrap(); - - let results = g - .v(v1[0].id()) - .out("child") - .local(__.out("child_child").sample(1)) //Local used here to only get one vertices from each child - .to_list() - .unwrap(); - - assert_eq!(results.len(), 2); -} - -#[test] -fn test_property_cardinality_v2() { - let client = graph_serializer(IoProtocol::GraphSONV2); - - drop_vertices(&client, "test_property_cardinality").unwrap(); - - let g = traversal().with_remote(client); - - let v1 = g - .add_v("test_property_cardinality") - .property("name", "a") - .to_list() - .unwrap(); - - assert!(v1.len() > 0); - - g.v(v1[0].id()) - .property_with_cardinality(Cardinality::List, "name", "b") - .next() - .unwrap(); - let new_v = g.v(v1[0].id()).property_map(()).next().unwrap().unwrap(); - assert_eq!(2, new_v["name"].get::().unwrap().len()); - - g.v(v1[0].id()) - .property_with_cardinality(Cardinality::Single, "name", "b") - .next() - .unwrap(); - let new_v = g.v(v1[0].id()).property_map(()).next().unwrap().unwrap(); - assert_eq!(1, new_v["name"].get::().unwrap().len()); -}