use of org.xwiki.notifications.filters.NotificationFilter in project xwiki-platform by xwiki.
the class DefaultNotificationFilterDisplayerTest method displayWithCustomTemplate.
@Test
public void displayWithCustomTemplate() throws Exception {
Template fakeTemplate = mock(Template.class);
when(templateManager.getTemplate(any(String.class))).thenReturn(fakeTemplate);
NotificationFilter filter = mock(NotificationFilter.class);
when(filter.getName()).thenReturn("filterName");
mocker.getComponentUnderTest().display(filter, mock(NotificationFilterPreference.class));
verify(templateManager, times(1)).execute(eq(fakeTemplate));
}
use of org.xwiki.notifications.filters.NotificationFilter in project xwiki-platform by xwiki.
the class DefaultNotificationFilterManagerTest method getFiltersWithMatchingFilters.
@Test
public void getFiltersWithMatchingFilters() throws Exception {
NotificationFilter fakeFilter1 = mock(NotificationFilter.class);
NotificationPreference preference = mock(NotificationPreference.class);
when(componentManager.getInstanceMap(NotificationFilter.class)).thenReturn(Collections.singletonMap("1", fakeFilter1));
when(fakeFilter1.matchesPreference(preference)).thenReturn(true);
Collection<NotificationFilter> filters = mocker.getComponentUnderTest().getFilters(testUser, preference);
assertEquals(1, filters.size());
assertTrue(filters.contains(fakeFilter1));
}
use of org.xwiki.notifications.filters.NotificationFilter in project xwiki-platform by xwiki.
the class DefaultNotificationFilterManagerTest method getFiltersWithOneBadFilter.
@Test
public void getFiltersWithOneBadFilter() throws Exception {
NotificationFilter fakeFilter1 = mock(NotificationFilter.class);
NotificationPreference preference = mock(NotificationPreference.class);
when(componentManager.getInstanceMap(NotificationFilter.class)).thenReturn(Collections.singletonMap("1", fakeFilter1));
when(fakeFilter1.matchesPreference(preference)).thenReturn(false);
Collection<NotificationFilter> filters = mocker.getComponentUnderTest().getFilters(testUser, preference);
assertEquals(0, filters.size());
}
use of org.xwiki.notifications.filters.NotificationFilter in project xwiki-platform by xwiki.
the class DefaultNotificationFilterManagerTest method testFilterPreferencesWithFilter.
@Test
public void testFilterPreferencesWithFilter() throws Exception {
NotificationFilterPreference filterPreference1 = mock(NotificationFilterPreference.class);
when(filterPreference1.getFilterName()).thenReturn("someFilter");
NotificationFilterPreference filterPreference2 = mock(NotificationFilterPreference.class);
when(filterPreference2.getFilterName()).thenReturn("fakeFilter");
when(testProvider.getFilterPreferences(testUser)).thenReturn(Sets.newSet(filterPreference1, filterPreference2));
NotificationFilter fakeFilter = mock(NotificationFilter.class);
when(fakeFilter.getName()).thenReturn("fakeFilter");
Set<NotificationFilterPreference> resultSet = mocker.getComponentUnderTest().getFilterPreferences(testUser, fakeFilter);
assertTrue(resultSet.contains(filterPreference2));
assertEquals(1, resultSet.size());
}
use of org.xwiki.notifications.filters.NotificationFilter in project xwiki-platform by xwiki.
the class DefaultLiveMimeMessageIterator method retrieveCompositeEventList.
/**
* For the given user, we will have to check that the composite event that we have to send matches the user
* preferences.
*
* If, for any reason, one of the events of the original composite event is not meant for the user, we clone
* the original composite event and remove the incriminated event.
*/
@Override
protected List<CompositeEvent> retrieveCompositeEventList(DocumentReference user) throws NotificationException {
CompositeEvent resultCompositeEvent = new CompositeEvent(this.compositeEvent);
if (this.hasCorrespondingNotificationPreference(user, resultCompositeEvent)) {
// Apply the filters that the user has defined in its notification preferences
// If one of the events present in the composite event does not match a user filter, remove the event
List<NotificationFilter> filters = new ArrayList<>(notificationFilterManager.getAllFilters(user));
Collections.sort(filters);
Iterator<Event> it = resultCompositeEvent.getEvents().iterator();
while (it.hasNext()) {
Event event = it.next();
if (isEventFiltered(filters, event, user)) {
it.remove();
}
}
if (resultCompositeEvent.getEvents().size() == 0) {
return Collections.emptyList();
}
return Collections.singletonList(resultCompositeEvent);
}
return Collections.emptyList();
}
Aggregations