for (ConceptDescription availableDescription : getDescriptions()) { Locale availableLocale = availableDescription.getLocale(); if (availableLocale.equals(desiredLocale)) {
/** * @see Concept#getDescriptions() */ @Test public void getDescriptions_shouldNotReturnNullIfDescriptionsListIsNull() { Concept c = new Concept(); c.setDescriptions(null); Assert.assertTrue(c.getDescriptions().isEmpty()); Assert.assertNotNull(c.getDescriptions()); }
/** * This test verifies that {@link ConceptDescription}s are fetched correctly from the hibernate * cache. (Or really, not fetched from the cache but instead are mapped with lazy=false. For * some reason Hibernate isn't able to find objects in the cache if a parent object was the one * that loaded them) * * @throws Exception */ @Test public void shouldFetchDescriptionsForConceptsThatWereFirstFetchedAsNumerics() { Concept concept = Context.getConceptService().getConcept(5089); ConceptNumeric conceptNumeric = Context.getConceptService().getConceptNumeric(5089); conceptNumeric.getDescriptions().size(); concept.getDescriptions().size(); }
/** * @see Concept#removeDescription(ConceptDescription) */ @Test public void removeDescription_shouldRemoveDescriptionPassedFromListOfDescriptions() { Concept c = new Concept(); ConceptDescription c1 = new ConceptDescription(1); c1.setDescription("Description 1"); ConceptDescription c2 = new ConceptDescription(2); c2.setDescription("Description 2"); c.addDescription(c1); c.addDescription(c2); Collection<ConceptDescription> descriptions = c.getDescriptions(); Assert.assertEquals(2, descriptions.size()); c.removeDescription(c1); descriptions = c.getDescriptions(); Assert.assertTrue(descriptions.contains(c2)); Assert.assertEquals(1, descriptions.size()); }
if (concept.getDescriptions() != null) { for (ConceptDescription cd : concept.getDescriptions()) { if (StringUtils.isBlank(cd.getDescription())) { concept.removeDescription(cd);
/** * @see org.openmrs.module.webservices.rest.web.resource.api.SubResource#doGetAll(java.lang.Object, * org.openmrs.module.webservices.rest.web.RequestContext) */ @Override public NeedsPaging<ConceptDescription> doGetAll(Concept parent, RequestContext context) throws ResponseException { //convert from a collection to a list List<ConceptDescription> descriptions = new ArrayList<ConceptDescription>(); if (parent != null) { for (ConceptDescription description : parent.getDescriptions()) { descriptions.add(description); } } return new NeedsPaging<ConceptDescription>(descriptions, context); }
this.setDescriptions(new HashSet<>(c.getDescriptions())); for (ConceptDescription cDescription : this.getDescriptions()) { cDescription.setConcept(this);
/** * Constructor from Concept. * * @param c */ public ConceptComplex(Concept c) { this.setAnswers(c.getAnswers(true)); this.setChangedBy(c.getChangedBy()); this.setConceptClass(c.getConceptClass()); this.setConceptId(c.getConceptId()); this.setConceptSets(c.getConceptSets()); this.setCreator(c.getCreator()); this.setDatatype(c.getDatatype()); this.setDateChanged(c.getDateChanged()); this.setDateCreated(c.getDateCreated()); this.setSet(c.getSet()); this.setNames(c.getNames()); this.setDescriptions(c.getDescriptions()); this.setConceptMappings(c.getConceptMappings()); this.setRetired(c.getRetired()); this.setVersion(c.getVersion()); this.setUuid(c.getUuid()); this.handler = ""; }
@Test public void equals_shouldNotBeTheSameReference() { Concept c = new Concept(123); ConceptNumeric cn = new ConceptNumeric(c); Assert.assertNotSame(c.getAnswers(), cn.getAnswers()); Assert.assertNotSame(c.getConceptSets(), cn.getConceptSets()); Assert.assertNotSame(cn.getConceptSets(), c.getConceptSets()); Assert.assertNotSame(c.getNames(), cn.getNames()); Assert.assertNotSame(c.getConceptMappings(), cn.getConceptMappings()); Assert.assertNotSame(c.getDescriptions(), cn.getDescriptions()); }
/** * @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getAllCount() */ @Override public long getAllCount() { return service.getConceptByUuid(conceptUuid).getDescriptions().size(); }
/** * @See {@link ConceptDescriptionResource1_8#create(String, SimpleObject, org.openmrs.module.webservices.rest.web.RequestContext)} * @throws Exception */ @Test public void shouldAddADescriptionToConcept() throws Exception { int before = service.getConceptByUuid(conceptUuid).getDescriptions().size(); String json = "{ \"description\":\"New Description\", \"locale\":\"fr\"}"; handle(newPostRequest(getURI(), json)); int after = service.getConceptByUuid(conceptUuid).getDescriptions().size(); Assert.assertEquals(before + 1, after); }
/** * @See {@link ConceptDescriptionResource1_8#purge(ConceptDescription, org.openmrs.module.webservices.rest.web.RequestContext)} * @throws Exception */ @Test public void shouldPurgeAConceptDescription() throws Exception { int before = service.getConceptByUuid(conceptUuid).getDescriptions().size(); handle(newDeleteRequest(getURI() + "/" + getUuid(), new Parameter("purge", ""))); int after = service.getConceptByUuid(conceptUuid).getDescriptions().size(); Assert.assertEquals(before - 1, after); }
/** * This tests that delete always delegates to * {@link ConceptDescriptionResource1_8#purge(ConceptDescription, org.openmrs.module.webservices.rest.web.RequestContext)} * since descriptions are not retirable/voidable * * @see {@link ConceptDescriptionResource1_8#delete(ConceptDescription, String, org.openmrs.module.webservices.rest.web.RequestContext)} * @throws Exception */ @Test public void shouldDeleteAConceptDescription() throws Exception { int before = service.getConceptByUuid(conceptUuid).getDescriptions().size(); handle(newDeleteRequest(getURI() + "/" + getUuid(), new Parameter("reason", "testing"))); int after = service.getConceptByUuid(conceptUuid).getDescriptions().size(); Assert.assertEquals(before - 1, after); }
/** * @See {@link ConceptDescriptionResource1_8#doGetAll(Concept, org.openmrs.module.webservices.rest.web.RequestContext)} * @throws Exception */ @Test public void shouldListDescriptionsForAConcept() throws Exception { //Add one more description for testing purposes Concept testConcept = Context.getConceptService().getConceptByUuid(conceptUuid); ConceptDescription testDescription = new ConceptDescription("another description", new Locale("fr")); testConcept.addDescription(testDescription); Context.getConceptService().saveConcept(testConcept); Assert.assertNotNull(testDescription.getConceptDescriptionId()); Assert.assertEquals(2, testConcept.getDescriptions().size()); SimpleObject response = deserialize(handle(newGetRequest(getURI()))); List<Object> resultsList = Util.getResultsList(response); Assert.assertEquals(2, resultsList.size()); List<Object> descriptions = Arrays.asList(PropertyUtils.getProperty(resultsList.get(0), "description"), PropertyUtils.getProperty(resultsList.get(1), "description")); Assert.assertTrue(descriptions.contains("Affirmative")); Assert.assertTrue(descriptions.contains("another description")); }