|
|
@ -94,7 +94,7 @@ fn simple_service_test() { |
|
|
|
"#; |
|
|
|
"#; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let query_options = QueryOptions::default(); |
|
|
|
let query_options = QueryOptions::default().with_service_handler(Box::new(TestServiceHandler)); |
|
|
|
let prepared_query = connection.prepare_query(query, &query_options).unwrap(); |
|
|
|
let prepared_query = connection.prepare_query(query, &query_options).unwrap(); |
|
|
|
let results = prepared_query.exec(&query_options).unwrap(); |
|
|
|
let results = prepared_query.exec(&query_options).unwrap(); |
|
|
|
if let QueryResult::Bindings(results) = results { |
|
|
|
if let QueryResult::Bindings(results) = results { |
|
|
@ -107,73 +107,78 @@ fn simple_service_test() { |
|
|
|
assert_eq!(true, false); |
|
|
|
assert_eq!(true, false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
/* |
|
|
|
|
|
|
|
#[derive(Clone,Copy)] |
|
|
|
|
|
|
|
struct TwoServiceTest; |
|
|
|
|
|
|
|
impl ServiceHandler for TwoServiceTest { |
|
|
|
|
|
|
|
fn handle<'a>(&'a self, named_node: NamedNode) -> Option<(fn(GraphPattern) -> Result<BindingsIterator<'a>>)> { |
|
|
|
|
|
|
|
println!("Handler called for {:?}", named_node);
|
|
|
|
|
|
|
|
let service1 = NamedNode::parse("http://service1.org").unwrap(); |
|
|
|
|
|
|
|
let service2 = NamedNode::parse("http://service2.org").unwrap(); |
|
|
|
|
|
|
|
if named_node == service1 { Some(TwoServiceTest::handle_service1) } |
|
|
|
|
|
|
|
else if named_node == service2 { Some(TwoServiceTest::handle_service2) } |
|
|
|
|
|
|
|
else { None}
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl TwoServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn handle_service1<'a>(graph_pattern: GraphPattern) -> Result<BindingsIterator<'a>> { |
|
|
|
|
|
|
|
let repository = MemoryRepository::default(); |
|
|
|
|
|
|
|
let mut connection = repository.connection().unwrap(); |
|
|
|
|
|
|
|
let file = br#" |
|
|
|
|
|
|
|
<http://example.com/bob> <http://xmlns.com/foaf/0.1/name> "Bob" .
|
|
|
|
|
|
|
|
<http://example.com/alice> <http://xmlns.com/foaf/0.1/name> "Alice" .
|
|
|
|
|
|
|
|
"#; |
|
|
|
|
|
|
|
connection.load_graph(file.as_ref(), GraphSyntax::NTriples, None, None).unwrap(); |
|
|
|
|
|
|
|
let prepared_query = connection.prepare_query_from_pattern(&graph_pattern, None).unwrap(); |
|
|
|
|
|
|
|
let result = prepared_query.exec(&Some(NoneService)).unwrap(); |
|
|
|
|
|
|
|
match result { |
|
|
|
|
|
|
|
QueryResult::Bindings(iterator) => { |
|
|
|
|
|
|
|
let (variables, iter) = iterator.destruct(); |
|
|
|
|
|
|
|
let cloned_iter = iter.collect::<Vec<_>>().into_iter(); |
|
|
|
|
|
|
|
let new_iter = BindingsIterator::new(variables, Box::new(cloned_iter)); |
|
|
|
|
|
|
|
Ok(new_iter) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
_ => Err(format_err!("Excpected bindings but got another QueryResult")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn two_service_test() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone,Copy)] |
|
|
|
|
|
|
|
struct TwoServiceTest; |
|
|
|
|
|
|
|
impl ServiceHandler for TwoServiceTest { |
|
|
|
|
|
|
|
fn handle<'a>(&'a self, named_node: NamedNode) -> Option<(fn(GraphPattern) -> Result<BindingsIterator<'a>>)> { |
|
|
|
|
|
|
|
println!("Handler called for {:?}", named_node);
|
|
|
|
|
|
|
|
let service1 = NamedNode::parse("http://service1.org").unwrap(); |
|
|
|
|
|
|
|
let service2 = NamedNode::parse("http://service2.org").unwrap(); |
|
|
|
|
|
|
|
if named_node == service1 { Some(TwoServiceTest::handle_service1) } |
|
|
|
|
|
|
|
else if named_node == service2 { Some(TwoServiceTest::handle_service2) } |
|
|
|
|
|
|
|
else { None}
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn handle_service2<'a>(graph_pattern: GraphPattern) -> Result<BindingsIterator<'a>> { |
|
|
|
impl TwoServiceTest { |
|
|
|
let repository = MemoryRepository::default(); |
|
|
|
|
|
|
|
let mut connection = repository.connection().unwrap(); |
|
|
|
fn handle_service1<'a>(graph_pattern: GraphPattern) -> Result<BindingsIterator<'a>> { |
|
|
|
let file = br#" |
|
|
|
let repository = MemoryRepository::default(); |
|
|
|
<http://example.com/bob> <http://xmlns.com/foaf/0.1/mbox> <mailto:bob@example.com> .
|
|
|
|
let mut connection = repository.connection().unwrap(); |
|
|
|
<http://example.com/alice> <http://xmlns.com/foaf/0.1/mbox> <mailto:alice@example.com> .
|
|
|
|
let file = br#" |
|
|
|
"#; |
|
|
|
<http://example.com/bob> <http://xmlns.com/foaf/0.1/name> "Bob" .
|
|
|
|
connection.load_graph(file.as_ref(), GraphSyntax::NTriples, None, None).unwrap(); |
|
|
|
<http://example.com/alice> <http://xmlns.com/foaf/0.1/name> "Alice" .
|
|
|
|
let prepared_query = connection.prepare_query_from_pattern(&graph_pattern, None).unwrap(); |
|
|
|
"#; |
|
|
|
let result = prepared_query.exec(&Some(NoneService)).unwrap(); |
|
|
|
connection.load_graph(file.as_ref(), GraphSyntax::NTriples, None, None).unwrap(); |
|
|
|
match result { |
|
|
|
let query_options = QueryOptions::default().with_service_handler(Box::new(TwoServiceTest)); |
|
|
|
QueryResult::Bindings(iterator) => { |
|
|
|
let prepared_query = connection.prepare_query_from_pattern(&graph_pattern, &query_options).unwrap(); |
|
|
|
let (variables, iter) = iterator.destruct(); |
|
|
|
let result = prepared_query.exec(&query_options).unwrap(); |
|
|
|
let cloned_iter = iter.collect::<Vec<_>>().into_iter(); |
|
|
|
match result { |
|
|
|
let new_iter = BindingsIterator::new(variables, Box::new(cloned_iter)); |
|
|
|
QueryResult::Bindings(iterator) => { |
|
|
|
Ok(new_iter) |
|
|
|
let (variables, iter) = iterator.destruct(); |
|
|
|
}, |
|
|
|
let cloned_iter = iter.collect::<Vec<_>>().into_iter(); |
|
|
|
_ => Err(format_err!("Excpected bindings but got another QueryResult")) |
|
|
|
let new_iter = BindingsIterator::new(variables, Box::new(cloned_iter)); |
|
|
|
|
|
|
|
Ok(new_iter) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
_ => Err(format_err!("Excpected bindings but got another QueryResult")) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn two_service_test() { |
|
|
|
fn handle_service2<'a>(graph_pattern: GraphPattern) -> Result<BindingsIterator<'a>> { |
|
|
|
|
|
|
|
let repository = MemoryRepository::default(); |
|
|
|
|
|
|
|
let mut connection = repository.connection().unwrap(); |
|
|
|
|
|
|
|
let file = br#" |
|
|
|
|
|
|
|
<http://example.com/bob> <http://xmlns.com/foaf/0.1/mbox> <mailto:bob@example.com> .
|
|
|
|
|
|
|
|
<http://example.com/alice> <http://xmlns.com/foaf/0.1/mbox> <mailto:alice@example.com> .
|
|
|
|
|
|
|
|
"#; |
|
|
|
|
|
|
|
connection.load_graph(file.as_ref(), GraphSyntax::NTriples, None, None).unwrap(); |
|
|
|
|
|
|
|
let query_options = QueryOptions::default().with_service_handler(Box::new(TwoServiceTest)); |
|
|
|
|
|
|
|
let prepared_query = connection.prepare_query_from_pattern(&graph_pattern, &query_options).unwrap(); |
|
|
|
|
|
|
|
let result = prepared_query.exec(&query_options).unwrap(); |
|
|
|
|
|
|
|
match result { |
|
|
|
|
|
|
|
QueryResult::Bindings(iterator) => { |
|
|
|
|
|
|
|
let (variables, iter) = iterator.destruct(); |
|
|
|
|
|
|
|
let cloned_iter = iter.collect::<Vec<_>>().into_iter(); |
|
|
|
|
|
|
|
let new_iter = BindingsIterator::new(variables, Box::new(cloned_iter)); |
|
|
|
|
|
|
|
Ok(new_iter) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
_ => Err(format_err!("Excpected bindings but got another QueryResult")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let repository = MemoryRepository::default(); |
|
|
|
let repository = MemoryRepository::default(); |
|
|
|
let connection = repository.connection().unwrap(); |
|
|
|
let connection = repository.connection().unwrap(); |
|
|
|
|
|
|
|
|
|
|
@ -193,9 +198,9 @@ fn two_service_test() { |
|
|
|
ORDER BY ?name |
|
|
|
ORDER BY ?name |
|
|
|
"#; |
|
|
|
"#; |
|
|
|
|
|
|
|
|
|
|
|
let prepared_query = connection.prepare_query(query, None).unwrap(); |
|
|
|
let query_options = QueryOptions::default().with_service_handler(Box::new(TwoServiceTest)); |
|
|
|
let service_handler = Some(TwoServiceTest); |
|
|
|
let prepared_query = connection.prepare_query(query, &query_options).unwrap(); |
|
|
|
let results = prepared_query.exec(&service_handler).unwrap(); |
|
|
|
let results = prepared_query.exec(&query_options).unwrap(); |
|
|
|
if let QueryResult::Bindings(results) = results { |
|
|
|
if let QueryResult::Bindings(results) = results { |
|
|
|
let collected = results.into_values_iter().map(move |b| b.unwrap()).collect::<Vec<_>>(); |
|
|
|
let collected = results.into_values_iter().map(move |b| b.unwrap()).collect::<Vec<_>>(); |
|
|
|
for c in collected.clone() { |
|
|
|
for c in collected.clone() { |
|
|
@ -212,6 +217,5 @@ fn two_service_test() { |
|
|
|
assert_eq!(true, false); |
|
|
|
assert_eq!(true, false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|