Search in sources :

Example 1 with WatchedEntityReference

use of org.xwiki.notifications.filters.watch.WatchedEntityReference in project xwiki-platform by xwiki.

the class DefaultWatchedEntitiesManagerTest method unwatchWhen2OppositeFilters.

@Test
public void unwatchWhen2OppositeFilters() 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.INCLUSIVE);
    when(pref1.isEnabled()).thenReturn(true);
    when(pref1.getFilterPreferenceName()).thenReturn("pref1");
    NotificationFilterPreference pref2 = mock(NotificationFilterPreference.class);
    when(pref2.getProperties(NotificationFilterProperty.EVENT_TYPE)).thenReturn(Collections.emptyList());
    when(pref2.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.ALERT, NotificationFormat.EMAIL));
    when(watchedEntityReference.matchExactly(pref2)).thenReturn(true);
    when(pref2.getFilterType()).thenReturn(NotificationFilterType.EXCLUSIVE);
    when(pref2.isEnabled()).thenReturn(true);
    when(pref2.getFilterPreferenceName()).thenReturn("pref2");
    when(notificationFilterManager.getFilterPreferences(user)).thenReturn(Sets.newSet(pref1, pref2));
    when(watchedEntityReference.isWatched(user)).thenReturn(true, false);
    // Test
    mocker.getComponentUnderTest().unwatchEntity(watchedEntityReference, user);
    // Checks
    verify(notificationFilterManager).deleteFilterPreference("pref1");
    verify(watchedEntityReference, never()).createExclusiveFilterPreference();
}
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 2 with WatchedEntityReference

use of org.xwiki.notifications.filters.watch.WatchedEntityReference in project xwiki-platform by xwiki.

the class DefaultWatchedEntitiesManagerTest method unwatchWhenExclusiveFilter.

@Test
public void unwatchWhenExclusiveFilter() 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(false);
    when(pref1.getFilterPreferenceName()).thenReturn("pref1");
    when(notificationFilterManager.getFilterPreferences(user)).thenReturn(Sets.newSet(pref1));
    when(watchedEntityReference.isWatched(user)).thenReturn(true, false);
    // Test
    mocker.getComponentUnderTest().unwatchEntity(watchedEntityReference, user);
    // Checks
    verify(notificationFilterManager).setFilterPreferenceEnabled("pref1", true);
    verify(watchedEntityReference, never()).createExclusiveFilterPreference();
}
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 3 with WatchedEntityReference

use of org.xwiki.notifications.filters.watch.WatchedEntityReference 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 4 with WatchedEntityReference

use of org.xwiki.notifications.filters.watch.WatchedEntityReference in project xwiki-platform by xwiki.

the class DefaultWatchedEntitiesManagerTest method watchWhenNoFilterMatch.

@Test
public void watchWhenNoFilterMatch() 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(notificationFilterManager.getFilterPreferences(user)).thenReturn(Sets.newSet(pref1));
    when(watchedEntityReference.isWatched(user)).thenReturn(false);
    NotificationFilterPreference createdPref = mock(NotificationFilterPreference.class);
    when(watchedEntityReference.createInclusiveFilterPreference()).thenReturn(createdPref);
    // Test
    mocker.getComponentUnderTest().watchEntity(watchedEntityReference, user);
    // Checks
    verify(notificationFilterManager).saveFilterPreferences(eq(Sets.newSet(createdPref)));
}
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 5 with WatchedEntityReference

use of org.xwiki.notifications.filters.watch.WatchedEntityReference in project xwiki-platform by xwiki.

the class DefaultWatchedEntitiesManagerTest method watchWhen2OppositeFilters.

@Test
public void watchWhen2OppositeFilters() 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.INCLUSIVE);
    when(pref1.isEnabled()).thenReturn(true);
    when(pref1.getFilterPreferenceName()).thenReturn("pref1");
    NotificationFilterPreference pref2 = mock(NotificationFilterPreference.class);
    when(pref2.getProperties(NotificationFilterProperty.EVENT_TYPE)).thenReturn(Collections.emptyList());
    when(pref2.getFilterFormats()).thenReturn(Sets.newSet(NotificationFormat.ALERT, NotificationFormat.EMAIL));
    when(watchedEntityReference.matchExactly(pref2)).thenReturn(true);
    when(pref2.getFilterType()).thenReturn(NotificationFilterType.EXCLUSIVE);
    when(pref2.isEnabled()).thenReturn(true);
    when(pref2.getFilterPreferenceName()).thenReturn("pref2");
    when(notificationFilterManager.getFilterPreferences(user)).thenReturn(Sets.newSet(pref1, pref2));
    when(watchedEntityReference.isWatched(user)).thenReturn(false, true);
    // Test
    mocker.getComponentUnderTest().watchEntity(watchedEntityReference, user);
    // Checks
    verify(notificationFilterManager).deleteFilterPreference("pref2");
    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)

Aggregations

Test (org.junit.Test)8 DocumentReference (org.xwiki.model.reference.DocumentReference)8 NotificationFilterPreference (org.xwiki.notifications.filters.NotificationFilterPreference)8 WatchedEntityReference (org.xwiki.notifications.filters.watch.WatchedEntityReference)8