use of org.xwiki.component.wiki.internal.WikiComponentManagerContext 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");
}
Aggregations