Search in sources :

Example 1 with ContentDependencies

use of com.enonic.xp.content.ContentDependencies 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 2 with ContentDependencies

use of com.enonic.xp.content.ContentDependencies 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 3 with ContentDependencies

use of com.enonic.xp.content.ContentDependencies 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)

Aggregations

Content (com.enonic.xp.content.Content)3 ContentDependencies (com.enonic.xp.content.ContentDependencies)3 ContentDependenciesAggregation (com.enonic.xp.content.ContentDependenciesAggregation)3 ContentQuery (com.enonic.xp.content.ContentQuery)3 FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)3 PropertyTree (com.enonic.xp.data.PropertyTree)3 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)3 Test (org.junit.jupiter.api.Test)3