use of com.google.inject.Injector in project acceptance-test-harness by jenkinsci.
the class TSRJenkinsAcceptanceTestRule method apply.
@Override
public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
final Description description = Description.createTestDescription(method.getMethod().getDeclaringClass(), method.getName(), method.getAnnotations());
return new Statement() {
@Inject
JenkinsController controller;
@Inject
Injector injector;
@Override
public void evaluate() throws Throwable {
World world = World.get();
Injector injector = world.getInjector();
world.startTestScope(description.getDisplayName());
injector.injectMembers(target);
injector.injectMembers(this);
System.out.println("=== Starting " + description.getDisplayName());
try {
decorateWithRules(base).evaluate();
} catch (AssumptionViolatedException e) {
throw e;
} catch (Exception | AssertionError e) {
// Errors and failures
controller.diagnose(e);
throw e;
} finally {
world.endTestScope();
}
}
/**
* Look for annotations on a test and honor {@link RuleAnnotation}s in them.
*/
private Statement decorateWithRules(Statement body) {
Set<Class<? extends Annotation>> annotations = new HashSet<>();
collectAnnotationTypes(method.getMethod(), annotations);
collectAnnotationTypes(target.getClass(), annotations);
Description testDescription = Description.createTestDescription(target.getClass(), method.getName(), method.getAnnotations());
for (Class<? extends Annotation> a : annotations) {
RuleAnnotation r = a.getAnnotation(RuleAnnotation.class);
if (r != null) {
TestRule tr = injector.getInstance(r.value());
body = tr.apply(body, testDescription);
}
}
return body;
}
private void collectAnnotationTypes(AnnotatedElement e, Collection<Class<? extends Annotation>> types) {
for (Annotation a : e.getAnnotations()) {
types.add(a.annotationType());
}
}
};
}
use of com.google.inject.Injector in project open-kilda by telstra.
the class AbstractTopologyRunner method startup.
public static void startup(Class<? extends AbstractTopologyRunner> klass, Module module) {
String overridesFile = null;
if (System.getProperty("storm.topology.config.overrides.file") != null) {
overridesFile = System.getProperty("storm.topology.config.overrides.file");
} else {
overridesFile = klass.getResource("kilda-overrides.yml").getPath();
}
Injector injector = Guice.createInjector(new YamlConfigModule(overridesFile), module);
AbstractTopologyRunner runner = injector.getInstance(klass);
runner.run();
}
use of com.google.inject.Injector in project open-kilda by telstra.
the class Main method main.
public static void main(String[] args) {
try {
Main.Initialize(args);
Injector injector = Guice.createInjector(new YamlConfigModule(System.getProperty("controller.config.overrides.file")));
Main main = injector.getInstance(Main.class);
main.Startup();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.google.inject.Injector in project airlift by airlift.
the class ConfigurationFactoryTest method testConfigurationThroughLegacyConfig.
@Test
public void testConfigurationThroughLegacyConfig() {
Map<String, String> properties = new TreeMap<>();
properties.put("string-value", "this is a");
properties.put("string-b", "this is b");
TestMonitor monitor = new TestMonitor();
Injector injector = createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class));
LegacyConfigPresent legacyConfigPresent = injector.getInstance(LegacyConfigPresent.class);
monitor.assertNumberOfErrors(0);
monitor.assertNumberOfWarnings(1);
monitor.assertMatchingWarningRecorded("string-value", "replaced", "Use 'string-a'");
assertNotNull(legacyConfigPresent);
assertEquals(legacyConfigPresent.getStringA(), "this is a");
assertEquals(legacyConfigPresent.getStringB(), "this is b");
}
use of com.google.inject.Injector in project airlift by airlift.
the class ConfigurationFactoryTest method testConfigurationThroughDeprecatedConfig.
@Test
public void testConfigurationThroughDeprecatedConfig() {
Map<String, String> properties = new TreeMap<>();
properties.put("string-a", "this is a");
properties.put("string-b", "this is b");
TestMonitor monitor = new TestMonitor();
Injector injector = createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(DeprecatedConfigPresent.class));
DeprecatedConfigPresent deprecatedConfigPresent = injector.getInstance(DeprecatedConfigPresent.class);
monitor.assertNumberOfErrors(0);
monitor.assertNumberOfWarnings(1);
monitor.assertMatchingWarningRecorded("string-a", "deprecated and should not be used");
assertNotNull(deprecatedConfigPresent);
assertEquals(deprecatedConfigPresent.getStringA(), "this is a");
assertEquals(deprecatedConfigPresent.getStringB(), "this is b");
}
Aggregations