Skip to content

Commit

Permalink
Added test to ensure that validation passes when editing an existing …
Browse files Browse the repository at this point in the history
…order frequency - TRUNK-4192
  • Loading branch information
wluyima committed Mar 19, 2014
1 parent ac6927b commit f087380
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
Expand Up @@ -52,7 +52,8 @@ public boolean supports(Class c) {
* @should fail if concept is null
* @should fail if the concept is not of class frequency
* @should fail if concept is used by another frequency
* @should pass if all fields are correct
* @should pass for a valid new order frequency
* @should pass for a valid existing order frequency
*/
public void validate(Object obj, Errors errors) {
OrderFrequency orderFrequency = (OrderFrequency) obj;
Expand Down
Expand Up @@ -13,10 +13,14 @@
*/
package org.openmrs.validator;

import static junit.framework.Assert.assertNotNull;

import org.junit.Assert;
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptName;
import org.openmrs.OrderFrequency;
import org.openmrs.api.ConceptService;
import org.openmrs.api.context.Context;
import org.openmrs.test.BaseContextSensitiveTest;
import org.openmrs.test.Verifies;
Expand Down Expand Up @@ -59,7 +63,7 @@ public void validate_shouldFailIfConceptIsNull() throws Exception {
*/
@Test
@Verifies(value = "should fail if the concept is not of class frequency", method = "validate(Object,Errors)")
public void validate_shouldFailIfConceptIsNotOfClassFrequency() throws Exception {
public void validate_shouldFailIfTheConceptIsNotOfClassFrequency() throws Exception {
OrderFrequency orderFrequency = new OrderFrequency();
orderFrequency.setConcept(Context.getConceptService().getConcept(88));
Errors errors = new BindException(orderFrequency, "orderFrequency");
Expand All @@ -83,13 +87,17 @@ public void validate_shouldFailIfConceptIsUsedByAnotherFrequency() throws Except
}

/**
* @see {@link OrderFrequencyValidator#validate(Object,Errors)}
* @verifies pass for a valid new order frequency
* @see OrderFrequencyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
@Verifies(value = "should pass if all fields are correct", method = "validate(Object,Errors)")
public void validate_shouldPassIfAllFieldsAreCorrect() throws Exception {
Concept concept = new Concept(1);
concept.setConceptClass(Context.getConceptService().getConceptClass(19));
public void validate_shouldPassForAValidNewOrderFrequency() throws Exception {
ConceptService cs = Context.getConceptService();
Concept concept = new Concept();
ConceptName cn = new ConceptName("new name", Context.getLocale());
concept.setConceptClass(cs.getConceptClass(19));
concept.addName(cn);
cs.saveConcept(concept);

OrderFrequency orderFrequency = new OrderFrequency();
orderFrequency.setConcept(concept);
Expand All @@ -98,4 +106,18 @@ public void validate_shouldPassIfAllFieldsAreCorrect() throws Exception {

Assert.assertFalse(errors.hasErrors());
}

/**
* @verifies pass for a valid existing order frequency
* @see OrderFrequencyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassForAValidExistingOrderFrequency() throws Exception {
OrderFrequency orderFrequency = Context.getOrderService().getOrderFrequency(1);
assertNotNull(orderFrequency);
Errors errors = new BindException(orderFrequency, "orderFrequency");
new OrderFrequencyValidator().validate(orderFrequency, errors);

Assert.assertFalse(errors.hasErrors());
}
}

0 comments on commit f087380

Please sign in to comment.