Skip to content

Commit

Permalink
Add TinCan based spec
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarmueller committed Sep 2, 2018
1 parent 2499ae8 commit c541ab2
Show file tree
Hide file tree
Showing 12 changed files with 287 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/test/resources/tincan/activity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "#activity",
"type": "object",
"required": ["id"],
"additionalProperties": false,
"properties": {
"objectType": {"enum": ["Activity"]},
"id": {"$ref": "#activityid!core"},
"definition": {"$ref": "#activity_definition"}
}
}
40 changes: 40 additions & 0 deletions src/test/resources/tincan/activity_definition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "#activity_definition",
"type": "object",
"oneOf": [
{
"properties": {
"interactionType": {"type": "null"},
"correctResponsesPattern": {"type": "null"},
"choices": {"type": "null"},
"scale": {"type": "null"},
"source": {"type": "null"},
"target": {"type": "null"},
"steps": {"type": "null"}
}
},
{"$ref": "#interactionactivity"}
],
"additionalProperties": false,
"properties": {
"name": {"$ref": "#languagemap"},
"description": {"$ref": "#languagemap"},
"type": {
"type": "string",
"format": "iri"
},
"moreInfo": {
"type": "string",
"format": "iri"
},
"interactionType": {},
"correctResponsesPattern": {},
"choices": {},
"scale": {},
"source": {},
"target": {},
"steps": {},
"extensions": {"$ref": "#extensions"}
}
}
13 changes: 13 additions & 0 deletions src/test/resources/tincan/activityid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "#activityid",
"type": "object",
"required": ["activityId"],
"properties": {
"activityId": {
"id": "#activityid!core",
"type": "string",
"format": "iri"
}
}
}
14 changes: 14 additions & 0 deletions src/test/resources/tincan/agent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "#agent",
"allOf": [{"$ref": "#inversefunctional"}],
"properties": {
"name": {"type": "string"},
"objectType": {"enum": ["Agent"]},
"mbox": {},
"mbox_sha1sum": {},
"account": {},
"openid": {}
},
"additionalProperties": false
}
8 changes: 8 additions & 0 deletions src/test/resources/tincan/group.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "#group",
"oneOf": [
{"$ref": "#anonymousgroup"},
{"$ref": "#identifiedgroup"}
]
}
10 changes: 10 additions & 0 deletions src/test/resources/tincan/inversefunctional.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "#inversefunctional",
"oneOf": [
{"$ref": "#mbox"},
{"$ref": "#mbox_sha1sum"},
{"$ref": "#openid"},
{"$ref": "#account"}
]
}
11 changes: 11 additions & 0 deletions src/test/resources/tincan/languagemap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "#languagemap",
"type": "object",
"patternProperties": {
"^(((([A-Za-z]{2,3}(-([A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-([A-Za-z]{4}))?(-([A-Za-z]{2}|[0-9]{3}))?(-([A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-([0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(x(-[A-Za-z0-9]{1,8})+))?)|(x(-[A-Za-z0-9]{1,8})+)|((en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang)))$": {
"type": "string"
}
},
"additionalProperties": false
}
16 changes: 16 additions & 0 deletions src/test/resources/tincan/mbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "#mbox",
"type": "object",
"required": ["mbox"],
"properties": {
"mbox": {
"id": "#mbox!core",
"type": "string",
"format": "mailto-iri"
},
"mbox_sha1sum": {"type": "null"},
"openid": {"type": "null"},
"account": {"type": "null"}
}
}
73 changes: 73 additions & 0 deletions src/test/resources/tincan/statement_base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "#statement_base",
"type": "object",
"required": ["actor", "verb", "object"],
"oneOf": [
{
"required": ["object"],
"properties": {
"object": {"$ref": "#activity"}
}
},
{
"required": ["object"],
"properties": {
"object": {"not": {"$ref": "#activity"}},
"context": {
"properties": {
"revision": {"type": "null"},
"platform": {"type": "null"}
}
}
}
}
],
"additionalProperties": false,
"properties": {
"objectType": {},
"id": {
"type": "string",
"format": "uuid"
},
"actor": {
"oneOf": [
{"$ref": "#agent"},
{"$ref": "#group"}
]
},
"verb": {"$ref": "#verb"},
"object": {"$ref": "#statement_object"},
"result": {"$ref": "#result"},
"context": {"$ref": "#context"},
"timestamp": {
"type": "string",
"format": "iso_date"
},
"stored": {
"type": "string",
"format": "iso_date"
},
"authority": {
"oneOf": [
{"$ref": "#agent"},
{
"allOf": [{"$ref": "#anonymousgroup"}],
"properties": {
"member": {
"type": "array",
"items": {"$ref": "#agent"},
"minItems": 2,
"maxItems": 2
}
}
}
]
},
"version": {"$ref": "#version"},
"attachments": {
"type": "array",
"items": {"$ref": "#attachment"}
}
}
}
17 changes: 17 additions & 0 deletions src/test/resources/tincan/statement_object.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "#statement_object",
"type": "object",
"oneOf": [
{"$ref": "#activity"},
{
"required": ["objectType"],
"oneOf":[
{"$ref": "#agent"},
{"$ref": "#group"},
{"$ref": "#statementref"},
{"$ref": "#substatement"}
]
}
]
}
14 changes: 14 additions & 0 deletions src/test/resources/tincan/verb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "#verb",
"type": "object",
"required": ["id"],
"properties": {
"id": {
"type": "string",
"format": "iri"
},
"display": {"$ref": "#languagemap"}
},
"additionalProperties": false
}
59 changes: 59 additions & 0 deletions src/test/scala/com/eclipsesource/schema/TinCanSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.eclipsesource.schema

import org.specs2.mutable.Specification
import play.api.libs.json.{JsValue, Json}

import scala.util.Try

class TinCanSpec extends Specification { self =>

import com.eclipsesource.schema.drafts.Version4

val instance = JsonSource.fromString(
"""
|{
| "actor": {
| "name": "Sally Glider",
| "mbox": "mailto:sally@example.com"
| },
| "verb": {
| "id": "http://adlnet.gov/expapi/verbs/experienced",
| "display": { "en-US": "experienced" }
| },
| "object": {
| "id": "http://example.com/activities/solo-hang-gliding",
| "definition": {
| "name": { "en-US": "Solo Hang Gliding" }
| }
| }
|}
""".stripMargin).get


"Tin Can Spec" should {

import Version4._

def readSchema(filename: String) =
JsonSource.schemaFromStream(self.getClass.getResourceAsStream(s"/tincan/$filename.json")).get

"validate basic statement object" in {

val validator = SchemaValidator(Some(Version4))
.addSchema("#agent", readSchema("agent"))
.addSchema("#group", readSchema("group"))
.addSchema("#inversefunctional", readSchema("inversefunctional"))
.addSchema("#mbox", readSchema("mbox"))
.addSchema("#statement_base", readSchema("statement_base"))
.addSchema("#statement_object", readSchema("statement_object"))
.addSchema("#verb", readSchema("verb"))
.addSchema("#languagemap", readSchema("languagemap"))
.addSchema("#activity", readSchema("activity"))
.addSchema("#activity_definition", readSchema("activity_definition"))
.addSchema("#activityid", readSchema("activityid"))

val result = validator.validate(readSchema("statement_base"), instance)
result.isSuccess must beTrue
}
}
}

0 comments on commit c541ab2

Please sign in to comment.