use of org.xwiki.notifications.filters.NotificationFilterPreference 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.NotificationFilterPreference in project xwiki-platform by xwiki.
the class DefaultNotificationFilterManagerTest method testFilterPreferences.
@Test
public void testFilterPreferences() throws Exception {
NotificationFilterPreference filterPreference1 = mock(NotificationFilterPreference.class);
NotificationFilterPreference filterPreference2 = mock(NotificationFilterPreference.class);
when(testProvider.getFilterPreferences(testUser)).thenReturn(Sets.newSet(filterPreference1, filterPreference2));
Set<NotificationFilterPreference> resultSet = mocker.getComponentUnderTest().getFilterPreferences(testUser);
assertTrue(resultSet.contains(filterPreference1));
assertTrue(resultSet.contains(filterPreference2));
assertEquals(2, resultSet.size());
}
use of org.xwiki.notifications.filters.NotificationFilterPreference in project xwiki-platform by xwiki.
the class DefaultNotificationFilterManagerTest method testFilterPreferencesWithFilterAndFilterType.
@Test
public void testFilterPreferencesWithFilterAndFilterType() throws Exception {
NotificationFilterPreference filterPreference1 = mock(NotificationFilterPreference.class);
when(filterPreference1.getFilterName()).thenReturn("someFilter");
when(filterPreference1.getFilterType()).thenReturn(NotificationFilterType.EXCLUSIVE);
NotificationFilterPreference filterPreference2 = mock(NotificationFilterPreference.class);
when(filterPreference2.getFilterName()).thenReturn("fakeFilter");
when(filterPreference2.getFilterType()).thenReturn(NotificationFilterType.EXCLUSIVE);
NotificationFilterPreference filterPreference3 = mock(NotificationFilterPreference.class);
when(filterPreference3.getFilterName()).thenReturn("someFilter");
when(filterPreference3.getFilterType()).thenReturn(NotificationFilterType.INCLUSIVE);
NotificationFilterPreference filterPreference4 = mock(NotificationFilterPreference.class);
when(filterPreference4.getFilterName()).thenReturn("fakeFilter");
when(filterPreference4.getFilterType()).thenReturn(NotificationFilterType.INCLUSIVE);
when(testProvider.getFilterPreferences(testUser)).thenReturn(Sets.newSet(filterPreference1, filterPreference2, filterPreference3, filterPreference4));
NotificationFilter fakeFilter = mock(NotificationFilter.class);
when(fakeFilter.getName()).thenReturn("fakeFilter");
Set<NotificationFilterPreference> resultSet = mocker.getComponentUnderTest().getFilterPreferences(testUser, fakeFilter, NotificationFilterType.INCLUSIVE);
assertTrue(resultSet.contains(filterPreference4));
assertEquals(1, resultSet.size());
}
use of org.xwiki.notifications.filters.NotificationFilterPreference in project xwiki-platform by xwiki.
the class ScopeNotificationFilterTest method mockNotificationFilterPreference.
private NotificationFilterPreference mockNotificationFilterPreference(String entityStringValue, EntityReference resultReference, NotificationFilterType filterType, String eventName) {
NotificationFilterProperty property;
if (resultReference.getType().equals(EntityType.DOCUMENT)) {
property = NotificationFilterProperty.PAGE;
} else if (resultReference.getType().equals(EntityType.SPACE)) {
property = NotificationFilterProperty.SPACE;
} else {
property = NotificationFilterProperty.WIKI;
}
NotificationFilterPreference preference = mock(NotificationFilterPreference.class);
when(preference.getProperties(property)).thenReturn(Collections.singletonList(entityStringValue));
when(preference.getFilterName()).thenReturn(ScopeNotificationFilter.FILTER_NAME);
when(preference.getProperties(eq(NotificationFilterProperty.EVENT_TYPE))).thenReturn(eventName != null ? Arrays.asList(eventName) : Collections.emptyList());
when(preference.getFilterType()).thenReturn(filterType);
when(preference.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.ALERT, NotificationFormat.EMAIL));
when(preference.isEnabled()).thenReturn(true);
when(resolver.resolve(entityStringValue, resultReference.getType())).thenReturn(resultReference);
when(serializer.serialize(eq(resultReference))).thenReturn(entityStringValue);
return preference;
}
use of org.xwiki.notifications.filters.NotificationFilterPreference in project xwiki-platform by xwiki.
the class EventUserFilterTest method mockPreferences.
private void mockPreferences() throws NotificationException {
NotificationFilterPreference p1 = mock(NotificationFilterPreference.class);
when(p1.isEnabled()).thenReturn(true);
when(p1.getFilterName()).thenReturn(EventUserFilter.FILTER_NAME);
when(p1.getProperties(NotificationFilterProperty.USER)).thenReturn(Arrays.asList(SERIALIZED_USER_A, SERIALIZED_USER_B));
when(p1.getFilterType()).thenReturn(NotificationFilterType.EXCLUSIVE);
when(p1.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.ALERT, NotificationFormat.EMAIL));
NotificationFilterPreference p2 = mock(NotificationFilterPreference.class);
when(p2.isEnabled()).thenReturn(true);
when(p2.getFilterName()).thenReturn(EventUserFilter.FILTER_NAME);
when(p2.getProperties(NotificationFilterProperty.USER)).thenReturn(Arrays.asList(SERIALIZED_USER_C));
when(p2.getFilterType()).thenReturn(NotificationFilterType.EXCLUSIVE);
when(p2.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.ALERT, NotificationFormat.EMAIL));
NotificationFilterPreference p3 = mock(NotificationFilterPreference.class);
when(p3.isEnabled()).thenReturn(false);
when(p3.getFilterName()).thenReturn(EventUserFilter.FILTER_NAME);
when(p3.getProperties(NotificationFilterProperty.USER)).thenReturn(Arrays.asList(SERIALIZED_USER_D));
when(p3.getFilterType()).thenReturn(NotificationFilterType.EXCLUSIVE);
when(p3.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.ALERT, NotificationFormat.EMAIL));
NotificationFilterPreference p4 = mock(NotificationFilterPreference.class);
when(p4.isEnabled()).thenReturn(true);
when(p4.getFilterName()).thenReturn(EventUserFilter.FILTER_NAME);
when(p4.getProperties(NotificationFilterProperty.USER)).thenReturn(Arrays.asList(SERIALIZED_USER_E));
when(p4.getFilterType()).thenReturn(NotificationFilterType.EXCLUSIVE);
when(p4.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.EMAIL));
when(notificationFilterManager.getFilterPreferences(eq(CURRENT_USER))).thenReturn(Sets.newSet(p1, p2, p3, p4));
}
Aggregations