use of org.openmrs.OrderFrequency in project openmrs-core by openmrs.
the class OrderFrequencyValidatorTest method validate_shouldFailIfConceptIsUsedByAnotherFrequency.
/**
* @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"));
}
use of org.openmrs.OrderFrequency in project openmrs-core by openmrs.
the class OrderFrequencyValidatorTest method validate_shouldBeInvokedWhenAnOrderFrequencyIsSaved.
/**
* @see OrderFrequencyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldBeInvokedWhenAnOrderFrequencyIsSaved() {
OrderFrequency orderFrequency = Context.getOrderService().getOrderFrequency(2);
orderFrequency.setConcept(null);
expectedException.expect(APIException.class);
String expectedMsg = "'" + orderFrequency + "' failed to validate with reason: concept: " + Context.getMessageSourceService().getMessage("Concept.noConceptSelected");
expectedException.expectMessage(expectedMsg);
Context.getOrderService().saveOrderFrequency(orderFrequency);
}
use of org.openmrs.OrderFrequency in project openmrs-core by openmrs.
the class OrderFrequencyValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see OrderFrequencyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
ConceptService cs = Context.getConceptService();
Concept concept = new Concept();
ConceptName cn = new ConceptName("new name", Context.getLocale());
concept.setDatatype(cs.getConceptDatatype(1));
concept.setConceptClass(cs.getConceptClass(19));
concept.addName(cn);
concept.addDescription(new ConceptDescription("some description", null));
cs.saveConcept(concept);
OrderFrequency orderFrequency = new OrderFrequency();
orderFrequency.setConcept(concept);
orderFrequency.setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
Errors errors = new BindException(orderFrequency, "orderFrequency");
new OrderFrequencyValidator().validate(orderFrequency, errors);
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
use of org.openmrs.OrderFrequency in project openmrs-core by openmrs.
the class OrderFrequencyValidatorTest method validate_shouldFailIfConceptIsNull.
/**
* @see OrderFrequencyValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfConceptIsNull() {
OrderFrequency orderFrequency = new OrderFrequency();
Errors errors = new BindException(orderFrequency, "orderFrequency");
new OrderFrequencyValidator().validate(orderFrequency, errors);
Assert.assertTrue(errors.hasFieldErrors("concept"));
}
use of org.openmrs.OrderFrequency in project openmrs-core by openmrs.
the class OrderFrequencyValidatorTest method validate_shouldPassForAValidNewOrderFrequency.
/**
* @see OrderFrequencyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassForAValidNewOrderFrequency() {
ConceptService cs = Context.getConceptService();
Concept concept = new Concept();
ConceptName cn = new ConceptName("new name", Context.getLocale());
concept.setDatatype(cs.getConceptDatatype(1));
concept.setConceptClass(cs.getConceptClass(19));
concept.addName(cn);
concept.addDescription(new ConceptDescription("some description", null));
cs.saveConcept(concept);
OrderFrequency orderFrequency = new OrderFrequency();
orderFrequency.setConcept(concept);
Errors errors = new BindException(orderFrequency, "orderFrequency");
new OrderFrequencyValidator().validate(orderFrequency, errors);
Assert.assertFalse(errors.hasErrors());
}
Aggregations