Search in sources :

Example 16 with WikiDescriptor

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

the class WikiTemplateManagerScriptTest method setTemplateWhenCurrentUserIsOwner.

@Test
public void setTemplateWhenCurrentUserIsOwner() throws Exception {
    WikiDescriptor wikiDescriptor = new WikiDescriptor("wikiId", "wikiAlias");
    wikiDescriptor.setOwnerId("mainWiki:XWiki.User");
    when(wikiDescriptorManager.getById("wikiId")).thenReturn(wikiDescriptor);
    // Test 1
    boolean result = mocker.getComponentUnderTest().setTemplate("wikiId", true);
    assertTrue(result);
    verify(wikiTemplateManager).setTemplate("wikiId", true);
    // Test 2
    result = mocker.getComponentUnderTest().setTemplate("wikiId", false);
    assertTrue(result);
    verify(wikiTemplateManager).setTemplate("wikiId", false);
}
Also used : WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 17 with WikiDescriptor

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

the class WikiTemplateManagerScriptTest method setTemplateErrorWithTemplateManager.

@Test
public void setTemplateErrorWithTemplateManager() throws Exception {
    WikiDescriptor wikiDescriptor = new WikiDescriptor("wikiId", "wikiAlias");
    when(wikiDescriptorManager.getById("wikiId")).thenReturn(wikiDescriptor);
    Exception exception = new WikiTemplateManagerException("error in setTemplate");
    doThrow(exception).when(wikiTemplateManager).setTemplate("wikiId", true);
    boolean result = mocker.getComponentUnderTest().setTemplate("wikiId", true);
    assertFalse(result);
    assertEquals(exception, mocker.getComponentUnderTest().getLastError());
    verify(mocker.getMockedLogger()).error("Failed to set the template value [true] for the wiki [wikiId].", exception);
}
Also used : WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException) Test(org.junit.Test)

Example 18 with WikiDescriptor

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

the class WikiTemplateManagerScriptTest method getTemplates.

@Test
public void getTemplates() throws Exception {
    Collection<WikiDescriptor> templates = new ArrayList<WikiDescriptor>();
    WikiDescriptor descriptor = new WikiDescriptor("templateId", "templateAlias");
    templates.add(descriptor);
    when(wikiTemplateManager.getTemplates()).thenReturn(templates);
    Collection<WikiDescriptor> results = mocker.getComponentUnderTest().getTemplates();
    assertEquals(templates, results);
}
Also used : ArrayList(java.util.ArrayList) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 19 with WikiDescriptor

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

the class DomainWikiReferenceExtractor method resolveDomainBasedWikiReference.

private String resolveDomainBasedWikiReference(String alias) {
    String wikiId;
    // Look for a Wiki Descriptor
    WikiDescriptor wikiDescriptor = getWikiDescriptorByAlias(alias);
    if (wikiDescriptor != null) {
        // Get the wiki id from the wiki descriptor
        wikiId = wikiDescriptor.getId();
    } else {
        // Fallback: No definition found based on the full domain name, consider the alias as a
        // domain name and try to use the first part of the domain name as the wiki name.
        String domainAlias = StringUtils.substringBefore(alias, ".");
        // - IP address
        if ("www".equals(domainAlias) || "localhost".equals(alias) || alias.matches("[0-9]{1,3}(?:\\.[0-9]{1,3}){3}")) {
            wikiId = getMainWikiId();
        } else {
            wikiId = normalizeWikiIdForNonExistentWikiDescriptor(domainAlias);
        }
    // Create a virtual descriptor and save it so that next call will resolve to it directly without needing
    // to query the entity store.
    // this.wikiDescriptorCache.add(new WikiDescriptor(wikiId, alias));
    // TODO: uncomment theses lines, find a solution
    }
    return wikiId;
}
Also used : WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor)

Example 20 with WikiDescriptor

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

the class XWikiTest method testGetDocumentWithEntityReference.

public void testGetDocumentWithEntityReference() throws Exception {
    Mock mockStore = registerMockComponent(XWikiStoreInterface.class);
    this.xwiki.setStore((XWikiStoreInterface) mockStore.proxy());
    mockStore.expects(atLeastOnce()).method("loadXWikiDoc").with(NOT_NULL, same(getContext())).will(new CustomStub("Implements XWikiStoreInterface.loadXWikiDoc") {

        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            return invocation.parameterValues.get(0);
        }
    });
    DocumentReference documentReference = new DocumentReference("wiki", "Main", "WebHome");
    WikiDescriptor mockWikiDescriptor = new WikiDescriptor("wiki", "wiki");
    mockWikiDescriptor.setMainPageReference(documentReference);
    this.mockWikiDescriptorManager.stubs().method("getById").with(same("wiki")).will(returnValue(mockWikiDescriptor));
    assertEquals(documentReference, this.xwiki.getDocument(new WikiReference("wiki"), getContext()).getDocumentReference());
    assertEquals(documentReference, this.xwiki.getDocument(new ObjectReference("object", documentReference), getContext()).getDocumentReference());
}
Also used : Invocation(org.jmock.core.Invocation) CustomStub(org.jmock.core.stub.CustomStub) ObjectReference(org.xwiki.model.reference.ObjectReference) BaseObject(com.xpn.xwiki.objects.BaseObject) WikiReference(org.xwiki.model.reference.WikiReference) Mock(org.jmock.Mock) DocumentReference(org.xwiki.model.reference.DocumentReference) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor)

Aggregations

WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)60 Test (org.junit.Test)40 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)28 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)17 WikiReference (org.xwiki.model.reference.WikiReference)11 XWikiContext (com.xpn.xwiki.XWikiContext)9 WikiTemplateManagerException (org.xwiki.wiki.template.WikiTemplateManagerException)9 ArrayList (java.util.ArrayList)7 DocumentReference (org.xwiki.model.reference.DocumentReference)6 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 BaseObject (com.xpn.xwiki.objects.BaseObject)5 DefaultWikiDescriptor (org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)5 WikiCreationRequest (org.xwiki.platform.wiki.creationjob.WikiCreationRequest)3 AuthorizationException (org.xwiki.security.authorization.AuthorizationException)3 WikiCopiedEvent (org.xwiki.bridge.event.WikiCopiedEvent)2 WikiCreatedEvent (org.xwiki.bridge.event.WikiCreatedEvent)2 WikiCreatingEvent (org.xwiki.bridge.event.WikiCreatingEvent)2 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)2 WikiDescriptorBuilderException (org.xwiki.wiki.internal.descriptor.builder.WikiDescriptorBuilderException)2