Search in sources :

Example 16 with Injector

use of com.google.inject.Injector in project druid by druid-io.

the class MapLookupExtractionFnSerDeTest method setup.

@BeforeClass
public static void setup() throws JsonProcessingException {
    Injector defaultInjector = GuiceInjectors.makeStartupInjector();
    mapper = defaultInjector.getInstance(Key.get(ObjectMapper.class, Json.class));
}
Also used : Injector(com.google.inject.Injector) BeforeClass(org.junit.BeforeClass)

Example 17 with Injector

use of com.google.inject.Injector in project che by eclipse.

the class CheBootstrap method contextDestroyed.

@Override
public void contextDestroyed(ServletContextEvent sce) {
    final ServletContext ctx = sce.getServletContext();
    final Injector injector = getInjector(ctx);
    if (injector != null) {
        injector.getInstance(Destroyer.class).destroy();
    }
    super.contextDestroyed(sce);
}
Also used : Injector(com.google.inject.Injector) ServletContext(javax.servlet.ServletContext) Destroyer(org.eclipse.che.inject.lifecycle.Destroyer)

Example 18 with Injector

use of com.google.inject.Injector in project che by eclipse.

the class CheBootstrapTest method readsConfigurationPropertiesFromSystemProperties.

@Test
public void readsConfigurationPropertiesFromSystemProperties() throws Exception {
    setSystemProperties(createTestProperties());
    ModuleScanner.modules.add(binder -> binder.bind(TestSystemPropertiesComponent.class));
    cheBootstrap.contextInitialized(new ServletContextEvent(servletContext));
    Injector injector = retrieveComponentFromServletContext(Injector.class);
    TestSystemPropertiesComponent testComponent = injector.getInstance(TestSystemPropertiesComponent.class);
    assertEquals(testComponent.parameter_pair, Pair.of("a", "b"));
    assertEquals(testComponent.parameter_pair2, Pair.of("a", (String) null));
    assertEquals(testComponent.parameter_pair3, Pair.of("a", ""));
    assertEquals(testComponent.parameter_pair_array, new Pair[] { Pair.of("a", "b"), Pair.of("c", "d") });
    assertEquals(testComponent.nullable, null);
    assertEquals(testComponent.parameter_uri, new URI("file:/a/b/c"));
    assertEquals(testComponent.parameter_url, new URL("http://localhost"));
    assertEquals(testComponent.parameter_file, new File("/a/b/c"));
    assertEquals(testComponent.parameter_strings, new String[] { "a", "b", "c" });
    assertEquals(testComponent.parameter_int, 123);
    assertEquals(testComponent.parameter_long, 123);
    assertEquals(testComponent.parameter_bool, true);
    assertEquals(testComponent.someDir, new File(System.getProperty("java.io.tmpdir"), "/some_dir"));
    assertEquals(testComponent.suffixedPath, System.getenv("PATH") + pathSeparator + "some_path");
}
Also used : Injector(com.google.inject.Injector) URI(java.net.URI) File(java.io.File) ServletContextEvent(javax.servlet.ServletContextEvent) URL(java.net.URL) Test(org.testng.annotations.Test)

Example 19 with Injector

use of com.google.inject.Injector in project che by eclipse.

the class CheBootstrapTest method environment_variables_prefixed_with_che_underscore_override_che_dot_prefixed_system_and_user_specified_and_che_properties.

@Test
public void environment_variables_prefixed_with_che_underscore_override_che_dot_prefixed_system_and_user_specified_and_che_properties() throws Exception {
    Properties cheProperties = new Properties();
    cheProperties.put("che.some.other.name", "che_value");
    cheProperties.put("che.some.name", "NULL");
    writePropertiesFile(che, "che.properties", cheProperties);
    Properties userProperties = new Properties();
    userProperties.put("che.some.other.name", "user_value");
    writePropertiesFile(userCongDir, "user.properties", userProperties);
    systemPropertiesHelper.property("che.some.other.name", "che_dot_system_property_value");
    ModuleScanner.modules.add(binder -> binder.bind(TestConfOverrideComponent.class));
    cheBootstrap.contextInitialized(new ServletContextEvent(servletContext));
    Injector injector = retrieveComponentFromServletContext(Injector.class);
    TestConfOverrideComponent testComponent = injector.getInstance(TestConfOverrideComponent.class);
    assertEquals(testComponent.otherString, System.getenv("CHE_SOME_OTHER_NAME"));
}
Also used : Injector(com.google.inject.Injector) Properties(java.util.Properties) SystemPropertiesHelper.overrideSystemProperties(org.eclipse.che.commons.test.SystemPropertiesHelper.overrideSystemProperties) ServletContextEvent(javax.servlet.ServletContextEvent) Test(org.testng.annotations.Test)

Example 20 with Injector

use of com.google.inject.Injector in project che by eclipse.

the class CheBootstrapTest method propertiesFromUserSpecifiedLocationOverrideCheProperties.

@Test
public void propertiesFromUserSpecifiedLocationOverrideCheProperties() throws Exception {
    systemPropertiesHelper.property(CHE_LOCAL_CONF_DIR, userCongDir.getAbsolutePath());
    Properties cheProperties = new Properties();
    cheProperties.put("che.some.name", "che_value");
    writePropertiesFile(che, "che.properties", cheProperties);
    Properties userProperties = new Properties();
    userProperties.put("che.some.name", "user_value");
    writePropertiesFile(userCongDir, "user.properties", userProperties);
    ModuleScanner.modules.add(binder -> binder.bind(TestConfOverrideComponent.class));
    cheBootstrap.contextInitialized(new ServletContextEvent(servletContext));
    Injector injector = retrieveComponentFromServletContext(Injector.class);
    TestConfOverrideComponent testComponent = injector.getInstance(TestConfOverrideComponent.class);
    assertEquals(testComponent.string, "user_value");
}
Also used : Injector(com.google.inject.Injector) Properties(java.util.Properties) SystemPropertiesHelper.overrideSystemProperties(org.eclipse.che.commons.test.SystemPropertiesHelper.overrideSystemProperties) ServletContextEvent(javax.servlet.ServletContextEvent) Test(org.testng.annotations.Test)

Aggregations

Injector (com.google.inject.Injector)2117 AbstractModule (com.google.inject.AbstractModule)624 Test (org.junit.Test)513 Module (com.google.inject.Module)386 Binder (com.google.inject.Binder)140 Before (org.junit.Before)116 Properties (java.util.Properties)110 Test (org.testng.annotations.Test)105 Key (com.google.inject.Key)91 HttpServletRequest (javax.servlet.http.HttpServletRequest)78 Map (java.util.Map)75 Provider (com.google.inject.Provider)74 TypeLiteral (com.google.inject.TypeLiteral)70 IOException (java.io.IOException)69 Set (java.util.Set)63 BeforeClass (org.junit.BeforeClass)61 File (java.io.File)59 ImmutableList (com.google.common.collect.ImmutableList)58 CConfiguration (co.cask.cdap.common.conf.CConfiguration)55 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)55