use of org.jaffa.rules.fieldvalidators.Validator in project jaffa-framework by jaffa-projects.
the class BatchValidatorTest method testValidationException.
/**
* Test that a validation exception is returned to the caller of the validation method
*
* @throws org.jaffa.exceptions.FrameworkException
*
* @throws org.jaffa.exceptions.ApplicationException
*/
@Test(expected = ApplicationException.class)
public void testValidationException() throws FrameworkException, ApplicationException {
// validator that will throw exception on validation
Validator mockValidator = mock(Validator.class);
doThrow(new MandatoryFieldException()).when(mockValidator).validate(anyObject());
// create bulk validator with a sub-validators that will throw an exception
BatchValidator validator = new BatchValidator();
validator.getValidatorSet().add(mockValidator);
// call validate
validator.validate(new Object());
}
use of org.jaffa.rules.fieldvalidators.Validator in project jaffa-framework by jaffa-projects.
the class BatchValidatorTest method testValidation.
/**
* Test that the bulk validator fires validate on all sub-validators
*
* @throws FrameworkException
* @throws ApplicationException
*/
@Test
public void testValidation() throws FrameworkException, ApplicationException {
// validators that will pass validation
Validator mockValidator1 = mock(Validator.class);
Validator mockValidator2 = mock(Validator.class);
// create bulk validator with 2 sub-validators
BatchValidator validator = new BatchValidator();
validator.getValidatorSet().add(mockValidator1);
validator.getValidatorSet().add(mockValidator2);
// call validate
Object object = new Object();
validator.validate(object);
// verify both sub-validators are called
verify(mockValidator1).validate(object);
verify(mockValidator2).validate(object);
}
use of org.jaffa.rules.fieldvalidators.Validator in project jaffa-framework by jaffa-projects.
the class PersistentConfigValidatorTest method testPersistentConfig.
/**
* Test Persistent has a validator pushed into it during construction
*/
@Test
public void testPersistentConfig() throws NoSuchFieldException, IllegalAccessException {
// creating a new instance of a persistent object should have its validator pushed into it
// automatically by persistent config
Persistent persistent = new TestModelPersistent();
Field f = persistent.getClass().getSuperclass().getDeclaredField("validator");
f.setAccessible(true);
Validator validator = (Validator) f.get(persistent);
assertNotNull(validator);
}
use of org.jaffa.rules.fieldvalidators.Validator in project jaffa-framework by jaffa-projects.
the class RuleValidatorFactoryTest method testNullValidator.
/**
* Test to verify that a null validator is returned if there is no validator available
* for the class name, realm, and variation provided.
*
* @throws Exception
*/
@Test
public void testNullValidator() throws Exception {
// setup
Object plainObj = new Object();
// execute
Validator validator = target.getValidator(plainObj);
// asserts
assertNull(validator);
}
use of org.jaffa.rules.fieldvalidators.Validator in project jaffa-framework by jaffa-projects.
the class RuleValidatorFactoryTest method testReturnValidator.
/**
* Test that rule manager returns a validator
*
* @throws Exception
*/
@Test
public void testReturnValidator() throws Exception {
target.addValidatorTypes("mandatory");
Validator validator = target.getValidator(fakeModel);
assertNotNull(validator);
assertTrue(validator instanceof BatchValidator);
BatchValidator domainModelValidator = (BatchValidator) validator;
assertTrue(domainModelValidator.getValidatorSet().size() == 1);
MandatoryValidator mandatoryValidator = (MandatoryValidator) domainModelValidator.getValidatorSet().iterator().next();
assertNotNull(mandatoryValidator);
assertEquals(fakeModel.getClass().getName(), mandatoryValidator.getActualClassName(fakeModel.getClass()));
assertTrue(mandatoryValidator.getRuleMap().size() == 2);
}
Aggregations