Search in sources :

Example 36 with OrderType

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]"));
}
Also used : Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 37 with OrderType

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());
}
Also used : Errors(org.springframework.validation.Errors) ConceptClass(org.openmrs.ConceptClass) OrderType(org.openmrs.OrderType) BindException(org.springframework.validation.BindException) HashSet(java.util.HashSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 38 with OrderType

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"));
}
Also used : Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 39 with OrderType

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"));
}
Also used : Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 40 with OrderType

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"));
}
Also used : Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

OrderType (org.openmrs.OrderType)54 Test (org.junit.Test)46 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)45 OrderUtilTest (org.openmrs.order.OrderUtilTest)29 BindException (org.springframework.validation.BindException)22 Errors (org.springframework.validation.Errors)22 Patient (org.openmrs.Patient)17 DrugOrder (org.openmrs.DrugOrder)16 CareSetting (org.openmrs.CareSetting)15 Encounter (org.openmrs.Encounter)11 GlobalProperty (org.openmrs.GlobalProperty)8 Order (org.openmrs.Order)8 TestOrder (org.openmrs.TestOrder)6 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)5 ConceptClass (org.openmrs.ConceptClass)5 HashSet (java.util.HashSet)4 Date (java.util.Date)3 ArrayList (java.util.ArrayList)2 Criteria (org.hibernate.Criteria)2 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)2