Search in sources :

Example 21 with LogAuditLogParams

use of com.enonic.xp.audit.LogAuditLogParams 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)

Example 22 with LogAuditLogParams

use of com.enonic.xp.audit.LogAuditLogParams in project xp by enonic.

the class ContentServiceImplTest_unpublish method audit_data.

@Test
public void audit_data() throws Exception {
    final ArgumentCaptor<LogAuditLogParams> captor = ArgumentCaptor.forClass(LogAuditLogParams.class);
    final Content content = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build());
    this.contentService.publish(PushContentParams.create().target(ContentConstants.BRANCH_MASTER).contentIds(ContentIds.from(content.getId())).build());
    final Context masterContext = ContextBuilder.from(ContextAccessor.current()).branch(ContentConstants.BRANCH_MASTER).build();
    assertTrue(masterContext.callWith(() -> contentService.contentExists(content.getId())));
    this.contentService.unpublishContent(UnpublishContentParams.create().contentIds(ContentIds.from(content.getId())).unpublishBranch(ContentConstants.BRANCH_MASTER).build());
    Mockito.verify(auditLogService, Mockito.timeout(5000).times(3)).log(captor.capture());
    final PropertySet logResultSet = captor.getValue().getData().getSet("result");
    assertEquals(content.getId().toString(), logResultSet.getStrings("unpublishedContents").iterator().next());
}
Also used : Context(com.enonic.xp.context.Context) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Aggregations

LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)22 Test (org.junit.jupiter.api.Test)20 Content (com.enonic.xp.content.Content)12 PropertyTree (com.enonic.xp.data.PropertyTree)12 PropertySet (com.enonic.xp.data.PropertySet)10 Context (com.enonic.xp.context.Context)8 CreateContentParams (com.enonic.xp.content.CreateContentParams)7 PrincipalKey (com.enonic.xp.security.PrincipalKey)6 User (com.enonic.xp.security.User)5 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)5 AuditLog (com.enonic.xp.audit.AuditLog)3 FindAuditLogResult (com.enonic.xp.audit.FindAuditLogResult)3 ContextBuilder (com.enonic.xp.context.ContextBuilder)3 CronCalendarImpl (com.enonic.xp.impl.scheduler.distributed.CronCalendarImpl)3 DescriptorKey (com.enonic.xp.page.DescriptorKey)3 CreateScheduledJobParams (com.enonic.xp.scheduler.CreateScheduledJobParams)3 ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)3 IdProviderKey (com.enonic.xp.security.IdProviderKey)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)3