Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wagmarcel committed Nov 2, 2023
1 parent 62db7a2 commit 0949ade
Show file tree
Hide file tree
Showing 14 changed files with 631 additions and 3 deletions.
7 changes: 6 additions & 1 deletion jsonldConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ if (!(argv.x === undefined) && !(argv.r === undefined)) {
console.error("Normalized and Expanded are mutally exclusive. Bye!")
process.exit(1)
}
if (argv.x === undefined && argv.r === undefined && argv.n === undefined) {
console.error("No processing switch selected. Bye!")
process.exit(1)
}


if (!Array.isArray(jsonObj)){
jsonArr = [jsonObj]
Expand Down Expand Up @@ -191,7 +196,7 @@ function normalizeExpandedForm(expanded) {
if (!("@type" in attr)) {
if ("https://uri.etsi.org/ngsi-ld/hasValue" in attr || "@value" in attr || "@id" in attr) {
attr["@type"] = "https://uri.etsi.org/ngsi-ld/Property"
} else if (!("https://uri.etsi.org/ngsi-ld/hasObject" in attr)) {
} else if ("https://uri.etsi.org/ngsi-ld/hasObject" in attr) {
attr["@type"] = "https://uri.etsi.org/ngsi-ld/Relationship"
}
if ("@value" in attr) {
Expand Down
2 changes: 2 additions & 0 deletions jsonschema2shacl.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ function scanConstraints(propertyShape, typeschema){
propertyShape.addConstraint(new Constraint(SHACL('in'), typeschema.enum))
}
if ("datatype" in typeschema){
// datatype constraints are not used actively. It is not testing the value but only checks if the formal
// datatype "tag" conforms
// propertyShape.addConstraint(new Constraint(SHACL('datatype'), typeschema.datatype))
}
if ("maxiumum" in typeschema){
Expand Down
2 changes: 1 addition & 1 deletion schema-ngsild-eclass/payload.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
},
"eclass:0173-1#02-AAH880#003": "10",
"id": "urn:x:1",
"type": "iffk:0173-1#01-AKJ975#017"
"type": "eclass:0173-1#01-AKJ975#017"
}
53 changes: 53 additions & 0 deletions tests/payload1.jsonld_n_c0
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[
{
"@context": [
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld",
{
"@vocab": "https://industry-fusion.org/base/v0.1/",
"eclass": {
"@id": "https://industry-fusion.org/eclass#",
"@prefix": true
},
"xsd": {
"@id": "http://www.w3.org/2001/XMLSchema#",
"@prefix": true
},
"iffb": {
"@id": "https://industry-fusion.org/base/v0.1/",
"@prefix": true
},
"iffk": {
"@id": "https://industry-fusion.org/knowledge/v0.1/",
"@prefix": true
},
"rdf": {
"@id": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"@prefix": true
},
"rdfs": {
"@id": "http://www.w3.org/2000/01/rdf-schema#",
"@prefix": true
},
"schema": {
"@id": "http://schema.org/",
"@prefix": true
},
"sh": {
"@id": "http://www.w3.org/ns/shacl#",
"@prefix": true
}
}
],
"id": "urn:x:1",
"type": "eclass:0173-1#01-AKJ975#017",
"hasFilter": {
"object": "urn:filter:1"
},
"machine_state": "Testing",
"machine_state_from_smartbox": "Offline_Idle",
"testiri": {
"id": "iffk:testiri"
},
"eclass:0173-1#02-AAH880#003": "10"
}
]
66 changes: 66 additions & 0 deletions tests/payload1.jsonld_r_c0
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[
{
"@context": [
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld",
{
"@vocab": "https://industry-fusion.org/base/v0.1/",
"eclass": {
"@id": "https://industry-fusion.org/eclass#",
"@prefix": true
},
"xsd": {
"@id": "http://www.w3.org/2001/XMLSchema#",
"@prefix": true
},
"iffb": {
"@id": "https://industry-fusion.org/base/v0.1/",
"@prefix": true
},
"iffk": {
"@id": "https://industry-fusion.org/knowledge/v0.1/",
"@prefix": true
},
"rdf": {
"@id": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"@prefix": true
},
"rdfs": {
"@id": "http://www.w3.org/2000/01/rdf-schema#",
"@prefix": true
},
"schema": {
"@id": "http://schema.org/",
"@prefix": true
},
"sh": {
"@id": "http://www.w3.org/ns/shacl#",
"@prefix": true
}
}
],
"id": "urn:x:1",
"type": "eclass:0173-1#01-AKJ975#017",
"hasFilter": {
"type": "Relationship",
"object": "urn:filter:1"
},
"machine_state": {
"type": "Property",
"value": "Testing"
},
"machine_state_from_smartbox": {
"type": "Property",
"value": "Offline_Idle"
},
"testiri": {
"type": "Property",
"value": {
"id": "iffk:testiri"
}
},
"eclass:0173-1#02-AAH880#003": {
"type": "Property",
"value": "10"
}
}
]
37 changes: 37 additions & 0 deletions tests/payload1.jsonld_x_c0
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
{
"https://industry-fusion.org/eclass#0173-1#02-AAH880#003": [
{
"@value": "10"
}
],
"https://industry-fusion.org/base/v0.1/hasFilter": [
{
"https://uri.etsi.org/ngsi-ld/hasObject": [
{
"@id": "urn:filter:1"
}
]
}
],
"@id": "urn:x:1",
"https://industry-fusion.org/base/v0.1/machine_state": [
{
"@value": "Testing"
}
],
"https://industry-fusion.org/base/v0.1/machine_state_from_smartbox": [
{
"@value": "Offline_Idle"
}
],
"https://industry-fusion.org/base/v0.1/testiri": [
{
"@id": "https://industry-fusion.org/knowledge/v0.1/testiri"
}
],
"@type": [
"https://industry-fusion.org/eclass#0173-1#01-AKJ975#017"
]
}
]
53 changes: 53 additions & 0 deletions tests/payload2.jsonld_n_c0
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[
{
"@context": [
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld",
{
"@vocab": "https://industry-fusion.org/base/v0.1/",
"eclass": {
"@id": "https://industry-fusion.org/eclass#",
"@prefix": true
},
"xsd": {
"@id": "http://www.w3.org/2001/XMLSchema#",
"@prefix": true
},
"iffb": {
"@id": "https://industry-fusion.org/base/v0.1/",
"@prefix": true
},
"iffk": {
"@id": "https://industry-fusion.org/knowledge/v0.1/",
"@prefix": true
},
"rdf": {
"@id": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"@prefix": true
},
"rdfs": {
"@id": "http://www.w3.org/2000/01/rdf-schema#",
"@prefix": true
},
"schema": {
"@id": "http://schema.org/",
"@prefix": true
},
"sh": {
"@id": "http://www.w3.org/ns/shacl#",
"@prefix": true
}
}
],
"id": "urn:x:1",
"type": "iffk:0173-1#01-AKJ975#017",
"hasFilter": {
"object": "urn:filter:1"
},
"machine_state": "Testing",
"machine_state_from_smartbox": "Offline_Idle",
"testiri": {
"id": "iffk:testiri"
},
"eclass:0173-1#02-AAH880#003": "10"
}
]
66 changes: 66 additions & 0 deletions tests/payload2.jsonld_r_c0
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[
{
"@context": [
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld",
{
"@vocab": "https://industry-fusion.org/base/v0.1/",
"eclass": {
"@id": "https://industry-fusion.org/eclass#",
"@prefix": true
},
"xsd": {
"@id": "http://www.w3.org/2001/XMLSchema#",
"@prefix": true
},
"iffb": {
"@id": "https://industry-fusion.org/base/v0.1/",
"@prefix": true
},
"iffk": {
"@id": "https://industry-fusion.org/knowledge/v0.1/",
"@prefix": true
},
"rdf": {
"@id": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"@prefix": true
},
"rdfs": {
"@id": "http://www.w3.org/2000/01/rdf-schema#",
"@prefix": true
},
"schema": {
"@id": "http://schema.org/",
"@prefix": true
},
"sh": {
"@id": "http://www.w3.org/ns/shacl#",
"@prefix": true
}
}
],
"id": "urn:x:1",
"type": "iffk:0173-1#01-AKJ975#017",
"hasFilter": {
"type": "Relationship",
"object": "urn:filter:1"
},
"machine_state": {
"type": "Property",
"value": "Testing"
},
"machine_state_from_smartbox": {
"type": "Property",
"value": "Offline_Idle"
},
"testiri": {
"type": "Property",
"value": {
"id": "iffk:testiri"
}
},
"eclass:0173-1#02-AAH880#003": {
"type": "Property",
"value": "10"
}
}
]
37 changes: 37 additions & 0 deletions tests/payload2.jsonld_x_c0
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
{
"@id": "urn:x:1",
"@type": [
"https://industry-fusion.org/knowledge/v0.1/0173-1#01-AKJ975#017"
],
"https://industry-fusion.org/base/v0.1/hasFilter": [
{
"https://uri.etsi.org/ngsi-ld/hasObject": [
{
"@id": "urn:filter:1"
}
]
}
],
"https://industry-fusion.org/base/v0.1/machine_state": [
{
"@value": "Testing"
}
],
"https://industry-fusion.org/base/v0.1/machine_state_from_smartbox": [
{
"@value": "Offline_Idle"
}
],
"https://industry-fusion.org/base/v0.1/testiri": [
{
"@id": "https://industry-fusion.org/knowledge/v0.1/testiri"
}
],
"https://industry-fusion.org/eclass#0173-1#02-AAH880#003": [
{
"@value": "10"
}
]
}
]
Loading

0 comments on commit 0949ade

Please sign in to comment.