|
|
@ -11,7 +11,7 @@ fn simple_service_test() { |
|
|
|
&'a self, |
|
|
|
&'a self, |
|
|
|
_: &NamedNode, |
|
|
|
_: &NamedNode, |
|
|
|
graph_pattern: &'a GraphPattern, |
|
|
|
graph_pattern: &'a GraphPattern, |
|
|
|
) -> Result<BindingsIterator<'a>> { |
|
|
|
) -> Result<QuerySolutionsIterator<'a>> { |
|
|
|
let triples = |
|
|
|
let triples = |
|
|
|
b"<http://example.com/s> <http://example.com/p> <http://example.com/o> .".as_ref(); |
|
|
|
b"<http://example.com/s> <http://example.com/p> <http://example.com/o> .".as_ref(); |
|
|
|
do_pattern(triples, graph_pattern, QueryOptions::default()) |
|
|
|
do_pattern(triples, graph_pattern, QueryOptions::default()) |
|
|
@ -30,16 +30,16 @@ fn simple_service_test() { |
|
|
|
.to_string(); |
|
|
|
.to_string(); |
|
|
|
|
|
|
|
|
|
|
|
let options = QueryOptions::default().with_service_handler(TestServiceHandler); |
|
|
|
let options = QueryOptions::default().with_service_handler(TestServiceHandler); |
|
|
|
let results = do_query(b"".as_ref(), query, options).unwrap(); |
|
|
|
let collected = do_query(b"".as_ref(), query, options) |
|
|
|
let collected = results |
|
|
|
.unwrap() |
|
|
|
.into_values_iter() |
|
|
|
.map(|b| { |
|
|
|
.map(move |b| b.unwrap()) |
|
|
|
b.unwrap() |
|
|
|
|
|
|
|
.iter() |
|
|
|
|
|
|
|
.map(|(_, v)| v.clone()) |
|
|
|
|
|
|
|
.collect::<Vec<_>>() |
|
|
|
|
|
|
|
}) |
|
|
|
.collect::<Vec<_>>(); |
|
|
|
.collect::<Vec<_>>(); |
|
|
|
let solution = vec![vec![ |
|
|
|
let solution = vec![vec![ex("s"), ex("p"), ex("o")]]; |
|
|
|
Some(ex(String::from("s"))), |
|
|
|
|
|
|
|
Some(ex(String::from("p"))), |
|
|
|
|
|
|
|
Some(ex(String::from("o"))), |
|
|
|
|
|
|
|
]]; |
|
|
|
|
|
|
|
assert_eq!(collected, solution); |
|
|
|
assert_eq!(collected, solution); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -52,7 +52,7 @@ fn two_service_test() { |
|
|
|
&'a self, |
|
|
|
&'a self, |
|
|
|
named_node: &NamedNode, |
|
|
|
named_node: &NamedNode, |
|
|
|
graph_pattern: &'a GraphPattern, |
|
|
|
graph_pattern: &'a GraphPattern, |
|
|
|
) -> Result<BindingsIterator<'a>> { |
|
|
|
) -> Result<QuerySolutionsIterator<'a>> { |
|
|
|
let service1 = NamedNode::parse("http://service1.org").unwrap(); |
|
|
|
let service1 = NamedNode::parse("http://service1.org").unwrap(); |
|
|
|
let service2 = NamedNode::parse("http://service2.org").unwrap(); |
|
|
|
let service2 = NamedNode::parse("http://service2.org").unwrap(); |
|
|
|
if named_node == &service1 { |
|
|
|
if named_node == &service1 { |
|
|
@ -93,20 +93,18 @@ fn two_service_test() { |
|
|
|
.to_string(); |
|
|
|
.to_string(); |
|
|
|
|
|
|
|
|
|
|
|
let options = QueryOptions::default().with_service_handler(TwoServiceTest); |
|
|
|
let options = QueryOptions::default().with_service_handler(TwoServiceTest); |
|
|
|
let results = do_query(b"".as_ref(), query, options).unwrap(); |
|
|
|
let collected = do_query(b"".as_ref(), query, options) |
|
|
|
let collected = results |
|
|
|
.unwrap() |
|
|
|
.into_values_iter() |
|
|
|
.map(|b| { |
|
|
|
.map(move |b| b.unwrap()) |
|
|
|
b.unwrap() |
|
|
|
|
|
|
|
.iter() |
|
|
|
|
|
|
|
.map(|(_, v)| v.clone()) |
|
|
|
|
|
|
|
.collect::<Vec<_>>() |
|
|
|
|
|
|
|
}) |
|
|
|
.collect::<Vec<_>>(); |
|
|
|
.collect::<Vec<_>>(); |
|
|
|
let solution = vec![ |
|
|
|
let solution = vec![ |
|
|
|
vec![ |
|
|
|
vec![literal("Alice"), mailto("alice@example.com")], |
|
|
|
Some(literal("Alice".to_string())), |
|
|
|
vec![literal("Bob"), mailto("bob@example.com")], |
|
|
|
Some(mailto("alice@example.com".to_string())), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
vec![ |
|
|
|
|
|
|
|
Some(literal("Bob".to_string())), |
|
|
|
|
|
|
|
Some(mailto("bob@example.com".to_string())), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
]; |
|
|
|
]; |
|
|
|
assert_eq!(collected, solution); |
|
|
|
assert_eq!(collected, solution); |
|
|
|
} |
|
|
|
} |
|
|
@ -120,7 +118,7 @@ fn silent_service_empty_set_test() { |
|
|
|
&'a self, |
|
|
|
&'a self, |
|
|
|
_: &NamedNode, |
|
|
|
_: &NamedNode, |
|
|
|
_: &'a GraphPattern, |
|
|
|
_: &'a GraphPattern, |
|
|
|
) -> Result<BindingsIterator<'a>> { |
|
|
|
) -> Result<QuerySolutionsIterator<'a>> { |
|
|
|
Err(Error::msg("This is supposed to fail")) |
|
|
|
Err(Error::msg("This is supposed to fail")) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -141,12 +139,7 @@ fn silent_service_empty_set_test() { |
|
|
|
|
|
|
|
|
|
|
|
let triples = b"".as_ref(); |
|
|
|
let triples = b"".as_ref(); |
|
|
|
let options = QueryOptions::default().with_service_handler(ServiceTest); |
|
|
|
let options = QueryOptions::default().with_service_handler(ServiceTest); |
|
|
|
let results = do_query(triples, query, options).unwrap(); |
|
|
|
assert_eq!(do_query(triples, query, options).unwrap().count(), 1); |
|
|
|
let collected = results |
|
|
|
|
|
|
|
.into_values_iter() |
|
|
|
|
|
|
|
.map(move |b| b.unwrap()) |
|
|
|
|
|
|
|
.collect::<Vec<_>>(); |
|
|
|
|
|
|
|
assert_eq!(collected.len(), 1); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
@ -158,7 +151,7 @@ fn non_silent_service_test() { |
|
|
|
&'a self, |
|
|
|
&'a self, |
|
|
|
_: &NamedNode, |
|
|
|
_: &NamedNode, |
|
|
|
_: &'a GraphPattern, |
|
|
|
_: &'a GraphPattern, |
|
|
|
) -> Result<BindingsIterator<'a>> { |
|
|
|
) -> Result<QuerySolutionsIterator<'a>> { |
|
|
|
Err(Error::msg("This is supposed to fail")) |
|
|
|
Err(Error::msg("This is supposed to fail")) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -179,26 +172,22 @@ fn non_silent_service_test() { |
|
|
|
|
|
|
|
|
|
|
|
let triples = b"".as_ref(); |
|
|
|
let triples = b"".as_ref(); |
|
|
|
let options = QueryOptions::default().with_service_handler(ServiceTest); |
|
|
|
let options = QueryOptions::default().with_service_handler(ServiceTest); |
|
|
|
let results = do_query(triples, query, options).unwrap(); |
|
|
|
let mut solutions = do_query(triples, query, options).unwrap(); |
|
|
|
let result = results.into_values_iter().next(); |
|
|
|
if let Some(Err(_)) = solutions.next() { |
|
|
|
match result { |
|
|
|
} else { |
|
|
|
Some(Err(_)) => assert_eq!(true, true), |
|
|
|
panic!("This should have been an error since the service fails") |
|
|
|
_ => assert_eq!( |
|
|
|
|
|
|
|
true, false, |
|
|
|
|
|
|
|
"This should have been an error since the service fails" |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn ex(id: String) -> Term { |
|
|
|
fn ex(id: &str) -> Term { |
|
|
|
Term::NamedNode(NamedNode::parse(format!("http://example.com/{}", &id)).unwrap()) |
|
|
|
Term::NamedNode(NamedNode::parse(format!("http://example.com/{}", id)).unwrap()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn mailto(id: String) -> Term { |
|
|
|
fn mailto(id: &str) -> Term { |
|
|
|
Term::NamedNode(NamedNode::parse(format!("mailto:{}", &id)).unwrap()) |
|
|
|
Term::NamedNode(NamedNode::parse(format!("mailto:{}", id)).unwrap()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn literal(str: String) -> Term { |
|
|
|
fn literal(str: &str) -> Term { |
|
|
|
Term::Literal(Literal::new_simple_literal(str)) |
|
|
|
Term::Literal(Literal::new_simple_literal(str)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -214,13 +203,13 @@ fn query_store<'a>( |
|
|
|
store: MemoryStore, |
|
|
|
store: MemoryStore, |
|
|
|
query: String, |
|
|
|
query: String, |
|
|
|
options: QueryOptions<'a>, |
|
|
|
options: QueryOptions<'a>, |
|
|
|
) -> Result<BindingsIterator<'a>> { |
|
|
|
) -> Result<QuerySolutionsIterator<'a>> { |
|
|
|
match store.prepare_query(&query, options)?.exec()? { |
|
|
|
match store.prepare_query(&query, options)?.exec()? { |
|
|
|
QueryResult::Bindings(iterator) => { |
|
|
|
QueryResult::Bindings(iterator) => { |
|
|
|
let (varaibles, iter) = iterator.destruct(); |
|
|
|
let (variables, iter) = iterator.destruct(); |
|
|
|
let collected = iter.collect::<Vec<_>>(); |
|
|
|
let collected = iter.collect::<Vec<_>>(); |
|
|
|
Ok(BindingsIterator::new( |
|
|
|
Ok(QuerySolutionsIterator::new( |
|
|
|
varaibles, |
|
|
|
variables, |
|
|
|
Box::new(collected.into_iter()), |
|
|
|
Box::new(collected.into_iter()), |
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
} |
|
|
@ -232,7 +221,7 @@ fn pattern_store<'a>( |
|
|
|
store: MemoryStore, |
|
|
|
store: MemoryStore, |
|
|
|
pattern: &'a GraphPattern, |
|
|
|
pattern: &'a GraphPattern, |
|
|
|
options: QueryOptions<'a>, |
|
|
|
options: QueryOptions<'a>, |
|
|
|
) -> Result<BindingsIterator<'a>> { |
|
|
|
) -> Result<QuerySolutionsIterator<'a>> { |
|
|
|
match store |
|
|
|
match store |
|
|
|
.prepare_query_from_pattern(&pattern, options)? |
|
|
|
.prepare_query_from_pattern(&pattern, options)? |
|
|
|
.exec()? |
|
|
|
.exec()? |
|
|
@ -240,7 +229,7 @@ fn pattern_store<'a>( |
|
|
|
QueryResult::Bindings(iterator) => { |
|
|
|
QueryResult::Bindings(iterator) => { |
|
|
|
let (varaibles, iter) = iterator.destruct(); |
|
|
|
let (varaibles, iter) = iterator.destruct(); |
|
|
|
let collected = iter.collect::<Vec<_>>(); |
|
|
|
let collected = iter.collect::<Vec<_>>(); |
|
|
|
Ok(BindingsIterator::new( |
|
|
|
Ok(QuerySolutionsIterator::new( |
|
|
|
varaibles, |
|
|
|
varaibles, |
|
|
|
Box::new(collected.into_iter()), |
|
|
|
Box::new(collected.into_iter()), |
|
|
|
)) |
|
|
|
)) |
|
|
@ -253,7 +242,7 @@ fn do_query<'a>( |
|
|
|
reader: impl BufRead, |
|
|
|
reader: impl BufRead, |
|
|
|
query: String, |
|
|
|
query: String, |
|
|
|
options: QueryOptions<'a>, |
|
|
|
options: QueryOptions<'a>, |
|
|
|
) -> Result<BindingsIterator<'a>> { |
|
|
|
) -> Result<QuerySolutionsIterator<'a>> { |
|
|
|
let store = make_store(reader)?; |
|
|
|
let store = make_store(reader)?; |
|
|
|
query_store(store, query, options) |
|
|
|
query_store(store, query, options) |
|
|
|
} |
|
|
|
} |
|
|
@ -262,7 +251,7 @@ fn do_pattern<'a>( |
|
|
|
reader: impl BufRead, |
|
|
|
reader: impl BufRead, |
|
|
|
pattern: &'a GraphPattern, |
|
|
|
pattern: &'a GraphPattern, |
|
|
|
options: QueryOptions<'a>, |
|
|
|
options: QueryOptions<'a>, |
|
|
|
) -> Result<BindingsIterator<'a>> { |
|
|
|
) -> Result<QuerySolutionsIterator<'a>> { |
|
|
|
let store = make_store(reader)?; |
|
|
|
let store = make_store(reader)?; |
|
|
|
pattern_store(store, pattern, options) |
|
|
|
pattern_store(store, pattern, options) |
|
|
|
} |
|
|
|
} |
|
|
|