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());
}
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));
}
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));
}
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));
}
Aggregations