Search in sources :

Example 1 with ContentVersion

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

the class AbstractContentServiceTest method assertVersions.

protected void assertVersions(final ContentId contentId, final int expected) {
    FindContentVersionsResult versions = this.contentService.getVersions(FindContentVersionsParams.create().contentId(contentId).build());
    assertEquals(expected, versions.getHits());
    final Iterator<ContentVersion> iterator = versions.getContentVersions().iterator();
    Instant lastModified = null;
    while (iterator.hasNext()) {
        final ContentVersion next = iterator.next();
        if (lastModified != null) {
            assertFalse(next.getModified().isAfter(lastModified));
        }
        lastModified = next.getModified();
    }
}
Also used : ContentVersion(com.enonic.xp.content.ContentVersion) FindContentVersionsResult(com.enonic.xp.content.FindContentVersionsResult) Instant(java.time.Instant)

Example 2 with ContentVersion

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

the class ContentServiceImplTest_publish method publish_with_message_no_message.

@Test
public void publish_with_message_no_message() {
    final Content content = createContent(ContentPath.ROOT, "a");
    this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).message(null).build());
    FindContentVersionsResult versions = this.contentService.getVersions(FindContentVersionsParams.create().contentId(content.getId()).build());
    Iterator<ContentVersion> iterator = versions.getContentVersions().iterator();
    assertTrue(iterator.hasNext());
    ContentVersion version = iterator.next();
    assertNotNull(version.getPublishInfo().getTimestamp());
    assertEquals("user:system:test-user", version.getPublishInfo().getPublisher().toString());
    assertNull(version.getPublishInfo().getMessage());
}
Also used : Content(com.enonic.xp.content.Content) ContentVersion(com.enonic.xp.content.ContentVersion) FindContentVersionsResult(com.enonic.xp.content.FindContentVersionsResult) Test(org.junit.jupiter.api.Test)

Example 3 with ContentVersion

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

the class ContentServiceImplTest_versions method get_published_versions.

@Test
public void get_published_versions() throws Exception {
    final Content content = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("content").parent(ContentPath.ROOT).name("myContent").type(ContentTypeName.folder()).build());
    this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).build());
    this.contentService.unpublishContent(UnpublishContentParams.create().contentIds(ContentIds.from(content.getId())).unpublishBranch(WS_OTHER).build());
    final FindContentVersionsResult result = this.contentService.getVersions(FindContentVersionsParams.create().contentId(content.getId()).build());
    assertEquals(3, result.getHits());
    assertEquals(3, result.getTotalHits());
    final Iterator<ContentVersion> versions = result.getContentVersions().iterator();
    assertNotNull(versions.next().getPublishInfo());
    assertNotNull(versions.next().getPublishInfo());
    assertNull(versions.next().getPublishInfo());
}
Also used : Content(com.enonic.xp.content.Content) ContentVersion(com.enonic.xp.content.ContentVersion) PropertyTree(com.enonic.xp.data.PropertyTree) FindContentVersionsResult(com.enonic.xp.content.FindContentVersionsResult) Test(org.junit.jupiter.api.Test)

Example 4 with ContentVersion

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

the class ContentServiceImplTest_versions method version_workflow_info.

@Test
public void version_workflow_info() throws Exception {
    final Map<String, WorkflowCheckState> checks = Map.of("checkName1", WorkflowCheckState.APPROVED, "checkName2", WorkflowCheckState.PENDING);
    final WorkflowInfo workflowInfo = WorkflowInfo.create().state(WorkflowState.IN_PROGRESS).checks(checks).build();
    final Content content = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my test content").parent(ContentPath.ROOT).name("myContent").type(ContentTypeName.folder()).workflowInfo(workflowInfo).build());
    final FindContentVersionsResult versions = this.contentService.getVersions(FindContentVersionsParams.create().contentId(content.getId()).build());
    final ContentVersion contentVersion = versions.getContentVersions().iterator().next();
    final WorkflowInfo retrievedWorkflowInfo = contentVersion.getWorkflowInfo();
    assertEquals(WorkflowState.IN_PROGRESS, retrievedWorkflowInfo.getState());
    assertEquals(WorkflowCheckState.APPROVED, retrievedWorkflowInfo.getChecks().get("checkName1"));
    assertEquals(WorkflowCheckState.PENDING, retrievedWorkflowInfo.getChecks().get("checkName2"));
}
Also used : Content(com.enonic.xp.content.Content) ContentVersion(com.enonic.xp.content.ContentVersion) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) PropertyTree(com.enonic.xp.data.PropertyTree) FindContentVersionsResult(com.enonic.xp.content.FindContentVersionsResult) WorkflowCheckState(com.enonic.xp.content.WorkflowCheckState) Test(org.junit.jupiter.api.Test)

Example 5 with ContentVersion

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

the class ContentServiceImplTest_publish method publish_with_message.

@Test
public void publish_with_message() {
    final Content content = createContent(ContentPath.ROOT, "a");
    this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).message("My message").build());
    FindContentVersionsResult versions = this.contentService.getVersions(FindContentVersionsParams.create().contentId(content.getId()).build());
    Iterator<ContentVersion> iterator = versions.getContentVersions().iterator();
    assertTrue(iterator.hasNext());
    ContentVersion version = iterator.next();
    assertNotNull(version.getPublishInfo().getTimestamp());
    assertEquals("user:system:test-user", version.getPublishInfo().getPublisher().toString());
    assertEquals("My message", version.getPublishInfo().getMessage());
}
Also used : Content(com.enonic.xp.content.Content) ContentVersion(com.enonic.xp.content.ContentVersion) FindContentVersionsResult(com.enonic.xp.content.FindContentVersionsResult) Test(org.junit.jupiter.api.Test)

Aggregations

ContentVersion (com.enonic.xp.content.ContentVersion)7 FindContentVersionsResult (com.enonic.xp.content.FindContentVersionsResult)6 Content (com.enonic.xp.content.Content)5 Test (org.junit.jupiter.api.Test)5 PropertyTree (com.enonic.xp.data.PropertyTree)3 ContentVersions (com.enonic.xp.content.ContentVersions)1 WorkflowCheckState (com.enonic.xp.content.WorkflowCheckState)1 WorkflowInfo (com.enonic.xp.content.WorkflowInfo)1 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)1 Instant (java.time.Instant)1