Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FILTER-12: Producing failing tests #20

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@
<artifactId>openmrs-test</artifactId>
<type>pom</type>
</dependency>
<dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep this simple, I think conversion of the tests to use testcontainers should be done separately as part of another ticket, just run H2 in mysql mode for now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @wluyima, I've tried the option you are talking about and the error never occurs. It's as if the option MODE=MYSQL is never considered altogether.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are you doing it? Do you mind sharing the code snippet?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always make tests fail on H2 that pass on MySQL by setting the mode and it is why I ended up adding this line and this, if you comment them out and set mode to mysql, some tests will fail and the same should happen for you, unless you are missing something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wluyima, I'm doing the above to reproduce the exact runtime error. Otherwise a different non-specific error occurs. See snippet in draft here.

Copy link
Member

@wluyima wluyima Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And which is the other error you get in tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I shared the other one above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please share full stacktrace, that is just a portion

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime/test failure with actual MySQL env

org.hibernate.exception.SQLGrammarException: could not extract ResultSet
	at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
	at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:67)
	at org.hibernate.loader.Loader.getResultSet(Loader.java:2341)
	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2094)
	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2056)
	at org.hibernate.loader.Loader.doQuery(Loader.java:953)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:350)
	at org.hibernate.loader.Loader.doList(Loader.java:2887)
	at org.hibernate.loader.Loader.doList(Loader.java:2869)
	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2701)
	at org.hibernate.loader.Loader.list(Loader.java:2696)
	at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109)
	at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1878)
	at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:370)
	at org.openmrs.api.db.hibernate.HibernateProviderDAO.getProvidersByPerson(HibernateProviderDAO.java:113)
	at org.openmrs.api.impl.ProviderServiceImpl.getProvidersByPerson(ProviderServiceImpl.java:125)
	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:498)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
	at com.sun.proxy.$Proxy183.getProvidersByPerson(Unknown Source)
	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:498)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.cache.interceptor.CacheInterceptor.lambda$invoke$0(CacheInterceptor.java:53)
	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:352)
	at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.openmrs.aop.LoggingAdvice.invoke(LoggingAdvice.java:123)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
	at com.sun.proxy.$Proxy184.getProvidersByPerson(Unknown Source)
	at org.openmrs.api.impl.ProviderServiceImpl.getProvidersByPerson(ProviderServiceImpl.java:137)
	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:498)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
	at com.sun.proxy.$Proxy183.getProvidersByPerson(Unknown Source)
	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:498)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.cache.interceptor.CacheInterceptor.lambda$invoke$0(CacheInterceptor.java:53)
	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:352)
	at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.openmrs.aop.LoggingAdvice.invoke(LoggingAdvice.java:123)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
	at com.sun.proxy.$Proxy184.getProvidersByPerson(Unknown Source)
	at org.openmrs.module.datafilter.impl.UserProgramBasedFilterTest.getProvidersByPerson_shouldFailWithSQLSyntaxErrorException(UserProgramBasedFilterTest.java:132)
	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:498)
	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.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
	at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
	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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
	at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:43)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.Iterator.forEachRemaining(Iterator.java:116)
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
	at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:82)
	at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:73)
	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:137)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:89)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
                            OR datafilter_ur.role NOT IN ()
                  ' at line 6
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1003)
	at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:1471)
	at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57)
	... 134 more

Error with H2 in MODE=MYSQL

org.hibernate.exception.SQLGrammarException: could not prepare statement
	at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
	at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:186)
	at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:151)
	at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:2141)
	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2078)
	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2056)
	at org.hibernate.loader.Loader.doQuery(Loader.java:953)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:350)
	at org.hibernate.loader.Loader.doList(Loader.java:2887)
	at org.hibernate.loader.Loader.doList(Loader.java:2869)
	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2701)
	at org.hibernate.loader.Loader.list(Loader.java:2696)
	at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109)
	at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1878)
	at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:370)
	at org.openmrs.api.db.hibernate.HibernateProviderDAO.getProvidersByPerson(HibernateProviderDAO.java:113)
	at org.openmrs.api.impl.ProviderServiceImpl.getProvidersByPerson(ProviderServiceImpl.java:125)
	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:498)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
	at com.sun.proxy.$Proxy174.getProvidersByPerson(Unknown Source)
	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:498)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.cache.interceptor.CacheInterceptor.lambda$invoke$0(CacheInterceptor.java:53)
	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:352)
	at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.openmrs.aop.LoggingAdvice.invoke(LoggingAdvice.java:123)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
	at com.sun.proxy.$Proxy175.getProvidersByPerson(Unknown Source)
	at org.openmrs.api.impl.ProviderServiceImpl.getProvidersByPerson(ProviderServiceImpl.java:137)
	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:498)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
	at com.sun.proxy.$Proxy174.getProvidersByPerson(Unknown Source)
	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:498)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.cache.interceptor.CacheInterceptor.lambda$invoke$0(CacheInterceptor.java:53)
	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:352)
	at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.openmrs.aop.LoggingAdvice.invoke(LoggingAdvice.java:123)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
	at com.sun.proxy.$Proxy175.getProvidersByPerson(Unknown Source)
	at org.openmrs.module.datafilter.impl.UserProgramBasedFilterTest.getProvidersByPerson_shouldFailWithSQLSyntaxErrorException(UserProgramBasedFilterTest.java:133)
	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:498)
	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.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
	at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
	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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
	at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:43)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.Iterator.forEachRemaining(Iterator.java:116)
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
	at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:82)
	at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:73)
	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:137)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:89)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SELECT THIS_.PROVIDER_ID AS PROVIDER1_87_0_, THIS_.PERSON_ID AS PERSON_I2_87_0_, THIS_.NAME AS NAME3_87_0_, THIS_.IDENTIFIER AS IDENTIFI4_87_0_, THIS_.CREATOR AS CREATOR5_87_0_, THIS_.ROLE_ID AS ROLE_ID6_87_0_, THIS_.SPECIALITY_ID AS SPECIALI7_87_0_, THIS_.DATE_CREATED AS DATE_CRE8_87_0_, THIS_.CHANGED_BY AS CHANGED_9_87_0_, THIS_.DATE_CHANGED AS DATE_CH10_87_0_, THIS_.RETIRED_BY AS RETIRED11_87_0_, THIS_.DATE_RETIRED AS DATE_RE12_87_0_, THIS_.RETIRE_REASON AS RETIRE_13_87_0_, THIS_.RETIRED AS RETIRED14_87_0_, THIS_.UUID AS UUID15_87_0_ FROM PROVIDER THIS_ WHERE (
            THIS_.PERSON_ID IN (
                SELECT DATAFILTER_US.PERSON_ID FROM USERS DATAFILTER_US
                    WHERE DATAFILTER_US.USER_ID IN (
                        SELECT DISTINCT DATAFILTER_UR.USER_ID FROM USER_ROLE DATAFILTER_UR
                            WHERE DATAFILTER_UR.ROLE IN ()[*]
                            OR DATAFILTER_UR.ROLE NOT IN ()
                    )
                    OR DATAFILTER_US.USER_ID NOT IN (SELECT DISTINCT DATAFILTER_UR2.USER_ID FROM USER_ROLE DATAFILTER_UR2)
                    OR DATAFILTER_US.USER_ID IN (
                        SELECT DISTINCT DATAFILTER_UR1.USER_ID FROM USER_ROLE DATAFILTER_UR1
                            WHERE DATAFILTER_UR1.ROLE IN (
                                SELECT DISTINCT DATAFILTER_EBM.ENTITY_IDENTIFIER FROM DATAFILTER_ENTITY_BASIS_MAP DATAFILTER_EBM
                                    WHERE DATAFILTER_EBM.ENTITY_TYPE = 'org.openmrs.Role'
                                    AND DATAFILTER_EBM.BASIS_TYPE = 'org.openmrs.Program'
                                    AND DATAFILTER_EBM.BASIS_IDENTIFIER IN (
                                        SELECT DISTINCT DATAFILTER_EBM2.BASIS_IDENTIFIER FROM DATAFILTER_ENTITY_BASIS_MAP DATAFILTER_EBM2
                                            WHERE DATAFILTER_EBM2.ENTITY_TYPE = 'org.openmrs.Role'
                                                AND DATAFILTER_EBM2.BASIS_TYPE = 'org.openmrs.Program'
                                                AND DATAFILTER_EBM2.ENTITY_IDENTIFIER IN ()
                                    )
                            )
                    )
            )
        ) AND THIS_.PERSON_ID=? ORDER BY THIS_.RETIRED ASC, THIS_.PROVIDER_ID ASC"; expected "NOT, EXISTS, INTERSECTS, UNIQUE"; SQL statement:
select this_.provider_id as provider1_87_0_, this_.person_id as person_i2_87_0_, this_.name as name3_87_0_, this_.identifier as identifi4_87_0_, this_.creator as creator5_87_0_, this_.role_id as role_id6_87_0_, this_.speciality_id as speciali7_87_0_, this_.date_created as date_cre8_87_0_, this_.changed_by as changed_9_87_0_, this_.date_changed as date_ch10_87_0_, this_.retired_by as retired11_87_0_, this_.date_retired as date_re12_87_0_, this_.retire_reason as retire_13_87_0_, this_.retired as retired14_87_0_, this_.uuid as uuid15_87_0_ from provider this_ where (
            this_.person_id IN (
                SELECT datafilter_us.person_id FROM users datafilter_us
                    WHERE datafilter_us.user_id IN (
                        SELECT DISTINCT datafilter_ur.user_id FROM user_role datafilter_ur
                            WHERE datafilter_ur.role IN ()
                            OR datafilter_ur.role NOT IN ()
                    )
                    OR datafilter_us.user_id NOT IN (SELECT DISTINCT datafilter_ur2.user_id FROM user_role datafilter_ur2)
                    OR datafilter_us.user_id IN (
                        SELECT DISTINCT datafilter_ur1.user_id FROM user_role datafilter_ur1
                            WHERE datafilter_ur1.role IN (
                                SELECT DISTINCT datafilter_ebm.entity_identifier FROM datafilter_entity_basis_map datafilter_ebm
                                    WHERE datafilter_ebm.entity_type = 'org.openmrs.Role'
                                    AND datafilter_ebm.basis_type = 'org.openmrs.Program'
                                    AND datafilter_ebm.basis_identifier IN (
                                        SELECT DISTINCT datafilter_ebm2.basis_identifier FROM datafilter_entity_basis_map datafilter_ebm2
                                            WHERE datafilter_ebm2.entity_type = 'org.openmrs.Role'
                                                AND datafilter_ebm2.basis_type = 'org.openmrs.Program'
                                                AND datafilter_ebm2.entity_identifier IN ()
                                    )
                            )
                    )
            )
        ) and this_.person_id=? order by this_.retired asc, this_.provider_id asc [42001-200]
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:453)
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
	at org.h2.message.DbException.getSyntaxError(DbException.java:243)
	at org.h2.command.Parser.getSyntaxError(Parser.java:1053)
	at org.h2.command.Parser.readTerm(Parser.java:4479)
	at org.h2.command.Parser.readFactor(Parser.java:3343)
	at org.h2.command.Parser.readSum(Parser.java:3330)
	at org.h2.command.Parser.readConcat(Parser.java:3305)
	at org.h2.command.Parser.readCondition(Parser.java:3108)
	at org.h2.command.Parser.readExpression(Parser.java:3059)
	at org.h2.command.Parser.readInPredicate(Parser.java:3274)
	at org.h2.command.Parser.readCondition(Parser.java:3191)
	at org.h2.command.Parser.readExpressionWithGlobalConditions(Parser.java:3046)
	at org.h2.command.Parser.parseSelect(Parser.java:2962)
	at org.h2.command.Parser.parseQuerySub(Parser.java:2817)
	at org.h2.command.Parser.parseSelectUnion(Parser.java:2649)
	at org.h2.command.Parser.parseQuery(Parser.java:2620)
	at org.h2.command.Parser.readInPredicate(Parser.java:3264)
	at org.h2.command.Parser.readCondition(Parser.java:3191)
	at org.h2.command.Parser.readExpressionWithGlobalConditions(Parser.java:3046)
	at org.h2.command.Parser.parseSelect(Parser.java:2962)
	at org.h2.command.Parser.parseQuerySub(Parser.java:2817)
	at org.h2.command.Parser.parseSelectUnion(Parser.java:2649)
	at org.h2.command.Parser.parseQuery(Parser.java:2620)
	at org.h2.command.Parser.readInPredicate(Parser.java:3264)
	at org.h2.command.Parser.readCondition(Parser.java:3191)
	at org.h2.command.Parser.readExpression(Parser.java:3059)
	at org.h2.command.Parser.readTerm(Parser.java:4344)
	at org.h2.command.Parser.readFactor(Parser.java:3343)
	at org.h2.command.Parser.readSum(Parser.java:3330)
	at org.h2.command.Parser.readConcat(Parser.java:3305)
	at org.h2.command.Parser.readCondition(Parser.java:3108)
	at org.h2.command.Parser.readExpressionWithGlobalConditions(Parser.java:3046)
	at org.h2.command.Parser.parseSelect(Parser.java:2962)
	at org.h2.command.Parser.parseQuerySub(Parser.java:2817)
	at org.h2.command.Parser.parseSelectUnion(Parser.java:2649)
	at org.h2.command.Parser.parseQuery(Parser.java:2620)
	at org.h2.command.Parser.parsePrepared(Parser.java:868)
	at org.h2.command.Parser.parse(Parser.java:843)
	at org.h2.command.Parser.parse(Parser.java:819)
	at org.h2.command.Parser.prepareCommand(Parser.java:738)
	at org.h2.engine.Session.prepareLocal(Session.java:657)
	at org.h2.engine.Session.prepareCommand(Session.java:595)
	at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1235)
	at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:76)
	at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:352)
	at com.mchange.v2.c3p0.impl.NewProxyConnection.prepareStatement(NewProxyConnection.java:567)
	at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:149)
	at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:176)
	... 134 more

Copy link
Member

@wluyima wluyima Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The stacktraces might not look 100% identical but if you closely analyze both of them, they are reporting the same issue i.e. the NOT IN clause having empty braces which is the real issue, H2 seems not to have an issue with it but MySQL does, so using MODE=MySQL should be sufficient to reproduce the bug in tests.

Feel free to create a separate ticket to update the module to use testcontainers

<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
<version>${mysqlTestContainerVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
<type>jar</type>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.hibernate.SessionFactory;
import org.openmrs.api.context.Context;


final class InterceptorUtil {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.datafilter.impl;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.dbunit.DatabaseUnitException;
import org.dbunit.DatabaseUnitRuntimeException;
import org.dbunit.database.DatabaseConfig;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.dbunit.ext.mysql.MySqlDataTypeFactory;
import org.dbunit.operation.DatabaseOperation;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.MySQL5Dialect;
import org.junit.Before;
import org.junit.BeforeClass;
import org.openmrs.GlobalProperty;
import org.openmrs.api.AdministrationService;
import org.openmrs.api.context.Context;
import org.openmrs.api.context.UsernamePasswordCredentials;
import org.openmrs.liquibase.ChangeLogVersionFinder;
import org.openmrs.liquibase.ChangeSetExecutorCallback;
import org.openmrs.module.datafilter.TestConstants;
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.openmrs.test.TestUtil;
import org.openmrs.util.DatabaseUpdater;
import org.openmrs.util.PrivilegeConstants;
import org.testcontainers.containers.MySQLContainer;
import liquibase.changelog.ChangeSet;

public abstract class BaseFilterMySQLBackedTest extends BaseModuleContextSensitiveTest {

private static final Logger log = LoggerFactory.getLogger(BaseFilterMySQLBackedTest.class);

private static MySQLContainer<?> mysqlContainer = new MySQLContainer("mysql:5.7.31");

private static String databaseUrl = "jdbc:mysql://localhost:DATABASE_PORT/openmrs?autoReconnect=true&sessionVariables=default_storage_engine%3DInnoDB&useUnicode=true&characterEncoding=UTF-8";

private static String databaseUsername = "user";

private static String databaseUserPasswword = "12345678";

private static String databaseDialect = MySQL5Dialect.class.getName();

private static String databaseDriver = "com.mysql.jdbc.Driver";

@BeforeClass
public static void setupMySqlDb() throws IOException {

mysqlContainer.withDatabaseName("openmrs");
mysqlContainer.withUsername(databaseUsername);
mysqlContainer.withPassword(databaseUserPasswword);
mysqlContainer.start();
System.setProperty("useInMemoryDatabase", "false");
}

@Override
public void baseSetupWithStandardDataAndAuthentication() throws SQLException {
// Open a session if needed
if (!Context.isSessionOpen()) {
Context.openSession();
}

ChangeLogVersionFinder changeLogVersionFinder = new ChangeLogVersionFinder();

String liquibaseSchemaFileName = changeLogVersionFinder.getLatestSchemaSnapshotFilename().get();
// String liquibaseCoreDataFileName = changeLogVersionFinder.getLatestCoreDataSnapshotFilename().get();

try {
DatabaseUpdater.executeChangelog(liquibaseSchemaFileName,
new PrintingChangeSetExecutorCallback("OpenMRS schema file"));
String datafilterLiquibase = getClass().getClassLoader().getResource("liquibase.xml").toURI().getPath();
DatabaseUpdater.executeChangelog("liquibase.xml",
new PrintingChangeSetExecutorCallback("Datafilter schema file"));
}
catch (Exception ex) {
throw new RuntimeException("Could not update database.", ex);
}
executeDataSet(INITIAL_XML_DATASET_PACKAGE_PATH);

//Commit so that it is not rolled back after a test.
getConnection().commit();

authenticate();
Context.clearSession();
}

@Override
public Properties getRuntimeProperties() {
if (runtimeProperties == null) {
runtimeProperties = TestUtil.getRuntimeProperties(getWebappName());
}
runtimeProperties.setProperty(Environment.URL,
databaseUrl.replaceAll("DATABASE_PORT", String.valueOf(mysqlContainer.getMappedPort(3306))));

runtimeProperties.setProperty(Environment.USER, "user");
runtimeProperties.setProperty(Environment.PASS, "12345678");
runtimeProperties.setProperty("connection.username", "user");
runtimeProperties.setProperty("connection.password", "12345678");
runtimeProperties.setProperty("connection.url",
databaseUrl.replaceAll("DATABASE_PORT", String.valueOf(mysqlContainer.getMappedPort(3306))));
runtimeProperties.setProperty(Environment.HBM2DDL_AUTO, "none");
runtimeProperties.setProperty(Environment.DIALECT, databaseDialect);
runtimeProperties.setProperty(Environment.DRIVER, databaseDialect);

return runtimeProperties;
}

@Override
public void executeDataSet(String dataset) {
try {
turnOffDBConstraints(getConnection());
super.executeDataSet(dataset);
turnOnDBConstraints(getConnection());
}
catch (SQLException e) {
throw new IllegalArgumentException(e);
}
}

@Override
public IDatabaseConnection setupDatabaseConnection(Connection connection) throws DatabaseUnitException {
IDatabaseConnection dbUnitConn = new DatabaseConnection(connection);

DatabaseConfig config = dbUnitConn.getConfig();
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory());

return dbUnitConn;
}

@Before
public void beforeTestMethod() throws SQLException {
executeDataSet(TestConstants.MODULE_TEST_DATASET_XML);
}

protected void reloginAs(String username, String password) {
Context.logout();
Context.authenticate(new UsernamePasswordCredentials(username, password));
}

@Override
public void updateSearchIndex() {
//Disable the interceptor so we can update the search index
String originalValue = null;
Context.addProxyPrivilege(PrivilegeConstants.MANAGE_GLOBAL_PROPERTIES);
AdministrationService as = Context.getAdministrationService();
GlobalProperty gp = as.getGlobalPropertyObject(ImplConstants.GP_RUN_IN_STRICT_MODE);
if (gp == null) {
gp = new GlobalProperty(ImplConstants.GP_RUN_IN_STRICT_MODE);
} else {
originalValue = gp.getPropertyValue();
}

gp.setPropertyValue("false");
as.saveGlobalProperty(gp);
Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_GLOBAL_PROPERTIES);
Context.flushSession();

try {
super.updateSearchIndex();
}
finally {
Context.addProxyPrivilege(PrivilegeConstants.MANAGE_GLOBAL_PROPERTIES);
gp.setPropertyValue(originalValue == null ? "" : originalValue);
as.saveGlobalProperty(gp);
Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_GLOBAL_PROPERTIES);
Context.flushSession();
}
}

private static class PrintingChangeSetExecutorCallback implements ChangeSetExecutorCallback {

private int i = 1;

private String message;

public PrintingChangeSetExecutorCallback(String message) {
this.message = message;
}

/**
* @see ChangeSetExecutorCallback#executing(liquibase.changelog.ChangeSet, int)
*/
@Override
public void executing(ChangeSet changeSet, int numChangeSetsToRun) {
log.info(message + " (" + i++ + "/" + numChangeSetsToRun + "): Author: " + changeSet.getAuthor() + " Comments: "
+ changeSet.getComments() + " Description: " + changeSet.getDescription());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
*/
package org.openmrs.module.datafilter.impl;

import java.io.IOException;
import java.util.Properties;

import org.hibernate.cfg.Environment;
import org.junit.Before;
import org.junit.BeforeClass;
import org.openmrs.GlobalProperty;
import org.openmrs.api.AdministrationService;
import org.openmrs.api.context.Context;
Expand All @@ -31,6 +33,11 @@ public Properties getRuntimeProperties() {
return props;
}

@BeforeClass
public static void setupDb() throws IOException {
System.setProperty("useInMemoryDatabase", "true");
}

@Before
public void beforeTestMethod() {
executeDataSet(TestConstants.MODULE_TEST_DATASET_XML);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.junit.Before;
import org.openmrs.module.datafilter.FilterTestUtils;

public abstract class BaseProgramBasedFilterTest extends BaseFilterTest {
public abstract class BaseProgramBasedFilterTest extends BaseFilterMySQLBackedTest {

protected final static String ROLE_COORDINATOR_PROG_1 = "Program 1 Coordinator";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.Collection;
import java.util.stream.Collectors;

Expand All @@ -26,6 +25,7 @@
import org.openmrs.module.datafilter.TestConstants;
import org.openmrs.module.datafilter.impl.api.DataFilterService;
import org.openmrs.test.TestUtil;
import org.openmrs.util.DatabaseUtil;
import org.openmrs.util.PrivilegeConstants;
import org.springframework.beans.factory.annotation.Autowired;

Expand Down Expand Up @@ -116,4 +116,24 @@ public void getUsers_shouldReturnAllUsersIfTheFilterIsDisabled() {
assertEquals(7, getUsers().size());
}

@Test
public void getProvidersByPerson_shouldFailWithSQLSyntaxErrorException() throws Exception {
// Setup
String exception = "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')\n"
+ " OR datafilter_ur.role NOT IN ()\n" + " ' at line 6";
String sql = "DELETE FROM datafilter_entity_basis_map";
FilterTestUtils.enableFilter(ImplConstants.PROGRAM_BASED_FILTER_NAME_USER);
DatabaseUtil.executeSQL(getConnection(), sql, false);
Context.logout();

// Replay
Context.addProxyPrivilege(PrivilegeConstants.GET_PERSONS);
Context.addProxyPrivilege(PrivilegeConstants.GET_PROVIDERS);
try {
Context.getProviderService().getProvidersByPerson(Context.getPersonService().getPerson(1001));
}
catch (Exception e) {
assertEquals(e.getCause().getMessage(), exception);
}
}
}
39 changes: 39 additions & 0 deletions api/src/test/resources/TestingApplicationContext.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
the terms of the Healthcare Disclaimer located at http://openmrs.org/license.

Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
graphic logo is a trademark of OpenMRS Inc.

-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<!--
From applicationContext-service.xml in openmrs-api
Needed to override and add hibernate mappings to the classpath since omod is not packaged yet
-->
<bean id="sessionFactory" class="org.openmrs.api.db.hibernate.HibernateSessionFactoryBean">
<property name="configLocations">
<list>
<value>classpath:hibernate.cfg.xml</value>
</list>
</property>
<property name="mappingJarLocations">
<ref bean="mappingJarResources"/>
</property>
<!-- default properties must be set in the hibernate.default.properties -->
<property name="packagesToScan">
<list>
<value>org.openmrs</value>
</list>
</property>
</bean>

</beans>
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<openmrsPlatformVersion>2.4.0</openmrsPlatformVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<freemarkerVersion>2.3.29</freemarkerVersion>
<mysqlTestContainerVersion>1.15.2</mysqlTestContainerVersion>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -114,6 +115,16 @@
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<reuseForks>false</reuseForks>
<!-- prevent the annoying ForkedBooter process from stealing window focus on Mac OS -->
<argLine>-Djava.awt.headless=true</argLine>
</configuration>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
Expand Down