Search in sources :

Example 6 with ExpressionNode

use of org.xwiki.notifications.filters.expression.ExpressionNode in project xwiki-platform by xwiki.

the class QueryGeneratorTest method generateQueryExpression.

@Test
public void generateQueryExpression() throws Exception {
    // Test
    ExpressionNode node = mocker.getComponentUnderTest().generateQueryExpression(new DocumentReference("xwiki", "XWiki", "UserA"), NotificationFormat.ALERT, null, startDate, null);
    // Verify
    assertEquals("((DATE >= \"Thu Jan 01 01:00:00 CET 1970\" " + "AND (TYPE = \"create\" AND DATE >= \"Fri Jan 02 04:46:40 CET 1970\")) AND HIDDEN <> true) " + "ORDER BY DATE DESC", node.toString());
    // Test 2
    mocker.getComponentUnderTest().generateQuery(new DocumentReference("xwiki", "XWiki", "UserA"), NotificationFormat.ALERT, null, startDate, null);
    verify(queryManager).createQuery("where ((" + "event.date >= :date_688218ea2b05763819a1e155109e4bf1e8921dd72e8b43d4c89c89133d4a5357) " + "AND ((event.type = :value_fa8847b0c33183273f5945508b31c3208a9e4ece58ca47233a05628d8dba3799) " + "AND (event.date >= :date_25db83d7521312b07fa98ca0023df696d1b94ee4fb7c49578c807f5aeb634f7a))) " + "AND (event.hidden <> true) " + "ORDER BY event.date DESC", Query.HQL);
    verify(query).bindValue("date_688218ea2b05763819a1e155109e4bf1e8921dd72e8b43d4c89c89133d4a5357", startDate);
    verify(query).bindValue("date_25db83d7521312b07fa98ca0023df696d1b94ee4fb7c49578c807f5aeb634f7a", pref1StartDate);
    verify(query).bindValue(eq("value_fa8847b0c33183273f5945508b31c3208a9e4ece58ca47233a05628d8dba3799"), eq("create"));
}
Also used : ExpressionNode(org.xwiki.notifications.filters.expression.ExpressionNode) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 7 with ExpressionNode

use of org.xwiki.notifications.filters.expression.ExpressionNode in project xwiki-platform by xwiki.

the class QueryGeneratorTest method generateQueryWithLocalUser.

@Test
public void generateQueryWithLocalUser() throws Exception {
    // Test
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWiki");
    ExpressionNode node = mocker.getComponentUnderTest().generateQueryExpression(new DocumentReference("xwiki", "XWiki", "UserA"), NotificationFormat.ALERT, null, startDate, null);
    // Verify
    assertEquals("(((DATE >= \"Thu Jan 01 01:00:00 CET 1970\" " + "AND (TYPE = \"create\" AND DATE >= \"Fri Jan 02 04:46:40 CET 1970\")) AND HIDDEN <> true) " + "AND WIKI = \"Wiki xwiki\") " + "ORDER BY DATE DESC", node.toString());
}
Also used : ExpressionNode(org.xwiki.notifications.filters.expression.ExpressionNode) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 8 with ExpressionNode

use of org.xwiki.notifications.filters.expression.ExpressionNode in project xwiki-platform by xwiki.

the class QueryGeneratorTest method generateQueryWithFilters.

@Test
public void generateQueryWithFilters() throws Exception {
    // Mocks
    NotificationFilter notificationFilter1 = mock(NotificationFilter.class);
    NotificationFilter notificationFilter2 = mock(NotificationFilter.class);
    when(notificationFilterManager.getFilters(any(DocumentReference.class), any(NotificationPreference.class))).thenReturn(Sets.newSet(notificationFilter1, notificationFilter2));
    when(notificationFilter1.filterExpression(any(DocumentReference.class), any(NotificationPreference.class))).thenReturn(new AndNode(new EqualsNode(new PropertyValueNode(EventProperty.PAGE), new StringValueNode("someValue1")), new EqualsNode(new StringValueNode("1"), new StringValueNode("1"))));
    when(notificationFilter2.filterExpression(any(DocumentReference.class), any(NotificationPreference.class))).thenReturn(new AndNode(new EqualsNode(new PropertyValueNode(EventProperty.TYPE), new StringValueNode("someValue2")), new EqualsNode(new StringValueNode("2"), new StringValueNode("2"))));
    when(notificationFilter1.matchesPreference(any(NotificationPreference.class))).thenReturn(true);
    when(notificationFilter2.matchesPreference(any(NotificationPreference.class))).thenReturn(true);
    // Test
    ExpressionNode node = mocker.getComponentUnderTest().generateQueryExpression(new DocumentReference("xwiki", "XWiki", "UserA"), NotificationFormat.ALERT, null, startDate, Arrays.asList("event1", "event2"));
    assertEquals("(((DATE >= \"Thu Jan 01 01:00:00 CET 1970\" " + "AND (((TYPE = \"create\" AND DATE >= \"Fri Jan 02 04:46:40 CET 1970\") " + "AND (PAGE = \"someValue1\" AND \"1\" = \"1\")) " + "AND (TYPE = \"someValue2\" AND \"2\" = \"2\"))) " + "AND NOT (ID IN (\"event1\", \"event2\"))) " + "AND HIDDEN <> true) " + "ORDER BY DATE DESC", node.toString());
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) ExpressionNode(org.xwiki.notifications.filters.expression.ExpressionNode) StringValueNode(org.xwiki.notifications.filters.expression.StringValueNode) AndNode(org.xwiki.notifications.filters.expression.AndNode) EqualsNode(org.xwiki.notifications.filters.expression.EqualsNode) PropertyValueNode(org.xwiki.notifications.filters.expression.PropertyValueNode) NotificationFilter(org.xwiki.notifications.filters.NotificationFilter) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 9 with ExpressionNode

use of org.xwiki.notifications.filters.expression.ExpressionNode in project xwiki-platform by xwiki.

the class QueryGeneratorTest method generateQueryWithNotOnlyUnread.

@Test
public void generateQueryWithNotOnlyUnread() throws Exception {
    // Test
    ExpressionNode node = mocker.getComponentUnderTest().generateQueryExpression(new DocumentReference("xwiki", "XWiki", "UserA"), NotificationFormat.ALERT, null, startDate, null);
    // Verify
    assertEquals("((DATE >= \"Thu Jan 01 01:00:00 CET 1970\" " + "AND (TYPE = \"create\" AND DATE >= \"Fri Jan 02 04:46:40 CET 1970\")) AND HIDDEN <> true) " + "ORDER BY DATE DESC", node.toString());
    // Test 2
    mocker.getComponentUnderTest().generateQuery(new DocumentReference("xwiki", "XWiki", "UserA"), NotificationFormat.ALERT, null, startDate, null);
    verify(queryManager).createQuery("where ((" + "event.date >= :date_688218ea2b05763819a1e155109e4bf1e8921dd72e8b43d4c89c89133d4a5357) " + "AND ((event.type = :value_fa8847b0c33183273f5945508b31c3208a9e4ece58ca47233a05628d8dba3799) " + "AND (event.date >= :date_25db83d7521312b07fa98ca0023df696d1b94ee4fb7c49578c807f5aeb634f7a))) " + "AND (event.hidden <> true) " + "ORDER BY event.date DESC", Query.HQL);
}
Also used : ExpressionNode(org.xwiki.notifications.filters.expression.ExpressionNode) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 10 with ExpressionNode

use of org.xwiki.notifications.filters.expression.ExpressionNode in project xwiki-platform by xwiki.

the class EventUserFilterTest method generateFilterExpression.

@Test
public void generateFilterExpression() throws Exception {
    // Preferences
    mockPreferences();
    // Test
    ExpressionNode node = mocker.getComponentUnderTest().filterExpression(CURRENT_USER, NotificationFilterType.EXCLUSIVE, NotificationFormat.ALERT);
    // Verify
    assertNotNull(node);
    assertEquals("NOT (USER IN (\"userA\", \"userB\", \"userC\"))", node.toString());
}
Also used : ExpressionNode(org.xwiki.notifications.filters.expression.ExpressionNode) Test(org.junit.Test)

Aggregations

ExpressionNode (org.xwiki.notifications.filters.expression.ExpressionNode)10 Test (org.junit.Test)9 DocumentReference (org.xwiki.model.reference.DocumentReference)9 Date (java.util.Date)3 NotificationFilter (org.xwiki.notifications.filters.NotificationFilter)3 NotificationPreference (org.xwiki.notifications.preferences.NotificationPreference)3 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 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Inject (javax.inject.Inject)1 Named (javax.inject.Named)1 Singleton (javax.inject.Singleton)1 Component (org.xwiki.component.annotation.Component)1 ConfigurationSource (org.xwiki.configuration.ConfigurationSource)1