Search in sources :

Example 41 with WikiDescriptor

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());
}
Also used : WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 42 with WikiDescriptor

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);
}
Also used : WikiReference(org.xwiki.model.reference.WikiReference) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 43 with WikiDescriptor

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());
}
Also used : WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 44 with WikiDescriptor

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);
}
Also used : ArrayList(java.util.ArrayList) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 45 with WikiDescriptor

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());
}
Also used : AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiReference(org.xwiki.model.reference.WikiReference) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) Test(org.junit.Test)

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