Created
November 24, 2019 05:22
-
-
Save bodiam/907b6937f9b1c4e07befc3dd5f194aec to your computer and use it in GitHub Desktop.
Validator test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.schematix.validator | |
import com.fasterxml.jackson.dataformat.csv.CsvMapper | |
import com.worldturner.medeia.api.UrlSchemaSource | |
import com.worldturner.medeia.api.jackson.MedeiaJacksonApi | |
import org.junit.jupiter.api.Test | |
class ValidatorTest { | |
@Test | |
fun `for erwin`() { | |
val api = MedeiaJacksonApi() | |
val input = "/cities/few-invalid-cities.csv" | |
val schema = "/cities/cities-schema.json" | |
val csvParser = CsvMapper().factory.createParser(javaClass.getResource(input)) | |
val source = UrlSchemaSource(javaClass.getResource(schema)) | |
val validator = api.loadSchema(source) | |
val validatedParser = api.decorateJsonParser(validator, csvParser) | |
api.parseAll(validatedParser) | |
} | |
} | |
/** | |
LatD, LatM, LatS, NS, LonD, LonM, LonS, EW, City, State | |
41, 5, 59, "N", 80, 39, 0, P, "Youngstown", OH | |
42, 52, 48, "N", 97, 23, 23, P, "Yankton", SD | |
46, 35, 59, "N", 120, 30, 36, W, "Yakima", WA | |
42, 16, 12, "N", 71, 48, 0, W, "Worcester", MA | |
43, 37, 48, "N", 89, 46, 11, W, "Wisconsin Dells", WI | |
36, 5, 59, "N", 80, 15, 0, W, "Winston-Salem", NC | |
{ | |
"definitions": {}, | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"$id": "http://example.com/root.json", | |
"type": "array", | |
"title": "The Root Schema", | |
"items": { | |
"$id": "#/items", | |
"type": "object", | |
"title": "The Items Schema", | |
"required": [ | |
"LatD", | |
"LatM", | |
"LatS", | |
"NS", | |
"LonD", | |
"LonM", | |
"LonS", | |
"EW", | |
"City", | |
"State" | |
], | |
"properties": { | |
"LatD": { | |
"$id": "#/items/properties/LatD", | |
"type": "string", | |
"title": "The Latd Schema", | |
"default": "", | |
"examples": [ | |
"41" | |
], | |
"pattern": "^(.*)$" | |
}, | |
"LatM": { | |
"$id": "#/items/properties/LatM", | |
"type": "string", | |
"title": "The Latm Schema", | |
"default": "", | |
"examples": [ | |
"5" | |
], | |
"pattern": "^(.*)$" | |
}, | |
"LatS": { | |
"$id": "#/items/properties/LatS", | |
"type": "string", | |
"title": "The Lats Schema", | |
"default": "", | |
"examples": [ | |
"59" | |
], | |
"pattern": "^(.*)$" | |
}, | |
"NS": { | |
"$id": "#/items/properties/NS", | |
"type": "string", | |
"title": "The Ns Schema", | |
"default": "", | |
"examples": [ | |
"\"N\"" | |
], | |
"pattern": "^(.*)$" | |
}, | |
"LonD": { | |
"$id": "#/items/properties/LonD", | |
"type": "string", | |
"title": "The Lond Schema", | |
"default": "", | |
"examples": [ | |
"80" | |
], | |
"pattern": "^(.*)$" | |
}, | |
"LonM": { | |
"$id": "#/items/properties/LonM", | |
"type": "string", | |
"title": "The Lonm Schema", | |
"default": "", | |
"examples": [ | |
"39" | |
], | |
"pattern": "^(.*)$" | |
}, | |
"LonS": { | |
"$id": "#/items/properties/LonS", | |
"type": "string", | |
"title": "The Lons Schema", | |
"default": "", | |
"examples": [ | |
"0" | |
], | |
"pattern": "^(.*)$" | |
}, | |
"EW": { | |
"$id": "#/items/properties/EW", | |
"type": "string", | |
"title": "The Ew Schema", | |
"default": "", | |
"examples": [ | |
"\"W\"" | |
], | |
"enum": ["X", "N", "W"] | |
}, | |
"City": { | |
"$id": "#/items/properties/City", | |
"type": "string", | |
"title": "The City Schema", | |
"default": "", | |
"examples": [ | |
"\"Youngstown\"" | |
], | |
"pattern": "^(.*)$" | |
}, | |
"State": { | |
"$id": "#/items/properties/State", | |
"type": "string", | |
"title": "The State Schema", | |
"default": "", | |
"examples": [ | |
"OH" | |
], | |
"pattern": "^(.*)$" | |
} | |
} | |
} | |
} | |
*/ |
Author
bodiam
commented
Nov 24, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment