Search in sources :

Example 36 with Provider

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

the class FilesystemResourceReferenceSerializerTest method serializeWithCSSPathAdjustmentsWithDocParentLevels.

@Test
public void serializeWithCSSPathAdjustmentsWithDocParentLevels() throws Exception {
    FilesystemExportContext exportContext = new FilesystemExportContext();
    exportContext.setExportDir(BASEDIR);
    exportContext.setDocParentLevels(2);
    Provider<FilesystemExportContext> exportContextProvider = this.mocker.getInstance(new DefaultParameterizedType(null, Provider.class, FilesystemExportContext.class));
    Mockito.when(exportContextProvider.get()).thenReturn(exportContext);
    WebJarsResourceReference reference = new WebJarsResourceReference("wiki:wiki", Arrays.asList("font-awesome", "4.7.0", "fonts/FontAwesome.otf"));
    // Verify that the returned URL is ok
    assertEquals("../../webjars/font-awesome/4.7.0/fonts/FontAwesome.otf", this.mocker.getComponentUnderTest().serialize(reference).serialize());
    // Also verify that the resource has been copied!
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/fonts/FontAwesome.otf").exists());
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) FilesystemExportContext(org.xwiki.url.filesystem.FilesystemExportContext) File(java.io.File) Provider(javax.inject.Provider) Test(org.junit.Test)

Example 37 with Provider

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

the class VfsResourceReferenceSerializerTest method setUp.

@Before
public void setUp() throws Exception {
    Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(componentManagerProvider.get()).thenReturn(this.mocker);
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Provider(javax.inject.Provider) Before(org.junit.Before)

Example 38 with Provider

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

the class VfsResourceReferenceHandlerTest method setUp.

private void setUp(String scheme, String wikiName, String spaceName, String pageName, String attachmentName, List<String> path) throws Exception {
    Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(componentManagerProvider.get()).thenReturn(this.mocker);
    String attachmentReferenceAsString = String.format("%s:%s:%s.%s@%s", scheme, wikiName, spaceName, pageName, attachmentName);
    this.reference = new VfsResourceReference(URI.create(attachmentReferenceAsString), path);
    ResourceReferenceSerializer<VfsResourceReference, URI> trueVfsResourceReferenceSerializer = this.mocker.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class, URI.class), "truevfs");
    String truevfsURIFragment = String.format("%s://%s:%s.%s/%s/%s", scheme, wikiName, spaceName, pageName, attachmentName, StringUtils.join(path, '/'));
    when(trueVfsResourceReferenceSerializer.serialize(this.reference)).thenReturn(URI.create(truevfsURIFragment));
    Provider<XWikiContext> xwikiContextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    XWikiContext xcontext = mock(XWikiContext.class);
    when(xwikiContextProvider.get()).thenReturn(xcontext);
    XWiki xwiki = mock(XWiki.class);
    when(xcontext.getWiki()).thenReturn(xwiki);
    DocumentReferenceResolver<String> documentReferenceResolver = mocker.registerMockComponent(DocumentReferenceResolver.TYPE_STRING);
    this.documentReference = new DocumentReference(wikiName, Arrays.asList(spaceName), pageName);
    String documentReferenceAsString = String.format("%s:%s.%s", wikiName, spaceName, pageName);
    when(documentReferenceResolver.resolve(documentReferenceAsString)).thenReturn(this.documentReference);
    XWikiDocument document = mock(XWikiDocument.class);
    when(xwiki.getDocument(this.documentReference, xcontext)).thenReturn(document);
    XWikiAttachment attachment = mock(XWikiAttachment.class);
    when(document.getAttachment(attachmentName)).thenReturn(attachment);
    when(attachment.getDate()).thenReturn(new Date());
    when(attachment.getContentSize(xcontext)).thenReturn(1000);
    when(attachment.getContentInputStream(xcontext)).thenReturn(createZipInputStream(StringUtils.join(path, '/'), "success!"));
    Container container = this.mocker.getInstance(Container.class);
    Response response = mock(Response.class);
    when(container.getResponse()).thenReturn(response);
    this.baos = new ByteArrayOutputStream();
    when(response.getOutputStream()).thenReturn(this.baos);
    // Register our custom Attach Driver in TrueVFS
    TConfig config = TConfig.current();
    // Note: Make sure we add our own Archive Detector to the existing Detector so that all archive formats
    // supported by TrueVFS are handled properly.
    config.setArchiveDetector(new TArchiveDetector(config.getArchiveDetector(), "attach", new AttachDriver(this.mocker)));
}
Also used : AttachDriver(org.xwiki.vfs.internal.attach.AttachDriver) ResourceReferenceSerializer(org.xwiki.resource.ResourceReferenceSerializer) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URI(java.net.URI) Date(java.util.Date) Provider(javax.inject.Provider) Response(org.xwiki.container.Response) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Container(org.xwiki.container.Container) ComponentManager(org.xwiki.component.manager.ComponentManager) TConfig(net.java.truevfs.access.TConfig) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) TArchiveDetector(net.java.truevfs.access.TArchiveDetector) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 39 with Provider

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

the class ExportURLFactory method init.

/**
 * Init the url factory.
 *
 * @param exportedPages the pages that will be exported.
 * @param exportDir the directory where to copy exported objects (attachments).
 * @param context the XWiki context.
 * @deprecated starting with 8.4.5/9.0, use {@link #init(Collection, File, FilesystemExportContext, XWikiContext)}
 */
@Deprecated
public void init(Collection<String> exportedPages, File exportDir, XWikiContext context) {
    Provider<FilesystemExportContext> exportContextProvider = Utils.getComponent(new DefaultParameterizedType(null, Provider.class, FilesystemExportContext.class));
    DocumentReferenceResolver<String> resolver = Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "current");
    List<DocumentReference> references = new ArrayList<>();
    for (String exportedPage : exportedPages) {
        references.add(resolver.resolve(exportedPage));
    }
    init(references, exportDir, exportContextProvider.get(), context);
}
Also used : ArrayList(java.util.ArrayList) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) FilesystemExportContext(org.xwiki.url.filesystem.FilesystemExportContext) DocumentReference(org.xwiki.model.reference.DocumentReference) Provider(javax.inject.Provider)

Example 40 with Provider

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

the class UIExtensionScriptServiceTest method setUp.

@Before
public void setUp() throws Exception {
    contextComponentManager = mock(ComponentManager.class);
    Provider<ComponentManager> componentManagerProvider = componentManager.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(componentManagerProvider.get()).thenReturn(contextComponentManager);
    this.uiExtensionManager = componentManager.getInstance(UIExtensionManager.class);
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) UIExtensionManager(org.xwiki.uiextension.UIExtensionManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Provider(javax.inject.Provider) Before(org.junit.Before)

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