I am trying to write tests for the new HibernateConditionDAO class in the Openmrs-core module. Every time I run mvn clean install
, I get the following error:
> <<< FAILURE! - in org.openmrs.api.db.hibernate.HibernateConditionDAOTest
> shouldGetConditionByUuid(org.openmrs.api.db.hibernate.HibernateConditionDAOTest) Time elapsed: 0.01 sec <<< ERROR!
> org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.openmrs.api.db.hibernate.HibernateConditionDAOTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.openmrs.api.db.hibernate.HibernateConditionDAO org.openmrs.api.db.hibernate.HibernateConditionDAOTest.dao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.openmrs.api.db.hibernate.HibernateConditionDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
I have the following in the applicationContext.xml:
<bean id="conditionDAO" class="org.openmrs.api.db.hibernate.HibernateConditionDAO">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
This is my basic test class:
public class HibernateConditionDAOTest extends BaseContextSensitiveTest {
private static final String CONDITIONS_XML = "org/openmrs/api/db/hibernate/include/HibernateConditionDAOTestDataSet.xml";
@Rule
public ExpectedException thrown = ExpectedException.none();
@Autowired
HibernateConditionDAO dao;
@Before
public void setUp() {
executeDataSet(CONDITIONS_XML);
updateSearchIndex();
}
@Test
public void shouldGetConditionByUuid() {
String uuid = "2cc6880e-2c46-11e4-9038-a6c5e4d22fb7";
Condition condition = dao.getConditionByUuid(uuid);
assertEquals(condition.getClinicalStatus(), "INACTIVE");
}
}
What do I need to do to make hibernate auto-wiring work here? cc: @dkayiwa