Search in sources :

Example 6 with StringValueNode

use of org.xwiki.notifications.filters.expression.StringValueNode 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 7 with StringValueNode

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

the class ExpressionNodeToHQLConverterTest method parseWithStringValueNode.

@Test
public void parseWithStringValueNode() {
    ExpressionNodeToHQLConverter.HQLQuery result = parser.parse(new StringValueNode(TEST_VALUE_1));
    assertEquals(String.format(":%s", TEST_VALUE_1_IDENTIFIER), result.getQuery());
    assertEquals(TEST_VALUE_1, result.getQueryParameters().get(TEST_VALUE_1_IDENTIFIER));
}
Also used : StringValueNode(org.xwiki.notifications.filters.expression.StringValueNode) Test(org.junit.Test)

Example 8 with StringValueNode

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

the class ExpressionNodeToHQLConverterTest method parseWithLesserThanNode.

@Test
public void parseWithLesserThanNode() {
    AbstractNode testAST = new LesserThanNode(new PropertyValueNode(EventProperty.DATE), new StringValueNode(TEST_VALUE_1));
    ExpressionNodeToHQLConverter.HQLQuery result = parser.parse(testAST);
    assertEquals(String.format("event.date <= :%s", TEST_VALUE_1_IDENTIFIER), result.getQuery());
    assertEquals(TEST_VALUE_1, result.getQueryParameters().get(TEST_VALUE_1_IDENTIFIER));
}
Also used : LesserThanNode(org.xwiki.notifications.filters.expression.LesserThanNode) AbstractNode(org.xwiki.notifications.filters.expression.generics.AbstractNode) StringValueNode(org.xwiki.notifications.filters.expression.StringValueNode) PropertyValueNode(org.xwiki.notifications.filters.expression.PropertyValueNode) Test(org.junit.Test)

Example 9 with StringValueNode

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

the class ExpressionNodeToHQLConverterTest method parseWithGreaterThanNode.

@Test
public void parseWithGreaterThanNode() {
    AbstractNode testAST = new GreaterThanNode(new PropertyValueNode(EventProperty.DATE), new StringValueNode(TEST_VALUE_1));
    ExpressionNodeToHQLConverter.HQLQuery result = parser.parse(testAST);
    assertEquals(String.format("event.date >= :%s", TEST_VALUE_1_IDENTIFIER), result.getQuery());
    assertEquals(TEST_VALUE_1, result.getQueryParameters().get(TEST_VALUE_1_IDENTIFIER));
}
Also used : AbstractNode(org.xwiki.notifications.filters.expression.generics.AbstractNode) StringValueNode(org.xwiki.notifications.filters.expression.StringValueNode) GreaterThanNode(org.xwiki.notifications.filters.expression.GreaterThanNode) PropertyValueNode(org.xwiki.notifications.filters.expression.PropertyValueNode) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 StringValueNode (org.xwiki.notifications.filters.expression.StringValueNode)9 AbstractNode (org.xwiki.notifications.filters.expression.generics.AbstractNode)7 PropertyValueNode (org.xwiki.notifications.filters.expression.PropertyValueNode)4 EqualsNode (org.xwiki.notifications.filters.expression.EqualsNode)3 NotEqualsNode (org.xwiki.notifications.filters.expression.NotEqualsNode)3 DocumentReference (org.xwiki.model.reference.DocumentReference)1 NotificationFilter (org.xwiki.notifications.filters.NotificationFilter)1 AndNode (org.xwiki.notifications.filters.expression.AndNode)1 ExpressionNode (org.xwiki.notifications.filters.expression.ExpressionNode)1 GreaterThanNode (org.xwiki.notifications.filters.expression.GreaterThanNode)1 InNode (org.xwiki.notifications.filters.expression.InNode)1 LesserThanNode (org.xwiki.notifications.filters.expression.LesserThanNode)1 NotNode (org.xwiki.notifications.filters.expression.NotNode)1 StartsWith (org.xwiki.notifications.filters.expression.StartsWith)1 NotificationPreference (org.xwiki.notifications.preferences.NotificationPreference)1