@Override protected ConceptSource getExistingObject() { return conceptService.getConceptSource(EXISTING_ID); } }
@Override protected ConceptSource getObjectById(Integer id) { return Context.getConceptService().getConceptSource(id); }
/** * @see ConceptServiceImpl#purgeConceptSource(ConceptSource) */ @Test public void purgeConceptSource_shouldPurgetTheGivenConceptSource() { Integer conceptSourceId = 1; ConceptSource conceptSource = conceptService.getConceptSource(conceptSourceId); conceptService.purgeConceptSource(conceptSource); assertNull(conceptService.getConceptSource(conceptSourceId)); }
/** * @see ConceptService#getConceptReferenceTermsBySource(ConceptSource) */ @Test public void getConceptReferenceTerms_shouldReturnOnlyTheConceptReferenceTermsFromTheGivenConceptSource() { Assert.assertEquals(9, conceptService.getConceptReferenceTerms(null, conceptService.getConceptSource(1), 0, null, true).size()); }
/** * @see ConceptService#retireConceptSource(ConceptSource,String) */ @Test public void retireConceptSource_shouldRetireConceptSource() { ConceptSource cs = conceptService.getConceptSource(3); conceptService.retireConceptSource(cs, "dummy reason for retirement"); cs = conceptService.getConceptSource(3); Assert.assertTrue(cs.getRetired()); Assert.assertEquals("dummy reason for retirement", cs.getRetireReason()); }
/** * @see ConceptService#getDrugByMapping(String, org.openmrs.ConceptSource, java.util.Collection */ @Test(expected = DAOException.class) public void getDrugByMapping_shouldFailIfMultipleDrugsAreFoundMatchingTheBestMapType() { executeDataSet(GET_DRUG_MAPPINGS); ConceptSource source = conceptService.getConceptSource(1); conceptService.getDrugByMapping("CD41003", source, Collections.singleton(conceptService.getConceptMapType(2))); }
/** * @see ConceptService#getDrugsByMapping(String, org.openmrs.ConceptSource, * java.util.Collection, boolean) */ @Test public void getDrugsByMapping_shouldReturnEmptyListIfNoMatchesAreFound() { executeDataSet(GET_DRUG_MAPPINGS); List<ConceptMapType> conceptMapTypeList = conceptService.getConceptMapTypes(false, true); List<Drug> drugs = conceptService.getDrugsByMapping("some radom code", conceptService.getConceptSource(2), conceptMapTypeList, false); assertTrue(drugs.isEmpty()); }
/** * @see ConceptService#getConceptMappingsToSource(ConceptSource) */ @Test public void getConceptMappingsToSource_shouldReturnAListOfConceptMapsFromTheGivenSource() { Assert.assertEquals(8, Context.getConceptService().getConceptMappingsToSource( Context.getConceptService().getConceptSource(1)).size()); }
/** * @see ConceptService#getDrugsByMapping(String, ConceptSource, Collection, boolean) */ @Test public void getDrugsByMapping_shouldMatchOnTheCode() { executeDataSet(GET_DRUG_MAPPINGS); ConceptSource source = conceptService.getConceptSource(1); List<Drug> drugs = conceptService.getDrugsByMapping("WGT234", source, null, false); assertEquals(1, drugs.size()); assertTrue(containsId(drugs, 2)); }
/** * @see ConceptService#getDrugsByMapping(String, ConceptSource, Collection, boolean) */ @Test public void getDrugsByMapping_shouldMatchOnTheConceptSource() { executeDataSet(GET_DRUG_MAPPINGS); List<Drug> drugs = conceptService.getDrugsByMapping(null, conceptService.getConceptSource(2), null, false); assertEquals(1, drugs.size()); assertTrue(containsId(drugs, 2)); }
/** * @see ConceptService#getDrugByMapping(String, org.openmrs.ConceptSource, java.util.Collection */ @Test public void getDrugByMapping_shouldReturnNullIfNoMatchFound() { executeDataSet(GET_DRUG_MAPPINGS); List<ConceptMapType> conceptMapTypeList = conceptService.getConceptMapTypes(false, true); Drug drug = conceptService.getDrugByMapping("random code", conceptService.getConceptSource(1), conceptMapTypeList); assertNull(drug); }
/** * @see ConceptService#getDrugByMapping(String, org.openmrs.ConceptSource, java.util.Collection */ @Test public void getDrugByMapping_shouldReturnADrugThatMatchesTheCodeAndSource() { executeDataSet(GET_DRUG_MAPPINGS); final Integer expectedDrugId = 2; Drug drug = conceptService.getDrugByMapping("WGT234", conceptService.getConceptSource(2), null); assertEquals(expectedDrugId, drug.getDrugId()); }
@Test public void validate_shouldNotFailIfATermHasTwoNewMappingsOnIt() { concept.addName(new ConceptName("my name", Context.getLocale())); ConceptReferenceTerm newTerm = new ConceptReferenceTerm(conceptService.getConceptSource(1), "1234", "term one two three four"); ConceptMap map1 = new ConceptMap(newTerm, conceptService.getConceptMapType(1)); concept.addConceptMapping(map1); ConceptReferenceTerm newTermTwo = new ConceptReferenceTerm(conceptService.getConceptSource(1), "12345", "term one two three four five"); ConceptMap map2 = new ConceptMap(newTermTwo, conceptService.getConceptMapType(1)); concept.addConceptMapping(map2); validator.validate(concept, errors); assertThat(errors, not(hasFieldErrors("conceptMappings[1]"))); }
@Test public void validate_shouldPassForAnEditedConceptWithAMapCreatedWithDeprecatedConceptMapMethods() { Concept concept = cd4Count; ConceptMap map = new ConceptMap(); map.getConceptReferenceTerm().setCode("unique code"); map.getConceptReferenceTerm().setConceptSource(conceptService.getConceptSource(1)); concept.addConceptMapping(map); ValidateUtil.validate(concept); }
/** * @see ConceptReferenceTermValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfTheCodeIsNull() { ConceptReferenceTerm term = new ConceptReferenceTerm(); term.setName("name"); term.setConceptSource(Context.getConceptService().getConceptSource(1)); Errors errors = new BindException(term, "term"); new ConceptReferenceTermValidator().validate(term, errors); Assert.assertEquals(true, errors.hasFieldErrors("code")); }
/** * @see ConceptReferenceTermValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfTheConceptReferenceTermCodeIsADuplicateInItsConceptSource() { ConceptReferenceTerm term = new ConceptReferenceTerm(); term.setName("name"); term.setCode("WGT234"); term.setConceptSource(Context.getConceptService().getConceptSource(1)); Errors errors = new BindException(term, "term"); new ConceptReferenceTermValidator().validate(term, errors); Assert.assertEquals(true, errors.hasFieldErrors("code")); }
/** * @see ConceptReferenceTermValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfTheCodeIsAWhiteSpaceCharacter() { ConceptReferenceTerm term = new ConceptReferenceTerm(); term.setName("name"); term.setCode(" "); term.setConceptSource(Context.getConceptService().getConceptSource(1)); Errors errors = new BindException(term, "term"); new ConceptReferenceTermValidator().validate(term, errors); Assert.assertEquals(true, errors.hasFieldErrors("code")); }
/** * @see ConceptReferenceTermValidator#validate(Object,Errors) */ @Test public void validate_shouldPassIfAllTheRequiredFieldsAreSetAndValid() { ConceptReferenceTerm term = new ConceptReferenceTerm(); term.setName("name"); term.setCode("code"); term.setConceptSource(Context.getConceptService().getConceptSource(1)); Errors errors = new BindException(term, "term"); new ConceptReferenceTermValidator().validate(term, errors); Assert.assertEquals(false, errors.hasErrors()); }
/** * @see ConceptService#saveConceptReferenceTerm(ConceptReferenceTerm) */ @Test public void saveConceptReferenceTerm_shouldAddAConceptReferenceTermToTheDatabaseAndAssignAnIdToIt() { ConceptReferenceTerm term = new ConceptReferenceTerm(); term.setName("test term"); term.setCode("test code"); ConceptSource source = Context.getConceptService().getConceptSource(1); term.setConceptSource(source); ConceptReferenceTerm savedTerm = Context.getConceptService().saveConceptReferenceTerm(term); Assert.assertNotNull(savedTerm.getId()); Assert.assertNotNull(Context.getConceptService().getConceptReferenceTermByName("test term", source)); }
@Test public void validate_shouldPassForANewConceptWithAMapCreatedWithDeprecatedConceptMapMethods() { concept.addName(new ConceptName("test name", Context.getLocale())); concept.addDescription(new ConceptDescription("some description",null)); concept.setConceptClass(new ConceptClass()); concept.setDatatype(new ConceptDatatype()); ConceptMap map = new ConceptMap(); map.getConceptReferenceTerm().setCode("unique code"); map.getConceptReferenceTerm().setConceptSource(conceptService.getConceptSource(1)); concept.addConceptMapping(map); ValidateUtil.validate(concept); }