Skip to content

Commit

Permalink
TRUNK-3190: add unit test for HibernateConceptDAO.getConceptsByAnswer
Browse files Browse the repository at this point in the history
(cherry picked from commit 34d76e2)
  • Loading branch information
david authored and dkayiwa committed Mar 1, 2013
1 parent 945d5c6 commit ae0957e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/src/main/java/org/openmrs/api/db/ConceptDAO.java
Expand Up @@ -243,6 +243,7 @@ public List<ConceptSearchResult> getConcepts(String phrase, List<Locale> locales

/**
* @see org.openmrs.api.ConceptService#getConceptsByAnswer(org.openmrs.Concept)
* @should return concepts for the given answer concept
*/
public List<Concept> getConceptsByAnswer(Concept concept) throws DAOException;

Expand Down
Expand Up @@ -635,7 +635,6 @@ public List<ConceptWord> getConceptWords(String phrase, List<Locale> locales, bo
*/
@SuppressWarnings("unchecked")
public List<Concept> getConceptsByAnswer(Concept concept) {
// TODO broken until Hibernate fixes component and HQL code
String q = "select c from Concept c join c.answers ca where ca.answerConcept = :answer";
Query query = sessionFactory.getCurrentSession().createQuery(q);
query.setParameter("answer", concept);
Expand Down
15 changes: 15 additions & 0 deletions api/src/test/java/org/openmrs/api/db/ConceptDAOTest.java
Expand Up @@ -439,4 +439,19 @@ public void getConcepts_shouldNotReturnConceptsWithMatchingNamesThatAreVoided()
Assert.assertEquals(0, dao.getConcepts("VOIDED", null, false, new ArrayList<ConceptClass>(),
new ArrayList<ConceptDatatype>()).size());
}

/**
* @see ConceptDAO#getConceptsByAnswer(Concept)
* @verifies return concepts for the given answer concept
*/
@Test
public void getConceptsByAnswer_shouldReturnConceptsForTheGivenAnswerConcept() throws Exception {
Concept concept = dao.getConcept(22);
List<Concept> conceptsByAnswer = dao.getConceptsByAnswer(concept);
Assert.assertNotNull(conceptsByAnswer);
Assert.assertEquals(1, conceptsByAnswer.size());
Concept conceptByAnswer = conceptsByAnswer.get(0);
Assert.assertEquals(21, conceptByAnswer.getConceptId().intValue());
}

}

0 comments on commit ae0957e

Please sign in to comment.