Hello guys! I have written some unit tests for the method i added. But i am getting test failures which i dont know how i am going to overcome. I have pasted the error log at pastebin. @dkayiwa, @herbert24, @captaindavinci. @kdaud and all those who would like to assist.
/**
* @see ConceptService#getConceptByNameOrIdOrMap(String)
*/
@Test
public void getConceptByNameOrIdOrMap_shouldFindAConceptByItsConceptId() {
String id = "3";
executeDataSet(GET_CONCEPTS_BY_SET_XML);
Assert.assertEquals("3", conceptService.getConceptByNameOrIdOrMap(id).getConceptId().toString());
}
/**
* @see ConceptService#getConceptByNameOrIdOrMap(String)
*/
@Test
public void getConceptByNameOrIdOrMap_shouldGetConceptByName() {
String nameToFetch = "Some non numeric concept name";
executeDataSet(INITIAL_CONCEPTS_XML);
Concept conceptByName = conceptService.getConceptByNameOrIdOrMap(nameToFetch);
assertEquals("Unable to fetch concept by name", 1, conceptByName.getId().intValue());
}
/**
* @see ConceptService#getConceptByNameOrIdOrMap(String)
*/
@Test
public void getConceptByNameOrIdOrMap_shouldFindAConceptByItsMapping() {
String mapping = "XIC:2345";
executeDataSet(INITIAL_CONCEPTS_XML);
Concept concept = conceptService.getConceptByNameOrIdOrMap(mapping);
Assert.assertEquals("Unable to fetch concept by map", 5, concept.getId().intValue());
}
/**
* @see ConceptService#getConceptByNameOrIdOrMap(String)
*/
@Test
public void getConceptByNameOrIdOrMap_shouldFindAConceptByItsUuid() {
String uniqueId = "0ade2ed3-cd5f-4f46-9459-26127c9265ab";
executeDataSet(INITIAL_CONCEPTS_XML);
Assert.assertEquals(uniqueId, conceptService.getConceptByNameOrIdOrMap(uniqueId).getUuid());
}
/**
* @see ConceptService#getConceptByNameOrIdOrMap(String)
*/
@Test
public void getConceptByNameOrIdOrMap_shouldFindAConceptWithNonStandardUuid() {
String nonStandId = "1000AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
executeDataSet(INITIAL_CONCEPTS_XML);
Assert.assertEquals(nonStandId, conceptService.getConceptByNameOrIdOrMap(nonStandId).getUuid());
}
/**
* @see ConceptService#getConceptByNameOrIdOrMap(String)
*/
@Test
public void getConceptByNameOrIdOrMap_shouldNotFindAConceptWithInvalidUuid() {
String invalidUuid = "1000";
executeDataSet(INITIAL_CONCEPTS_XML);
Assert.assertNull(conceptService.getConceptByNameOrIdOrMap(invalidUuid));
}
/**
* @see ConceptService#getConceptByNameOrIdOrMap(String)
*/
@Test
public void getConceptByNameOrIdOrMap_shouldFindAConceptByStaticConstant() {
assertThat(conceptService.getConceptByNameOrIdOrMap("org.openmrs.api.ConceptServiceTest.TEST_CONCEPT_CONSTANT_ID"), notNullValue());
assertThat(conceptService.getConceptByNameOrIdOrMap("org.openmrs.api.ConceptServiceTest.TEST_CONCEPT_CONSTANT_UUID"), notNullValue());
assertThat(conceptService.getConceptByNameOrIdOrMap("org.openmrs.api.ConceptServiceTest.TEST_CONCEPT_CONSTANT_MAPPING"), notNullValue());
}
/**
* @see ConceptService#getConceptByNameOrIdOrMap(String)
*/
@Test
public void getConceptByNameOrIdOrMap_shouldReturnNullOtherwise() {
executeDataSet(INITIAL_CONCEPTS_XML);
String conceptRef = null;
Assert.assertNull(conceptService.getConceptByNameOrIdOrMap(conceptRef));
conceptRef = "";
Assert.assertNull(conceptService.getConceptByNameOrIdOrMap(conceptRef));
conceptRef = "name does not exist in initialConcepts";
Assert.assertNull(conceptService.getConceptByNameOrIdOrMap(conceptRef));
}
that is the unit tests i managed to add in conceptServiceTest class
@jnsereko I guess you have used the wrong column name in the data set please have a look here at the OpenMRS data model. Also I donāt think there is a need to run executeDataSet(INITIAL_CONCEPTS_XML);
again and again just use the `@Beforeā annotation and make a setup function and use this command in that function. Hope this helps!
1 Like