Search in sources :

Example 11 with OrderFrequency

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

the class OrderFrequencyValidatorTest method validate_shouldFailIfOrderFrequencyIsNull.

/**
 * @see OrderFrequencyValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfOrderFrequencyIsNull() {
    Errors errors = new BindException(new OrderFrequency(), "orderFrequency");
    new OrderFrequencyValidator().validate(null, errors);
    Assert.assertTrue(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) OrderFrequency(org.openmrs.OrderFrequency) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 12 with OrderFrequency

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

the class OrderFrequencyValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see OrderFrequencyValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    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("retireReason");
    Errors errors = new BindException(orderFrequency, "orderFrequency");
    new OrderFrequencyValidator().validate(orderFrequency, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Concept(org.openmrs.Concept) Errors(org.springframework.validation.Errors) ConceptName(org.openmrs.ConceptName) BindException(org.springframework.validation.BindException) ConceptDescription(org.openmrs.ConceptDescription) ConceptService(org.openmrs.api.ConceptService) OrderFrequency(org.openmrs.OrderFrequency) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 13 with OrderFrequency

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

the class OrderFrequencyValidatorTest method validate_shouldFailIfTheConceptIsNotOfClassFrequency.

/**
 * @see OrderFrequencyValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfTheConceptIsNotOfClassFrequency() {
    OrderFrequency orderFrequency = new OrderFrequency();
    orderFrequency.setConcept(Context.getConceptService().getConcept(88));
    Errors errors = new BindException(orderFrequency, "orderFrequency");
    new OrderFrequencyValidator().validate(orderFrequency, errors);
    Assert.assertTrue(errors.hasFieldErrors("concept"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) OrderFrequency(org.openmrs.OrderFrequency) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 14 with OrderFrequency

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

the class OrderFrequencyValidatorTest method validate_shouldPassForAValidExistingOrderFrequency.

/**
 * @see OrderFrequencyValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldPassForAValidExistingOrderFrequency() {
    OrderFrequency orderFrequency = Context.getOrderService().getOrderFrequency(1);
    assertNotNull(orderFrequency);
    Errors errors = new BindException(orderFrequency, "orderFrequency");
    new OrderFrequencyValidator().validate(orderFrequency, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) OrderFrequency(org.openmrs.OrderFrequency) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 15 with OrderFrequency

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

the class OrderServiceTest method retireOrderFrequency_shouldRetireGivenOrderFrequency.

@Test
public void retireOrderFrequency_shouldRetireGivenOrderFrequency() {
    OrderFrequency orderFrequency = orderService.getOrderFrequency(1);
    assertNotNull(orderFrequency);
    Assert.assertFalse(orderFrequency.getRetired());
    Assert.assertNull(orderFrequency.getRetireReason());
    Assert.assertNull(orderFrequency.getDateRetired());
    orderService.retireOrderFrequency(orderFrequency, "retire reason");
    orderFrequency = orderService.getOrderFrequency(1);
    assertNotNull(orderFrequency);
    assertTrue(orderFrequency.getRetired());
    assertEquals("retire reason", orderFrequency.getRetireReason());
    assertNotNull(orderFrequency.getDateRetired());
    // Should not change the number of order frequencies.
    assertEquals(3, orderService.getOrderFrequencies(true).size());
}
Also used : OrderFrequency(org.openmrs.OrderFrequency) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Aggregations

OrderFrequency (org.openmrs.OrderFrequency)19 Test (org.junit.Test)17 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)17 OrderUtilTest (org.openmrs.order.OrderUtilTest)8 BindException (org.springframework.validation.BindException)8 Errors (org.springframework.validation.Errors)8 Concept (org.openmrs.Concept)6 ConceptDescription (org.openmrs.ConceptDescription)5 ConceptName (org.openmrs.ConceptName)5 ConceptService (org.openmrs.api.ConceptService)3 Locale (java.util.Locale)1 Criteria (org.hibernate.Criteria)1 ConceptDatatype (org.openmrs.ConceptDatatype)1