Search in sources :

Example 11 with ConceptNameTag

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

the class ConceptNameTagValidatorTest method validate_shouldNotFailIfTheConceptNameTagIsTheSame.

@Test
public void validate_shouldNotFailIfTheConceptNameTagIsTheSame() {
    String objectName = "duplicate concept name tag";
    ConceptNameTag cnt = Context.getConceptService().getConceptNameTag(1);
    Errors errors = new BindException(cnt, objectName);
    new ConceptNameTagValidator().validate(cnt, errors);
    Assert.assertFalse(errors.hasErrors());
    Assert.assertEquals(false, errors.hasFieldErrors("tag"));
}
Also used : Errors(org.springframework.validation.Errors) ConceptNameTag(org.openmrs.ConceptNameTag) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 12 with ConceptNameTag

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

the class ConceptNameTagValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues.

/**
 * @see ConceptNameTagValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
    ConceptNameTag cnt = new ConceptNameTag();
    cnt.setTag("tag");
    Errors errors = new BindException(cnt, "cnt");
    new ConceptNameTagValidator().validate(cnt, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) ConceptNameTag(org.openmrs.ConceptNameTag) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 13 with ConceptNameTag

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

the class ConceptNameTagValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see ConceptNameTagValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    ConceptNameTag cnt = new ConceptNameTag();
    cnt.setTag("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    cnt.setVoidReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    Errors errors = new BindException(cnt, "cnt");
    new ConceptNameTagValidator().validate(cnt, errors);
    Assert.assertEquals(true, errors.hasFieldErrors("tag"));
    Assert.assertEquals(true, errors.hasFieldErrors("voidReason"));
}
Also used : Errors(org.springframework.validation.Errors) ConceptNameTag(org.openmrs.ConceptNameTag) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 14 with ConceptNameTag

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

the class ConceptNameTagValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see ConceptNameTagValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    ConceptNameTag cnt = new ConceptNameTag();
    cnt.setTag("tag");
    cnt.setVoidReason("VoidReason");
    Errors errors = new BindException(cnt, "cnt");
    new ConceptNameTagValidator().validate(cnt, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) ConceptNameTag(org.openmrs.ConceptNameTag) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 15 with ConceptNameTag

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

the class ConceptNameTagValidatorTest method validate_shouldFailIfTheConceptNameTagIsADuplicate.

/**
 * @see ConceptNameTagValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfTheConceptNameTagIsADuplicate() {
    String objectName = "duplicate concept name tag";
    ConceptNameTag existing = Context.getConceptService().getConceptNameTag(1);
    ConceptNameTag cnt = new ConceptNameTag();
    cnt.setTag(existing.getTag());
    Errors errors = new BindException(cnt, objectName);
    new ConceptNameTagValidator().validate(cnt, errors);
    Assert.assertTrue(errors.hasErrors());
    Assert.assertEquals(true, errors.hasFieldErrors("tag"));
}
Also used : Errors(org.springframework.validation.Errors) ConceptNameTag(org.openmrs.ConceptNameTag) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

ConceptNameTag (org.openmrs.ConceptNameTag)20 Test (org.junit.Test)18 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)18 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 ConceptName (org.openmrs.ConceptName)4 ArrayList (java.util.ArrayList)1 Concept (org.openmrs.Concept)1 ConceptClass (org.openmrs.ConceptClass)1 ConceptDatatype (org.openmrs.ConceptDatatype)1 ConceptDescription (org.openmrs.ConceptDescription)1 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)1