Search in sources :

Example 1 with DeleteContentParams

use of com.enonic.xp.content.DeleteContentParams in project xp by enonic.

the class ContentServiceImplTest_delete method create_delete_content.

@Test
public void create_delete_content() throws Exception {
    // Creates a content
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").name("myContent").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    // Deletes the content
    final DeleteContentParams deleteContentParams = DeleteContentParams.create().contentPath(content.getPath()).build();
    final DeleteContentsResult deletedContents = this.contentService.deleteWithoutFetch(deleteContentParams);
    assertNotNull(deletedContents);
    assertEquals(1, deletedContents.getDeletedContents().getSize());
    assertEquals(content.getId(), deletedContents.getDeletedContents().first());
    // Checks that the content is deleted
    final ContentIds contentIds = ContentIds.from(content.getId());
    final GetContentByIdsParams getContentByIdsParams = new GetContentByIdsParams(contentIds);
    final Contents foundContents = this.contentService.getByIds(getContentByIdsParams);
    assertEquals(0, foundContents.getSize());
}
Also used : DeleteContentParams(com.enonic.xp.content.DeleteContentParams) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) Contents(com.enonic.xp.content.Contents) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentIds(com.enonic.xp.content.ContentIds) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) Test(org.junit.jupiter.api.Test)

Example 2 with DeleteContentParams

use of com.enonic.xp.content.DeleteContentParams in project xp by enonic.

the class ContentServiceImplTest_delete method create_delete_published_content.

@Test
public void create_delete_published_content() throws Exception {
    final Content content = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").name("myContent").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build());
    refresh();
    final PublishContentResult result = this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).build());
    assertEquals(1, result.getPushedContents().getSize());
    // Deletes the content
    final DeleteContentParams deleteContentParams = DeleteContentParams.create().contentPath(content.getPath()).build();
    final DeleteContentsResult deletedContents = this.contentService.deleteWithoutFetch(deleteContentParams);
    assertNotNull(deletedContents);
    assertEquals(1, deletedContents.getPendingContents().getSize());
    for (ContentId deletedContent : deletedContents.getPendingContents()) {
        assertTrue(NodeState.PENDING_DELETE == this.nodeService.getById(NodeId.from(deletedContent)).getNodeState());
    }
    // Checks that the content is marked for deletion
    final Content foundContent = this.contentService.getById(content.getId());
    assertTrue(ContentState.PENDING_DELETE == foundContent.getContentState());
}
Also used : DeleteContentParams(com.enonic.xp.content.DeleteContentParams) PublishContentResult(com.enonic.xp.content.PublishContentResult) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentId(com.enonic.xp.content.ContentId) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) Test(org.junit.jupiter.api.Test)

Example 3 with DeleteContentParams

use of com.enonic.xp.content.DeleteContentParams in project xp by enonic.

the class ContentServiceImplTest_delete method create_delete_published_content_with_children.

@Test
public void create_delete_published_content_with_children() throws Exception {
    // Creates a content with children
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Root Content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    final CreateContentParams createChild1ContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Child1 Content").parent(content.getPath()).type(ContentTypeName.folder()).build();
    final Content child1Content = this.contentService.create(createChild1ContentParams);
    final CreateContentParams createChild2ContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Child2 Content").parent(content.getPath()).type(ContentTypeName.folder()).build();
    final Content child2Content = this.contentService.create(createChild2ContentParams);
    final CreateContentParams createSubChildContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("SubChild Content").parent(child1Content.getPath()).type(ContentTypeName.folder()).build();
    final Content subChildContent = this.contentService.create(createSubChildContentParams);
    // Publishes the content
    final PushContentParams pushParams = PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).build();
    refresh();
    this.contentService.publish(pushParams);
    // Deletes the content
    final DeleteContentParams deleteContentParams = DeleteContentParams.create().contentPath(content.getPath()).build();
    final DeleteContentsResult deletedContents = this.contentService.deleteWithoutFetch(deleteContentParams);
    assertNotNull(deletedContents);
    assertEquals(4, deletedContents.getPendingContents().getSize());
    // Checks that the content and children are marked for deletion
    final ContentIds contentIds = ContentIds.from(content.getId(), child1Content.getId(), child2Content.getId(), subChildContent.getId());
    final GetContentByIdsParams getContentByIdsParams = new GetContentByIdsParams(contentIds);
    final Contents foundContents = this.contentService.getByIds(getContentByIdsParams);
    assertEquals(4, foundContents.getSize());
    for (Content foundContent : foundContents) {
        assertTrue(ContentState.PENDING_DELETE == foundContent.getContentState());
    }
}
Also used : DeleteContentParams(com.enonic.xp.content.DeleteContentParams) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) Contents(com.enonic.xp.content.Contents) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentIds(com.enonic.xp.content.ContentIds) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) PushContentParams(com.enonic.xp.content.PushContentParams) Test(org.junit.jupiter.api.Test)

Example 4 with DeleteContentParams

use of com.enonic.xp.content.DeleteContentParams in project xp by enonic.

the class ContentServiceImplTest_delete method audit_data.

@Test
public void audit_data() {
    final ArgumentCaptor<LogAuditLogParams> captor = ArgumentCaptor.forClass(LogAuditLogParams.class);
    // Creates a content with children
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Root Content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    final CreateContentParams createChild1ContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Child1 Content").parent(content.getPath()).type(ContentTypeName.folder()).build();
    this.contentService.create(createChild1ContentParams);
    final DeleteContentParams deleteContentParams = DeleteContentParams.create().contentPath(content.getPath()).build();
    this.contentService.deleteWithoutFetch(deleteContentParams);
    Mockito.verify(auditLogService, Mockito.timeout(5000).times(3)).log(captor.capture());
    final PropertySet logResultSet = captor.getValue().getData().getSet("result");
    final Iterable<String> deletedContents = logResultSet.getStrings("deletedContents");
    assertEquals(2, StreamSupport.stream(deletedContents.spliterator(), false).count());
}
Also used : DeleteContentParams(com.enonic.xp.content.DeleteContentParams) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 5 with DeleteContentParams

use of com.enonic.xp.content.DeleteContentParams in project xp by enonic.

the class ContentServiceImplTest_publish method doDelete.

private void doDelete(final ContentPath f1Path, boolean instantly) {
    final DeleteContentParams deleteContentParams = DeleteContentParams.create().contentPath(f1Path).deleteOnline(instantly).build();
    this.contentService.deleteWithoutFetch(deleteContentParams);
}
Also used : DeleteContentParams(com.enonic.xp.content.DeleteContentParams)

Aggregations

DeleteContentParams (com.enonic.xp.content.DeleteContentParams)6 Content (com.enonic.xp.content.Content)4 PropertyTree (com.enonic.xp.data.PropertyTree)4 Test (org.junit.jupiter.api.Test)4 CreateContentParams (com.enonic.xp.content.CreateContentParams)3 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)3 ContentIds (com.enonic.xp.content.ContentIds)2 Contents (com.enonic.xp.content.Contents)2 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)2 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)1 ContentId (com.enonic.xp.content.ContentId)1 PublishContentResult (com.enonic.xp.content.PublishContentResult)1 PushContentParams (com.enonic.xp.content.PushContentParams)1 PropertySet (com.enonic.xp.data.PropertySet)1