Search in sources :

Example 1 with AuditLog

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

the class CreateAuditLogHandlerTest method mockCreateLog.

public void mockCreateLog() {
    PropertyTree data = new PropertyTree();
    data.setString("custom", "string");
    data.addDouble("somevalue", 2.5);
    AuditLog mocklog1 = auditLogBuilder(LogAuditLogParams.create().type("testlog").build()).source("testbundle").build();
    AuditLog mocklog2 = auditLogBuilder(LogAuditLogParams.create().type("testlog").source("testbundle").user(PrincipalKey.ofAnonymous()).objectUris(AuditLogUris.from("some:resource:uri")).data(data).build()).build();
    Mockito.when(this.auditLogService.log(Mockito.any(LogAuditLogParams.class))).thenReturn(mocklog1).thenReturn(mocklog2);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) AuditLog(com.enonic.xp.audit.AuditLog)

Example 2 with AuditLog

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

the class FindAuditLogCommand method runQuery.

private FindAuditLogResult runQuery() {
    final NodeQuery query = createQuery();
    if (query == null) {
        return FindAuditLogResult.empty();
    }
    FindNodesByQueryResult result = nodeService.findByQuery(query);
    List<AuditLog> logs = result.getNodeIds().stream().map(nodeService::getById).map(AuditLogSerializer::fromNode).collect(Collectors.toList());
    return FindAuditLogResult.create().total(result.getTotalHits()).hits(AuditLogs.from(logs)).build();
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) AuditLog(com.enonic.xp.audit.AuditLog)

Example 3 with AuditLog

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

the class AuditLogServiceImplTest method get_by_id.

@Test
public void get_by_id() {
    AuditLog log = auditLogService.get(new AuditLogId());
    assertLog(log);
}
Also used : AuditLogId(com.enonic.xp.audit.AuditLogId) AuditLog(com.enonic.xp.audit.AuditLog) Test(org.junit.jupiter.api.Test)

Example 4 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 5 with AuditLog

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

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