use of org.openmrs.Allergen in project openmrs-core by openmrs.
the class AllergyValidatorTest method validate_shouldRejectADuplicateNonCodedAllergen.
/**
* @see AllergyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldRejectADuplicateNonCodedAllergen() {
PowerMockito.mockStatic(Context.class);
MessageSourceService ms = mock(MessageSourceService.class);
when(Context.getMessageSourceService()).thenReturn(ms);
Allergies allergies = new Allergies();
Concept nonCodedConcept = createMockConcept(getOtherNonCodedConceptUuid());
final String freeText = "some text";
Allergen allergen1 = new Allergen(AllergenType.DRUG, nonCodedConcept, freeText);
allergies.add(new Allergy(null, allergen1, null, null, null));
when(ps.getAllergies(any(Patient.class))).thenReturn(allergies);
Allergen duplicateAllergen = new Allergen(AllergenType.FOOD, nonCodedConcept, freeText);
Allergy allergy = new Allergy(mock(Patient.class), duplicateAllergen, null, null, null);
Errors errors = new BindException(allergy, "allergy");
validator.validate(allergy, errors);
assertTrue(errors.hasFieldErrors("allergen"));
assertThat(errors.getFieldError("allergen").getCode(), is("allergyapi.message.duplicateAllergen"));
}
use of org.openmrs.Allergen in project openmrs-core by openmrs.
the class AllergyValidatorTest method validate_shouldFailIfCodedAndNonCodedAllergenAreNull.
/**
* @see AllergyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailIfCodedAndNonCodedAllergenAreNull() {
Allergen allergen = new Allergen(AllergenType.DRUG, null, null);
allergy.setAllergen(allergen);
validator.validate(allergy, errors);
assertTrue(errors.hasFieldErrors("allergen"));
assertThat(errors.getFieldError("allergen").getCode(), is("allergyapi.allergen.codedOrNonCodedAllergen.required"));
}
use of org.openmrs.Allergen in project openmrs-core by openmrs.
the class AllergyValidatorTest method validate_shouldFailIdAllergenTypeIsNull.
/**
* @see AllergyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailIdAllergenTypeIsNull() {
allergy.setAllergen(new Allergen());
validator.validate(allergy, errors);
assertTrue(errors.hasFieldErrors("allergen"));
assertThat(errors.getFieldError("allergen").getCode(), is("allergyapi.allergenType.required"));
}
use of org.openmrs.Allergen in project openmrs-core by openmrs.
the class AllergyValidatorTest method validate_shouldRejectADuplicateAllergen.
/**
* @see AllergyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldRejectADuplicateAllergen() {
PowerMockito.mockStatic(Context.class);
MessageSourceService ms = mock(MessageSourceService.class);
when(Context.getMessageSourceService()).thenReturn(ms);
Allergies allergies = new Allergies();
Concept aspirin = createMockConcept();
Allergen allergen1 = new Allergen(AllergenType.DRUG, aspirin, null);
allergies.add(new Allergy(null, allergen1, null, null, null));
when(ps.getAllergies(any(Patient.class))).thenReturn(allergies);
Allergen duplicateAllergen = new Allergen(AllergenType.FOOD, aspirin, null);
Allergy allergy = new Allergy(mock(Patient.class), duplicateAllergen, null, null, null);
Errors errors = new BindException(allergy, "allergy");
validator.validate(allergy, errors);
assertTrue(errors.hasFieldErrors("allergen"));
assertThat(errors.getFieldError("allergen").getCode(), is("allergyapi.message.duplicateAllergen"));
}
Aggregations