use of com.enonic.xp.audit.LogAuditLogParams in project xp by enonic.
the class AuditLogServiceImplTest_log method log_anonymous.
@Test
public void log_anonymous() {
final Context context = ContextBuilder.create().repositoryId(AuditLogConstants.AUDIT_LOG_REPO_ID).branch(AuditLogConstants.AUDIT_LOG_BRANCH).authInfo(AuthenticationInfo.create().principals(PrincipalKey.ofAnonymous()).user(User.ANONYMOUS).build()).build();
assertThrows(NodeAccessException.class, () -> context.runWith(() -> {
LogAuditLogParams params = LogAuditLogParams.create().type("test").build();
auditLogService.log(params);
}));
}
use of com.enonic.xp.audit.LogAuditLogParams in project xp by enonic.
the class ContentServiceImplTest_create method audit_data.
@Test
public void audit_data() {
final ArgumentCaptor<LogAuditLogParams> captor = ArgumentCaptor.forClass(LogAuditLogParams.class);
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);
Mockito.verify(auditLogService, Mockito.timeout(5000).times(1)).log(captor.capture());
final PropertySet logResultSet = captor.getValue().getData().getSet("result");
assertEquals(content.getId().toString(), logResultSet.getString("id"));
assertEquals(content.getPath().toString(), logResultSet.getString("path"));
}
use of com.enonic.xp.audit.LogAuditLogParams in project xp by enonic.
the class ScheduleAuditLogSupportImpl method log.
private void log(final String type, final PropertyTree data, final AuditLogUris uris, final Context rootContext) {
final PrincipalKey userPrincipalKey = rootContext.getAuthInfo().getUser() != null ? rootContext.getAuthInfo().getUser().getKey() : PrincipalKey.ofAnonymous();
final LogAuditLogParams logParams = LogAuditLogParams.create().type(type).source(SOURCE_CORE_CONTENT).data(data).objectUris(uris).user(userPrincipalKey).build();
runAsAuditLog(() -> auditLogService.log(logParams), rootContext);
}
use of com.enonic.xp.audit.LogAuditLogParams in project xp by enonic.
the class AuditLogServiceImplTest_log method get.
@Test
public void get() {
final LogAuditLogParams params = LogAuditLogParams.create().type("test").build();
final AuditLog log1 = AuditLogContext.createAdminContext().callWith(() -> auditLogService.log(params));
final AuditLog log2 = AuditLogContext.createAdminContext().callWith(() -> auditLogService.get(log1.getId()));
assertEquals(log1, log2);
}
use of com.enonic.xp.audit.LogAuditLogParams 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());
}
Aggregations