org.deephacks.tools4j.config.test.integration.IntegrationTestsBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tools4j-config-tck Show documentation
Show all versions of tools4j-config-tck Show documentation
Functional Tests for Tools4j Config
package org.deephacks.tools4j.config.test.integration;
import org.deephacks.tools4j.config.RuntimeContext;
import org.deephacks.tools4j.config.admin.AdminContext;
import org.deephacks.tools4j.config.model.Lookup;
import org.deephacks.tools4j.config.spi.BeanManager;
import org.deephacks.tools4j.config.spi.SchemaManager;
import org.deephacks.tools4j.config.test.FeatureTestsBuilder;
import java.util.ArrayList;
import java.util.List;
/**
* IntegrationTestSuiteBuilder assume impl of RuntimeContext and AdminContext
* to be available on classpath during 'test' phase.
*/
public class IntegrationTestsBuilder extends FeatureTestsBuilder {
private ArrayList> tests = new ArrayList<>();
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;
}
public IntegrationTestsBuilder addTest(Class> cls) {
tests.add(cls);
return this;
}
@Override
protected List> getTests() {
if( tests != null && !tests.isEmpty()) {
return tests;
}
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");
AdminContext admin = (AdminContext) adminCls.newInstance();
RuntimeContext runtime = (RuntimeContext) runtimeCls.newInstance();
Lookup.get().register(RuntimeContext.class, runtime);
Lookup.get().register(AdminContext.class, admin);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}