org.deephacks.tools4j.config.test.integration.IntegrationTestsBuilder Maven / Gradle / Ivy
package org.deephacks.tools4j.config.test.integration;
import java.util.ArrayList;
import java.util.List;
import org.deephacks.tools4j.config.RuntimeContext;
import org.deephacks.tools4j.config.admin.AdminContext;
import org.deephacks.tools4j.config.spi.BeanManager;
import org.deephacks.tools4j.config.spi.SchemaManager;
import org.deephacks.tools4j.config.test.FeatureTestsBuilder;
import org.deephacks.tools4j.config.test.MockLookup;
/**
* IntegrationTestSuiteBuilder assume impl of RuntimeContext and AdminContext
* to be available on classpath during 'test' phase.
*/
public class IntegrationTestsBuilder extends FeatureTestsBuilder {
static {
/** set default context instances to be found by Lookup.get().loopkup() */
bootstapContextLookup();
}
public IntegrationTestsBuilder() {
}
public static IntegrationTestsBuilder named(String name) {
IntegrationTestsBuilder builder = new IntegrationTestsBuilder();
builder.name = name;
return builder;
}
public IntegrationTestsBuilder using(BeanManager manager) {
using(BeanManager.class, manager);
return this;
}
public IntegrationTestsBuilder using(SchemaManager manager) {
using(SchemaManager.class, manager);
return this;
}
@Override
protected List> getTests() {
ArrayList> tests = new ArrayList>();
tests.add(IntegrationConfigTests.class);
withSetUp(new IntegrationConfigTests());
tests.add(IntegrationValidationTests.class);
withSetUp(new IntegrationValidationTests());
return tests;
}
/**
* Bootstrap RuntimeContext and AdminContext and inject into Lookup object pool.
*/
private static void bootstapContextLookup() {
try {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class> runtimeCls = cl
.loadClass("org.deephacks.tools4j.config.internal.core.runtime.RuntimeCoreContext");
Class> adminCls = cl
.loadClass("org.deephacks.tools4j.config.internal.core.admin.AdminCoreContext");
Object adminCtx = adminCls.newInstance();
Object runtimeCtx = runtimeCls.newInstance();
MockLookup.addMockInstances(RuntimeContext.class, runtimeCtx);
MockLookup.addMockInstances(AdminContext.class, adminCtx);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy