I have specified PackagesWithMappedClasses tag in Config.xml
<packagesWithMappedClasses> org.openmrs.module.oauth2 </packagesWithMappedClasses>
I created TestingApplicationContext.xml which should override the sessionFactory bean of applicationContext-service.xml by default and I added the following property
<property name="packagesToScan"> <list> <value>org.openmrs.module.oauth2</value> </list> </property>
I created a Question on Ask, but haven’t been able to resolve it yet.
So I delved a but deeper and it turns out that the org.hibernate.SessionFactory instance is not being configured to read the values specified in TestingApplicationContext.xml. Any ideas what needs to be done to wire the tests to read from TestingApplicationContext.xml??
Here is how I drew the conclusion:
I debugged the test and added a breakpoint in AbstractBeanFactory class of Spring Framework. On studying the values of the variables for the bean “sessionFactory” originally defined in openmrs-core at /api/src/main/resources/ applicationContext-service.xml, I see that the variables such as packagesToScan,mappingResources,mappingLocations, annotatedClasses, annotatedPackages are always null throughout the test.
Here is a screenshot:
The String value of packagesToScan and mappingResources were
I added a test-hibernate.cfg.xml and modified the TestingApplicationContext.xml as follows
<property name="configLocations"> <list merge="true"> <value>classpath:hibernate.cfg.xml</value> <value>classpath:test-hibernate.cfg.xml</value> </list> </property>
On debugging again, the configLocations variable showed only 1 value, i.e.,
class path resouce[hibernate.cfg.xml]
I am out of ideas currently of how to get the annonated classes to be mapped by hibernate during tests. How should I proceed? Thanks