Search in sources :

Example 11 with NotificationFilter

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

Example 12 with NotificationFilter

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

Example 13 with NotificationFilter

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

Example 14 with NotificationFilter

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

Example 15 with NotificationFilter

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;
}
Also used : HashMap(java.util.HashMap) NotificationException(org.xwiki.notifications.NotificationException) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) XWikiException(com.xpn.xwiki.XWikiException) NotificationException(org.xwiki.notifications.NotificationException) BaseObject(com.xpn.xwiki.objects.BaseObject) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) NotificationFilter(org.xwiki.notifications.filters.NotificationFilter) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

NotificationFilter (org.xwiki.notifications.filters.NotificationFilter)18 Test (org.junit.Test)10 NotificationFilterPreference (org.xwiki.notifications.filters.NotificationFilterPreference)5 NotificationPreference (org.xwiki.notifications.preferences.NotificationPreference)5 DocumentReference (org.xwiki.model.reference.DocumentReference)4 ArrayList (java.util.ArrayList)3 NotificationException (org.xwiki.notifications.NotificationException)3 ExpressionNode (org.xwiki.notifications.filters.expression.ExpressionNode)3 HashMap (java.util.HashMap)2 AndNode (org.xwiki.notifications.filters.expression.AndNode)2 EqualsNode (org.xwiki.notifications.filters.expression.EqualsNode)2 PropertyValueNode (org.xwiki.notifications.filters.expression.PropertyValueNode)2 StringValueNode (org.xwiki.notifications.filters.expression.StringValueNode)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 Collection (java.util.Collection)1 Date (java.util.Date)1