Search in sources :

Example 41 with OrderType

use of org.openmrs.OrderType in project openmrs-core by openmrs.

the class OrderTypeValidatorTest method validate_shouldFailIfNameIsADuplicate.

/**
 * @see OrderTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfNameIsADuplicate() {
    OrderType orderType = new OrderType();
    orderType.setName(orderService.getOrderType(1).getName());
    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 42 with OrderType

use of org.openmrs.OrderType in project openmrs-core by openmrs.

the class OrderTypeValidatorTest method validate_shouldFailIfTheOrderTypeObjectIsNull.

/**
 * @see OrderTypeValidator#validate(Object,Errors)
 */
@Test(expected = IllegalArgumentException.class)
public void validate_shouldFailIfTheOrderTypeObjectIsNull() {
    Errors errors = new BindException(new OrderType(), "orderType");
    new OrderTypeValidator().validate(null, errors);
}
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 43 with OrderType

use of org.openmrs.OrderType in project openmrs-core by openmrs.

the class OrderTypeValidatorTest method validate_shouldFailIfNameIsWhiteSpace.

/**
 * @see OrderTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfNameIsWhiteSpace() {
    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 44 with OrderType

use of org.openmrs.OrderType in project openmrs-core by openmrs.

the class OrderTypeValidatorTest method validate_shouldBeInvokedWhenAnOrderTypeIsSaved.

/**
 * @see OrderTypeValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldBeInvokedWhenAnOrderTypeIsSaved() {
    OrderType orderType = orderService.getOrderType(1);
    orderType.setName(null);
    expectedException.expect(APIException.class);
    String expectedMsg = "'" + orderType + "' failed to validate with reason: name: " + Context.getMessageSourceService().getMessage("error.name");
    expectedException.expectMessage(expectedMsg);
    orderService.saveOrderType(orderType);
}
Also used : OrderType(org.openmrs.OrderType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 45 with OrderType

use of org.openmrs.OrderType in project openmrs-core by openmrs.

the class HibernateOrderDAO method getOrderType.

/**
 * @see org.openmrs.api.db.OrderDAO#getOrderType(Integer)
 */
@Override
public OrderType getOrderType(Integer orderTypeId) {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(OrderType.class);
    criteria.add(Restrictions.eq("orderTypeId", orderTypeId));
    return (OrderType) criteria.uniqueResult();
}
Also used : OrderType(org.openmrs.OrderType) Criteria(org.hibernate.Criteria)

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