Search in sources :

Example 6 with AuditLog

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

the class AuditLogServiceImplTest_find method find_type.

@Test
public void find_type() {
    AuditLog log1 = logAsAdmin(LogAuditLogParams.create().type("type1").build());
    AuditLog log2 = logAsAdmin(LogAuditLogParams.create().type("type2").build());
    FindAuditLogResult result = findAsAdmin(FindAuditLogParams.create().type("type1").build());
    assertEquals(1L, result.getCount());
    assertEquals(log1, result.getHits().first());
    result = findAsAdmin(FindAuditLogParams.create().type("type2").build());
    assertEquals(1L, result.getCount());
    assertEquals(log2, result.getHits().first());
}
Also used : FindAuditLogResult(com.enonic.xp.audit.FindAuditLogResult) AuditLog(com.enonic.xp.audit.AuditLog) Test(org.junit.jupiter.api.Test)

Example 7 with AuditLog

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

the class AuditLogServiceImplTest_find method find_to.

@Test
public void find_to() {
    AuditLog log = logAsAdmin(LogAuditLogParams.create().type("test").time(Instant.now()).build());
    FindAuditLogResult result = findAsAdmin(FindAuditLogParams.create().to(Instant.now().minus(30, ChronoUnit.DAYS)).build());
    assertEquals(0L, result.getCount());
    result = findAsAdmin(FindAuditLogParams.create().to(Instant.now()).build());
    assertEquals(1L, result.getCount());
    assertEquals(log, result.getHits().first());
}
Also used : FindAuditLogResult(com.enonic.xp.audit.FindAuditLogResult) AuditLog(com.enonic.xp.audit.AuditLog) Test(org.junit.jupiter.api.Test)

Example 8 with AuditLog

use of com.enonic.xp.audit.AuditLog 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 9 with AuditLog

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

the class AuditLogServiceImplTest_find method find_source.

@Test
public void find_source() {
    AuditLog log1 = logAsAdmin(LogAuditLogParams.create().type("test").source("source1").build());
    AuditLog log2 = logAsAdmin(LogAuditLogParams.create().type("test").source("source2").build());
    FindAuditLogResult result = findAsAdmin(FindAuditLogParams.create().source("source1").build());
    assertEquals(1L, result.getCount());
    assertEquals(log1, result.getHits().first());
    result = findAsAdmin(FindAuditLogParams.create().source("source2").build());
    assertEquals(1L, result.getCount());
    assertEquals(log2, result.getHits().first());
}
Also used : FindAuditLogResult(com.enonic.xp.audit.FindAuditLogResult) AuditLog(com.enonic.xp.audit.AuditLog) Test(org.junit.jupiter.api.Test)

Example 10 with AuditLog

use of com.enonic.xp.audit.AuditLog 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);
}
Also used : LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) AuditLog(com.enonic.xp.audit.AuditLog) Test(org.junit.jupiter.api.Test)

Aggregations

AuditLog (com.enonic.xp.audit.AuditLog)14 Test (org.junit.jupiter.api.Test)10 FindAuditLogResult (com.enonic.xp.audit.FindAuditLogResult)6 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)3 AuditLogId (com.enonic.xp.audit.AuditLogId)2 FindAuditLogParams (com.enonic.xp.audit.FindAuditLogParams)1 Context (com.enonic.xp.context.Context)1 AuditLogContext (com.enonic.xp.core.impl.audit.AuditLogContext)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)1 NodeQuery (com.enonic.xp.node.NodeQuery)1