Search in sources :

Example 46 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class QueryGeneratorTest method generateQueryWithNoRelevantFilters.

@Test
public void generateQueryWithNoRelevantFilters() throws Exception {
    // Mocks
    NotificationFilter notificationFilter1 = mock(NotificationFilter.class);
    when(notificationFilterManager.getFilters(any(DocumentReference.class), any(NotificationPreference.class))).thenReturn(Collections.singleton(notificationFilter1));
    when(notificationFilter1.filterExpression(any(DocumentReference.class), any(NotificationPreference.class))).thenReturn(new EmptyNode());
    when(notificationFilter1.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 NOT (ID IN (\"event1\", \"event2\"))) " + "AND HIDDEN <> true) " + "ORDER BY DATE DESC", node.toString());
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) EmptyNode(org.xwiki.notifications.filters.expression.EmptyNode) ExpressionNode(org.xwiki.notifications.filters.expression.ExpressionNode) NotificationFilter(org.xwiki.notifications.filters.NotificationFilter) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 47 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class QueryGeneratorTest method generateQueryWithUntilDateAndBlackList.

@Test
public void generateQueryWithUntilDateAndBlackList() throws Exception {
    Date untilDate = new Date(1000000000000L);
    // Test
    ExpressionNode node = mocker.getComponentUnderTest().generateQueryExpression(new DocumentReference("xwiki", "XWiki", "UserA"), NotificationFormat.ALERT, untilDate, null, Arrays.asList("event1", "event2"));
    // Verify
    assertEquals("((((TYPE = \"create\" " + "AND DATE >= \"Fri Jan 02 04:46:40 CET 1970\") " + "AND NOT (ID IN (\"event1\", \"event2\"))) " + "AND DATE <= \"Sun Sep 09 03:46:40 CEST 2001\") " + "AND HIDDEN <> true) " + "ORDER BY DATE DESC", node.toString());
}
Also used : ExpressionNode(org.xwiki.notifications.filters.expression.ExpressionNode) Date(java.util.Date) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 48 with DocumentReference

use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.

the class QueryGeneratorTest method generateQueryWhenHiddenDocsAreEnabled.

@Test
public void generateQueryWhenHiddenDocsAreEnabled() throws Exception {
    // Mock
    when(userPreferencesSource.getProperty("displayHiddenDocuments", 0)).thenReturn(1);
    // 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\")) " + "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)) " + "ORDER BY event.date DESC", Query.HQL);
    verify(query).bindValue(eq("date_688218ea2b05763819a1e155109e4bf1e8921dd72e8b43d4c89c89133d4a5357"), eq(startDate));
    verify(query).bindValue(eq("value_fa8847b0c33183273f5945508b31c3208a9e4ece58ca47233a05628d8dba3799"), eq("create"));
    verify(query).bindValue("date_25db83d7521312b07fa98ca0023df696d1b94ee4fb7c49578c807f5aeb634f7a", pref1StartDate);
}
Also used : ExpressionNode(org.xwiki.notifications.filters.expression.ExpressionNode) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 49 with DocumentReference

use of org.xwiki.model.reference.DocumentReference 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 50 with DocumentReference

use of org.xwiki.model.reference.DocumentReference 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)

Aggregations

DocumentReference (org.xwiki.model.reference.DocumentReference)1324 Test (org.junit.Test)711 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)482 BaseObject (com.xpn.xwiki.objects.BaseObject)250 XWikiContext (com.xpn.xwiki.XWikiContext)186 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)157 ArrayList (java.util.ArrayList)128 WikiReference (org.xwiki.model.reference.WikiReference)127 XWikiException (com.xpn.xwiki.XWikiException)121 EntityReference (org.xwiki.model.reference.EntityReference)113 SpaceReference (org.xwiki.model.reference.SpaceReference)96 XWiki (com.xpn.xwiki.XWiki)82 HashMap (java.util.HashMap)54 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)52 Expectations (org.jmock.Expectations)50 Before (org.junit.Before)50 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)46 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)45 AttachmentReference (org.xwiki.model.reference.AttachmentReference)44 Date (java.util.Date)42