Search in sources :

Example 6 with FindContentIdsByQueryResult

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);
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) ContentDependenciesAggregation(com.enonic.xp.content.ContentDependenciesAggregation) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentDependencies(com.enonic.xp.content.ContentDependencies) Test(org.junit.jupiter.api.Test)

Example 7 with FindContentIdsByQueryResult

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);
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) ContentDependenciesAggregation(com.enonic.xp.content.ContentDependenciesAggregation) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentDependencies(com.enonic.xp.content.ContentDependencies) Test(org.junit.jupiter.api.Test)

Example 8 with FindContentIdsByQueryResult

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());
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) Test(org.junit.jupiter.api.Test)

Example 9 with FindContentIdsByQueryResult

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);
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) ContentDependenciesAggregation(com.enonic.xp.content.ContentDependenciesAggregation) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentDependencies(com.enonic.xp.content.ContentDependencies) Test(org.junit.jupiter.api.Test)

Example 10 with FindContentIdsByQueryResult

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());
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) DynamicOrderExpr(com.enonic.xp.query.expr.DynamicOrderExpr) NodeQuery(com.enonic.xp.node.NodeQuery) Test(org.junit.jupiter.api.Test)

Aggregations

FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)17 ContentQuery (com.enonic.xp.content.ContentQuery)13 Test (org.junit.jupiter.api.Test)12 Content (com.enonic.xp.content.Content)8 PropertyTree (com.enonic.xp.data.PropertyTree)5 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)4 ReprocessContentRequestJson (com.enonic.xp.impl.server.rest.model.ReprocessContentRequestJson)4 AbstractRunnableTaskTest (com.enonic.xp.task.AbstractRunnableTaskTest)4 RunnableTask (com.enonic.xp.task.RunnableTask)4 ContentDependencies (com.enonic.xp.content.ContentDependencies)3 ContentDependenciesAggregation (com.enonic.xp.content.ContentDependenciesAggregation)3 Contents (com.enonic.xp.content.Contents)3 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)3 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)2 Buckets (com.enonic.xp.aggregation.Buckets)2 Aggregations (com.enonic.xp.aggregation.Aggregations)1 StatsAggregation (com.enonic.xp.aggregation.StatsAggregation)1 ContentId (com.enonic.xp.content.ContentId)1 ContentPath (com.enonic.xp.content.ContentPath)1 ContentService (com.enonic.xp.content.ContentService)1