Search in sources :

Example 6 with Validator

use of org.jaffa.rules.fieldvalidators.Validator in project jaffa-framework by jaffa-projects.

the class RuleValidatorFactoryTest method testGetValidator.

/**
 * Test to verify that the validator factory creates a validator based on class name, realm, and variation.
 * Also, verify that the validator is cached.
 *
 * @throws Exception
 */
@Test
public void testGetValidator() throws Exception {
    Validator validator1 = target.getValidator(fakeModel);
    assertNotNull(validator1);
    Validator validator2 = target.getValidator(fakeModel);
    assertNotNull(validator2);
    assertSame(validator1, validator2);
}
Also used : Validator(org.jaffa.rules.fieldvalidators.Validator) Test(org.junit.Test)

Example 7 with Validator

use of org.jaffa.rules.fieldvalidators.Validator in project jaffa-framework by jaffa-projects.

the class PersistentConfigTest method testFallBackToPersistent.

/**
 * Test add fallback pattern to the static context causes the class to initialize
 */
@Test
public void testFallBackToPersistent() throws PreAddFailedException, NoSuchFieldException, IllegalAccessException {
    TestPersistentBean persistent = StaticContext.configure(new TestPersistentBean());
    Field f = persistent.getClass().getSuperclass().getDeclaredField("validator");
    f.setAccessible(true);
    Validator validator = (Validator) f.get(persistent);
    assertNotNull("bean should be initialized without a config for TestPersistentBean", validator);
}
Also used : Field(java.lang.reflect.Field) TestPersistentBean(org.jaffa.beans.factory.config.TestPersistentBean) Validator(org.jaffa.rules.fieldvalidators.Validator) Test(org.junit.Test)

Example 8 with Validator

use of org.jaffa.rules.fieldvalidators.Validator in project jaffa-framework by jaffa-projects.

the class RuleValidatorFactoryTest method testCaching.

/**
 * Multiple hits to the same class/realm/variation should return the same instance.
 */
@Test
public void testCaching() {
    Validator validator1 = target.getValidator(new FakeModel());
    Validator validator2 = target.getValidator(new FakeModel());
    assertSame(validator1, validator2);
}
Also used : FakeModel(org.jaffa.persistence.FakeModel) Validator(org.jaffa.rules.fieldvalidators.Validator) Test(org.junit.Test)

Aggregations

Validator (org.jaffa.rules.fieldvalidators.Validator)8 Test (org.junit.Test)8 Field (java.lang.reflect.Field)2 Matchers.anyObject (org.mockito.Matchers.anyObject)2 TestPersistentBean (org.jaffa.beans.factory.config.TestPersistentBean)1 MandatoryFieldException (org.jaffa.datatypes.exceptions.MandatoryFieldException)1 FakeModel (org.jaffa.persistence.FakeModel)1 Persistent (org.jaffa.persistence.Persistent)1