use of org.xwiki.notifications.filters.NotificationFilter in project xwiki-platform by xwiki.
the class DefaultNotificationFilterDisplayerTest method displayWithDefaultTemplate.
@Test
public void displayWithDefaultTemplate() throws Exception {
when(templateManager.getTemplate(any(String.class))).thenReturn(null);
NotificationFilter filter = mock(NotificationFilter.class);
when(filter.getName()).thenReturn("filterName");
mocker.getComponentUnderTest().display(filter, mock(NotificationFilterPreference.class));
verify(templateManager, times(1)).execute(eq("notification/filters/default.vm"));
}
use of org.xwiki.notifications.filters.NotificationFilter 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.NotificationFilter in project xwiki-platform by xwiki.
the class DefaultNotificationFilterManagerTest method getAllNotificationsFiltersWithSubWiki.
@Test
public void getAllNotificationsFiltersWithSubWiki() throws Exception {
NotificationFilter fakeFilter1 = mock(NotificationFilter.class);
NotificationFilter fakeFilter2 = mock(NotificationFilter.class);
when(wikiDescriptorManager.getMainWikiId()).thenReturn("somethingElseThanwiki");
when(componentManager.getInstanceList(NotificationFilter.class)).thenReturn(Arrays.asList(fakeFilter1, fakeFilter2));
Collection<NotificationFilter> filters = mocker.getComponentUnderTest().getAllFilters(testUser);
assertEquals(2, filters.size());
assertTrue(filters.contains(fakeFilter1));
assertTrue(filters.contains(fakeFilter2));
}
use of org.xwiki.notifications.filters.NotificationFilter in project xwiki-platform by xwiki.
the class DefaultNotificationFilterManagerTest method getAllFiltersWithMainWiki.
@Test
public void getAllFiltersWithMainWiki() throws Exception {
NotificationFilter fakeFilter1 = mock(NotificationFilter.class);
when(componentManager.getInstanceMap(NotificationFilter.class)).thenReturn(Collections.singletonMap("1", fakeFilter1));
Collection<NotificationFilter> filters = mocker.getComponentUnderTest().getAllFilters(testUser);
assertEquals(1, filters.size());
assertTrue(filters.contains(fakeFilter1));
}
use of org.xwiki.notifications.filters.NotificationFilter in project xwiki-platform by xwiki.
the class DefaultModelBridge method getToggeableFilterActivations.
@Override
public Map<String, Boolean> getToggeableFilterActivations(DocumentReference user) throws NotificationException {
XWikiContext context = contextProvider.get();
XWiki xwiki = context.getWiki();
final DocumentReference notificationPreferencesScopeClass = TOGGLEABLE_FILTER_PREFERENCE_CLASS.setWikiReference(user.getWikiReference());
Map<String, Boolean> filterStatus = new HashMap<>();
try {
XWikiDocument doc = xwiki.getDocument(user, context);
for (NotificationFilter filter : componentManager.<NotificationFilter>getInstanceList(NotificationFilter.class)) {
if (filter instanceof ToggleableNotificationFilter) {
ToggleableNotificationFilter toggleableFilter = (ToggleableNotificationFilter) filter;
boolean status = toggleableFilter.isEnabledByDefault();
BaseObject obj = doc.getXObject(notificationPreferencesScopeClass, FIELD_FILTER_NAME, filter.getName());
if (obj != null) {
status = obj.getIntValue(FIELD_IS_ENABLED, status ? 1 : 0) != 0;
}
filterStatus.put(filter.getName(), status);
}
}
} catch (Exception e) {
throw new NotificationException(String.format("Failed to get the toggleable filters preferences for the user [%s].", user), e);
}
return filterStatus;
}
Aggregations