use of org.xwiki.notifications.preferences.NotificationPreference in project xwiki-platform by xwiki.
the class XWikiEventTypesEnablerTest method whenOneXWikiEventTypesIsEnabled.
@Test
public void whenOneXWikiEventTypesIsEnabled() throws Exception {
NotificationPreference pref = mock(NotificationPreference.class);
when(pref.isNotificationEnabled()).thenReturn(true);
Map<NotificationPreferenceProperty, Object> properties = new HashMap<>();
properties.put(NotificationPreferenceProperty.EVENT_TYPE, "update");
when(pref.getProperties()).thenReturn(properties);
when(notificationPreferenceManager.getAllPreferences(eq(currentUser))).thenReturn(Arrays.asList(pref));
mocker.getComponentUnderTest().ensureXWikiNotificationsAreEnabled();
verify(notificationPreferenceManager, never()).savePreferences(anyList());
}
use of org.xwiki.notifications.preferences.NotificationPreference in project xwiki-platform by xwiki.
the class XWikiEventTypesEnablerTest method whenOtherEventTypesIsEnabled.
@Test
public void whenOtherEventTypesIsEnabled() throws Exception {
NotificationPreference pref = mock(NotificationPreference.class);
when(pref.isNotificationEnabled()).thenReturn(true);
Map<NotificationPreferenceProperty, Object> properties = new HashMap<>();
properties.put(NotificationPreferenceProperty.EVENT_TYPE, "blog");
when(pref.getProperties()).thenReturn(properties);
when(notificationPreferenceManager.getAllPreferences(eq(currentUser))).thenReturn(Arrays.asList(pref));
doAnswer(invocationOnMock -> {
List<NotificationPreference> preferencesToSave = invocationOnMock.getArgument(0);
// Ensure there is a preference to save for each event type and each format = 8 items
assertEquals(8, preferencesToSave.size());
return null;
}).when(notificationPreferenceManager).savePreferences(anyList());
mocker.getComponentUnderTest().ensureXWikiNotificationsAreEnabled();
verify(notificationPreferenceManager).savePreferences(anyList());
}
use of org.xwiki.notifications.preferences.NotificationPreference 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.preferences.NotificationPreference 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.preferences.NotificationPreference in project xwiki-platform by xwiki.
the class SystemUserNotificationFilterTest method filterExpression.
@Test
public void filterExpression() throws Exception {
NotificationPreference fakePreference = mock(NotificationPreference.class);
assertNull(mocker.getComponentUnderTest().filterExpression(randomUser, fakePreference));
assertEquals("USER <> \"serializedSystemUser\"", mocker.getComponentUnderTest().filterExpression(randomUser, NotificationFilterType.EXCLUSIVE, null).toString());
}
Aggregations