/** * @see org.openmrs.api.ConceptService#getAllConcepts() */ @Override @Transactional(readOnly = true) public List<Concept> getAllConcepts() throws APIException { return Context.getConceptService().getAllConcepts(null, true, true); }
/** * @see ConceptService#getAllConcepts(String,null,null) */ @Test public void getAllConcepts_shouldOrderByConceptIdDescendingWhenSetAscParameterToFalse() { final List<Concept> allConcepts = conceptService.getAllConcepts(null, false, true); assertEquals(36, allConcepts.size()); assertEquals(5497, allConcepts.get(0).getConceptId().intValue()); }
/** * @see ConceptService#getAllConcepts(String,null,null) */ @Test public void getAllConcepts_shouldOrderByConceptIdAndIncludeRetiredWhenGivenNoParameters() { final List<Concept> allConcepts = conceptService.getAllConcepts(); assertEquals(36, allConcepts.size()); assertEquals(3, allConcepts.get(0).getConceptId().intValue()); }
/** * @see ConceptService#getAllConcepts(String,null,null) */ @Test public void getAllConcepts_shouldExcludeRetiredConceptsWhenSetIncludeRetiredToFalse() { final List<Concept> allConcepts = conceptService.getAllConcepts(null, true, false); assertEquals(34, allConcepts.size()); assertEquals(3, allConcepts.get(0).getConceptId().intValue()); }
/** * @see ConceptService#getAllConcepts(String,null,null) */ @Test public void getAllConcepts_shouldOrderByAConceptField() { List<Concept> allConcepts = conceptService.getAllConcepts("dateCreated", true, true); assertEquals(36, allConcepts.size()); assertEquals(88, allConcepts.get(0).getConceptId().intValue()); assertEquals(27, allConcepts.get(allConcepts.size() - 1).getConceptId().intValue()); //check desc order allConcepts = conceptService.getAllConcepts("dateCreated", false, true); assertEquals(36, allConcepts.size()); assertEquals(23, allConcepts.get(0).getConceptId().intValue()); assertEquals(88, allConcepts.get(allConcepts.size() - 1).getConceptId().intValue()); }
/** * @see ConceptService#getAllConcepts(String,null,null) */ @Test public void getAllConcepts_shouldOrderByAConceptNameField() { List<Concept> allConcepts = conceptService.getAllConcepts("name", true, false); assertEquals(34, allConcepts.size()); assertEquals("ANTIRETROVIRAL TREATMENT GROUP", allConcepts.get(0).getName().getName()); assertEquals("tab (s)", allConcepts.get(allConcepts.size() - 1).getName().getName()); //test the desc order allConcepts = conceptService.getAllConcepts("name", false, false); assertEquals(34, allConcepts.size()); assertEquals("tab (s)", allConcepts.get(0).getName().getName()); assertEquals("ANTIRETROVIRAL TREATMENT GROUP", allConcepts.get(allConcepts.size() - 1).getName().getName()); }
/** * This test will fail if it takes more than 15 seconds to run. (Checks for an error with the * iterator looping forever) The @Timed annotation is used as an alternative to * "@Test(timeout=15000)" so that the Spring transactions work correctly. Junit has a "feature" * where it executes the befores/afters in a thread separate from the one that the actual test * ends up running in when timed. * * @see ConceptService#conceptIterator() */ @Test() public void conceptIterator_shouldStartWithTheSmallestConceptId() { List<Concept> allConcepts = Context.getConceptService().getAllConcepts(); int numberofconcepts = allConcepts.size(); // sanity check Assert.assertTrue(numberofconcepts > 0); // now count up the number of concepts the iterator returns int iteratorCount = 0; Iterator<Concept> iterator = Context.getConceptService().conceptIterator(); while (iterator.hasNext() && iteratorCount < numberofconcepts + 5) { // the lt check is in case of infinite loops iterator.next(); iteratorCount++; } Assert.assertEquals(numberofconcepts, iteratorCount); }
@Test public void saveConcept_shouldCreateNewConceptInDatabase() { executeDataSet(INITIAL_CONCEPTS_XML); Concept conceptToAdd = new Concept(); ConceptName cn = new ConceptName("new name", Context.getLocale()); conceptToAdd.addName(cn); conceptToAdd.addDescription(new ConceptDescription("some description",null)); conceptToAdd.setDatatype(new ConceptDatatype(1)); conceptToAdd.setConceptClass(new ConceptClass(1)); assertFalse(conceptService.getAllConcepts().contains(conceptToAdd)); conceptService.saveConcept(conceptToAdd); assertTrue(conceptService.getAllConcepts().contains(conceptToAdd)); }
/** * This test fetches all concepts in the xml test dataset and ensures that every locale for a * concept name is among those listed in the global property 'locale.allowed.list' and default * locale. NOTE that it doesn't test a particular API method directly. */ @Test public void saveConcept_shouldNotAcceptALocaleThatIsNeitherAmongTheLocaleAllowedListNorADefaultLocale() { List<Concept> concepts = Context.getConceptService().getAllConcepts(); Set<Locale> allowedLocales = LocaleUtility.getLocalesInOrder(); for (Concept concept : concepts) { if (!CollectionUtils.isEmpty(concept.getNames())) { for (ConceptName cn : concept.getNames()) { Assert.assertTrue("The locale '" + cn.getLocale() + "' of conceptName with id: " + cn.getConceptNameId() + " is not among those listed in the global property 'locale.allowed.list'", allowedLocales .contains(cn.getLocale())); } } } }
/** * This test is run against the xml test dataset for all concepts to ensure that in every locale * with one or more names, there isn't more than one name explicitly marked as locale preferred. * NOTE that it doesn't test a particular API method directly */ @Test public void saveConcept_shouldEnsureThatEveryConcepNameLocaleHasExactlyOnePreferredName() { List<Concept> concepts = Context.getConceptService().getAllConcepts(); Set<Locale> allowedLocales = LocaleUtility.getLocalesInOrder(); for (Concept concept : concepts) { for (Locale locale : allowedLocales) { Collection<ConceptName> namesInLocale = concept.getNames(locale); if (!CollectionUtils.isEmpty(namesInLocale)) { int preferredNamesFound = 0; for (ConceptName conceptName : namesInLocale) { if (conceptName.getLocalePreferred()) { preferredNamesFound++; Assert.assertTrue("Found multiple preferred names for conceptId: " + concept.getConceptId() + " in the locale '" + locale + "'", preferredNamesFound < 2); } } } } } }
/** * This test fetches all concepts in the xml test dataset and ensures that every locale that has * atleast one conceptName has a name marked as preferred. NOTE that it doesn't test a * particular API method directly. */ @Test public void saveConcept_shouldAlwaysReturnAPreferredNameForEveryLocaleThatHasAtleastOneUnvoidedName() { List<Concept> concepts = Context.getConceptService().getAllConcepts(); Set<Locale> allowedLocales = LocaleUtility.getLocalesInOrder(); for (Concept concept : concepts) { for (Locale locale : allowedLocales) { if (!CollectionUtils.isEmpty(concept.getNames(locale))) { Assert.assertNotNull("Concept with Id: " + concept.getConceptId() + " has no preferred name in locale:" + locale, concept.getPreferredName(locale)); Assert.assertEquals(true, concept.getPreferredName(locale).getLocalePreferred()); } } } }
/** * @see MainResourceControllerTest#getAllCount() */ @Override public long getAllCount() { return service.getAllConcepts(null, true, false).size(); }
@Override public List<? extends MRSConcept> getAllConcepts() { List<Concept> allConcepts = conceptService.getAllConcepts(); List<MRSConcept> concepts = new ArrayList<>(); for (Concept concept : allConcepts) { try { ConceptName conceptName = concept.getNames().iterator().next(); concepts.add(new OpenMRSConcept(new OpenMRSConceptName(conceptName.getName()))); } catch (NoSuchElementException x) { return null; } } return concepts; }
/** * This does not include retired concepts * * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected NeedsPaging<Concept> doGetAll(RequestContext context) { List<Concept> allConcepts = Context.getConceptService().getAllConcepts(null, true, context.getIncludeAll()); return new NeedsPaging<Concept>(allConcepts, context); }
@Test public void shouldCreateAConcept() throws Exception { int originalCount = service.getAllConcepts().size(); String json = "{ \"names\": [{\"name\":\"test concept\", \"locale\":\"en\", \"conceptNameType\":\"" + ConceptNameType.FULLY_SPECIFIED + "\"}], \"datatype\":\"8d4a4c94-c2cc-11de-8d13-0010c6dffd0f\", \"conceptClass\":\"Diagnosis\" }"; MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes()); Object newConcept = deserialize(handle(req)); Assert.assertNotNull(PropertyUtils.getProperty(newConcept, "uuid")); Assert.assertEquals(originalCount + 1, service.getAllConcepts().size()); }
@Test public void shouldPurgeAConcept() throws Exception { int originalCount = service.getAllConcepts().size(); String uuid = "11716f9c-1434-4f8d-b9fc-9aa14c4d6129"; MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + uuid); req.addParameter("purge", "true"); handle(req); Assert.assertNull(service.getConceptByUuid(uuid)); Assert.assertEquals(originalCount - 1, service.getAllConcepts().size()); }
@Test public void shouldListAllUnRetiredConcepts() throws Exception { int totalCount = service.getAllConcepts(null, true, true).size(); MockHttpServletRequest req = request(RequestMethod.GET, getURI()); SimpleObject result = deserialize(handle(req)); Assert.assertNotNull(result); Assert.assertTrue(totalCount > result.size()); Assert.assertEquals(24, Util.getResultsList(result).size()); // there are 25 concepts and one is retired, so should only get 24 here }