https://pact.io logo
#pact-jvm
Title
# pact-jvm
a

Akash

05/10/2022, 4:21 AM
Hi. I’m using
au.com.dius.pact.consumer:junit:4.2.20
on an android client and I keep running into a
java.lang.AssertionError: expected:<200> but was:<500>
error. It’s unclear to me what’s causing the problem. I’ve found a similar issue that was opened in the past which is marked as resolved but probably isn’t.
Also worth mentioning that the only thing different for this endpoint is the path and the expected response body. Everything else (request and response headers, state, response status code) is the same between this one and other pacts that we have currently.
m

Matt (pactflow.io / pact-js / pact-go)

05/10/2022, 4:29 AM
Check the logs. A
500
means the mock server likely got the wrong request it was expecting
It should produce a junit report with the details
a

Akash

05/10/2022, 4:37 AM
Thanks for the reply Matt. The only relevant logs that I keep receiving (for similar 500 issues in the past as well) are:
Copy code
java.lang.AssertionError: Pact Test function failed with an exception, possibly due to Mismatches(mismatches=[UnexpectedRequest(request=	method: GET
	path: /api/participants/00000000-0000-0000-0000-000000000012/notifications
	query: {}
	headers: {Accept-encoding=[gzip], Connection=[Keep-Alive], Host=[localhost:1234], User-agent=[okhttp/4.7.2], Authorization=[Bearer blah]}
	matchers: MatchingRules(rules={})
	generators: Generators(categories={})
	body: EMPTY)])
	at au.com.dius.pact.consumer.junit.JUnitTestSupport.validateMockServerResult(JUnitTestSupport.kt:79)
	at au.com.dius.pact.consumer.junit.BaseProviderRule.validateResult(BaseProviderRule.java:207)
	at au.com.dius.pact.consumer.junit.BaseProviderRule$1.evaluate(BaseProviderRule.java:106)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
	at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
	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.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:121)
	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.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
	at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.AssertionError: expected:<200> but was:<500>
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.failNotEquals(Assert.java:835)
	at org.junit.Assert.assertEquals(Assert.java:647)
	at org.junit.Assert.assertEquals(Assert.java:633)
	at ai.a2i2.conductor.sdk.pacts.ParticipantsPacts.validateParticipantServicePact(ParticipantsPacts.java:196)
	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.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at au.com.dius.pact.consumer.junit.BaseProviderRule.lambda$runPactTest$2(BaseProviderRule.java:192)
	at au.com.dius.pact.consumer.BaseMockServer.runAndWritePact(MockHttpServer.kt:135)
	at au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest(ConsumerPactRunner.kt:32)
	at au.com.dius.pact.consumer.junit.BaseProviderRule.runPactTest(BaseProviderRule.java:190)
	at au.com.dius.pact.consumer.junit.BaseProviderRule$1.evaluate(BaseProviderRule.java:105)
	... 42 more
I’m not sure how to decipher these further.
Ah, please disregard. The path ID parameter was different in the pact definition and the unit test performing the request. I wonder if there’s a better way instead of requiring to hardcode those IDs…
👍 1
m

Matt (pactflow.io / pact-js / pact-go)

05/10/2022, 4:59 AM
there should be a junit report
a

Akash

05/10/2022, 4:59 AM
Yep, those logs are same between stdout and junit report
m

Matt (pactflow.io / pact-js / pact-go)

05/10/2022, 4:59 AM
but the error above also shows the problem, which I think you’ve also figured out!
a

Akash

05/10/2022, 5:00 AM
Yeah! The error text wasn’t immediately clear. Thanks again 🙂
👍 1
m

Matt (pactflow.io / pact-js / pact-go)

05/10/2022, 5:00 AM
Ah, please disregard. The path ID parameter was different in the pact definition and the unit test performing the request. I wonder if there’s a better way instead of requiring to hardcode those IDs…
On the consumer side you can use matchers, but because it’s a unit test you should be able to control these things. The provider must know about them though (or you can use the provider state generators to swap them out at test time)
👀 1
2 Views