/** * @see ConceptServiceImpl#getPrevConcept(Concept) */ @Test public void getPrevConcept_shouldReturnTheConceptPreviousToTheGivenConcept() { Integer conceptId = 4; Integer prevConceptId = 3; Concept returnedConcept = conceptService.getPrevConcept(conceptService.getConcept(conceptId)); assertEquals(returnedConcept, conceptService.getConcept(prevConceptId)); }
/** * @see ConceptServiceImpl#getNextConcept(Concept) */ @Test public void getNextConcept_shouldReturnTheConceptNextToTheGivenConcept() { Integer conceptId = 3; Integer nextConceptId = 4; Concept returnedConcept = conceptService.getNextConcept(conceptService.getConcept(conceptId)); assertEquals(returnedConcept, conceptService.getConcept(nextConceptId)); }
/** * @see ConceptServiceImpl#purgeConcept(Concept) */ @Test public void purgeConcept_shouldPurgeTheConceptIfNotBeingUsedByAnObs() { int conceptId = 88; conceptService.purgeConcept(conceptService.getConcept(conceptId)); assertNull(conceptService.getConcept(conceptId)); }
/** * @see OrderService#(OrderSearchCriteria) */ @Test public void getOrders_shouldGetOrdersByConcepts() { List<Concept> concepts = new ArrayList<>(); concepts.add(conceptService.getConcept(88)); // aspirin concepts.add(conceptService.getConcept(3)); // cough syrup OrderSearchCriteria orderSearchCriteria = new OrderSearchCriteriaBuilder().setConcepts(concepts).build(); List<Order> orders = orderService.getOrders(orderSearchCriteria); assertEquals(6, orders.size()); }
/** * @see ConceptService#getConcept(Integer) */ @Test(expected = APIException.class) public void changeConceptFromBooleanToCoded_shouldFailIfTheDatatypeOfTheConceptIsNotBoolean() { Concept concept = conceptService.getConcept(5497); conceptService.convertBooleanConceptToCoded(concept); }
/** * @see ConceptServiceImpl#findConceptAnswers(String, Locale, Concept) */ @Test public void findConceptAnswers_shouldReturnAListOfAllMatchingConceptSearchResults() { Locale locale = new Locale("en", "GB"); String phrase = "CD4 COUNT"; int conceptId = 5497; List<ConceptSearchResult> concepts = conceptService.findConceptAnswers(phrase, locale, conceptService.getConcept(conceptId)); assertEquals(concepts.get(0).getConceptName().getName(), phrase); }
/** * @see ConceptService#getConcept(String) */ @Test public void getConcept_shouldReturnNullGivenNullParameter() { Assert.assertNull(Context.getConceptService().getConcept((String) null)); }
/** * @see FormService#getFormsContainingConcept(Concept) */ @Test public void getFormsContainingConcept_shouldGetAllFormsForConcept() { Concept concept = Context.getConceptService().getConcept(3); assertEquals(1, Context.getFormService().getFormsContainingConcept(concept).size()); }
/** * @see ConceptServiceImpl#getSetsContainingConcept(Concept) */ @Test public void getSetsContainingConcept_shouldGiveAListOfConceptSetContainingTheGivenConcept() { Concept concept = conceptService.getConcept(18); List<ConceptSet> conceptSets = conceptService.getSetsContainingConcept(concept); assertNotNull(conceptSets); assertEquals(conceptSets.get(0).getConcept(), concept); }
@Test(expected = APIAuthenticationException.class) public void before_shouldThrowAPIAuthenticationException() { Context.getUserContext().logout(); Context.getConceptService().getConcept(3); }
@Test public void validate_shouldFailIfCodedConceptContainsItselfAsAnAnswer() { Concept concept = conceptService.getConcept(30); ConceptAnswer conceptAnswer = new ConceptAnswer(concept); concept.addAnswer(conceptAnswer); Errors errors = new BindException(concept, "concept"); validator.validate(concept, errors); assertThat(errors, hasGlobalErrors("Concept.contains.itself.as.answer")); }
/** * @see OrderService#getOrderHistoryByConcept(Patient, Concept) */ @Test public void getOrderHistoryByConcept_shouldReturnEmptyListForConceptWithoutOrders() { Concept concept = Context.getConceptService().getConcept(21); Patient patient = Context.getPatientService().getPatient(2); List<Order> orders = orderService.getOrderHistoryByConcept(patient, concept); Assert.assertEquals(0, orders.size()); }
/** * @see OrderService#getOrderTypeByConcept(Concept) */ @Test public void getOrderTypeByConcept_shouldGetOrderTypeMappedToTheGivenConcept() { OrderType orderType = orderService.getOrderTypeByConcept(Context.getConceptService().getConcept(5089)); Assert.assertNotNull(orderType); Assert.assertEquals(2, orderType.getOrderTypeId().intValue()); }
@Test public void saveConcept_shouldUpdateConceptIfConceptIsAttachedToAnObservationAndItIsANonDatatypeChange() { executeDataSet(INITIAL_CONCEPTS_XML); Concept concept = conceptService.getConcept(1); assertNotNull(concept); ObsService obsService = Context.getObsService(); Obs obs = new Obs(new Person(1), concept, new Date(), new Location(1)); obs.setValueCoded(Context.getConceptService().getConcept(7)); obsService.saveObs(obs, "Creating a new observation with a concept"); conceptService.saveConcept(concept); }
@Test public void saveProgram_shouldAlsoSaveOutcomesConcept() { Concept outcomesConcept = Context.getConceptService().getConcept(3); Program program = createProgram(); program.setOutcomesConcept(outcomesConcept); int id = dao.saveProgram(program).getId(); clearHibernateCache(); Program savedProgram = dao.getProgram(id); Assert.assertEquals(3, savedProgram.getOutcomesConcept().getId().intValue()); }
/** * @see ConceptServiceImpl#retireConcept(Concept,String) */ @Test public void retireConcept_shouldRetireTheGivenConcept() { String retireReason = "dummy reason"; Concept concept = conceptService.getConcept(3); assertFalse(concept.getRetired()); conceptService.retireConcept(concept, retireReason); assertTrue(concept.getRetired()); assertEquals(retireReason, concept.getRetireReason()); }
/** * @see ConceptService@getTrueConcept() */ @Test public void getTrueConcept_shouldReturnProperTrueConcept() { Concept trueConceptLoadedManually = Context.getConceptService().getConcept( Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_TRUE_CONCEPT)); Concept trueConceptLoadedByServiceMethod = Context.getConceptService().getTrueConcept(); Assert.assertTrue(trueConceptLoadedManually.equals(trueConceptLoadedByServiceMethod)); }
/** * @see ConceptService@getFalseConcept() */ @Test public void getFalseConcept_shouldReturnProperFalseConcept() { Concept falseConceptLoadedManually = Context.getConceptService().getConcept( Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_FALSE_CONCEPT)); Concept falseConceptLoadedByServiceMethod = Context.getConceptService().getFalseConcept(); Assert.assertTrue(falseConceptLoadedManually.equals(falseConceptLoadedByServiceMethod)); }
/** * @see ProgramValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfProgramNameAlreadyInUse() { Program prog = new Program(); prog.setName("MDR-TB PROGRAM"); prog.setConcept(Context.getConceptService().getConcept(3)); Errors errors = new BindException(prog, "prog"); programValidator.validate(prog, errors); Assert.assertTrue(errors.hasFieldErrors("name")); }
/** * @see OrderFrequencyValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfConceptIsUsedByAnotherFrequency() { OrderFrequency orderFrequency = new OrderFrequency(); orderFrequency.setConcept(Context.getConceptService().getConcept(113)); Errors errors = new BindException(orderFrequency, "orderFrequency"); new OrderFrequencyValidator().validate(orderFrequency, errors); Assert.assertTrue(errors.hasFieldErrors("concept")); }