use of org.xwiki.notifications.filters.watch.WatchedEntityReference in project xwiki-platform by xwiki.
the class DefaultWatchedEntitiesManagerTest method unwatchWhen2OppositeFilters.
@Test
public void unwatchWhen2OppositeFilters() 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");
NotificationFilterPreference pref2 = mock(NotificationFilterPreference.class);
when(pref2.getProperties(NotificationFilterProperty.EVENT_TYPE)).thenReturn(Collections.emptyList());
when(pref2.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.ALERT, NotificationFormat.EMAIL));
when(watchedEntityReference.matchExactly(pref2)).thenReturn(true);
when(pref2.getFilterType()).thenReturn(NotificationFilterType.EXCLUSIVE);
when(pref2.isEnabled()).thenReturn(true);
when(pref2.getFilterPreferenceName()).thenReturn("pref2");
when(notificationFilterManager.getFilterPreferences(user)).thenReturn(Sets.newSet(pref1, pref2));
when(watchedEntityReference.isWatched(user)).thenReturn(true, false);
// Test
mocker.getComponentUnderTest().unwatchEntity(watchedEntityReference, user);
// Checks
verify(notificationFilterManager).deleteFilterPreference("pref1");
verify(watchedEntityReference, never()).createExclusiveFilterPreference();
}
use of org.xwiki.notifications.filters.watch.WatchedEntityReference in project xwiki-platform by xwiki.
the class DefaultWatchedEntitiesManagerTest method unwatchWhenExclusiveFilter.
@Test
public void unwatchWhenExclusiveFilter() 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.EXCLUSIVE);
when(pref1.isEnabled()).thenReturn(false);
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).setFilterPreferenceEnabled("pref1", true);
verify(watchedEntityReference, never()).createExclusiveFilterPreference();
}
use of org.xwiki.notifications.filters.watch.WatchedEntityReference in project xwiki-platform by xwiki.
the class DefaultWatchedEntitiesManagerTest method watchWhenExclusiveFilter.
@Test
public void watchWhenExclusiveFilter() 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.EXCLUSIVE);
when(pref1.isEnabled()).thenReturn(true);
when(pref1.getFilterPreferenceName()).thenReturn("pref1");
when(notificationFilterManager.getFilterPreferences(user)).thenReturn(Sets.newSet(pref1));
when(watchedEntityReference.isWatched(user)).thenReturn(false, true);
// Test
mocker.getComponentUnderTest().watchEntity(watchedEntityReference, user);
// Checks
verify(notificationFilterManager).deleteFilterPreference("pref1");
verify(watchedEntityReference, never()).createInclusiveFilterPreference();
}
use of org.xwiki.notifications.filters.watch.WatchedEntityReference in project xwiki-platform by xwiki.
the class DefaultWatchedEntitiesManagerTest method watchWhenNoFilterMatch.
@Test
public void watchWhenNoFilterMatch() 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(false);
NotificationFilterPreference createdPref = mock(NotificationFilterPreference.class);
when(watchedEntityReference.createInclusiveFilterPreference()).thenReturn(createdPref);
// Test
mocker.getComponentUnderTest().watchEntity(watchedEntityReference, user);
// Checks
verify(notificationFilterManager).saveFilterPreferences(eq(Sets.newSet(createdPref)));
}
use of org.xwiki.notifications.filters.watch.WatchedEntityReference in project xwiki-platform by xwiki.
the class DefaultWatchedEntitiesManagerTest method watchWhen2OppositeFilters.
@Test
public void watchWhen2OppositeFilters() 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");
NotificationFilterPreference pref2 = mock(NotificationFilterPreference.class);
when(pref2.getProperties(NotificationFilterProperty.EVENT_TYPE)).thenReturn(Collections.emptyList());
when(pref2.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.ALERT, NotificationFormat.EMAIL));
when(watchedEntityReference.matchExactly(pref2)).thenReturn(true);
when(pref2.getFilterType()).thenReturn(NotificationFilterType.EXCLUSIVE);
when(pref2.isEnabled()).thenReturn(true);
when(pref2.getFilterPreferenceName()).thenReturn("pref2");
when(notificationFilterManager.getFilterPreferences(user)).thenReturn(Sets.newSet(pref1, pref2));
when(watchedEntityReference.isWatched(user)).thenReturn(false, true);
// Test
mocker.getComponentUnderTest().watchEntity(watchedEntityReference, user);
// Checks
verify(notificationFilterManager).deleteFilterPreference("pref2");
verify(watchedEntityReference, never()).createInclusiveFilterPreference();
}
Aggregations