Search in sources :

Example 6 with Provider

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

the class ClasspathManagerTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    Provider<ProjectRegistry> projectRegistryProvider = (Provider<ProjectRegistry>) mock(Provider.class);
    when(projectRegistryProvider.get()).thenReturn(projectRegistry);
    MavenServerManagerTest.MyMavenServerProgressNotifier mavenNotifier = new MavenServerManagerTest.MyMavenServerProgressNotifier();
    MavenTerminal terminal = (level, message, throwable) -> {
        System.out.println(message);
        if (throwable != null) {
            throwable.printStackTrace();
        }
    };
    localRepository = new File(new File("target/localRepo").getAbsolutePath());
    localRepository.mkdirs();
    mavenServerManager.setLocalRepository(localRepository);
    MavenWrapperManager wrapperManager = new MavenWrapperManager(mavenServerManager);
    mavenProjectManager = new MavenProjectManager(wrapperManager, mavenServerManager, terminal, mavenNotifier, new EclipseWorkspaceProvider());
    classpathManager = new ClasspathManager(root.getAbsolutePath(), wrapperManager, mavenProjectManager, terminal, mavenNotifier);
    mavenWorkspace = new MavenWorkspace(mavenProjectManager, mavenNotifier, new MavenExecutorService(), projectRegistryProvider, new MavenCommunication() {

        @Override
        public void sendUpdateMassage(Set<MavenProject> updated, List<MavenProject> removed) {
        }

        @Override
        public void sendNotification(NotificationMessage message) {
            System.out.println(message.toString());
        }

        @Override
        public void send(JsonObject object, MessageType type) {
        }
    }, classpathManager, eventService, new EclipseWorkspaceProvider());
}
Also used : MavenWrapperManager(org.eclipse.che.plugin.maven.server.MavenWrapperManager) JsonObject(com.google.gson.JsonObject) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Assert.assertNull(org.testng.Assert.assertNull) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) Mock(org.mockito.Mock) MavenWorkspace(org.eclipse.che.plugin.maven.server.core.MavenWorkspace) Test(org.testng.annotations.Test) MavenCommunication(org.eclipse.che.plugin.maven.server.core.MavenCommunication) AfterMethod(org.testng.annotations.AfterMethod) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest) IProject(org.eclipse.core.resources.IProject) BaseTest(org.eclipse.che.plugin.maven.server.BaseTest) ClasspathManager(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathManager) IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaCore(org.eclipse.jdt.core.JavaCore) BeforeMethod(org.testng.annotations.BeforeMethod) MessageType(org.eclipse.che.plugin.maven.shared.MessageType) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) Assert.assertNotNull(org.testng.Assert.assertNotNull) MavenExecutorService(org.eclipse.che.plugin.maven.server.core.MavenExecutorService) File(java.io.File) IoUtil(org.eclipse.che.commons.lang.IoUtil) IType(org.eclipse.jdt.core.IType) Provider(com.google.inject.Provider) NotificationMessage(org.eclipse.che.plugin.maven.shared.dto.NotificationMessage) List(java.util.List) MavenProjectManager(org.eclipse.che.plugin.maven.server.core.MavenProjectManager) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) Mockito.mock(org.mockito.Mockito.mock) MavenWrapperManager(org.eclipse.che.plugin.maven.server.MavenWrapperManager) ClasspathManager(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathManager) Set(java.util.Set) JsonObject(com.google.gson.JsonObject) MavenCommunication(org.eclipse.che.plugin.maven.server.core.MavenCommunication) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) Provider(com.google.inject.Provider) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) MavenExecutorService(org.eclipse.che.plugin.maven.server.core.MavenExecutorService) NotificationMessage(org.eclipse.che.plugin.maven.shared.dto.NotificationMessage) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) MavenWorkspace(org.eclipse.che.plugin.maven.server.core.MavenWorkspace) List(java.util.List) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest) File(java.io.File) MavenProjectManager(org.eclipse.che.plugin.maven.server.core.MavenProjectManager) MessageType(org.eclipse.che.plugin.maven.shared.MessageType) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with Provider

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

the class ProjectWizardPresenter method getWizardForProjectType.

/** Creates or returns project wizard for the specified projectType with the given dataObject. */
private ProjectWizard getWizardForProjectType(@NotNull ProjectTypeDto projectType, @NotNull MutableProjectConfig configDto) {
    if (wizardsCache.containsKey(projectType)) {
        return wizardsCache.get(projectType);
    }
    final ProjectWizardRegistrar wizardRegistrar = wizardRegistry.getWizardRegistrar(projectType.getId());
    if (wizardRegistrar == null) {
        // should never occur
        throw new IllegalStateException("WizardRegistrar for the project type " + projectType.getId() + " isn't registered.");
    }
    List<Provider<? extends WizardPage<MutableProjectConfig>>> pageProviders = wizardRegistrar.getWizardPages();
    final ProjectWizard projectWizard = createDefaultWizard(configDto, wizardMode);
    for (Provider<? extends WizardPage<MutableProjectConfig>> provider : pageProviders) {
        projectWizard.addPage(provider.get(), 1, false);
    }
    wizardsCache.put(projectType, projectWizard);
    return projectWizard;
}
Also used : MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) WizardPage(org.eclipse.che.ide.api.wizard.WizardPage) ProjectWizard(org.eclipse.che.ide.projecttype.wizard.ProjectWizard) ProjectWizardRegistrar(org.eclipse.che.ide.api.project.type.wizard.ProjectWizardRegistrar) Provider(com.google.inject.Provider)

Example 8 with Provider

use of com.google.inject.Provider in project ninja by ninjaframework.

the class RouteBuilderImplTest method testWithFiltersClass.

@Test
public void testWithFiltersClass() throws Exception {
    // given        
    DummyFilter dummyFilter = new DummyFilter();
    Result expectedResult = Mockito.mock(Result.class);
    Context context = Mockito.mock(Context.class);
    Provider filterProvider = Mockito.mock(Provider.class);
    Mockito.when(injector.getProvider(DummyFilter.class)).thenReturn(filterProvider);
    Mockito.when(filterProvider.get()).thenReturn(dummyFilter);
    routeBuilder.GET().route("/").filters(DummyFilter.class).with(() -> expectedResult);
    Route route = routeBuilder.buildRoute(injector);
    FilterChain filterChain = route.getFilterChain();
    // when
    Result result = filterChain.next(context);
    // then
    assertThat(dummyFilter.executed, Matchers.equalTo(1));
    assertThat(result, org.hamcrest.Matchers.equalTo(expectedResult));
}
Also used : Provider(com.google.inject.Provider) Test(org.junit.Test)

Example 9 with Provider

use of com.google.inject.Provider in project ninja by ninjaframework.

the class RouteBuilderImplTest method testWithFiltersList.

@Test
public void testWithFiltersList() throws Exception {
    // given        
    DummyFilter dummyFilter = new DummyFilter();
    Result expectedResult = Mockito.mock(Result.class);
    Context context = Mockito.mock(Context.class);
    Provider filterProvider = Mockito.mock(Provider.class);
    Mockito.when(injector.getProvider(DummyFilter.class)).thenReturn(filterProvider);
    Mockito.when(filterProvider.get()).thenReturn(dummyFilter);
    routeBuilder.GET().route("/").filters(Lists.newArrayList(DummyFilter.class)).with(() -> expectedResult);
    Route route = routeBuilder.buildRoute(injector);
    FilterChain filterChain = route.getFilterChain();
    // when
    Result result = filterChain.next(context);
    // then
    assertThat(dummyFilter.executed, Matchers.equalTo(1));
    assertThat(result, org.hamcrest.Matchers.equalTo(expectedResult));
}
Also used : Provider(com.google.inject.Provider) Test(org.junit.Test)

Example 10 with Provider

use of com.google.inject.Provider in project platformlayer by platformlayer.

the class GuiceDataSourceProvider method bindJndi.

public static Provider<? extends DataSource> bindJndi(final String key) {
    Provider<DataSource> provider = new Provider<DataSource>() {

        @Override
        public DataSource get() {
            try {
                InitialContext context = new InitialContext();
                DataSource dataSource = (DataSource) context.lookup(key);
                return dataSource;
            } catch (NamingException e) {
                throw new IllegalStateException("Error getting JDNI connection: " + key, e);
            }
        }
    };
    return provider;
}
Also used : NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) Provider(com.google.inject.Provider) DataSource(javax.sql.DataSource)

Aggregations

Provider (com.google.inject.Provider)132 Injector (com.google.inject.Injector)72 AbstractModule (com.google.inject.AbstractModule)63 Module (com.google.inject.Module)44 Key (com.google.inject.Key)17 TypeLiteral (com.google.inject.TypeLiteral)10 ArrayList (java.util.ArrayList)10 ProvisionException (com.google.inject.ProvisionException)9 Dependency (com.google.inject.spi.Dependency)9 Map (java.util.Map)8 Before (org.junit.Before)7 CurrentUser (com.google.gerrit.server.CurrentUser)6 RequestContext (com.google.gerrit.server.util.RequestContext)6 ThreadLocalRequestContext (com.google.gerrit.server.util.ThreadLocalRequestContext)6 InMemoryModule (com.google.gerrit.testutil.InMemoryModule)6 PrivateModule (com.google.inject.PrivateModule)6 Scope (com.google.inject.Scope)6 List (java.util.List)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Annotation (java.lang.annotation.Annotation)5