Search in sources :

Example 16 with NotificationFilterPreference

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();
}
Also used : NotificationFilterPreference(org.xwiki.notifications.filters.NotificationFilterPreference) WatchedEntityReference(org.xwiki.notifications.filters.watch.WatchedEntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 17 with NotificationFilterPreference

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

Example 18 with NotificationFilterPreference

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

Example 19 with NotificationFilterPreference

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;
}
Also used : NotificationFilterProperty(org.xwiki.notifications.filters.NotificationFilterProperty) NotificationFilterPreference(org.xwiki.notifications.filters.NotificationFilterPreference)

Example 20 with NotificationFilterPreference

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));
}
Also used : NotificationFilterPreference(org.xwiki.notifications.filters.NotificationFilterPreference)

Aggregations

NotificationFilterPreference (org.xwiki.notifications.filters.NotificationFilterPreference)29 Test (org.junit.Test)14 DocumentReference (org.xwiki.model.reference.DocumentReference)13 WatchedEntityReference (org.xwiki.notifications.filters.watch.WatchedEntityReference)8 BaseObject (com.xpn.xwiki.objects.BaseObject)4 HashSet (java.util.HashSet)4 XWiki (com.xpn.xwiki.XWiki)3 XWikiContext (com.xpn.xwiki.XWikiContext)3 XWikiException (com.xpn.xwiki.XWikiException)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)3 HashMap (java.util.HashMap)3 NotificationException (org.xwiki.notifications.NotificationException)3 NotificationPreference (org.xwiki.notifications.preferences.NotificationPreference)3 Set (java.util.Set)2 Event (org.xwiki.eventstream.Event)2 SpaceReference (org.xwiki.model.reference.SpaceReference)2 WikiReference (org.xwiki.model.reference.WikiReference)2 NotificationFilter (org.xwiki.notifications.filters.NotificationFilter)2 NotificationFilterProperty (org.xwiki.notifications.filters.NotificationFilterProperty)2 NotificationPreferenceProperty (org.xwiki.notifications.preferences.NotificationPreferenceProperty)2