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