Search in sources :

Example 71 with WikiReference

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

the class InstanceInputFilterStream method read.

@Override
protected void read(Object filter, InstanceFilter proxyFilter) throws FilterException {
    FilterEventParameters parameters = new FilterEventParameters();
    for (InstanceInputEventGenerator generator : this.eventGenerators) {
        generator.setWikiFarmParameters(parameters);
    }
    proxyFilter.beginWikiFarm(parameters);
    for (InstanceInputEventGenerator generator : this.eventGenerators) {
        generator.setFilter(filter);
        generator.beginWikiFarm(parameters);
    }
    for (WikiReference wikiReference : this.instanceModel.getWikiReferences()) {
        if (isWikiEnabled(wikiReference)) {
            writeWiki(wikiReference, filter, proxyFilter);
        }
    }
    for (InstanceInputEventGenerator generator : this.eventGenerators) {
        generator.endWikiFarm(parameters);
    }
    proxyFilter.endWikiFarm(parameters);
}
Also used : FilterEventParameters(org.xwiki.filter.FilterEventParameters) WikiReference(org.xwiki.model.reference.WikiReference) InstanceInputEventGenerator(org.xwiki.filter.instance.input.InstanceInputEventGenerator)

Example 72 with WikiReference

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

the class DefaultSkinReferenceFactoryTest method createReferenceWhenSkinOnFS.

@Test
public void createReferenceWhenSkinOnFS() throws Exception {
    // Mocks
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wikiId");
    DocumentReference skinDocRef = new DocumentReference("wikiId", "Main", "Flamingo");
    when(documentReferenceResolver.resolve(eq("flamingo"), eq(new WikiReference("wikiId")))).thenReturn(skinDocRef);
    when(xwiki.exists(skinDocRef, xcontext)).thenReturn(true);
    XWikiDocument skinDoc = mock(XWikiDocument.class);
    when(xwiki.getDocument(skinDocRef, xcontext)).thenReturn(skinDoc);
    when(skinDoc.getXObjectSize(eq(new DocumentReference("wikiId", "XWiki", "XWikiSkins")))).thenReturn(0);
    // Test
    SkinReference skinReference = mocker.getComponentUnderTest().createReference("flamingo");
    // Verify
    assertTrue(skinReference instanceof FSSkinReference);
    FSSkinReference fsSkinRef = (FSSkinReference) skinReference;
    assertEquals("flamingo", fsSkinRef.getSkinName());
    assertEquals("SkinFS[flamingo]", fsSkinRef.toString());
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 73 with WikiReference

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

the class DefaultSkinReferenceFactoryTest method createReferenceWhenSkinOnDB.

@Test
public void createReferenceWhenSkinOnDB() throws Exception {
    // Mocks
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wikiId");
    DocumentReference skinDocRef = new DocumentReference("wikiId", "XWiki", "MySkin");
    when(documentReferenceResolver.resolve(eq("XWiki.MySkin"), eq(new WikiReference("wikiId")))).thenReturn(skinDocRef);
    when(xwiki.exists(skinDocRef, xcontext)).thenReturn(true);
    XWikiDocument skinDoc = mock(XWikiDocument.class);
    when(xwiki.getDocument(skinDocRef, xcontext)).thenReturn(skinDoc);
    when(skinDoc.getXObjectSize(eq(new DocumentReference("wikiId", "XWiki", "XWikiSkins")))).thenReturn(1);
    // Test
    SkinReference skinReference = mocker.getComponentUnderTest().createReference("XWiki.MySkin");
    // Verify
    assertTrue(skinReference instanceof DocumentSkinReference);
    DocumentSkinReference docSkinRef = (DocumentSkinReference) skinReference;
    assertEquals(skinDocRef, docSkinRef.getSkinDocument());
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 74 with WikiReference

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

the class DefaultTranslationBundleContextTest method getBundlesSwitchContext.

@Test
public void getBundlesSwitchContext() throws Exception {
    // Mock the first wiki bundles.
    ComponentManager mockWiki1ComponentManager = mock(ComponentManager.class);
    when(this.mockContextComponentManagerProvider.get()).thenReturn(mockWiki1ComponentManager);
    TranslationBundle mockWiki1TranslationBundle = mock(TranslationBundle.class);
    List<TranslationBundle> wiki1Bundles = Arrays.asList(mockWiki1TranslationBundle);
    when(mockWiki1ComponentManager.<TranslationBundle>getInstanceList(TranslationBundle.class)).thenReturn(wiki1Bundles);
    Collection<TranslationBundle> firstBundles = this.mocker.getComponentUnderTest().getBundles();
    // Check the output
    assertEquals(1, firstBundles.size());
    assertEquals(mockWiki1TranslationBundle, firstBundles.iterator().next());
    // Switch context wiki to the second wiki.
    when(this.mockModelContext.getCurrentEntityReference()).thenReturn(new WikiReference("otherWiki"));
    // Mock the second wiki bundles.
    ComponentManager mockWiki2ComponentManager = mock(ComponentManager.class);
    when(this.mockContextComponentManagerProvider.get()).thenReturn(mockWiki2ComponentManager);
    TranslationBundle mockWiki2TranslationBundle = mock(TranslationBundle.class);
    List<TranslationBundle> wiki2Bundles = Arrays.asList(mockWiki2TranslationBundle);
    when(mockWiki2ComponentManager.<TranslationBundle>getInstanceList(TranslationBundle.class)).thenReturn(wiki2Bundles);
    Collection<TranslationBundle> secondBundles = this.mocker.getComponentUnderTest().getBundles();
    // Check the output.
    assertEquals(1, secondBundles.size());
    assertEquals(mockWiki2TranslationBundle, secondBundles.iterator().next());
    // Check that we get different results on different wikis.
    // Note: We are comparing values instead of the actual sets because we did not mock the compareTo method on the
    // bundles to simplify the test.
    assertNotEquals(firstBundles.iterator().next(), secondBundles.iterator().next());
    // Switch back to the first wiki and get the same (cached) first bundles.
    when(this.mockModelContext.getCurrentEntityReference()).thenReturn(new WikiReference("currentWiki"));
    Collection<TranslationBundle> thirdBundles = this.mocker.getComponentUnderTest().getBundles();
    assertEquals(firstBundles.iterator().next(), thirdBundles.iterator().next());
}
Also used : TranslationBundle(org.xwiki.localization.TranslationBundle) ComponentManager(org.xwiki.component.manager.ComponentManager) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 75 with WikiReference

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

the class ScopeNotificationFilterTest method complexCase1.

@Test
public void complexCase1() throws Exception {
    // Preferences:
    // 
    // α: "update" event type enabled for format ALERT
    // 
    // β: Exclusive filter on "wikiA".
    // γ: Inclusive filter on "wikiA:SpaceB"
    // δ: Exclusive filter on "wikiA:SpaceB.SpaceC"
    // ε: Exclusive filter on "wikiA:SpaceB.SpaceC.SpaceD"
    // Mock α
    NotificationPreference preference = mock(NotificationPreference.class);
    when(preference.getFormat()).thenReturn(NotificationFormat.ALERT);
    Map<NotificationPreferenceProperty, Object> properties = new HashMap<>();
    properties.put(NotificationPreferenceProperty.EVENT_TYPE, "update");
    when(preference.getProperties()).thenReturn(properties);
    // Mock β
    WikiReference wikiReference = new WikiReference("wikiA");
    NotificationFilterPreference prefβ = mockNotificationFilterPreference("wikiA", wikiReference, NotificationFilterType.EXCLUSIVE, null);
    // Mock γ
    SpaceReference spaceReferenceB = new SpaceReference("SpaceB", wikiReference);
    NotificationFilterPreference prefγ = mockNotificationFilterPreference("wikiA:SpaceB", spaceReferenceB, NotificationFilterType.INCLUSIVE, "update");
    // Mock δ
    SpaceReference spaceReferenceC = new SpaceReference("SpaceC", spaceReferenceB);
    NotificationFilterPreference prefδ = mockNotificationFilterPreference("wikiA:SpaceB.SpaceC", spaceReferenceC, NotificationFilterType.EXCLUSIVE, null);
    // Mock ε
    SpaceReference spaceReferenceD = new SpaceReference("SpaceD", spaceReferenceC);
    NotificationFilterPreference prefε = mockNotificationFilterPreference("wikiA:SpaceB.SpaceC.SpaceD", spaceReferenceD, NotificationFilterType.INCLUSIVE, null);
    when(notificationFilterManager.getFilterPreferences(any(DocumentReference.class))).thenReturn(Sets.newSet(prefβ, prefγ, prefδ, prefε));
    DocumentReference user = new DocumentReference("xwiki", "XWiki", "User");
    // Test 1
    String result = mocker.getComponentUnderTest().filterExpression(user, preference).toString();
    assertEquals("(((NOT (WIKI = \"wikiA\") OR (WIKI = \"wikiA\" AND SPACE STARTS WITH \"wikiA:SpaceB\"))" + " OR (WIKI = \"wikiA\" AND SPACE STARTS WITH \"wikiA:SpaceB.SpaceC.SpaceD\")) AND (NOT ((WIKI = \"wikiA\" " + "AND SPACE STARTS WITH \"wikiA:SpaceB.SpaceC\")) OR (WIKI = \"wikiA\" " + "AND SPACE STARTS WITH \"wikiA:SpaceB.SpaceC.SpaceD\")))", result);
    // Test with wikiA:SpaceE (filtered by β)
    Event event1 = mock(Event.class);
    when(event1.getSpace()).thenReturn(new SpaceReference("SpaceE", wikiReference));
    assertEquals(NotificationFilter.FilterPolicy.FILTER, mocker.getComponentUnderTest().filterEvent(event1, user, NotificationFormat.ALERT));
    // Test with wikiA:SpaceB.DocumentE (kept by γ)
    Event event2 = mock(Event.class);
    when(event2.getDocument()).thenReturn(new DocumentReference("DocumentE", spaceReferenceB));
    assertEquals(NotificationFilter.FilterPolicy.NO_EFFECT, mocker.getComponentUnderTest().filterEvent(event2, user, NotificationFormat.ALERT));
    // Test with wikiA:SpaceB.SpaceC.DocumentF (filtered by δ)
    Event event3 = mock(Event.class);
    when(event3.getDocument()).thenReturn(new DocumentReference("DocumentF", spaceReferenceC));
    assertEquals(NotificationFilter.FilterPolicy.FILTER, mocker.getComponentUnderTest().filterEvent(event3, user, NotificationFormat.ALERT));
    // Test with wikiA:SpaceB.SpaceC.SpaceD.DocumentG (kept by ε)
    Event event4 = mock(Event.class);
    when(event4.getDocument()).thenReturn(new DocumentReference("DocumentG", spaceReferenceD));
    assertEquals(NotificationFilter.FilterPolicy.NO_EFFECT, mocker.getComponentUnderTest().filterEvent(event4, user, NotificationFormat.ALERT));
    // Test with wikiB:SpaceH.DocumentI - kept because nothing match and there is no top level inclusive filter
    Event event5 = mock(Event.class);
    when(event5.getDocument()).thenReturn(new DocumentReference("wikiB", "SpaceH", "DocumentI"));
    assertEquals(NotificationFilter.FilterPolicy.NO_EFFECT, mocker.getComponentUnderTest().filterEvent(event5, user, NotificationFormat.ALERT));
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) HashMap(java.util.HashMap) SpaceReference(org.xwiki.model.reference.SpaceReference) NotificationFilterPreference(org.xwiki.notifications.filters.NotificationFilterPreference) NotificationPreferenceProperty(org.xwiki.notifications.preferences.NotificationPreferenceProperty) Event(org.xwiki.eventstream.Event) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) 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