How To Debug DAO Unit Test Errors

15 views
Skip to first unread message

Debapriya Patra

unread,
Jun 21, 2021, 9:17:49 PMJun 21
to jOOQ User Group
Hello,

I am writing unit tests for my DAO class methods by keeping the mock data in a .txt file. The interesting part with Jooq is, it has a common error which does not really say what is going wrong with your mock data setup. 


Can someone help me understand how I can debug this issue in a better way? Moreover I wanted to see the clear error message due to which the tests are breaking.

Here is a sample error log.


18:12:50.170 [Test worker] DEBUG org.jooq.tools.LoggerListener - Executing query          : select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?))
18:12:50.172 [Test worker] DEBUG org.jooq.tools.LoggerListener - -> with bind values      : select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in ('a32ba478-90d9-4c7c-85e9-2899bddab41f', 'a32ba478-90d9-4c7c-85e9-2899bddab42f') and (`content_management`.`edu_course_content`.`course_id` = '132ba478-90d9-4c7c-85e9-2899bddab41f' or `content_management`.`edu_course_content`.`edu_custom_course_id` = '132ba478-90d9-4c7c-85e9-2899bddab41f'))
18:12:50.197 [Test worker] DEBUG org.jooq.tools.LoggerListener - Exception                
org.jooq.exception.DataAccessException: SQL [select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?))]; Invalid SQL: select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?))
Possible reasons include: 
  Your regular expressions are case sensitive.
  Your regular expressions use constant literals (e.g. 'Hello'), but the above SQL string uses bind variable placeholders (e.g. ?).
  Your regular expressions did not quote special characters (e.g. \?).
  Your regular expressions' whitespace doesn't match the input SQL's whitespace.
at org.jooq_3.14.8.MYSQL.debug(Unknown Source)
at org.jooq.impl.Tools.translate(Tools.java:2903)
at org.jooq.impl.DefaultExecuteContext.sqlException(DefaultExecuteContext.java:757)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:389)
at org.jooq.impl.AbstractResultQuery.fetch(AbstractResultQuery.java:333)
at org.jooq.impl.AbstractResultQuery.fetchInto(AbstractResultQuery.java:1550)
at org.jooq.impl.SelectImpl.fetchInto(SelectImpl.java:3936)
at com.chegg.edu.content.mgmt.service.dao.EduCourseContentRepository.getCourseContentsByContentIds(EduCourseContentRepository.java:92)
at com.chegg.edu.content.mgmt.service.dao.EduCourseContentRepositoryTest.testGetCourseContentsByContentIds(EduCourseContentRepositoryTest.java:98)
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:688)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
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:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
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:210)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:206)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:131)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:65)
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:129)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
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:143)
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:129)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
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:143)
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:129)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
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:248)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
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.$Proxy5.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:133)
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.sql.SQLException: Invalid SQL: select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?))
Possible reasons include: 
  Your regular expressions are case sensitive.
  Your regular expressions use constant literals (e.g. 'Hello'), but the above SQL string uses bind variable placeholders (e.g. ?).
  Your regular expressions did not quote special characters (e.g. \?).
  Your regular expressions' whitespace doesn't match the input SQL's whitespace.
at org.jooq.tools.jdbc.MockFileDatabase.execute(MockFileDatabase.java:396)
at org.jooq.tools.jdbc.MockStatement.execute0(MockStatement.java:192)
at org.jooq.tools.jdbc.MockStatement.execute(MockStatement.java:273)
at org.jooq.tools.jdbc.MockStatement.execute(MockStatement.java:268)
at org.jooq.tools.jdbc.DefaultPreparedStatement.execute(DefaultPreparedStatement.java:214)
at org.jooq.impl.Tools.executeStatementAndGetFirstResultSet(Tools.java:4201)
at org.jooq.impl.AbstractResultQuery.execute(AbstractResultQuery.java:279)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:375)
... 93 common frames omitted

SQL [select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?))]; Invalid SQL: select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?))
Possible reasons include: 
  Your regular expressions are case sensitive.
  Your regular expressions use constant literals (e.g. 'Hello'), but the above SQL string uses bind variable placeholders (e.g. ?).
  Your regular expressions did not quote special characters (e.g. \?).
  Your regular expressions' whitespace doesn't match the input SQL's whitespace.
org.jooq.exception.DataAccessException: SQL [select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?))]; Invalid SQL: select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?))
Possible reasons include: 
  Your regular expressions are case sensitive.
  Your regular expressions use constant literals (e.g. 'Hello'), but the above SQL string uses bind variable placeholders (e.g. ?).
  Your regular expressions did not quote special characters (e.g. \?).
  Your regular expressions' whitespace doesn't match the input SQL's whitespace.
at org.jooq_3.14.8.MYSQL.debug(Unknown Source)
at org.jooq.impl.Tools.translate(Tools.java:2903)
at org.jooq.impl.DefaultExecuteContext.sqlException(DefaultExecuteContext.java:757)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:389)
at org.jooq.impl.AbstractResultQuery.fetch(AbstractResultQuery.java:333)
at org.jooq.impl.AbstractResultQuery.fetchInto(AbstractResultQuery.java:1550)
at org.jooq.impl.SelectImpl.fetchInto(SelectImpl.java:3936)
at com.chegg.edu.content.mgmt.service.dao.EduCourseContentRepository.getCourseContentsByContentIds(EduCourseContentRepository.java:92)
at com.chegg.edu.content.mgmt.service.dao.EduCourseContentRepositoryTest.testGetCourseContentsByContentIds(EduCourseContentRepositoryTest.java:98)
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:688)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
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:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
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:210)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:206)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:131)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:65)
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:129)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
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:143)
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:129)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
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:143)
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:129)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
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:248)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
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.$Proxy5.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:133)
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.sql.SQLException: Invalid SQL: select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?))
Possible reasons include: 
  Your regular expressions are case sensitive.
  Your regular expressions use constant literals (e.g. 'Hello'), but the above SQL string uses bind variable placeholders (e.g. ?).
  Your regular expressions did not quote special characters (e.g. \?).
  Your regular expressions' whitespace doesn't match the input SQL's whitespace.
at org.jooq.tools.jdbc.MockFileDatabase.execute(MockFileDatabase.java:396)
at org.jooq.tools.jdbc.MockStatement.execute0(MockStatement.java:192)
at org.jooq.tools.jdbc.MockStatement.execute(MockStatement.java:273)
at org.jooq.tools.jdbc.MockStatement.execute(MockStatement.java:268)
at org.jooq.tools.jdbc.DefaultPreparedStatement.execute(DefaultPreparedStatement.java:214)
at org.jooq.impl.Tools.executeStatementAndGetFirstResultSet(Tools.java:4201)
at org.jooq.impl.AbstractResultQuery.execute(AbstractResultQuery.java:279)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:375)
... 93 more


EduCourseContentRepositoryTest > testGetCourseContentsByContentIds() FAILED
    org.jooq.exception.DataAccessException: SQL [select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?))]; Invalid SQL: select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?))
    Possible reasons include: 
      Your regular expressions are case sensitive.
      Your regular expressions use constant literals (e.g. 'Hello'), but the above SQL string uses bind variable placeholders (e.g. ?).
      Your regular expressions did not quote special characters (e.g. \?).
      Your regular expressions' whitespace doesn't match the input SQL's whitespace.
        at org.jooq_3.14.8.MYSQL.debug(Unknown Source)
        at org.jooq.impl.Tools.translate(Tools.java:2903)
        at org.jooq.impl.DefaultExecuteContext.sqlException(DefaultExecuteContext.java:757)
        at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:389)
        at org.jooq.impl.AbstractResultQuery.fetch(AbstractResultQuery.java:333)
        at org.jooq.impl.AbstractResultQuery.fetchInto(AbstractResultQuery.java:1550)
        at org.jooq.impl.SelectImpl.fetchInto(SelectImpl.java:3936)
        at com.chegg.edu.content.mgmt.service.dao.EduCourseContentRepository.getCourseContentsByContentIds(EduCourseContentRepository.java:92)
        at com.chegg.edu.content.mgmt.service.dao.EduCourseContentRepositoryTest.testGetCourseContentsByContentIds(EduCourseContentRepositoryTest.java:98)
        Caused by:
        java.sql.SQLException: Invalid SQL: select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?))
        Possible reasons include: 
          Your regular expressions are case sensitive.
          Your regular expressions use constant literals (e.g. 'Hello'), but the above SQL string uses bind variable placeholders (e.g. ?).
          Your regular expressions did not quote special characters (e.g. \?).
          Your regular expressions' whitespace doesn't match the input SQL's whitespace.
            at org.jooq.tools.jdbc.MockFileDatabase.execute(MockFileDatabase.java:396)
            at org.jooq.tools.jdbc.MockStatement.execute0(MockStatement.java:192)
            at org.jooq.tools.jdbc.MockStatement.execute(MockStatement.java:273)
            at org.jooq.tools.jdbc.MockStatement.execute(MockStatement.java:268)
            at org.jooq.tools.jdbc.DefaultPreparedStatement.execute(DefaultPreparedStatement.java:214)
            at org.jooq.impl.Tools.executeStatementAndGetFirstResultSet(Tools.java:4201)
            at org.jooq.impl.AbstractResultQuery.execute(AbstractResultQuery.java:279)
            at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:375)
            ... 5 more
--------------------------------------------------------------------
|  Results: FAILURE (1 tests, 0 successes, 1 failures, 0 skipped)  |
--------------------------------------------------------------------

Thanks,
Deba

Lukas Eder

unread,
Jun 22, 2021, 3:44:27 AMJun 22
to jOOQ User Group
Hi Deba,

What's missing from the error message, in your opinion? 

Invalid SQL: select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?))
        Possible reasons include: 
          Your regular expressions are case sensitive.
          Your regular expressions use constant literals (e.g. 'Hello'), but the above SQL string uses bind variable placeholders (e.g. ?).
          Your regular expressions did not quote special characters (e.g. \?).
          Your regular expressions' whitespace doesn't match the input SQL's whitespace.

The query that was executed above simply wasn't matched by your file (assuming you're using the https://www.jooq.org/doc/latest/manual/sql-execution/mock-file-database).

How could the error message be improved to indicate this?

Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/f14ed478-d572-4c91-92be-ae0f1fb520a6n%40googlegroups.com.

Debapriya Patra

unread,
Jun 22, 2021, 10:40:40 AMJun 22
to jooq...@googlegroups.com
Hi Lukas,

This is not really telling me what exactly the error is. I have tried all possible ways but for any issues in the mock data the error is same and it’s not possible to find out the error easily. In this case I am not sure what is the real issue with the mock data.

Thanks,
Deba

--
Cheers,
Debapriya Patra
650.933.6852

Lukas Eder

unread,
Jun 22, 2021, 11:12:16 AMJun 22
to jOOQ User Group
I can have a look, can you share your .txt file?

Debapriya Patra

unread,
Jun 22, 2021, 1:50:23 PMJun 22
to jOOQ User Group
Here is my mock data file and the last one I have added for a new DAO function to test which is causing the error.

#testCreateCourseContent
insert into `content_management`.`edu_course_content` (`course_id`, `edu_content_id`) values (?, ?);
> edu_content_id course_id edu_custom_course_id created_ts updated_ts
> -------------------------------------- -------------------------------------- ----------------------- --------------------- ---------------------
> a32ba478-90d9-4c7c-85e9-2899bddab41f a32ba478-90d9-4c7c-85e9-2899bddab41f null 2021-04-27 11:27:46 2021-04-27 11:27:46
@ rows: 1

#testDeleteEduCourseContent
delete from `content_management`.`edu_course_content` where `content_management`.`edu_course_content`.`edu_content_id` = 'a32ba478-90d9-4c7c-85e9-2899bddab41f';
@ rows: 0

#testGetCoursesByContentIds
select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where `content_management`.`edu_course_content`.`edu_content_id` in (?);
> seq edu_content_id course_id edu_custom_course_id created_ts updated_ts
> ----- -------------------------------------- ------------------------------------- ----------------------- --------------------- ---------------------
> 1 a32ba478-90d9-4c7c-85e9-2899bddab41f a32ba478-90d9-4c7c-85e9-2899bddab41f null 2021-04-27 11:27:46 2021-04-27 11:27:46
> 2 a32ba478-90d9-4c7c-85e9-2899bddab41f a32ba478-90d9-4c7c-85e9-2899bddab41e null 2021-04-27 11:27:46 2021-04-27 11:27:46
@ rows: 2

#testGetCourseByContentId
select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where `content_management`.`edu_course_content`.`edu_content_id` = ?;
> seq edu_content_id course_id edu_custom_course_id created_ts updated_ts
> ----- -------------------------------------- ------------------------------------- ----------------------- --------------------- ---------------------
> 1 a32ba478-90d9-4c7c-85e9-2899bddab41f a32ba478-90d9-4c7c-85e9-2899bddab41f null 2021-04-27 11:27:46 2021-04-27 11:27:46
@ rows: 1

#testGetCourseContentsByContentIds
select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?))]; Invalid SQL: select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?));
> seq course_id edu_custom_course_id edu_content_id
> ----- ------------------------------------- ----------------------- --------------------------------------
> 1 132ba478-90d9-4c7c-85e9-2899bddab41f null a32ba478-90d9-4c7c-85e9-2899bddab41f
> 2 132ba478-90d9-4c7c-85e9-2899bddab41e null a32ba478-90d9-4c7c-85e9-2899bddab42f
@ rows: 2 

Rob Sargent

unread,
Jun 22, 2021, 2:00:23 PMJun 22
to jooq...@googlegroups.com
On 6/22/21 11:50 AM, Debapriya Patra wrote:
> Here is my mock data file and the last one I have added for a new DAO
> function to test which is causing the error.
>
> #testGetCourseContentsByContentIds
> select `content_management`.`edu_course_content`.`course_id`,
> `content_management`.`edu_course_content`.`edu_custom_course_id`,
> `content_management`.`edu_course_content`.`edu_content_id` from
> `content_management`.`edu_course_content` where
> (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?)
> and (`content_management`.`edu_course_content`.`course_id` = ? or
> `content_management`.`edu_course_content`.`edu_custom_course_id` =
> ?))]; Invalid SQL: select
> `content_management`.`edu_course_content`.`course_id`,
> `content_management`.`edu_course_content`.`edu_custom_course_id`,
> `content_management`.`edu_course_content`.`edu_content_id` from
> `content_management`.`edu_course_content` where
> (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?)
> and (`content_management`.`edu_course_content`.`course_id` = ? or
> `content_management`.`edu_course_content`.`edu_custom_course_id` = ?));
> > seq course_id edu_custom_course_id edu_content_id
> > ----- ------------------------------------- -----------------------
> --------------------------------------
> > 1 132ba478-90d9-4c7c-85e9-2899bddab41f null
> a32ba478-90d9-4c7c-85e9-2899bddab41f
> > 2 132ba478-90d9-4c7c-85e9-2899bddab41e null
> a32ba478-90d9-4c7c-85e9-2899bddab42f
> @ rows: 2
edu_custom_course_id = null is never going to be true.

Debapriya Patra

unread,
Jun 22, 2021, 3:44:29 PMJun 22
to jOOQ User Group
That is why my query has the or condition.


 (`content_management`.`edu_course_content`.`course_id` = ? or`content_management`.`edu_course_content`.`edu_custom_course_id` = ?)

And this is working just that my unit test is breaking when I add this mock data in txt file.

Rob Sargent

unread,
Jun 22, 2021, 4:12:06 PMJun 22
to jooq...@googlegroups.com
From the original post
select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in ('a32ba478-90d9-4c7c-85e9-2899bddab41f', 'a32ba478-90d9-4c7c-85e9-2899bddab42f') and (`content_management`.`edu_course_content`.`course_id` = '132ba478-90d9-4c7c-85e9-2899bddab41f' or `content_management`.`edu_course_content`.`edu_custom_course_id` = '132ba478-90d9-4c7c-85e9-2899bddab41f'))
is it expected that the first course_id value will be used twice from the input data?
> seq    course_id                             edu_custom_course_id     edu_content_id
> ----- ------------------------------------- ----------------------- --------------------------------------
> 1      132ba478-90d9-4c7c-85e9-2899bddab41f                    null   a32ba478-90d9-4c7c-85e9-2899bddab41f
> 2      132ba478-90d9-4c7c-85e9-2899bddab41e                    null   a32ba478-90d9-4c7c-85e9-2899bddab42f
@ rows: 2

Looks like your faking UUIDs!  This can lead to confusion.

Debapriya Patra

unread,
Jun 22, 2021, 4:29:36 PMJun 22
to jOOQ User Group
yes, when the courseId is passed it might be a match with course_id column value or edu_custom_course_id column value and returns that row. Regarding the fake UUID, yes, the same is being passed to the unit test case to match the data.

Thanks,
Deba

Lukas Eder

unread,
Jun 23, 2021, 3:06:14 AMJun 23
to jOOQ User Group
This might be a good opportunity to remind you again of the possibility of switching from mocking (which is usually not recommended for non-trivial tests and non-quick-and-dirty-setups, see also comments in the doc or Javadoc) to integration testing using e.g. https://www.testcontainers.org. Just a thought :)

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.

Lukas Eder

unread,
Jun 23, 2021, 3:09:44 AMJun 23
to jOOQ User Group
So, in your test file...

On Tue, Jun 22, 2021 at 7:50 PM Debapriya Patra <debapri...@gmail.com> wrote:

#testGetCourseContentsByContentIds
select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?))]; Invalid SQL: select `content_management`.`edu_course_content`.`course_id`, `content_management`.`edu_course_content`.`edu_custom_course_id`, `content_management`.`edu_course_content`.`edu_content_id` from `content_management`.`edu_course_content` where (`content_management`.`edu_course_content`.`edu_content_id` in (?, ?) and (`content_management`.`edu_course_content`.`course_id` = ? or `content_management`.`edu_course_content`.`edu_custom_course_id` = ?));
> seq course_id edu_custom_course_id edu_content_id
> ----- ------------------------------------- ----------------------- --------------------------------------
> 1 132ba478-90d9-4c7c-85e9-2899bddab41f null a32ba478-90d9-4c7c-85e9-2899bddab41f
> 2 132ba478-90d9-4c7c-85e9-2899bddab41e null a32ba478-90d9-4c7c-85e9-2899bddab42f
@ rows: 2 

You put the error message in there "Invalid SQL ..."

Meaning your original SQL query never matches any expected query in the test file. I mean, we can improve the error message and replace "Invalid SQL" by "SQL statement not matched by any statement in the MockFileDatabase", but the rest still remains. It's not possible to help you spot that particular mistake. The input simply doesn't match any content

I hope this helps,
Lukas

Lukas Eder

unread,
Jun 23, 2021, 3:12:55 AMJun 23
to jOOQ User Group
Error message improvement task: https://github.com/jOOQ/jOOQ/issues/12042

Debapriya Patra

unread,
Jun 23, 2021, 10:34:24 AMJun 23
to jOOQ User Group
Thank you so much!
Reply all
Reply to author
Forward
0 new messages