Search in sources :

Example 31 with WikiDescriptorManager

use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.

the class WikiTemplateManagerScriptTest method setUp.

@Before
public void setUp() throws Exception {
    wikiTemplateManager = mocker.getInstance(WikiTemplateManager.class);
    wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    authorizationManager = mocker.getInstance(AuthorizationManager.class);
    entityReferenceSerializer = mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceSerializer.class, String.class));
    xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    xcontext = mock(XWikiContext.class);
    when(xcontextProvider.get()).thenReturn(xcontext);
    execution = mocker.getInstance(Execution.class);
    executionContext = new ExecutionContext();
    when(execution.getContext()).thenReturn(executionContext);
    currentUserRef = new DocumentReference("mainWiki", "XWiki", "User");
    when(xcontext.getUserReference()).thenReturn(currentUserRef);
    currentDoc = mock(XWikiDocument.class);
    when(xcontext.getDoc()).thenReturn(currentDoc);
    when(xcontext.getMainXWiki()).thenReturn("mainWiki");
    when(entityReferenceSerializer.serialize(currentUserRef)).thenReturn("mainWiki:XWiki.User");
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) XWikiContext(com.xpn.xwiki.XWikiContext) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentReference(org.xwiki.model.reference.DocumentReference) WikiTemplateManager(org.xwiki.wiki.template.WikiTemplateManager) Before(org.junit.Before)

Example 32 with WikiDescriptorManager

use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.

the class AbstractTestDocumentConfigurationSource method before.

@Before
public void before() throws Exception {
    this.mockCache = mock(Cache.class);
    this.mockConverter = this.componentManager.getInstance(ConverterManager.class);
    when(this.mockConverter.convert(any(Type.class), anyObject())).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return invocation.getArguments()[1];
        }
    });
    CacheManager cacheManager = this.componentManager.getInstance(CacheManager.class);
    when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(this.mockCache);
    WikiDescriptorManager wikiManager = this.componentManager.getInstance(WikiDescriptorManager.class);
    when(wikiManager.getCurrentWikiId()).thenReturn(CURRENT_WIKI);
    DocumentReferenceResolver<EntityReference> mockCurrentEntityResolver = this.componentManager.registerMockComponent(DocumentReferenceResolver.TYPE_REFERENCE, "current");
    when(mockCurrentEntityResolver.resolve(eq(getClassReference()), any(DocumentReference.class))).thenReturn(new DocumentReference(getClassReference(), new WikiReference(CURRENT_WIKI)));
}
Also used : WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) Type(java.lang.reflect.Type) ConverterManager(org.xwiki.properties.ConverterManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) EntityReference(org.xwiki.model.reference.EntityReference) CacheManager(org.xwiki.cache.CacheManager) BaseObject(com.xpn.xwiki.objects.BaseObject) ArgumentMatchers.anyObject(org.mockito.ArgumentMatchers.anyObject) WikiReference(org.xwiki.model.reference.WikiReference) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Cache(org.xwiki.cache.Cache) Before(org.junit.Before)

Example 33 with WikiDescriptorManager

use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.

the class DefaultNotificationFilterManagerTest method setUp.

@Before
public void setUp() throws Exception {
    componentManager = mocker.registerMockComponent(ComponentManager.class);
    wikiDescriptorManager = mocker.registerMockComponent(WikiDescriptorManager.class);
    modelBridge = mocker.registerMockComponent(ModelBridge.class, "cached");
    testUser = new DocumentReference("wiki", "test", "user");
    testProvider = mock(NotificationFilterPreferenceProvider.class);
    when(componentManager.getInstanceList(NotificationFilterPreferenceProvider.class)).thenReturn(Collections.singletonList(testProvider));
    // Set a default comportment for the wikiDescriptorManager
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("wiki");
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("currentWikiId");
    when(wikiDescriptorManager.getAllIds()).thenReturn(Arrays.asList("wiki", "currentWikiId"));
}
Also used : WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) NotificationFilterPreferenceProvider(org.xwiki.notifications.filters.NotificationFilterPreferenceProvider) ComponentManager(org.xwiki.component.manager.ComponentManager) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Example 34 with WikiDescriptorManager

use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.

the class GroupsClassPropertyValuesProviderTest method getValuesLocalAndGlobal.

@Test
public void getValuesLocalAndGlobal() throws Exception {
    // We can have local groups.
    when(this.wikiUserManager.getUserScope(this.classReference.getWikiReference().getName())).thenReturn(UserScope.GLOBAL_ONLY);
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("chess");
    this.mocker.getComponentUnderTest().getValues(this.propertyReference, 5, "foo");
    verify(this.allowedValuesQuery).setWiki("chess");
    verify(this.allowedValuesQuery, times(2)).execute();
}
Also used : WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) Test(org.junit.Test)

Example 35 with WikiDescriptorManager

use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.

the class UsersClassPropertyValuesProviderTest method getValuesLocalAndGlobal.

@Test
public void getValuesLocalAndGlobal() throws Exception {
    when(this.wikiUserManager.getUserScope(this.classReference.getWikiReference().getName())).thenReturn(UserScope.LOCAL_AND_GLOBAL);
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("chess");
    DocumentReference aliceReference = new DocumentReference("wiki", "Users", "Alice");
    when(this.xcontext.getWiki().getDocument(aliceReference, this.xcontext)).thenReturn(mock(XWikiDocument.class, "alice"));
    DocumentReference bobReference = new DocumentReference("chess", "Users", "Bob");
    when(this.xcontext.getWiki().getDocument(bobReference, this.xcontext)).thenReturn(mock(XWikiDocument.class, "bob"));
    when(this.allowedValuesQuery.execute()).thenReturn(Collections.singletonList(bobReference), Collections.singletonList(aliceReference));
    PropertyValues values = this.mocker.getComponentUnderTest().getValues(this.propertyReference, 5, "foo");
    assertEquals(2, values.getPropertyValues().size());
    assertEquals("Alice", values.getPropertyValues().get(0).getMetaData().get("label"));
    assertEquals("Bob", values.getPropertyValues().get(1).getMetaData().get("label"));
    verify(this.allowedValuesQuery).setWiki("chess");
    verify(this.allowedValuesQuery, times(2)).execute();
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) PropertyValues(org.xwiki.rest.model.jaxb.PropertyValues) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)40 Test (org.junit.Test)17 DocumentReference (org.xwiki.model.reference.DocumentReference)14 Before (org.junit.Before)13 XWikiContext (com.xpn.xwiki.XWikiContext)11 Execution (org.xwiki.context.Execution)9 ExecutionContext (org.xwiki.context.ExecutionContext)9 XWiki (com.xpn.xwiki.XWiki)8 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)8 ExtensionId (org.xwiki.extension.ExtensionId)6 AuthorizationManager (org.xwiki.security.authorization.AuthorizationManager)6 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)6 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)6 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)5 ExtendedURL (org.xwiki.url.ExtendedURL)5 WebJarsResourceReference (org.xwiki.webjars.internal.WebJarsResourceReference)5 InstalledExtension (org.xwiki.extension.InstalledExtension)4 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)4 Query (org.xwiki.query.Query)4 BaseObject (com.xpn.xwiki.objects.BaseObject)3