use of com.enonic.xp.content.Contents in project xp by enonic.
the class ContentServiceImplTest_getByPaths method test_publish_expired_draft.
@Test
public void test_publish_expired_draft() throws Exception {
final Content content1 = createContent(ContentPath.ROOT);
final Content content2 = createContent(ContentPath.ROOT, ContentPublishInfo.create().from(Instant.now().minus(Duration.ofDays(1))).to(Instant.now().minus(Duration.ofDays(1))).build());
final ContentPaths paths = ContentPaths.from(content1.getPath(), content2.getPath());
final Contents contents = this.contentService.getByPaths(paths);
assertEquals(contents.getSize(), 2);
assertTrue(contents.contains(content1));
assertTrue(contents.contains(content2));
}
use of com.enonic.xp.content.Contents in project xp by enonic.
the class ContentServiceImplTest_getByPaths method one.
@Test
public void one() throws Exception {
final Content content = createContent(ContentPath.ROOT);
final Contents contents = this.contentService.getByPaths(ContentPaths.from(content.getPath()));
assertNotNull(contents);
assertEquals(1, contents.getSize());
}
use of com.enonic.xp.content.Contents in project xp by enonic.
the class ContentServiceImplTest_getByPaths method invalid_and_valid_path.
@Test
public void invalid_and_valid_path() throws Exception {
final Content content1 = createContent(ContentPath.ROOT);
final Content content2 = createContent(content1.getPath());
final Contents contents = this.contentService.getByPaths(ContentPaths.from("/test_invalid_path", content1.getPath().toString(), content2.getPath().toString()));
assertNotNull(contents);
assertEquals(2, contents.getSize());
}
use of com.enonic.xp.content.Contents in project xp by enonic.
the class PublishContentHandlerTest method exampleResult.
private static PublishContentResult exampleResult() {
Contents published = Contents.from(exampleContent(PUB_ID_1, "mycontent", "My Content", "/mysite/somepage", "myfield", "Hello World"), exampleContent(PUB_ID_2, "content2", "Content 2", "/mysite/page2", "myfield", "No. 2"), exampleContent(PUB_ID_3, "content3", "Content 3", "/mysite/page3", "myfield", "Hello x 3"));
Contents deleted = Contents.from(exampleContent(DEL_ID, "nocontent", "No Content", "/mysite/leave", "myop", "Delete"));
Contents failed = Contents.from(exampleContent(FAIL_ID, "badcontent", "Bad bad Content", "/mysite/fail", "myop", "Publish"));
return PublishContentResult.create().setPushed(published.getIds()).setDeleted(deleted.getIds()).setFailed(failed.getIds()).build();
}
use of com.enonic.xp.content.Contents in project xp by enonic.
the class QueryContentHandlerTest method setupQuery.
private void setupQuery(final int count, final boolean aggs, final boolean addHighlight) {
final Contents contents = TestDataFixtures.newContents(count);
final Instant t1 = Instant.parse("2014-09-01T00:00:00.00Z");
final Instant t2 = Instant.parse("2014-10-01T00:00:00.00Z");
final Instant t3 = Instant.parse("2014-11-01T00:00:00.00Z");
final Buckets buckets1 = Buckets.create().add(Bucket.create().key("male").docCount(10).build()).add(Bucket.create().key("female").docCount(12).build()).build();
final Buckets buckets2 = Buckets.create().add(Bucket.create().key("2014-01").docCount(8).build()).add(Bucket.create().key("2014-02").docCount(10).build()).add(Bucket.create().key("2014-03").docCount(12).build()).build();
final Buckets buckets3 = Buckets.create().add(NumericRangeBucket.create().key("a").docCount(2).to(50).build()).add(NumericRangeBucket.create().key("b").docCount(4).from(50).to(100).build()).add(NumericRangeBucket.create().key("c").docCount(4).from(100).build()).build();
final Buckets buckets4 = Buckets.create().add(DateRangeBucket.create().from(t1).docCount(2).key("date range bucket key").build()).add(DateRangeBucket.create().to(t1).from(t2).docCount(5).build()).add(DateRangeBucket.create().to(t3).docCount(7).build()).build();
final BucketAggregation aggr1 = BucketAggregation.bucketAggregation("genders").buckets(buckets1).build();
final BucketAggregation aggr2 = BucketAggregation.bucketAggregation("by_month").buckets(buckets2).build();
final BucketAggregation aggr3 = BucketAggregation.bucketAggregation("price_ranges").buckets(buckets3).build();
final BucketAggregation aggr4 = BucketAggregation.bucketAggregation("my_date_range").buckets(buckets4).build();
final StatsAggregation aggr5 = StatsAggregation.create("item_count").avg(3).max(5).min(1).sum(15).count(5).build();
final Aggregations aggregations = Aggregations.from(aggr1, aggr2, aggr3, aggr4, aggr5);
final Map<ContentId, HighlightedProperties> highlight = Map.of(ContentId.from("123"), HighlightedProperties.create().add(HighlightedProperty.create().name("property1").addFragment("fragment1_1").addFragment("fragment1_2").build()).build(), ContentId.from("456"), HighlightedProperties.create().add(HighlightedProperty.create().name("property2").addFragment("fragment2_1").addFragment("fragment2_2").build()).build());
final FindContentIdsByQueryResult findResult = FindContentIdsByQueryResult.create().hits(contents.getSize()).totalHits(20).contents(contents.getIds()).aggregations(aggs ? aggregations : null).highlight(addHighlight ? highlight : null).build();
Mockito.when(this.contentService.find(Mockito.isA(ContentQuery.class))).thenReturn(findResult);
Mockito.when(this.contentService.getByIds(Mockito.isA(GetContentByIdsParams.class))).thenReturn(contents);
}
Aggregations