Skip to content

Commit

Permalink
test(cognitarium): add variable describe tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Jun 17, 2023
1 parent b6a37cc commit a97b0c1
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion contracts/okp4-cognitarium/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub mod query {
TriplePattern {
subject: VarOrNode::Variable(var.clone()),
predicate: VarOrNode::Variable(format!("{var}{p}")),
object: VarOrNodeOrLiteral::Variable(format!("{var}{p}")),
object: VarOrNodeOrLiteral::Variable(format!("{var}{o}")),
},
)));

Expand Down Expand Up @@ -1218,4 +1218,82 @@ mod tests {
);
}
}

#[test]
fn variable_describe() {
let cases = vec![
(
QueryMsg::Describe {
query: DescribeQuery {
prefixes: vec![Prefix { prefix: "core".to_string(), namespace: "https://ontology.okp4.space/core/".to_string() }],
resource: VarOrNamedNode::Variable("a".to_string()),
r#where: vec![WhereCondition::Simple(TriplePattern(
msg::TriplePattern {
subject: VarOrNode::Variable("a".to_string()),
predicate: VarOrNode::Node(NamedNode(Prefixed(
"core:hasDescription".to_string(),
))),
object: VarOrNodeOrLiteral::Literal(Literal::LanguageTaggedString { value: "A test Dataset.".to_string(), language: "en".to_string() }),
},
))],
},
format: Some(DataFormat::Turtle),
},
DescribeResponse {
format: DataFormat::Turtle,
data: Binary::from(
"<https://ontology.okp4.space/dataverse/dataset/metadata/d1615703-4ee1-4e2f-997e-15aecf1eea4e> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> , <https://ontology.okp4.space/metadata/dataset/GeneralMetadata> ;
\t<https://ontology.okp4.space/core/hasTag> \"test\" ;
\t<https://ontology.okp4.space/core/hasTitle> \"test Dataset\"@en , \"Dataset de test\"@fr ;
\t<https://ontology.okp4.space/core/hasTopic> <https://ontology.okp4.space/thesaurus/topic/Test> ;
\t<https://ontology.okp4.space/core/describes> <https://ontology.okp4.space/dataverse/dataset/0ea1fc7a-dd97-4adc-a10e-169c6597bcde> ;
\t<https://ontology.okp4.space/core/hasFormat> <https://ontology.okp4.space/thesaurus/media-type/application_vndms-excel> ;
\t<https://ontology.okp4.space/core/hasCreator> \"Me\" ;
\t<https://ontology.okp4.space/core/hasLicense> <https://ontology.okp4.space/thesaurus/license/LO-FR-1_0> ;
\t<https://ontology.okp4.space/core/hasPublisher> \"OKP4\" ;
\t<https://ontology.okp4.space/core/hasDescription> \"Un Dataset de test.\"@fr , \"A test Dataset.\"@en .
\
".to_string().as_bytes().to_vec()),
}
),
];

let mut deps = mock_dependencies();

let info = mock_info("owner", &[]);
instantiate(
deps.as_mut(),
mock_env(),
info.clone(),
InstantiateMsg {
limits: StoreLimitsInput::default(),
},
)
.unwrap();

execute(
deps.as_mut(),
mock_env(),
info,
InsertData {
format: Some(DataFormat::RDFXml),
data: read_test_data("sample.rdf.xml"),
},
)
.unwrap();

for (q, expected) in cases {
let res = query(deps.as_ref(), mock_env(), q);

assert!(res.is_ok());

let result = from_binary::<DescribeResponse>(&res.unwrap()).unwrap();

assert_eq!(result.format, expected.format);
assert_eq!(
String::from_utf8_lossy(&result.data),
String::from_utf8_lossy(&expected.data)
);
}
}
}

0 comments on commit a97b0c1

Please sign in to comment.