Search in sources :

Example 51 with ComponentManager

use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.

the class UIExtensionScriptService method getExtensions.

/**
 * Retrieves all the {@link UIExtension}s for a given Extension Point.
 *
 * @param extensionPointId The ID of the Extension Point to retrieve the {@link UIExtension}s for
 * @return the list of {@link UIExtension} for the given Extension Point
 */
public List<UIExtension> getExtensions(String extensionPointId) {
    UIExtensionManager manager = this.uiExtensionManager;
    ComponentManager componentManager = contextComponentManagerProvider.get();
    if (componentManager.hasComponent(UIExtensionManager.class, extensionPointId)) {
        try {
            // Look for a specific UI extension manager for the given extension point
            manager = componentManager.getInstance(UIExtensionManager.class, extensionPointId);
        } catch (ComponentLookupException e) {
            this.logger.error("Failed to initialize UI extension manager", e);
        }
    }
    return manager.get(extensionPointId);
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) UIExtensionManager(org.xwiki.uiextension.UIExtensionManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 52 with ComponentManager

use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.

the class DefaultIOTargetServiceTest method registerComponents.

@Override
protected void registerComponents() throws Exception {
    super.registerComponents();
    // register the dab
    this.dabMock = registerMockComponent(DocumentAccessBridge.class);
    getMockery().checking(new Expectations() {

        {
            allowing(dabMock).getCurrentUserReference();
        }
    });
    this.classResolver = registerMockComponent(DocumentReferenceResolver.TYPE_STRING);
    // We don't care about multi CM
    DefaultComponentDescriptor<ComponentManager> componentDescriptor = new DefaultComponentDescriptor<>();
    componentDescriptor.setRoleType(ComponentManager.class);
    componentDescriptor.setRoleHint("context");
    getComponentManager().registerComponent(componentDescriptor, getComponentManager());
}
Also used : Expectations(org.jmock.Expectations) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ComponentManager(org.xwiki.component.manager.ComponentManager)

Example 53 with ComponentManager

use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.

the class DefaultWikiMacroManagerTest method registerWikiMacroWhenUserVisibilityAndAllowed.

@Test
public void registerWikiMacroWhenUserVisibilityAndAllowed() throws Exception {
    DefaultWikiMacro wikiMacro = generateWikiMacro(WikiMacroVisibility.USER);
    // Simulate a user who's allowed for the USER visibility
    WikiMacroFactory wikiMacroFactory = this.mocker.getInstance(WikiMacroFactory.class);
    when(wikiMacroFactory.isAllowed(wikiMacro.getDocumentReference(), WikiMacroVisibility.USER)).thenReturn(true);
    ComponentManager userComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "user");
    // Test registration
    WikiMacroManager wikiMacroManager = this.mocker.getComponentUnderTest();
    wikiMacroManager.registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro);
    assertTrue(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference()));
    // Verify that the WikiMacroManager has registered the macro against the user CM
    verify(userComponentManager).registerComponent(any(DefaultComponentDescriptor.class), eq(wikiMacro));
    // Test unregistration
    wikiMacroManager.unregisterWikiMacro(wikiMacro.getDocumentReference());
    assertFalse(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference()));
    // Verify that the WikiMacroManager has unregistered the macro against the user CM
    verify(userComponentManager).unregisterComponent(Macro.class, "testwikimacro");
}
Also used : WikiMacroFactory(org.xwiki.rendering.macro.wikibridge.WikiMacroFactory) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) ComponentManager(org.xwiki.component.manager.ComponentManager) WikiMacroManager(org.xwiki.rendering.macro.wikibridge.WikiMacroManager) Test(org.junit.Test)

Example 54 with ComponentManager

use of org.xwiki.component.manager.ComponentManager 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 55 with ComponentManager

use of org.xwiki.component.manager.ComponentManager 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)

Aggregations

ComponentManager (org.xwiki.component.manager.ComponentManager)76 Test (org.junit.Test)34 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)23 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)18 DocumentReference (org.xwiki.model.reference.DocumentReference)17 Provider (javax.inject.Provider)14 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)12 Before (org.junit.Before)11 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)11 XWikiContext (com.xpn.xwiki.XWikiContext)9 Expectations (org.jmock.Expectations)9 WikiReference (org.xwiki.model.reference.WikiReference)9 HashMap (java.util.HashMap)7 Execution (org.xwiki.context.Execution)7 SpaceReference (org.xwiki.model.reference.SpaceReference)7 XWiki (com.xpn.xwiki.XWiki)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)6 ArrayList (java.util.ArrayList)6 ExecutionContext (org.xwiki.context.ExecutionContext)6 MimeMessage (javax.mail.internet.MimeMessage)5