use of com.enonic.xp.content.FindContentIdsByQueryResult in project xp by enonic.
the class ContentDependenciesResolverTest method resolve_inbound_dependencies.
@Test
public void resolve_inbound_dependencies() throws Exception {
final Content content = createContent("folderRefContent1", new PropertyTree(), ContentTypeName.folder());
final FindContentIdsByQueryResult findContentByQueryResult = FindContentIdsByQueryResult.create().aggregations(Aggregations.from(BucketAggregation.bucketAggregation("type").buckets(Buckets.create().add(Bucket.create().key("portal:site").docCount(2).build()).add(Bucket.create().key("base:folder").docCount(1).build()).build()).build())).build();
Mockito.when(contentService.getById(content.getId())).thenReturn(content);
Mockito.when(contentService.getByIds(Mockito.any())).thenReturn(Contents.empty());
Mockito.when(contentService.find(Mockito.isA(ContentQuery.class))).thenReturn(findContentByQueryResult);
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().name("mycontenttype").icon(Icon.from(new byte[] { 1 }, "mime", Instant.now())).setBuiltIn(true).build());
final ContentDependencies result = resolver.resolve(content.getId());
assertEquals(result.getInbound().size(), 2);
final ContentDependenciesAggregation siteAggregation = (ContentDependenciesAggregation) result.getInbound().toArray()[0];
assertEquals(siteAggregation.getType(), ContentTypeName.site());
assertEquals(siteAggregation.getCount(), 2);
final ContentDependenciesAggregation folderAggregation = (ContentDependenciesAggregation) result.getInbound().toArray()[1];
assertEquals(folderAggregation.getType(), ContentTypeName.folder());
assertEquals(folderAggregation.getCount(), 1);
}
use of com.enonic.xp.content.FindContentIdsByQueryResult in project xp by enonic.
the class ContentDependenciesResolverTest method resolve_outbound_with_missing_dependency.
@Test
public void resolve_outbound_with_missing_dependency() throws Exception {
final PropertyTree data = new PropertyTree();
final Content folderRefContent1 = createContent("folderRefContent1", data, ContentTypeName.folder());
final Content folderRefContent2 = createContent("folderRefContent2", data, ContentTypeName.folder());
data.addReference("myRef1", Reference.from(folderRefContent1.getId().toString()));
data.addReference("myRef2", Reference.from(folderRefContent2.getId().toString()));
data.addReference("myRef3", Reference.from("some-id"));
final Content content = createContent("content", data, ContentTypeName.site());
final FindContentIdsByQueryResult findContentByQueryResult = FindContentIdsByQueryResult.create().aggregations(Aggregations.from(BucketAggregation.bucketAggregation("type").buckets(Buckets.create().build()).build())).build();
Mockito.when(contentService.getByIds(Mockito.any())).thenReturn(Contents.from(folderRefContent1, folderRefContent2));
Mockito.when(contentService.getById(content.getId())).thenReturn(content);
Mockito.when(contentService.find(Mockito.isA(ContentQuery.class))).thenReturn(findContentByQueryResult);
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().name("mycontenttype").icon(Icon.from(new byte[] { 1 }, "mime", Instant.now())).setBuiltIn(true).build());
final ContentDependencies result = resolver.resolve(content.getId());
assertEquals(result.getOutbound().size(), 1);
final ContentDependenciesAggregation folderAggregation = (ContentDependenciesAggregation) result.getOutbound().toArray()[0];
assertEquals(folderAggregation.getType(), ContentTypeName.folder());
assertEquals(folderAggregation.getCount(), 2);
}
use of com.enonic.xp.content.FindContentIdsByQueryResult in project xp by enonic.
the class ContentServiceImplTest_find method multipleFilters.
@Test
public void multipleFilters() throws Exception {
createContent(ContentPath.ROOT, "title1");
createContent(ContentPath.ROOT, "title2");
FindContentIdsByQueryResult result = this.contentService.find(ContentQuery.create().queryFilter(ValueFilter.create().fieldName(ContentPropertyNames.DISPLAY_NAME).addValue(ValueFactory.newString("title1")).build()).queryFilter(ValueFilter.create().fieldName(ContentPropertyNames.DISPLAY_NAME).addValue(ValueFactory.newString("title2")).build()).build());
// Filters will be "must", and no entry matches both titles
assertEquals(0, result.getHits());
}
use of com.enonic.xp.content.FindContentIdsByQueryResult in project xp by enonic.
the class ContentDependenciesResolverTest method resolve_outbound_dependencies.
@Test
public void resolve_outbound_dependencies() throws Exception {
final PropertyTree data = new PropertyTree();
final Content folderRefContent1 = createContent("folderRefContent1", data, ContentTypeName.folder());
final Content folderRefContent2 = createContent("folderRefContent2", data, ContentTypeName.folder());
final Content siteRefContent1 = createContent("siteRefContent1", data, ContentTypeName.site());
data.addReference("myRef1", Reference.from(folderRefContent1.getId().toString()));
data.addReference("myRef2", Reference.from(folderRefContent2.getId().toString()));
data.addReference("myRef3", Reference.from(siteRefContent1.getId().toString()));
data.addReference("refToMyself", Reference.from("contentId"));
final Content content = createContent("contentId", data, ContentTypeName.site());
final FindContentIdsByQueryResult findContentByQueryResult = FindContentIdsByQueryResult.create().aggregations(Aggregations.from(BucketAggregation.bucketAggregation("type").buckets(Buckets.create().build()).build())).build();
Mockito.when(contentService.getByIds(Mockito.any())).thenReturn(Contents.from(folderRefContent1, folderRefContent2, siteRefContent1));
Mockito.when(contentService.getById(content.getId())).thenReturn(content);
Mockito.when(contentService.find(Mockito.isA(ContentQuery.class))).thenReturn(findContentByQueryResult);
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().name("mycontenttype").icon(Icon.from(new byte[] { 1 }, "mime", Instant.now())).setBuiltIn(true).build());
final ContentDependencies result = resolver.resolve(content.getId());
assertEquals(result.getOutbound().size(), 2);
final ContentDependenciesAggregation siteAggregation = (ContentDependenciesAggregation) result.getOutbound().toArray()[0];
assertEquals(siteAggregation.getType(), ContentTypeName.site());
assertEquals(siteAggregation.getCount(), 1);
final ContentDependenciesAggregation folderAggregation = (ContentDependenciesAggregation) result.getOutbound().toArray()[1];
assertEquals(folderAggregation.getType(), ContentTypeName.folder());
assertEquals(folderAggregation.getCount(), 2);
}
use of com.enonic.xp.content.FindContentIdsByQueryResult in project xp by enonic.
the class FindContentIdsByQueryCommandTest method test.
@Test
public void test() {
FindNodesByQueryResult nodesByQueryResult = FindNodesByQueryResult.create().addNodeHit(NodeHit.create().nodeId(NodeId.from("nodeId")).score(1.0f).sort(SortValuesProperty.create().values(84).build()).highlight(HighlightedProperties.create().add(HighlightedProperty.create().name("name").addFragment("fragment").build()).build()).build()).hits(1).build();
Mockito.when(nodeService.findByQuery(Mockito.any(NodeQuery.class))).thenReturn(nodesByQueryResult);
FindContentIdsByQueryCommand command = FindContentIdsByQueryCommand.create().translator(translator).nodeService(nodeService).contentTypeService(contentTypeService).eventPublisher(eventPublisher).query(ContentQuery.create().queryExpr(QueryExpr.from(null, new DynamicOrderExpr(FunctionExpr.from("geoDistance", ValueExpr.string("my-value"), ValueExpr.geoPoint("83,80"), ValueExpr.string("km")), OrderExpr.Direction.ASC))).build()).build();
FindContentIdsByQueryResult result = command.execute();
Assertions.assertFalse(result.getSort().isEmpty());
Assertions.assertEquals(1, result.getSort().size());
Assertions.assertEquals(1, result.getScore().size());
}
Aggregations