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());
}
}
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);
}
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));
}
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");
}
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);
}
}
}
Aggregations