Search in sources :

Example 1 with Realm

use of org.jaffa.rules.realm.Realm in project jaffa-framework by jaffa-projects.

the class RealmRepositoryTest method testAddRealm.

/**
 * Registering a Rule should behave as though it were loaded from an XML element.
 */
@Test
public void testAddRealm() {
    Realm realm = new Realm("x");
    realm.setSource("s");
    RealmRepository target = RealmRepository.instance();
    target.addRealm(realm);
    List<Realm> actual = target.getRealmsBySource("s");
    assertEquals(1, actual.size());
    assertSame(realm, actual.get(0));
}
Also used : RealmRepository(org.jaffa.rules.realm.RealmRepository) Realm(org.jaffa.rules.realm.Realm) Test(org.junit.Test)

Example 2 with Realm

use of org.jaffa.rules.realm.Realm in project jaffa-framework by jaffa-projects.

the class RealmTest method testRealmConfig.

/**
 * Test code configuration.
 */
// This is flakey when run with other repository tests.
// @Test
public void testRealmConfig() {
    Realm target = new Realm("oz").regex(TestModel.class.getName()).inheritanceRulesToInclude("a,b").inheritanceRulesToExclude("x,y").register();
    assertEquals("oz", RealmRepository.instance().find(TestModel.class.getName()));
    List<String> regexes = target.getClassRegexes();
    assertNotNull(regexes);
    assertEquals(1, regexes.size());
    assertEquals(TestModel.class.getName(), regexes.get(0));
    assertEquals("a", target.getInheritanceRulesToInclude().get(0));
    assertEquals("b", target.getInheritanceRulesToInclude().get(1));
    assertEquals("x", target.getInheritanceRulesToExclude().get(0));
    assertEquals("y", target.getInheritanceRulesToExclude().get(1));
}
Also used : Realm(org.jaffa.rules.realm.Realm) TestModel(org.jaffa.rules.TestModel)

Example 3 with Realm

use of org.jaffa.rules.realm.Realm in project jaffa-framework by jaffa-projects.

the class PersistentConfigValidatorTest method setup.

/**
 * Common setup
 *
 * @throws Exception
 */
@Before
public void setup() throws Exception {
    // create app context, do not need to include PersistentContext directly
    AnnotationConfigApplicationContext appContext = new AnnotationConfigApplicationContext(JaffaRulesConfig.class, TestModelPersistentConfig.class);
    assertNotNull(appContext);
    new StaticContext().setApplicationContext(appContext);
    // get validator factory bean from combined app context
    ValidatorFactory target = appContext.getBean(ValidatorFactory.class);
    assertNotNull(target);
    Realm realm = new Realm("realm");
    realm.setSource("Test");
    realm.regex(TestModelPersistent.class.getName());
    realm.register();
    ClassMetaData classMetaData = new ClassMetaData();
    classMetaData.setName(TestModelPersistent.class.getName());
    classMetaData.setVariation("DEF");
    classMetaData.setExecutionRealm(realm.getName());
    classMetaData.register();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ValidatorFactory(org.jaffa.rules.fieldvalidators.ValidatorFactory) Realm(org.jaffa.rules.realm.Realm) ClassMetaData(org.jaffa.rules.meta.ClassMetaData) StaticContext(org.jaffa.beans.factory.config.StaticContext) Before(org.junit.Before)

Example 4 with Realm

use of org.jaffa.rules.realm.Realm in project jaffa-framework by jaffa-projects.

the class TestConfig method realm.

private Realm realm(String name) {
    Realm realm = new Realm(name);
    realm.setSource("RealmConfig");
    return realm;
}
Also used : Realm(org.jaffa.rules.realm.Realm)

Example 5 with Realm

use of org.jaffa.rules.realm.Realm in project jaffa-framework by jaffa-projects.

the class RuleInitializerFactoryTest method before.

/**
 * Setup common data.
 */
@Before
public void before() {
    VariationContext.setVariation("A");
    Realm realm = new Realm("realm");
    realm.setSource("Test");
    realm.regex(TestModel.class.getName());
    realm.register();
    ClassMetaData data = new ClassMetaData(TestModel.class);
    data.property("field1").initialize(FieldInitializerTest.FIELD1_INIT_VALUE);
    data.property("field2").initialize(FieldInitializerTest.FIELD2_INIT_VALUE.toString());
    data.setExecutionRealm(realm.getName());
    data.setVariation(VariationContext.getVariation());
    data.register();
    new TestConfig().initializeRule();
    target = new RuleInitializerFactory();
}
Also used : TestConfig(org.jaffa.rules.TestConfig) Realm(org.jaffa.rules.realm.Realm) TestModel(org.jaffa.rules.TestModel) ClassMetaData(org.jaffa.rules.meta.ClassMetaData) Before(org.junit.Before)

Aggregations

Realm (org.jaffa.rules.realm.Realm)5 TestModel (org.jaffa.rules.TestModel)2 ClassMetaData (org.jaffa.rules.meta.ClassMetaData)2 Before (org.junit.Before)2 StaticContext (org.jaffa.beans.factory.config.StaticContext)1 TestConfig (org.jaffa.rules.TestConfig)1 ValidatorFactory (org.jaffa.rules.fieldvalidators.ValidatorFactory)1 RealmRepository (org.jaffa.rules.realm.RealmRepository)1 Test (org.junit.Test)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1