Skip to content

Instantly share code, notes, and snippets.

@bodiam
Created November 24, 2019 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bodiam/907b6937f9b1c4e07befc3dd5f194aec to your computer and use it in GitHub Desktop.
Save bodiam/907b6937f9b1c4e07befc3dd5f194aec to your computer and use it in GitHub Desktop.
Validator test
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": "^(.*)$"
}
}
}
}
*/
@bodiam
Copy link
Author

bodiam commented Nov 24, 2019


com.worldturner.medeia.api.ValidationFailedException: [Validation Failure
------------------
Rule:     items
Message:  Schema for all items failed to validate
Location: at 1:6 in com.fasterxml.jackson.dataformat.csv.impl.UTF8Reader@5e63cad
Details:
    Rule:     type
    Message:  Type mismatch, data has string and schema has object
    Location: at 1:6 in com.fasterxml.jackson.dataformat.csv.impl.UTF8Reader@5e63cad
    -----
]

	at com.worldturner.medeia.schema.validation.stream.SchemaValidatingConsumer.consume(SchemaValidatingJsonConsumer.kt:31)
	at com.worldturner.medeia.parser.jackson.JacksonTokenDataJsonParser.nextToken(JacksonTokenDataJsonParser.kt:42)
	at com.worldturner.medeia.api.jackson.MedeiaJacksonApi.parseAll(MedeiaJacksonApi.kt:65)
	at net.schematix.validator.ValidatorTest.for erwin(ValidatorTest.kt:71)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:132)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:124)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:74)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:202)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:198)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment