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()));
}
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());
}
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);
});
}
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());
}
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());
}
Aggregations