Search in sources :

Example 61 with ComponentManager

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

the class DefaultClassPropertyValuesProviderTest method getValuesWithMissingProvider.

@Test
public void getValuesWithMissingProvider() throws Exception {
    ClassPropertyReference propertyReference = new ClassPropertyReference("category", this.classReference);
    ComponentManager contextComponentManager = this.mocker.getInstance(ComponentManager.class, "context");
    when(contextComponentManager.getInstance(ClassPropertyValuesProvider.class, "DBList")).thenThrow(new ComponentLookupException("Component not found."));
    try {
        this.mocker.getComponentUnderTest().getValues(propertyReference, 13, "one");
        fail();
    } catch (XWikiRestException expected) {
        assertEquals("There's no value provider registered for the [DBList] property type.", expected.getMessage());
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) Test(org.junit.Test)

Example 62 with ComponentManager

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

Example 63 with ComponentManager

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

the class StandardExtendedURLResourceReferenceSerializerTest method serialize.

@Test
public void serialize() throws Exception {
    TestResourceReference resource = new TestResourceReference();
    ResourceReferenceSerializer serializer = mock(ResourceReferenceSerializer.class);
    ComponentManager componentManager = this.mocker.getInstance(ComponentManager.class, "context");
    when(componentManager.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, TestResourceReference.class, ExtendedURL.class), "standard")).thenReturn(serializer);
    this.mocker.getComponentUnderTest().serialize(resource);
    // Verify the serializer is called and with the proper parameters
    verify(serializer).serialize(same(resource));
}
Also used : ResourceReferenceSerializer(org.xwiki.resource.ResourceReferenceSerializer) ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) ExtendedURL(org.xwiki.url.ExtendedURL) Test(org.junit.Test)

Example 64 with ComponentManager

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

the class DefaultWikiComponentManagerTest method registerAndUnregisterWikiComponent.

@Test
public void registerAndUnregisterWikiComponent() throws Exception {
    WikiComponentManagerContext wcmc = this.mocker.getInstance(WikiComponentManagerContext.class);
    when(wcmc.getCurrentEntityReference()).thenReturn(DOC_REFERENCE);
    when(wcmc.getCurrentUserReference()).thenReturn(AUTHOR_REFERENCE);
    WikiComponent component = new TestImplementation(DOC_REFERENCE, AUTHOR_REFERENCE, WikiComponentScope.WIKI);
    ComponentManager wikiComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "wiki");
    // Register the wiki component
    this.mocker.getComponentUnderTest().registerWikiComponent(component);
    // Test 1: we verify that the component has been registered against the CM
    verify(wikiComponentManager, times(1)).registerComponent(any(ComponentDescriptor.class), eq(component));
    // Try to register the wiki component again
    this.mocker.getComponentUnderTest().registerWikiComponent(component);
    // Test 2: we verify that the component has been registered again against the CM
    verify(wikiComponentManager, times(2)).registerComponent(any(ComponentDescriptor.class), eq(component));
    // Unregister the wiki component
    this.mocker.getComponentUnderTest().unregisterWikiComponents(DOC_REFERENCE);
    // Test 3: we verify that the component has been unregistered from the CM
    // Note that indirectly this tests that the wiki component has been added to the wiki component cache during
    // the call to registerWikiComponent()
    verify(wikiComponentManager, times(1)).unregisterComponent(TestRole.class, "roleHint");
    // Try to unregister the wiki component again
    this.mocker.getComponentUnderTest().unregisterWikiComponents(DOC_REFERENCE);
    // Test 4: We verify that nothing happens on the CM since the wiki component is not in the wiki cache.
    // Note: the times(1) comes from the previous call in test 2 above.
    verify(wikiComponentManager, times(1)).unregisterComponent(TestRole.class, "roleHint");
}
Also used : ComponentDescriptor(org.xwiki.component.descriptor.ComponentDescriptor) ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultWikiComponentManager(org.xwiki.component.wiki.internal.DefaultWikiComponentManager) WikiComponentManagerContext(org.xwiki.component.wiki.internal.WikiComponentManagerContext) Test(org.junit.Test)

Example 65 with ComponentManager

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

the class WikiDeletedListener method onEvent.

@Override
public void onEvent(Event event, Object o, Object context) {
    String wiki = ((WikiDeletedEvent) event).getWikiId();
    ComponentManager componentManager = this.componentManagerManager.getComponentManager(new WikiNamespace(wiki).serialize(), false);
    if (componentManager instanceof Disposable) {
        try {
            ((Disposable) componentManager).dispose();
        } catch (ComponentLifecycleException e) {
            this.logger.error(String.format("Failed to dispose component manager for wiki [%s]", wiki), e);
        }
    }
}
Also used : Disposable(org.xwiki.component.phase.Disposable) WikiNamespace(org.xwiki.model.namespace.WikiNamespace) ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLifecycleException(org.xwiki.component.manager.ComponentLifecycleException) WikiDeletedEvent(org.xwiki.bridge.event.WikiDeletedEvent)

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