pact-jvm: Json parsing error thrown while running the service consumer test
Hey guys,
We have a pact-jvm(pact-jvm-consumer-junit_2.11:3.4.1) setup running the junit tests to generate the pact file.Recently we have started getting this error while running the tests. Stacktrace doesnt give a lot of info but looks like some discrepancy in reading the Pact file. Not sure if its how I am generating the response causing the issue.
groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object
The current character read is '?' with an int value of 0
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 255
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
...............................................................................................................................................................................................................................................................^
at groovy.json.internal.JsonParserCharArray.decodeValueInternal(JsonParserCharArray.java:206)
at groovy.json.internal.JsonParserCharArray.decodeValue(JsonParserCharArray.java:157)
at groovy.json.internal.JsonParserCharArray.decodeFromChars(JsonParserCharArray.java:46)
at groovy.json.internal.JsonParserCharArray.parse(JsonParserCharArray.java:384)
at groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:128)
at groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:151)
at groovy.json.JsonSlurper.parseFile(JsonSlurper.java:365)
at groovy.json.JsonSlurper.parse(JsonSlurper.java:348)
at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:232)
at au.com.dius.pact.model.PactReader.loadFile(PactReader.groovy:159)
at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:232)
at au.com.dius.pact.model.PactReader.loadPact(PactReader.groovy:26)
at au.com.dius.pact.model.PactReader.loadPact(PactReader.groovy)
at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:232)
at au.com.dius.pact.model.BasePact.write(BasePact.groovy:109)
at au.com.dius.pact.consumer.BaseMockServer.runAndWritePact(MockHttpServer.kt:147)
at au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest(ConsumerPactRunner.kt:13)
at au.com.dius.pact.consumer.BaseProviderRule.runPactTest(BaseProviderRule.java:148)
at au.com.dius.pact.consumer.BaseProviderRule.access$100(BaseProviderRule.java:21)
at au.com.dius.pact.consumer.BaseProviderRule$1.evaluate(BaseProviderRule.java:76)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:114)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:57)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:66)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:377)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
This is one of the interaction setup where we are getting this error,
@Pact(consumer = CONSUMER_ID)
public RequestResponsePact getBoardsForMobile(PactDslWithProvider builder) {
return builder
.given("Project with boards")
.uponReceiving("GET all boards")
.matchPath(BOARDS_API_PATTERN, BOARDS_API_EXAMPLE)
.method("GET")
.query("maxResults=10")
.willRespondWith()
.status(HttpStatus.SC_OK)
.headers(ImmutableMap.of("Content-Type", "application/json"))
.body(new PactDslJsonBody()
.minArrayLike("values", 1)
.id()
.stringMatcher("type", "CORE")
.stringMatcher("name", "Business")
.stringMatcher("moduleKey", CORE_MODULE_EXAMPLE)
.closeObject()
.object()
.id()
.stringMatcher("type", "SCRUM")
.stringMatcher("name", "DEMO board")
.stringMatcher("moduleKey", AGILE_MODULE_EXAMPLE)
.closeObject()
.closeArray()
.asBody())
.toPact();
}
And this is how the json from pact file looks like,
mobile-rest-plugin will respond with:
{
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"values": [
{
"name": "Business",
"id": 8124081232,
"type": "CORE",
"moduleKey": "core-mobile-board-service"
},
{
"name": "DEMO board",
"id": 4597649782,
"type": "SCRUM",
"moduleKey": "agile-mobile-board-service"
}
]
}
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (7 by maintainers)
Commits related to this issue
- Add a synchanisation block and file system lock around merging a pact with an existing one on the file system #475 — committed to pact-foundation/pact-jvm by deleted user 7 years ago
- Updated the file system lock code to work on windows #475 — committed to pact-foundation/pact-jvm by deleted user 7 years ago
- Add a synchanisation block and file system lock around merging a pact with an existing one on the file system #475 Conflicts: pact-jvm-model/src/main/groovy/au/com/dius/pact/model/BasePact.groovy p... — committed to pact-foundation/pact-jvm by deleted user 7 years ago
- Updated the file system lock code to work on windows #475 Conflicts: pact-jvm-consumer-junit/src/test/java/au/com/dius/pact/consumer/Defect464Test.java — committed to pact-foundation/pact-jvm by deleted user 7 years ago
Version 3.5.2 has been released with synchronisation and file locking on the pact file.
I definitely need to put that synchronisation check in before writing the pact file.