Search in sources :

Example 21 with QueryRestrictionGroup

use of com.celements.search.lucene.query.QueryRestrictionGroup in project celements-blog by celements.

the class ArticleLuceneQueryBuilderTest method testGetDateRestrictions_published_future_noEditRights.

@Test
public void testGetDateRestrictions_published_future_noEditRights() {
    Set<DateMode> modes = new HashSet<>(Arrays.asList(DateMode.PUBLISHED, DateMode.FUTURE));
    Date date = new Date();
    boolean hasEditRights = false;
    QueryRestrictionGroup ret = builder.getDateRestrictions(modes, date, hasEditRights);
    assertEquals(getPublishedQuery(date), ret.getQueryString());
}
Also used : DateMode(com.celements.blog.article.ArticleLoadParameter.DateMode) Date(java.util.Date) HashSet(java.util.HashSet) QueryRestrictionGroup(com.celements.search.lucene.query.QueryRestrictionGroup) Test(org.junit.Test)

Example 22 with QueryRestrictionGroup

use of com.celements.search.lucene.query.QueryRestrictionGroup in project celements-blog by celements.

the class ArticleLuceneQueryBuilderTest method testGetDateRestrictions_all.

@Test
public void testGetDateRestrictions_all() {
    Set<DateMode> modes = new HashSet<>(Arrays.asList(DateMode.PUBLISHED, DateMode.ARCHIVED, DateMode.FUTURE));
    Date date = new Date();
    boolean hasEditRights = true;
    QueryRestrictionGroup ret = builder.getDateRestrictions(modes, date, hasEditRights);
    assertEquals("", ret.getQueryString());
}
Also used : DateMode(com.celements.blog.article.ArticleLoadParameter.DateMode) Date(java.util.Date) HashSet(java.util.HashSet) QueryRestrictionGroup(com.celements.search.lucene.query.QueryRestrictionGroup) Test(org.junit.Test)

Example 23 with QueryRestrictionGroup

use of com.celements.search.lucene.query.QueryRestrictionGroup in project celements-blog by celements.

the class ArticleLuceneQueryBuilderTest method testGetSubsSpaceRestriction_noEditRights.

@Test
public void testGetSubsSpaceRestriction_noEditRights() throws Exception {
    ArticleLoadParameter param = new ArticleLoadParameter();
    param.setBlogDocRef(docRef);
    param.setDateModes(Arrays.asList(DateMode.PUBLISHED.name(), DateMode.FUTURE.name()));
    param.setSubscriptionModes(Arrays.asList(SubscriptionMode.SUBSCRIBED.name(), SubscriptionMode.UNSUBSCRIBED.name()));
    SpaceReference spaceRef = new SpaceReference("artSpace", wikiRef);
    expectSpaceRightsCheck(spaceRef, null, false);
    replayDefault();
    QueryRestrictionGroup ret = builder.getSubsSpaceRestriction(param, spaceRef);
    verifyDefault();
    assertEquals(getSubsPublishQuery(spaceRef, param.getExecutionDate()), ret.getQueryString());
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) QueryRestrictionGroup(com.celements.search.lucene.query.QueryRestrictionGroup) Test(org.junit.Test)

Example 24 with QueryRestrictionGroup

use of com.celements.search.lucene.query.QueryRestrictionGroup in project celements-blog by celements.

the class ArticleLuceneQueryBuilderTest method testGetArticleSubsRestrictions_subscribed_unsubscribed_noEditRights.

@Test
public void testGetArticleSubsRestrictions_subscribed_unsubscribed_noEditRights() {
    Set<SubscriptionMode> modes = new HashSet<>(Arrays.asList(SubscriptionMode.SUBSCRIBED, SubscriptionMode.UNSUBSCRIBED));
    boolean hasEditRights = false;
    QueryRestrictionGroup ret = builder.getArticleSubsRestrictions(modes, docRef, hasEditRights);
    assertEquals(getSubsQuery(false), ret.getQueryString());
}
Also used : SubscriptionMode(com.celements.blog.article.ArticleLoadParameter.SubscriptionMode) HashSet(java.util.HashSet) QueryRestrictionGroup(com.celements.search.lucene.query.QueryRestrictionGroup) Test(org.junit.Test)

Example 25 with QueryRestrictionGroup

use of com.celements.search.lucene.query.QueryRestrictionGroup in project celements-blog by celements.

the class ArticleLuceneQueryBuilderTest method testGetSubsRestrictions_multipleSub.

@Test
public void testGetSubsRestrictions_multipleSub() throws Exception {
    DocumentReference subsBlogDocRef1 = new DocumentReference("subsBlog1", spaceRef);
    DocumentReference subsBlogDocRef2 = new DocumentReference("subsBlog2", spaceRef);
    DocumentReference subsBlogDocRef3 = new DocumentReference("subsBlog3", spaceRef);
    DocumentReference subsBlogDocRef4 = new DocumentReference("subsBlog4", spaceRef);
    SpaceReference subsSpaceRef1 = new SpaceReference("artSpace1", wikiRef);
    SpaceReference subsSpaceRef2 = new SpaceReference("artSpace2", wikiRef);
    SpaceReference subsSpaceRef3 = new SpaceReference("artSpace3", wikiRef);
    ArticleLoadParameter param = new ArticleLoadParameter();
    param.setBlogDocRef(docRef);
    param.setSubscribedToBlogs(Arrays.asList(subsBlogDocRef1, subsBlogDocRef2, subsBlogDocRef3, subsBlogDocRef4));
    param.setDateModes(Arrays.asList(DateMode.PUBLISHED.name()));
    param.setSubscriptionModes(Arrays.asList(SubscriptionMode.SUBSCRIBED.name()));
    expect(builder.blogService.getBlogSpaceRef(eq(subsBlogDocRef1))).andReturn(subsSpaceRef1).once();
    expectSpaceRightsCheck(subsSpaceRef1, true, true);
    expect(builder.blogService.getBlogSpaceRef(eq(subsBlogDocRef2))).andReturn(subsSpaceRef2).once();
    expectSpaceRightsCheck(subsSpaceRef2, false, null);
    expect(builder.blogService.getBlogSpaceRef(eq(subsBlogDocRef3))).andReturn(subsSpaceRef3).once();
    expectSpaceRightsCheck(subsSpaceRef3, true, true);
    expect(builder.blogService.getBlogSpaceRef(eq(subsBlogDocRef4))).andReturn(null).once();
    expectSpaceRightsCheck(null, false, null);
    replayDefault();
    QueryRestrictionGroup ret = builder.getSubsRestrictions(param);
    verifyDefault();
    assertNotNull(ret);
    String expected = "(" + RESTR_ARTICLE_ISSUBS + " AND (" + getSubsPublishQuery(subsSpaceRef1, param.getExecutionDate()) + " OR " + getSubsPublishQuery(subsSpaceRef3, param.getExecutionDate()) + "))";
    assertEquals(expected, ret.getQueryString());
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentReference(org.xwiki.model.reference.DocumentReference) QueryRestrictionGroup(com.celements.search.lucene.query.QueryRestrictionGroup) Test(org.junit.Test)

Aggregations

QueryRestrictionGroup (com.celements.search.lucene.query.QueryRestrictionGroup)45 Test (org.junit.Test)37 HashSet (java.util.HashSet)28 DateMode (com.celements.blog.article.ArticleLoadParameter.DateMode)15 SubscriptionMode (com.celements.blog.article.ArticleLoadParameter.SubscriptionMode)15 Date (java.util.Date)15 SpaceReference (org.xwiki.model.reference.SpaceReference)8 DocumentReference (org.xwiki.model.reference.DocumentReference)7 IQueryRestriction (com.celements.search.lucene.query.IQueryRestriction)4 LuceneQuery (com.celements.search.lucene.query.LuceneQuery)1 QueryRestriction (com.celements.search.lucene.query.QueryRestriction)1 WikiReference (org.xwiki.model.reference.WikiReference)1