Search in sources :

Example 1 with FakeModel

use of org.jaffa.persistence.FakeModel in project jaffa-framework by jaffa-projects.

the class TestSupport method setupContext.

/**
 * Common initializations
 *
 * @throws Exception
 */
@BeforeClass
public static void setupContext() throws Exception {
    synchronized (lockObject) {
        if (appContext != null) {
            return;
        }
        // System.out.println("setupContext()");
        appContext = new AnnotationConfigApplicationContext(JaffaRulesConfig.class, TestConfig.class);
        assertNotNull(appContext);
        Rule label = new Rule();
        label.setName("label");
        Parameter value = new Parameter();
        value.setName("value");
        label.addParameter(value);
        Parameter condition = new Parameter();
        condition.setName("condition");
        label.addParameter(condition);
        RuleRepository.instance().addRule(label);
        // get fake model bean from combined app context
        fakeModel = appContext.getBean("fakeModel", FakeModel.class);
        assertNotNull(fakeModel);
        engine = mock(IPersistenceEngine.class);
        IPersistenceEngineFactory persistenceEngineFactory = mock(IPersistenceEngineFactory.class);
        when(persistenceEngineFactory.newPersistenceEngine()).thenReturn(engine);
        PersistenceEngineFactory.setFactory(persistenceEngineFactory);
    }
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) IPersistenceEngineFactory(org.jaffa.persistence.engines.IPersistenceEngineFactory) JaffaRulesConfig(org.jaffa.config.JaffaRulesConfig) Parameter(org.jaffa.rules.rulemeta.Parameter) FakeModel(org.jaffa.persistence.FakeModel) Rule(org.jaffa.rules.rulemeta.Rule) IPersistenceEngine(org.jaffa.persistence.engines.IPersistenceEngine) BeforeClass(org.junit.BeforeClass)

Example 2 with FakeModel

use of org.jaffa.persistence.FakeModel in project jaffa-framework by jaffa-projects.

the class RuleInitializerFactoryTest method testDifferent.

/**
 * Hits with different classes should return different instances.
 */
@Test
public void testDifferent() throws JaffaRulesFrameworkException {
    Initializer<TestModel> initializer1 = target.getInitializer(new TestModel());
    Initializer<FakeModel> initializer2 = target.getInitializer(new FakeModel());
    assertNotSame(initializer1, initializer2);
}
Also used : FakeModel(org.jaffa.persistence.FakeModel) TestModel(org.jaffa.rules.TestModel) Test(org.junit.Test)

Example 3 with FakeModel

use of org.jaffa.persistence.FakeModel 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

FakeModel (org.jaffa.persistence.FakeModel)3 Test (org.junit.Test)2 JaffaRulesConfig (org.jaffa.config.JaffaRulesConfig)1 IPersistenceEngine (org.jaffa.persistence.engines.IPersistenceEngine)1 IPersistenceEngineFactory (org.jaffa.persistence.engines.IPersistenceEngineFactory)1 TestModel (org.jaffa.rules.TestModel)1 Validator (org.jaffa.rules.fieldvalidators.Validator)1 Parameter (org.jaffa.rules.rulemeta.Parameter)1 Rule (org.jaffa.rules.rulemeta.Rule)1 BeforeClass (org.junit.BeforeClass)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1