Skip to content

Commit c96e777

Browse files
committed
test: Add test code for serializatoin and deserialization of the plan from JSON
1 parent d38bcf1 commit c96e777

File tree

3 files changed

+56
-23
lines changed

3 files changed

+56
-23
lines changed

plan/src/data_type.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ pub type RcRefCellPlan<T> = Rc<RefCell<Plan<T>>>;
2222
pub const DEFAULT_FRAGMENT: &'static str = "default";
2323
// Plan states in unit structs
2424

25-
#[derive(Clone, Serialize, Deserialize)]
25+
#[derive(Clone, Serialize, Deserialize, PartialEq)]
2626
pub struct PlanEdge {
2727
pub fragment: String,
2828
pub direction: EdgeDirection,
2929
}
3030

31-
#[derive(Debug, Clone, Serialize, Deserialize)]
31+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
3232
pub enum EdgeDirection {
3333
Left,
3434
Right,

plan/src/lib.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ mod tests {
226226
use std::collections::{HashMap, HashSet};
227227

228228
use operator::{Iterator, Projection, Rename, Source};
229+
use petgraph::algo::is_isomorphic_matching;
229230
use states::Processed;
230231

231232
use super::*;
@@ -299,4 +300,38 @@ mod tests {
299300

300301
Ok(())
301302
}
303+
304+
#[test]
305+
fn test_plan_serialization() -> Result<(), PlanError> {
306+
let plan = generate_dummy_processed_plan()?;
307+
plan.non_empty_plan_check()?;
308+
309+
let plan_json_string = plan.to_json_string().map_err(|_| {
310+
PlanError::GenericError(format!(
311+
"Something went wrong while serializing to json: {:?}",
312+
plan
313+
))
314+
})?;
315+
316+
let plan_serialized: DiGraphOperators =
317+
serde_json::from_str(&plan_json_string)
318+
.map_err(|err| PlanError::GenericError(err.to_string()))?;
319+
320+
let node_match_fn = |node1: &PlanNode, node2: &PlanNode| -> bool {
321+
node1.operator == node2.operator
322+
};
323+
324+
let edge_match_fn =
325+
|edge1: &PlanEdge, edge2: &PlanEdge| -> bool { edge1 == edge2 };
326+
327+
let plan_graph: &DiGraphOperators = &plan.graph.borrow_mut();
328+
assert!(is_isomorphic_matching(
329+
plan_graph,
330+
&plan_serialized,
331+
node_match_fn,
332+
edge_match_fn,
333+
));
334+
335+
Ok(())
336+
}
302337
}
Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
@prefix rr: <http://www.w3.org/ns/r2rml#> .
2-
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
3-
@prefix ex: <http://example.com/> .
4-
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
5-
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
6-
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
7-
@base <http://example.com/base/> .
1+
@prefix faldo: <http://biohackathon.org/resource/faldo#>.
2+
@prefix rr: <http://www.w3.org/ns/r2rml#>.
3+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
4+
@prefix ex: <http://example.com/>.
5+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
6+
@prefix rml: <http://semweb.mmlab.be/ns/rml#>.
7+
@prefix ql: <http://semweb.mmlab.be/ns/ql#>.
88

99
<TriplesMap1> a rr:TriplesMap;
10-
11-
rml:logicalSource [
10+
rml:logicalSource [
1211
rml:source "student.csv";
13-
rml:referenceFormulation ql:CSV
12+
rml:referenceFormulation ql:CSV;
1413
];
15-
16-
rr:subjectMap [
14+
rr:subjectMap [
1715
rr:template "http://example.com/{ID}/{Name}";
18-
rr:class foaf:Person
16+
rr:class foaf:Person;
1917
];
20-
21-
rr:predicateObjectMap [
22-
rr:predicate ex:id ;
23-
rr:objectMap [ rml:reference "ID" ]
18+
rr:predicateObjectMap [
19+
rr:predicate ex:id;
20+
rr:objectMap [ rml:reference "ID" ];
2421
];
25-
26-
rr:predicateObjectMap [
27-
rr:predicate foaf:name ;
28-
rr:objectMap [ rml:reference "Name" ]
22+
rr:predicateObjectMap [
23+
rr:predicate foaf:name;
24+
rr:objectMap [ rml:reference "Name" ];
2925
].
3026

27+
28+

0 commit comments

Comments
 (0)