Search in sources :

Example 6 with WatchedEntityReference

use of org.xwiki.notifications.filters.watch.WatchedEntityReference in project xwiki-platform by xwiki.

the class DefaultWatchedEntitiesManagerTest method testWithSeveralFilterPreferences.

@Test
public void testWithSeveralFilterPreferences() throws Exception {
    // Mocks
    WatchedEntityReference watchedEntityReference = mock(WatchedEntityReference.class);
    DocumentReference user = new DocumentReference("xwiki", "XWiki", "User");
    // Filters
    NotificationFilterPreference pref1 = mock(NotificationFilterPreference.class);
    when(pref1.getProperties(NotificationFilterProperty.EVENT_TYPE)).thenReturn(Collections.emptyList());
    when(pref1.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.ALERT, NotificationFormat.EMAIL));
    NotificationFilterPreference pref2 = mock(NotificationFilterPreference.class);
    when(pref2.getProperties(NotificationFilterProperty.EVENT_TYPE)).thenReturn(Arrays.asList("update"));
    when(pref2.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.ALERT, NotificationFormat.EMAIL));
    when(watchedEntityReference.matchExactly(pref2)).thenReturn(true);
    NotificationFilterPreference pref3 = mock(NotificationFilterPreference.class);
    when(pref3.getProperties(NotificationFilterProperty.EVENT_TYPE)).thenReturn(Collections.emptyList());
    when(pref3.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.ALERT));
    when(watchedEntityReference.matchExactly(pref3)).thenReturn(true);
    NotificationFilterPreference pref4 = mock(NotificationFilterPreference.class);
    when(pref4.getProperties(NotificationFilterProperty.EVENT_TYPE)).thenReturn(Collections.emptyList());
    when(pref4.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.ALERT, NotificationFormat.EMAIL));
    when(watchedEntityReference.matchExactly(pref4)).thenReturn(true);
    when(pref4.getFilterType()).thenReturn(NotificationFilterType.INCLUSIVE);
    when(pref4.isEnabled()).thenReturn(false);
    when(pref4.getFilterPreferenceName()).thenReturn("pref4");
    when(notificationFilterManager.getFilterPreferences(user)).thenReturn(Sets.newSet(pref1, pref2, pref3, pref4));
    when(watchedEntityReference.isWatched(user)).thenReturn(false, true);
    // Test
    mocker.getComponentUnderTest().watchEntity(watchedEntityReference, user);
    // Checks
    verify(watchedEntityReference, never()).matchExactly(pref2);
    verify(watchedEntityReference, never()).matchExactly(pref3);
    verify(notificationFilterManager).setFilterPreferenceEnabled("pref4", true);
    verify(watchedEntityReference, never()).createInclusiveFilterPreference();
}
Also used : NotificationFilterPreference(org.xwiki.notifications.filters.NotificationFilterPreference) WatchedEntityReference(org.xwiki.notifications.filters.watch.WatchedEntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 7 with WatchedEntityReference

use of org.xwiki.notifications.filters.watch.WatchedEntityReference in project xwiki-platform by xwiki.

the class DefaultWatchedEntitiesManagerTest method unwatchWhenNoFilterMatch.

@Test
public void unwatchWhenNoFilterMatch() throws Exception {
    // Mocks
    WatchedEntityReference watchedEntityReference = mock(WatchedEntityReference.class);
    DocumentReference user = new DocumentReference("xwiki", "XWiki", "User");
    // Filters
    NotificationFilterPreference pref1 = mock(NotificationFilterPreference.class);
    when(pref1.getProperties(NotificationFilterProperty.EVENT_TYPE)).thenReturn(Collections.emptyList());
    when(pref1.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.ALERT, NotificationFormat.EMAIL));
    when(notificationFilterManager.getFilterPreferences(user)).thenReturn(Sets.newSet(pref1));
    when(watchedEntityReference.isWatched(user)).thenReturn(true);
    NotificationFilterPreference createdPref = mock(NotificationFilterPreference.class);
    when(watchedEntityReference.createExclusiveFilterPreference()).thenReturn(createdPref);
    // Test
    mocker.getComponentUnderTest().unwatchEntity(watchedEntityReference, user);
    // Checks
    verify(notificationFilterManager).saveFilterPreferences(eq(Sets.newSet(createdPref)));
}
Also used : NotificationFilterPreference(org.xwiki.notifications.filters.NotificationFilterPreference) WatchedEntityReference(org.xwiki.notifications.filters.watch.WatchedEntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 8 with WatchedEntityReference

use of org.xwiki.notifications.filters.watch.WatchedEntityReference in project xwiki-platform by xwiki.

the class DefaultWatchedEntitiesManagerTest method unwatchWhenInclusiveFilter.

@Test
public void unwatchWhenInclusiveFilter() throws Exception {
    // Mocks
    WatchedEntityReference watchedEntityReference = mock(WatchedEntityReference.class);
    DocumentReference user = new DocumentReference("xwiki", "XWiki", "User");
    // Filters
    NotificationFilterPreference pref1 = mock(NotificationFilterPreference.class);
    when(pref1.getProperties(NotificationFilterProperty.EVENT_TYPE)).thenReturn(Collections.emptyList());
    when(pref1.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.ALERT, NotificationFormat.EMAIL));
    when(watchedEntityReference.matchExactly(pref1)).thenReturn(true);
    when(pref1.getFilterType()).thenReturn(NotificationFilterType.INCLUSIVE);
    when(pref1.isEnabled()).thenReturn(true);
    when(pref1.getFilterPreferenceName()).thenReturn("pref1");
    when(notificationFilterManager.getFilterPreferences(user)).thenReturn(Sets.newSet(pref1));
    when(watchedEntityReference.isWatched(user)).thenReturn(true, false);
    // Test
    mocker.getComponentUnderTest().unwatchEntity(watchedEntityReference, user);
    // Checks
    verify(notificationFilterManager).deleteFilterPreference("pref1");
    verify(watchedEntityReference, never()).createExclusiveFilterPreference();
}
Also used : NotificationFilterPreference(org.xwiki.notifications.filters.NotificationFilterPreference) WatchedEntityReference(org.xwiki.notifications.filters.watch.WatchedEntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 DocumentReference (org.xwiki.model.reference.DocumentReference)8 NotificationFilterPreference (org.xwiki.notifications.filters.NotificationFilterPreference)8 WatchedEntityReference (org.xwiki.notifications.filters.watch.WatchedEntityReference)8