Search in sources :

Example 6 with LogAuditLogParams

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

the class AuditLogServiceImplTest_find method find.

@Test
public void find() {
    LogAuditLogParams params = LogAuditLogParams.create().type("test").build();
    AuditLog log = logAsAdmin(params);
    FindAuditLogResult result = findAsAdmin(FindAuditLogParams.create().ids(AuditLogIds.from(log.getId())).build());
    assertEquals(1L, result.getCount());
    assertEquals(log, result.getHits().first());
}
Also used : LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) FindAuditLogResult(com.enonic.xp.audit.FindAuditLogResult) AuditLog(com.enonic.xp.audit.AuditLog) Test(org.junit.jupiter.api.Test)

Example 7 with LogAuditLogParams

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

the class AuditLogServiceImplTest_find method find_anonymous.

@Test
public void find_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();
    AuditLogContext.createAdminContext().runWith(() -> {
        LogAuditLogParams params = LogAuditLogParams.create().type("test").build();
        AuditLog log = auditLogService.log(params);
        context.runWith(() -> {
            FindAuditLogResult result = auditLogService.find(FindAuditLogParams.create().ids(AuditLogIds.from(log.getId())).build());
            assertEquals(0L, result.getCount());
        });
    });
}
Also used : AuditLogContext(com.enonic.xp.core.impl.audit.AuditLogContext) Context(com.enonic.xp.context.Context) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) FindAuditLogResult(com.enonic.xp.audit.FindAuditLogResult) AuditLog(com.enonic.xp.audit.AuditLog) Test(org.junit.jupiter.api.Test)

Example 8 with LogAuditLogParams

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

the class AuditLogServiceImplTest_find method find_none.

@Test
public void find_none() {
    LogAuditLogParams params = LogAuditLogParams.create().type("test").build();
    logAsAdmin(params);
    FindAuditLogResult result = findAsAdmin(FindAuditLogParams.create().build());
    assertEquals(1L, result.getCount());
}
Also used : LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) FindAuditLogResult(com.enonic.xp.audit.FindAuditLogResult) Test(org.junit.jupiter.api.Test)

Example 9 with LogAuditLogParams

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

the class ContentServiceImplTest_applyPermissions method audit_data.

@Test
public void audit_data() throws Exception {
    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);
    final ApplyContentPermissionsParams applyParams = ApplyContentPermissionsParams.create().contentId(content.getId()).applyContentPermissionsListener(Mockito.mock(ApplyPermissionsListener.class)).build();
    final ApplyContentPermissionsResult result = this.contentService.applyPermissions(applyParams);
    Mockito.verify(auditLogService, Mockito.timeout(5000).times(2)).log(captor.capture());
    final PropertySet logResultSet = captor.getValue().getData().getSet("result");
    assertEquals(content.getPath().toString(), logResultSet.getStrings("succeedContents").iterator().next());
}
Also used : LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ApplyContentPermissionsParams(com.enonic.xp.content.ApplyContentPermissionsParams) PropertySet(com.enonic.xp.data.PropertySet) ApplyContentPermissionsResult(com.enonic.xp.content.ApplyContentPermissionsResult) Test(org.junit.jupiter.api.Test)

Example 10 with LogAuditLogParams

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

the class ContentServiceImplTest_duplicate method audit_data.

@Test
public void audit_data() throws Exception {
    final ArgumentCaptor<LogAuditLogParams> captor = ArgumentCaptor.forClass(LogAuditLogParams.class);
    final Content rootContent = createContent(ContentPath.ROOT);
    final Content childContent = createContent(rootContent.getPath());
    final Content duplicatedContent = doDuplicateContent(rootContent);
    Mockito.verify(auditLogService, Mockito.timeout(5000).times(3)).log(captor.capture());
    final PropertySet logResultSet = captor.getValue().getData().getSet("result");
    final Iterable<String> ids = logResultSet.getStrings("duplicatedContents");
    assertEquals(2, StreamSupport.stream(ids.spliterator(), false).count());
    assertTrue(StreamSupport.stream(ids.spliterator(), false).anyMatch(id -> id.equals(duplicatedContent.getId().toString())));
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) IdProviderKey(com.enonic.xp.security.IdProviderKey) DuplicateContentParams(com.enonic.xp.content.DuplicateContentParams) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ContextAccessor(com.enonic.xp.context.ContextAccessor) DuplicateContentsResult(com.enonic.xp.content.DuplicateContentsResult) StreamSupport(java.util.stream.StreamSupport) ContextBuilder(com.enonic.xp.context.ContextBuilder) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) PropertyTree(com.enonic.xp.data.PropertyTree) User(com.enonic.xp.security.User) ContentPropertyNames(com.enonic.xp.content.ContentPropertyNames) ContentPath(com.enonic.xp.content.ContentPath) PropertySet(com.enonic.xp.data.PropertySet) ContentInheritType(com.enonic.xp.content.ContentInheritType) Content(com.enonic.xp.content.Content) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeId(com.enonic.xp.node.NodeId) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) PrincipalKey(com.enonic.xp.security.PrincipalKey) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) Content(com.enonic.xp.content.Content) 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