Search in sources :

Example 46 with CreateContentParams

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

the class ContentServiceImplTest_applyPermissions method success.

@Test
public void success() throws Exception {
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    final Content child = this.contentService.create(CreateContentParams.create(createContentParams).parent(content.getPath()).build());
    final ApplyContentPermissionsParams applyParams = ApplyContentPermissionsParams.create().contentId(content.getId()).applyContentPermissionsListener(Mockito.mock(ApplyPermissionsListener.class)).build();
    final ApplyContentPermissionsResult result = this.contentService.applyPermissions(applyParams);
    assertEquals(result.getSkippedContents().getSize(), 0);
    assertEquals(result.getSucceedContents().getSize(), 2);
    assertTrue(result.getSucceedContents().contains(child.getPath()));
    assertTrue(result.getSucceedContents().contains(content.getPath()));
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ApplyContentPermissionsParams(com.enonic.xp.content.ApplyContentPermissionsParams) ApplyContentPermissionsResult(com.enonic.xp.content.ApplyContentPermissionsResult) Test(org.junit.jupiter.api.Test)

Example 47 with CreateContentParams

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

the class ContentServiceImplTest_create method create_with_root_language.

@Test
public void create_with_root_language() throws Exception {
    final Content root = this.contentService.getByPath(ContentPath.ROOT);
    contentService.update(new UpdateContentParams().contentId(root.getId()).modifier(ContextAccessor.current().getAuthInfo().getUser().getKey()).editor(edit -> edit.language = Locale.ENGLISH));
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    final Content storedContent = this.contentService.getById(content.getId());
    assertEquals(Locale.ENGLISH, storedContent.getLanguage());
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContentConstants(com.enonic.xp.content.ContentConstants) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) WorkflowState(com.enonic.xp.content.WorkflowState) ArgumentCaptor(org.mockito.ArgumentCaptor) ContextAccessor(com.enonic.xp.context.ContextAccessor) Locale(java.util.Locale) WorkflowCheckState(com.enonic.xp.content.WorkflowCheckState) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) PropertyTree(com.enonic.xp.data.PropertyTree) CreateSiteParams(com.enonic.xp.site.CreateSiteParams) ContentPath(com.enonic.xp.content.ContentPath) PropertySet(com.enonic.xp.data.PropertySet) Content(com.enonic.xp.content.Content) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) Instant(java.time.Instant) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) SiteConfigs(com.enonic.xp.site.SiteConfigs) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Attachments(com.enonic.xp.attachment.Attachments) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 48 with CreateContentParams

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

the class ContentServiceImplTest_create method create_incorrect_content.

@Test
public void create_incorrect_content() throws Exception {
    final PropertyTree contentData = new PropertyTree();
    contentData.addString("target", "aStringValue");
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(contentData).displayName("This is my shortcut").parent(ContentPath.ROOT).type(ContentTypeName.shortcut()).build();
    assertThrows(IllegalArgumentException.class, () -> {
        this.contentService.create(createContentParams);
    });
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 49 with CreateContentParams

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

the class ContentServiceImplTest_create method create_with_publish_info.

@Test
public void create_with_publish_info() throws Exception {
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).contentPublishInfo(ContentPublishInfo.create().from(Instant.parse("2016-11-03T10:42:00Z")).from(Instant.parse("2016-11-23T10:42:00Z")).build()).build();
    final Content content = this.contentService.create(createContentParams);
    assertNotNull(content.getPublishInfo());
    assertNotNull(content.getPublishInfo().getFrom());
    final Content storedContent = this.contentService.getById(content.getId());
    assertNotNull(storedContent.getPublishInfo());
    assertNotNull(storedContent.getPublishInfo().getFrom());
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 50 with CreateContentParams

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

the class ContentAuditLogSupportImplTest method testCreateContent.

@Test
public void testCreateContent() throws Exception {
    final PropertyTree propertyTree = new PropertyTree();
    propertyTree.addString("test-data", "test-data");
    final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.site()).parent(ContentPath.ROOT).contentData(propertyTree).displayName("displayName").build();
    final Content content = Content.create().id(ContentId.from("contentId")).type(ContentTypeName.site()).name("contentName").displayName("displayName").parentPath(ContentPath.ROOT).build();
    final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.system(), "testUser")).displayName("Test User").modifiedTime(Instant.now()).email("test-user@enonic.com").login("test-user").build();
    final AuthenticationInfo authInfo = AuthenticationInfo.create().user(user).principals(RoleKeys.ADMIN_LOGIN).build();
    final Context context = ContextBuilder.create().branch(ContentConstants.BRANCH_DRAFT).repositoryId(RepositoryId.from("test-repository")).authInfo(authInfo).build();
    // test
    context.runWith(() -> support.createContent(params, content));
    executor.shutdown();
    executor.awaitTermination(1, TimeUnit.MINUTES);
    // verify and assert
    final ArgumentCaptor<LogAuditLogParams> argumentCaptor = ArgumentCaptor.forClass(LogAuditLogParams.class);
    Mockito.verify(auditLogService, Mockito.times(1)).log(argumentCaptor.capture());
    Assertions.assertEquals(user.getKey(), argumentCaptor.getValue().getUser());
}
Also used : Context(com.enonic.xp.context.Context) User(com.enonic.xp.security.User) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) PropertyTree(com.enonic.xp.data.PropertyTree) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Test(org.junit.jupiter.api.Test)

Aggregations

CreateContentParams (com.enonic.xp.content.CreateContentParams)81 Test (org.junit.jupiter.api.Test)66 PropertyTree (com.enonic.xp.data.PropertyTree)63 Content (com.enonic.xp.content.Content)52 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)25 PropertySet (com.enonic.xp.data.PropertySet)14 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)11 ContentType (com.enonic.xp.schema.content.ContentType)10 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)9 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)9 PublishContentResult (com.enonic.xp.content.PublishContentResult)7 ProcessCreateResult (com.enonic.xp.content.processor.ProcessCreateResult)7 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)6 ExtraData (com.enonic.xp.content.ExtraData)6 ProcessCreateParams (com.enonic.xp.content.processor.ProcessCreateParams)6 Attachments (com.enonic.xp.attachment.Attachments)5 Node (com.enonic.xp.node.Node)5 ByteSource (com.google.common.io.ByteSource)5 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)4 ExtraDatas (com.enonic.xp.content.ExtraDatas)4