Search in sources :

Example 1 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class XarExtensionPlan method getNextXarExtension.

public LocalExtension getNextXarExtension(DocumentReference documentReference) {
    WikiReference wikiReference = documentReference.getWikiReference();
    LocalDocumentReference localDocumentReference = new LocalDocumentReference(documentReference);
    return getNextXarExtension(wikiReference.getName(), localDocumentReference);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) WikiReference(org.xwiki.model.reference.WikiReference)

Example 2 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class EventAndFactoryTest method testSpace.

@Test
public void testSpace() {
    Assert.assertNull(this.defaultEvent.getSpace());
    DocumentReference doc = new DocumentReference("wiki1", "Space1", "Page");
    SpaceReference space = new SpaceReference("Space2", new WikiReference("wiki2"));
    this.defaultEvent.setDocument(doc);
    Assert.assertEquals(doc.getLastSpaceReference(), this.defaultEvent.getSpace());
    Assert.assertEquals("Space1", this.defaultEvent.getSpace().getName());
    this.defaultEvent.setSpace(space);
    Assert.assertEquals(space, this.defaultEvent.getSpace());
    Assert.assertEquals("Space2", this.defaultEvent.getSpace().getName());
    this.defaultEvent.setSpace(null);
    Assert.assertEquals(doc.getLastSpaceReference(), this.defaultEvent.getSpace());
    this.defaultEvent.setDocument(null);
    Assert.assertNull(this.defaultEvent.getSpace());
    Assert.assertNull(this.rawEvent.getSpace());
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 3 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class EventAndFactoryTest method testWiki.

@Test
public void testWiki() {
    Assert.assertNull(this.defaultEvent.getWiki());
    DocumentReference doc = new DocumentReference("wiki1", "Space1", "Page");
    SpaceReference space = new SpaceReference("Space2", new WikiReference("wiki2"));
    WikiReference wiki = new WikiReference("wiki3");
    this.defaultEvent.setDocument(doc);
    Assert.assertEquals(doc.getWikiReference(), this.defaultEvent.getWiki());
    Assert.assertEquals("wiki1", this.defaultEvent.getWiki().getName());
    this.defaultEvent.setSpace(space);
    Assert.assertEquals(space.getRoot(), this.defaultEvent.getWiki());
    Assert.assertEquals("wiki2", this.defaultEvent.getWiki().getName());
    this.defaultEvent.setWiki(wiki);
    Assert.assertEquals(wiki, this.defaultEvent.getWiki());
    Assert.assertEquals("wiki3", this.defaultEvent.getWiki().getName());
    this.defaultEvent.setWiki(null);
    Assert.assertEquals(space.getRoot(), this.defaultEvent.getWiki());
    this.defaultEvent.setSpace(null);
    Assert.assertEquals(doc.getWikiReference(), this.defaultEvent.getWiki());
    this.defaultEvent.setDocument(null);
    Assert.assertNull(this.defaultEvent.getWiki());
    Assert.assertNull(this.rawEvent.getWiki());
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 4 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class JavaIntegrationTest method registerConfiguration.

@BeforeComponent
public void registerConfiguration() throws Exception {
    this.configuration = new TestMailSenderConfiguration(this.mail.getSmtp().getPort(), null, null, new Properties());
    this.componentManager.registerComponent(MailSenderConfiguration.class, this.configuration);
    // Set the current wiki in the Context
    ModelContext modelContext = this.componentManager.registerMockComponent(ModelContext.class);
    when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("wiki"));
    XWikiContext xcontext = mock(XWikiContext.class);
    when(xcontext.getWikiId()).thenReturn("wiki");
    Provider<XWikiContext> xwikiContextProvider = this.componentManager.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    when(xwikiContextProvider.get()).thenReturn(xcontext);
    this.componentManager.registerMockComponent(ExecutionContextManager.class);
    this.componentManager.registerMockComponent(Execution.class);
    this.componentManager.registerMockComponent(new DefaultParameterizedType(null, Copier.class, ExecutionContext.class));
    EnvironmentConfiguration environmentConfiguration = this.componentManager.registerMockComponent(EnvironmentConfiguration.class);
    when(environmentConfiguration.getPermanentDirectoryPath()).thenReturn(System.getProperty("java.io.tmpdir"));
}
Also used : ModelContext(org.xwiki.model.ModelContext) ExecutionContext(org.xwiki.context.ExecutionContext) EnvironmentConfiguration(org.xwiki.environment.internal.EnvironmentConfiguration) Copier(org.xwiki.mail.internal.thread.context.Copier) XWikiContext(com.xpn.xwiki.XWikiContext) Properties(java.util.Properties) WikiReference(org.xwiki.model.reference.WikiReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) BeforeComponent(org.xwiki.test.annotation.BeforeComponent)

Example 5 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class NotificationPreferenceScriptServiceTest method isEventTypeEnabledForWiki.

@Test
public void isEventTypeEnabledForWiki() throws Exception {
    WikiReference wiki = new WikiReference("whatever");
    when(notificationPreferenceManager.getAllPreferences(wiki)).thenReturn(Collections.emptyList());
    assertFalse(mocker.getComponentUnderTest().isEventTypeEnabled("update", NotificationFormat.ALERT, wiki.getName()));
    NotificationPreference pref1 = mock(NotificationPreference.class);
    NotificationPreference pref2 = mock(NotificationPreference.class);
    when(pref1.getFormat()).thenReturn(NotificationFormat.EMAIL);
    Map<NotificationPreferenceProperty, Object> properties1 = new HashMap<>();
    properties1.put(NotificationPreferenceProperty.EVENT_TYPE, "update");
    when(pref1.getProperties()).thenReturn(properties1);
    when(pref2.getFormat()).thenReturn(NotificationFormat.ALERT);
    Map<NotificationPreferenceProperty, Object> properties2 = new HashMap<>();
    properties2.put(NotificationPreferenceProperty.EVENT_TYPE, "update");
    when(pref2.getProperties()).thenReturn(properties2);
    when(pref2.isNotificationEnabled()).thenReturn(true);
    when(notificationPreferenceManager.getAllPreferences(wiki)).thenReturn(Arrays.asList(pref1, pref2));
    assertTrue(mocker.getComponentUnderTest().isEventTypeEnabled("update", NotificationFormat.ALERT, wiki.getName()));
    assertFalse(mocker.getComponentUnderTest().isEventTypeEnabled("update", NotificationFormat.EMAIL, wiki.getName()));
}
Also used : AbstractNotificationPreference(org.xwiki.notifications.preferences.internal.AbstractNotificationPreference) NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) HashMap(java.util.HashMap) NotificationPreferenceProperty(org.xwiki.notifications.preferences.NotificationPreferenceProperty) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Aggregations

WikiReference (org.xwiki.model.reference.WikiReference)220 DocumentReference (org.xwiki.model.reference.DocumentReference)127 Test (org.junit.Test)106 SpaceReference (org.xwiki.model.reference.SpaceReference)58 XWikiContext (com.xpn.xwiki.XWikiContext)33 XWikiException (com.xpn.xwiki.XWikiException)24 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 ArrayList (java.util.ArrayList)19 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)18 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)15 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)11 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)10 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)10 XWiki (com.xpn.xwiki.XWiki)9 BaseObject (com.xpn.xwiki.objects.BaseObject)9 ComponentManager (org.xwiki.component.manager.ComponentManager)9 Expectations (org.jmock.Expectations)8 Before (org.junit.Before)8 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)8