Search in sources :

Example 1 with TestBeanFactory

use of core.framework.test.inject.TestBeanFactory in project core-ng-project by neowu.

the class AbstractTestModule method configure.

public final void configure(TestBeanFactory beanFactory) {
    logger.info("initialize test context");
    context = new ModuleContext(beanFactory, new MockFactoryImpl());
    logger.info("initialize application");
    initialize();
    context.config.validate();
    ((TestBeanFactory) context.beanFactory).validateOverrideBindings();
}
Also used : TestBeanFactory(core.framework.test.inject.TestBeanFactory) ModuleContext(core.framework.impl.module.ModuleContext)

Example 2 with TestBeanFactory

use of core.framework.test.inject.TestBeanFactory in project core-ng-project by neowu.

the class IntegrationExtension method postProcessTestInstance.

@Override
public void postProcessTestInstance(Object testInstance, ExtensionContext context) {
    ExtensionContext.Store store = context.getRoot().getStore(ExtensionContext.Namespace.GLOBAL);
    Class<?> testClass = context.getRequiredTestClass();
    TestBeanFactory beanFactory = store.getOrComputeIfAbsent(TestBeanFactory.class, key -> createTestBeanFactory(testClass, store), TestBeanFactory.class);
    beanFactory.inject(testInstance);
}
Also used : TestBeanFactory(core.framework.test.inject.TestBeanFactory) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext)

Example 3 with TestBeanFactory

use of core.framework.test.inject.TestBeanFactory in project core-ng-project by neowu.

the class IntegrationExtension method createTestBeanFactory.

private TestBeanFactory createTestBeanFactory(Class<?> testClass, ExtensionContext.Store store) {
    Boolean initialized = store.get(KEY_INITIALIZED, Boolean.class);
    if (Boolean.TRUE.equals(initialized))
        throw new Error("test context failed to initialize, please check error message from previous integration test");
    store.put(KEY_INITIALIZED, true);
    Context context = findContext(testClass);
    TestBeanFactory beanFactory = new TestBeanFactory();
    try {
        AbstractTestModule module = context.module().getConstructor().newInstance();
        module.configure(beanFactory);
    } catch (ReflectiveOperationException e) {
        throw new Error("failed to create test context", e);
    }
    return beanFactory;
}
Also used : ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) AbstractTestModule(core.framework.test.module.AbstractTestModule) TestBeanFactory(core.framework.test.inject.TestBeanFactory)

Aggregations

TestBeanFactory (core.framework.test.inject.TestBeanFactory)3 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)2 ModuleContext (core.framework.impl.module.ModuleContext)1 AbstractTestModule (core.framework.test.module.AbstractTestModule)1