@Test public void setValueBoolean_shouldNotSetValueForNonBooleanConcept() throws Exception { Obs obs = createObs(2); ConceptDatatype dataType = new ConceptDatatype(); dataType.setUuid(ConceptDatatype.CODED_UUID); obs.getConcept().setDatatype(dataType); assertNotNull(obs.getValueCoded()); obs.setValueBoolean(null); assertNotNull(obs.getValueCoded()); } }
/** * @see ObsValidator#validate(Object,Errors) */ @Test public void validate_shouldPassIfAnswerConceptAndConceptOfValueDrugMatch() { Obs obs = new Obs(); obs.setPerson(new Person(7)); obs.setObsDatetime(new Date()); Concept questionConcept = new Concept(100); ConceptDatatype dt = new ConceptDatatype(1); dt.setUuid(ConceptDatatype.CODED_UUID); questionConcept.setDatatype(dt); obs.setConcept(questionConcept); Concept answerConcept = new Concept(101); obs.setValueCoded(answerConcept); Drug drug = new Drug(); drug.setConcept(answerConcept); obs.setValueDrug(drug); Errors errors = new BindException(obs, "obs"); obsValidator.validate(obs, errors); assertFalse(errors.hasFieldErrors()); }
/** * @see ObsValidator#validate(Object,Errors) */ @Test public void validate_shouldRejectAnInvalidConceptAndDrugCombination() { Obs obs = new Obs(); obs.setPerson(new Person(7)); obs.setObsDatetime(new Date()); Concept questionConcept = new Concept(100); ConceptDatatype dt = new ConceptDatatype(1); dt.setUuid(ConceptDatatype.CODED_UUID); questionConcept.setDatatype(dt); obs.setConcept(questionConcept); obs.setValueCoded(new Concept(101)); Drug drug = new Drug(); drug.setConcept(new Concept(102)); obs.setValueDrug(drug); Errors errors = new BindException(obs, "obs"); obsValidator.validate(obs, errors); assertTrue(errors.hasFieldErrors("valueDrug")); }
@Test public void testShowUnitsUsingTrue() { ConceptDatatype numeric = new ConceptDatatype(); numeric.setUuid(ConceptDatatype.NUMERIC_UUID); ConceptNumeric weight = new ConceptNumeric(); String units = "kg"; weight.setUnits(units); weight.setDatatype(numeric); mockStatic(HtmlFormEntryUtil.class); mockStatic(Context.class); PowerMockito.when(HtmlFormEntryUtil.getConcept(anyString())).thenReturn(weight); PowerMockito.when(Context.getRegisteredComponent("htmlformentry.ConceptCompatibility", ConceptCompatibility.class)).thenReturn(new ConceptCompatibility1_9()); params.put("showUnits", "true"); params.put("conceptId", "5089"); params.put("locale", "ht"); ObsSubmissionElement element = new ObsSubmissionElement(context, params); String html = element.generateHtml(context); TestUtil.assertContains("<span class=\"units\">" + units + "</span>", html); }
@Test @Ignore public void testShowUnitsUsingCode() { ConceptDatatype numeric = new ConceptDatatype(); numeric.setUuid(ConceptDatatype.NUMERIC_UUID); ConceptNumeric weight = new ConceptNumeric(); weight.setUnits("kg"); weight.setDatatype(numeric); mockStatic(HtmlFormEntryUtil.class); PowerMockito.when(HtmlFormEntryUtil.getConcept(anyString())).thenReturn(weight); String unitsCode = "units.kg"; params.put("showUnits", unitsCode); params.put("conceptId", "5089"); ObsSubmissionElement element = new ObsSubmissionElement(context, params); String html = element.generateHtml(context); TestUtil.assertContains("<span class=\"units\">" + unitsCode + "</span>", html); }
@Test public void testForcingLocaleOnCheckboxLabel() throws Exception { ConceptDatatype coded = new ConceptDatatype(); coded.setUuid(ConceptDatatype.CODED_UUID); Concept option = new Concept(456); option.addName(new ConceptName("English", Locale.ENGLISH)); option.addName(new ConceptName("Kreyol", LocaleUtility.fromSpecification("ht"))); Concept options = new Concept(123); options.setDatatype(coded); options.addAnswer(new ConceptAnswer(option)); mockStatic(HtmlFormEntryUtil.class); PowerMockito.when(HtmlFormEntryUtil.getConcept("123")).thenReturn(options); PowerMockito.when(HtmlFormEntryUtil.getConcept("456")).thenReturn(option); params.put("conceptId", "123"); params.put("answerConceptId", "456"); params.put("locale", "ht"); ObsSubmissionElement element = new ObsSubmissionElement(context, params); String html = element.generateHtml(context); assertTrue(html.matches(".*<label.*>Kreyol</label>.*")); }
@Test public void testForcingLocale() throws Exception { ConceptDatatype numeric = new ConceptDatatype(); numeric.setUuid(ConceptDatatype.NUMERIC_UUID); ConceptName primaryName = new ConceptName("Weight", Locale.ENGLISH); primaryName.setLocalePreferred(true); primaryName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED); ConceptNumeric weight = new ConceptNumeric(); String units = "kg"; weight.setUnits(units); weight.setDatatype(numeric); weight.addName(primaryName); weight.addName(new ConceptName("Pwa", LocaleUtility.fromSpecification("ht"))); mockStatic(HtmlFormEntryUtil.class); mockStatic(Context.class); PowerMockito.when(HtmlFormEntryUtil.getConcept(anyString())).thenReturn(weight); PowerMockito.when(Context.getRegisteredComponent("htmlformentry.ConceptCompatibility", ConceptCompatibility.class)).thenReturn(new ConceptCompatibility1_9()); params.put("conceptId", "5089"); params.put("locale", "ht"); params.put("labelNameTag", "default"); ObsSubmissionElement element = new ObsSubmissionElement(context, params); String html = element.generateHtml(context); assertTrue(html.startsWith("Pwa")); }
@Test public void testForcingLocaleOnRadioLabels() throws Exception { ConceptDatatype coded = new ConceptDatatype(); coded.setUuid(ConceptDatatype.CODED_UUID); Concept option1 = new Concept(1); option1.addName(new ConceptName("English 1", Locale.ENGLISH)); option1.addName(new ConceptName("Kreyol 1", LocaleUtility.fromSpecification("ht"))); Concept option2 = new Concept(1); option2.addName(new ConceptName("English 2", Locale.ENGLISH)); option2.addName(new ConceptName("Kreyol 2", LocaleUtility.fromSpecification("ht"))); Concept options = new Concept(123); options.setDatatype(coded); options.addAnswer(new ConceptAnswer(option1)); options.addAnswer(new ConceptAnswer(option2)); mockStatic(HtmlFormEntryUtil.class); PowerMockito.when(HtmlFormEntryUtil.getConcept("123")).thenReturn(options); PowerMockito.when(HtmlFormEntryUtil.getConcept("1")).thenReturn(option1); PowerMockito.when(HtmlFormEntryUtil.getConcept("2")).thenReturn(option2); params.put("conceptId", "123"); params.put("answerConceptIds", "1,2"); params.put("style", "radio"); params.put("locale", "ht"); ObsSubmissionElement element = new ObsSubmissionElement(context, params); String html = element.generateHtml(context); System.out.println(html); assertTrue(html.matches(".*<label.*>Kreyol 1</label>.*<label.*>Kreyol 2</label>.*")); }
@Test @Verifies(value="shouldSetTheValueComplexOfObsIfConceptIsComplex",method="createObs(Concept concept, Object value, Date datetime, String accessionNumber)") public void createObs_shouldSetTheValueComplexOfObsIfConceptIsComplex(){ ComplexData complexData=new ComplexData("test", null); Concept c=new Concept(); ConceptDatatype cd=new ConceptDatatype(); cd.setUuid(HtmlFormEntryConstants.COMPLEX_UUID); c.setDatatype(cd); Obs o=HtmlFormEntryUtil.createObs(c, complexData, null, null); Assert.assertEquals(o.getValueComplex(),complexData.getTitle()); }