Search in sources :

Example 6 with NotificationPreference

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());
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) HashMap(java.util.HashMap) NotificationPreferenceProperty(org.xwiki.notifications.preferences.NotificationPreferenceProperty) Test(org.junit.Test)

Example 7 with NotificationPreference

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());
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) HashMap(java.util.HashMap) NotificationPreferenceProperty(org.xwiki.notifications.preferences.NotificationPreferenceProperty) Test(org.junit.Test)

Example 8 with NotificationPreference

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));
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) NotificationFilter(org.xwiki.notifications.filters.NotificationFilter) Test(org.junit.Test)

Example 9 with NotificationPreference

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());
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) NotificationFilter(org.xwiki.notifications.filters.NotificationFilter) Test(org.junit.Test)

Example 10 with NotificationPreference

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());
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) Test(org.junit.Test)

Aggregations

NotificationPreference (org.xwiki.notifications.preferences.NotificationPreference)32 Test (org.junit.Test)18 DocumentReference (org.xwiki.model.reference.DocumentReference)12 HashMap (java.util.HashMap)8 List (java.util.List)8 NotificationPreferenceProperty (org.xwiki.notifications.preferences.NotificationPreferenceProperty)8 Date (java.util.Date)7 ArrayList (java.util.ArrayList)6 WikiReference (org.xwiki.model.reference.WikiReference)5 NotificationException (org.xwiki.notifications.NotificationException)4 NotificationFormat (org.xwiki.notifications.NotificationFormat)4 NotificationFilterPreference (org.xwiki.notifications.filters.NotificationFilterPreference)4 TargetableNotificationPreference (org.xwiki.notifications.preferences.TargetableNotificationPreference)4 Map (java.util.Map)3 NotificationFilter (org.xwiki.notifications.filters.NotificationFilter)3 NotificationPreferenceManager (org.xwiki.notifications.preferences.NotificationPreferenceManager)3 Query (org.xwiki.query.Query)3 XWiki (com.xpn.xwiki.XWiki)2 XWikiContext (com.xpn.xwiki.XWikiContext)2 XWikiException (com.xpn.xwiki.XWikiException)2