use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class WikiManagerScriptServiceTest method getByIdError.
@Test
public void getByIdError() throws Exception {
Exception exception = new WikiManagerException("error in getById");
when(wikiDescriptorManager.getById("wikiId")).thenThrow(exception);
WikiDescriptor result = mocker.getComponentUnderTest().getById("wikiId");
assertNull(result);
assertEquals(exception, mocker.getComponentUnderTest().getLastError());
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class WikiManagerScriptServiceTest method saveDescriptorWhenIAmLocalAdmin.
@Test
public void saveDescriptorWhenIAmLocalAdmin() throws Exception {
WikiDescriptor oldDescriptor = new WikiDescriptor("wikiId", "wikiAlias");
oldDescriptor.setOwnerId("SomeUser");
when(wikiDescriptorManager.getById(oldDescriptor.getId())).thenReturn(oldDescriptor);
// Local admin.
when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(currentUserRef), eq(new WikiReference("wikiId")))).thenReturn(true);
// Changing some value, not the owner.
WikiDescriptor descriptor = new WikiDescriptor(oldDescriptor.getId(), "wikiAlias");
descriptor.setOwnerId(oldDescriptor.getOwnerId());
boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor);
assertTrue(result);
// The right has been checked
verify(authorizationManager).hasAccess(eq(Right.ADMIN), eq(currentUserRef), eq(new WikiReference("wikiId")));
// The descriptor has been saved
verify(wikiDescriptorManager).saveDescriptor(descriptor);
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class WikiManagerScriptServiceTest method createWikiError.
@Test
public void createWikiError() throws Exception {
Exception exception = new WikiManagerException("error on create");
when(wikiManager.create("newwiki", "alias", true)).thenThrow(exception);
WikiDescriptor result = mocker.getComponentUnderTest().createWiki("newwiki", "alias", "userA", true);
assertNull(result);
assertEquals(exception, mocker.getComponentUnderTest().getLastError());
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class WikiManagerScriptServiceTest method getAll.
@Test
public void getAll() throws Exception {
WikiDescriptor descriptor1 = new WikiDescriptor("wikiId1", "wikiAlias1");
WikiDescriptor descriptor2 = new WikiDescriptor("wikiId2", "wikiAlias2");
Collection<WikiDescriptor> descriptors = new ArrayList<WikiDescriptor>();
descriptors.add(descriptor1);
descriptors.add(descriptor2);
when(wikiDescriptorManager.getAll()).thenReturn(descriptors);
Collection<WikiDescriptor> result = mocker.getComponentUnderTest().getAll();
assertEquals(descriptors, result);
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class WikiManagerScriptServiceTest method saveDescriptorWhenIAmNotOwnerNorLocalAdminNorGlobalAdmin.
@Test
public void saveDescriptorWhenIAmNotOwnerNorLocalAdminNorGlobalAdmin() throws Exception {
WikiDescriptor oldDescriptor = new WikiDescriptor("wikiId", "wikiAlias");
oldDescriptor.setOwnerId("SomeUser");
when(wikiDescriptorManager.getById(oldDescriptor.getId())).thenReturn(oldDescriptor);
when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(currentUserRef), eq(new WikiReference("wikiId")))).thenReturn(false);
// Changing some value, not the owner.
WikiDescriptor descriptor = new WikiDescriptor(oldDescriptor.getId(), "wikiAlias");
oldDescriptor.setOwnerId(oldDescriptor.getOwnerId());
boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor);
assertFalse(result);
// The descriptor has not been saved
verify(wikiDescriptorManager, never()).saveDescriptor(descriptor);
Exception exception = new AccessDeniedException(currentUserRef, new WikiReference("wikiId"));
assertEquals(exception.getMessage(), mocker.getComponentUnderTest().getLastError().getMessage());
assertEquals(exception.getClass(), mocker.getComponentUnderTest().getLastError().getClass());
}
Aggregations