Search in sources :

Example 41 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class ComponentScriptServiceTest method configure.

@Before
public void configure() throws Exception {
    this.dab = this.mocker.getInstance(DocumentAccessBridge.class);
    this.contextComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "context");
    Provider<ComponentManager> contextComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(contextComponentManagerProvider.get()).thenReturn(this.contextComponentManager);
    this.contextrootComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "context/root");
    Provider<ComponentManager> contextrootComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context/root");
    when(contextrootComponentManagerProvider.get()).thenReturn(this.contextrootComponentManager);
    this.rootComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "root");
    this.componentManagerManager = this.mocker.getInstance(ComponentManagerManager.class);
    when(this.componentManagerManager.getComponentManager(null, false)).thenReturn(this.rootComponentManager);
    this.execution = this.mocker.getInstance(Execution.class);
}
Also used : ComponentManagerManager(org.xwiki.component.internal.multi.ComponentManagerManager) Execution(org.xwiki.context.Execution) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Provider(javax.inject.Provider) ContextComponentManagerProvider(org.xwiki.component.internal.ContextComponentManagerProvider) Before(org.junit.Before)

Example 42 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class LocalizationScriptServiceTest method setUp.

@Before
public void setUp() throws Exception {
    componentManager = mock(ComponentManager.class);
    Provider<ComponentManager> componentManagerProvider = mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(componentManagerProvider.get()).thenReturn(componentManager);
    renderer = mock(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString());
    when(componentManager.getInstance(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString())).thenReturn(renderer);
    localizationContext = mocker.getInstance(LocalizationContext.class);
    localizationManager = mocker.getInstance(LocalizationManager.class);
    localizationScriptService = (LocalizationScriptService) mocker.getComponentUnderTest();
    translation = mock(Translation.class);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            WikiPrinter printer = (WikiPrinter) invocation.getArguments()[1];
            printer.print("print result");
            return null;
        }
    }).when(renderer).render(eq(new WordBlock("message")), any(WikiPrinter.class));
    when(translation.render(Locale.ROOT, ArrayUtils.EMPTY_OBJECT_ARRAY)).thenReturn(new WordBlock("message"));
    when(localizationManager.getTranslation("key", Locale.ROOT)).thenReturn(translation);
    when(localizationContext.getCurrentLocale()).thenReturn(Locale.ROOT);
    environment = mocker.getInstance(Environment.class);
}
Also used : Translation(org.xwiki.localization.Translation) LocalizationContext(org.xwiki.localization.LocalizationContext) WordBlock(org.xwiki.rendering.block.WordBlock) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) Provider(javax.inject.Provider) BlockRenderer(org.xwiki.rendering.renderer.BlockRenderer) LocalizationManager(org.xwiki.localization.LocalizationManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ComponentManager(org.xwiki.component.manager.ComponentManager) Environment(org.xwiki.environment.Environment) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Before(org.junit.Before)

Example 43 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class ExportURLFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    this.urlFactory = new ExportURLFactory();
    this.tmpDir = this.tmpDirRule.newFolder("xwikitests");
    new File(this.tmpDir, "attachment").mkdir();
    Provider<FilesystemExportContext> exportContextProvider = this.oldcoreRule.getMocker().getInstance(new DefaultParameterizedType(null, Provider.class, FilesystemExportContext.class));
    this.exportContext = exportContextProvider.get();
    doReturn("/xwiki").when(this.oldcoreRule.getSpyXWiki()).getWebAppPath(any(XWikiContext.class));
    XWikiContext context = this.oldcoreRule.getXWikiContext();
    XWikiRequest request = mock(XWikiRequest.class);
    context.setRequest(request);
    context.setURL(new URL("http://www.xwiki.org/"));
    this.urlFactory.init(null, this.tmpDir, this.exportContext, context);
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) File(java.io.File) FilesystemExportContext(org.xwiki.url.filesystem.FilesystemExportContext) URL(java.net.URL) Provider(javax.inject.Provider) Before(org.junit.Before)

Example 44 with Provider

use of javax.inject.Provider in project eclipse.platform.runtime by eclipse.

the class InjectorImpl method getProviderType.

/**
 * Returns null if not a provider
 */
private Class<?> getProviderType(Type type) {
    if (!(type instanceof ParameterizedType))
        return null;
    Type rawType = ((ParameterizedType) type).getRawType();
    if (!Provider.class.equals(rawType))
        return null;
    Type[] actualTypes = ((ParameterizedType) type).getActualTypeArguments();
    if (actualTypes.length != 1)
        return null;
    if (!(actualTypes[0] instanceof Class<?>))
        return null;
    return (Class<?>) actualTypes[0];
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Provider(javax.inject.Provider)

Example 45 with Provider

use of javax.inject.Provider in project actframework by actframework.

the class GenieInjector method genie.

public Genie genie() {
    if (null == genie) {
        synchronized (this) {
            if (null == genie) {
                InjectListener listener = new GenieListener(this);
                genie = Genie.create(listener, modules.toArray(new Object[modules.size()]));
                for (Map.Entry<Class, DependencyInjectionBinder> entry : binders.entrySet()) {
                    genie.registerProvider(entry.getKey(), entry.getValue());
                }
                $.F2<Class, NamedProvider, Void> namedProviderRegister = new $.F2<Class, NamedProvider, Void>() {

                    @Override
                    public Void apply(Class aClass, NamedProvider namedProvider) throws NotAppliedException, Osgl.Break {
                        genie.registerNamedProvider(aClass, namedProvider);
                        return null;
                    }
                };
                $.F2<Class, Provider, Void> register = new $.F2<Class, Provider, Void>() {

                    @Override
                    public Void apply(Class aClass, Provider provider) throws NotAppliedException, Osgl.Break {
                        genie.registerProvider(aClass, provider);
                        return null;
                    }
                };
                genie.registerQualifiers(Bind.class, Param.class);
                genie.registerScopeAlias(Singleton.class, Stateless.class);
                genie.registerScopeAlias(Singleton.class, InheritedStateless.class);
                genie.registerScopeAlias(StopInheritedScope.class, Stateful.class);
                List<ActionMethodParamAnnotationHandler> list = Act.pluginManager().pluginList(ActionMethodParamAnnotationHandler.class);
                for (ActionMethodParamAnnotationHandler h : list) {
                    Set<Class<? extends Annotation>> set = h.listenTo();
                    for (Class<? extends Annotation> c : set) {
                        genie.registerQualifiers(c);
                    }
                }
                ActProviders.registerBuiltInProviders(ActProviders.class, register);
                ActProviders.registerBuiltInProviders(GenieProviders.class, register);
                ActProviders.registerBuiltInNamedProviders(ActProviders.class, namedProviderRegister);
                ActProviders.registerBuiltInNamedProviders(GenieProviders.class, namedProviderRegister);
                for (Class<? extends Annotation> injectTag : injectTags) {
                    genie.registerInjectTag(injectTag);
                }
                genie.registerProvider(Genie.class, new Provider<Genie>() {

                    @Override
                    public Genie get() {
                        return genie;
                    }
                });
            }
        }
    }
    return genie;
}
Also used : ActionMethodParamAnnotationHandler(act.controller.ActionMethodParamAnnotationHandler) org.osgl.$(org.osgl.$) Osgl(org.osgl.Osgl) Annotation(java.lang.annotation.Annotation) Provider(javax.inject.Provider)

Aggregations

Provider (javax.inject.Provider)53 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)23 Test (org.junit.Test)15 ComponentManager (org.xwiki.component.manager.ComponentManager)15 Before (org.junit.Before)11 HashMap (java.util.HashMap)9 File (java.io.File)7 FilesystemExportContext (org.xwiki.url.filesystem.FilesystemExportContext)7 ArrayList (java.util.ArrayList)6 XWikiContext (com.xpn.xwiki.XWikiContext)5 Map (java.util.Map)5 DocumentReference (org.xwiki.model.reference.DocumentReference)5 Maps (com.google.common.collect.Maps)4 Type (java.lang.reflect.Type)4 Query (org.graylog.plugins.views.search.Query)4 QueryResult (org.graylog.plugins.views.search.QueryResult)4 SearchJob (org.graylog.plugins.views.search.SearchJob)4 SearchType (org.graylog.plugins.views.search.SearchType)4 IndexLookup (org.graylog.plugins.views.search.elasticsearch.IndexLookup)4 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)4