public BootLogger getBootLogger() { return getInstance(BootLogger.class); }
/** * Returns a DI-bound instance of a given class, throwing if this class is not explicitly bound in DI. * * @param <T> a type of the instance to return. * @param type a class or interface bound in DI. * @return a DI-bound instance of a given type. * @since 0.12 */ public <T> T getInstance(Class<T> type) { return getInstance(Key.get(type)); }
/** * Locates internal {@link Runner} and calls its run method. * * @return outcome of the runner execution. * @since 0.23 */ public CommandOutcome run() { return getInstance(Runner.class).run(); }
/** * Verifies that runtime contains expected modules. * * @param runtime a Bootique runtime whose contents we are testing. * @param expectedModules a vararg array of expected module types. */ @SafeVarargs public static void testModulesLoaded(BQRuntime runtime, Class<? extends Module>... expectedModules) { final ModulesMetadata modulesMetadata = runtime.getInstance(ModulesMetadata.class); final List<String> actualModules = modulesMetadata .getModules() .stream() .map(ModuleMetadata::getName) .collect(toList()); final String[] expectedModuleNames = Stream.of(expectedModules) .map(Class::getSimpleName) .toArray(String[]::new); // Using class names for checking module existing - weak. assertThat(actualModules, hasItems(expectedModuleNames)); } }
protected void testMetadata() { testWithFactory(testFactory -> { // must auto-load modules to ensure all tested module dependencies are present... BQRuntime runtime = testFactory.app().autoLoadModules().createRuntime(); BQModuleProvider provider = matchingProvider(); String providerName = provider.name(); // loading metadata ensures that all annotations are properly applied... Optional<ModuleMetadata> moduleMetadata = runtime .getInstance(ModulesMetadata.class) .getModules() .stream() .filter(mmd -> providerName.equals(mmd.getProviderName())) .findFirst(); assertTrue("No module metadata available for provider: '" + providerName + "'", moduleMetadata.isPresent()); moduleMetadata.get().getConfigs(); }); }
public BootLogger getBootLogger() { return getInstance(BootLogger.class); }
/** * Returns a DI-bound instance of a given class, throwing if this class is not explicitly bound in DI. * * @param <T> a type of the instance to return. * @param type a class or interface bound in DI. * @return a DI-bound instance of a given type. * @since 0.12 */ public <T> T getInstance(Class<T> type) { return getInstance(Key.get(type)); }
/** * @return an instance of {@link Runner} DI singleton. * @deprecated since 0.23. Just use 'getInstance(Runner.class)' or {@link #run()} if you simply need to execute the * run sequence. */ @Deprecated public Runner getRunner() { return getInstance(Runner.class); }
/** * Locates internal {@link Runner} and calls its run method. * * @return outcome of the runner execution. * @since 0.23 */ public CommandOutcome run() { return getInstance(Runner.class).run(); }
/** * @return a new instance of builder for the test runtime stack. * @since 0.20 */ @Override public Builder app(String... args) { Function<BQRuntime, Boolean> startupCheck = r -> r.getInstance(Server.class).isStarted(); return new Builder(runtimes, args).startupCheck(startupCheck).modules(JettyModule.class); }
/** Create the compiler runtime. * * @param args the command line arguments. * @return the runtime. */ @SuppressWarnings("static-method") protected BQRuntime createRuntime(String... args) { SARLStandaloneSetup.doPreSetup(); final BQRuntime runtime = Bootique.app(args).autoLoadModules().createRuntime(); SARLStandaloneSetup.doPostSetup(runtime.getInstance(Injector.class)); return runtime; }
/** Replies the options of the program. * * @return the options of the program. */ public List<HelpOption> getOptions() { final BQRuntime runtime = createRuntime(); final ApplicationMetadata application = runtime.getInstance(ApplicationMetadata.class); final HelpOptions helpOptions = new HelpOptions(); application.getCommands().forEach(c -> { helpOptions.add(c.asOption()); c.getOptions().forEach(o -> helpOptions.add(o)); }); application.getOptions().forEach(o -> helpOptions.add(o)); return helpOptions.getOptions(); }