use of org.openmrs.OrderType in project openmrs-core by openmrs.
the class OrderTypeValidatorTest method validate_shouldFailIfConceptClassIsADuplicate.
/**
* @see OrderTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfConceptClassIsADuplicate() {
OrderType orderType = new OrderType();
orderType.setName("concept class test");
OrderType existing = orderService.getOrderType(2);
assertEquals(1, existing.getConceptClasses().size());
orderType.addConceptClass(existing.getConceptClasses().iterator().next());
Errors errors = new BindException(orderType, "orderType");
new OrderTypeValidator().validate(orderType, errors);
Assert.assertEquals(true, errors.hasFieldErrors("conceptClasses[0]"));
}
use of org.openmrs.OrderType in project openmrs-core by openmrs.
the class OrderTypeValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see OrderTypeValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
OrderType orderType = new OrderType();
orderType.setName("unique name");
orderType.setJavaClassName("org.openmrs.TestDrugOrder");
Collection<ConceptClass> col = new HashSet<>();
col.add(Context.getConceptService().getConceptClass(2));
orderType.setConceptClasses(col);
orderType.setDescription("description");
orderType.setRetireReason("retireReason");
Errors errors = new BindException(orderType, "orderType");
new OrderTypeValidator().validate(orderType, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.OrderType in project openmrs-core by openmrs.
the class OrderTypeValidatorTest method validate_shouldFailIfParentIsAlsoADirectChild.
/**
* @see OrderTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfParentIsAlsoADirectChild() {
OrderType orderType = orderService.getOrderType(8);
OrderType descendant = orderService.getOrderType(12);
Assert.assertTrue(descendant.getParent().equals(orderType));
orderType.setParent(descendant);
Errors errors = new BindException(orderType, "orderType");
new OrderTypeValidator().validate(orderType, errors);
Assert.assertEquals(true, errors.hasFieldErrors("parent"));
}
use of org.openmrs.OrderType in project openmrs-core by openmrs.
the class OrderTypeValidatorTest method validate_shouldFailIfNameIsEmpty.
/**
* @see OrderTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfNameIsEmpty() {
OrderType orderType = new OrderType();
orderType.setName("");
Errors errors = new BindException(orderType, "orderType");
new OrderTypeValidator().validate(orderType, errors);
Assert.assertEquals(true, errors.hasFieldErrors("name"));
}
use of org.openmrs.OrderType in project openmrs-core by openmrs.
the class OrderTypeValidatorTest method validate_shouldFailIfNameIsNull.
/**
* @see OrderTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfNameIsNull() {
OrderType orderType = new OrderType();
Errors errors = new BindException(orderType, "orderType");
new OrderTypeValidator().validate(orderType, errors);
Assert.assertEquals(true, errors.hasFieldErrors("name"));
}
Aggregations