1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.wa.starter.audit;
20
21 import static org.mockito.ArgumentMatchers.any;
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.verify;
24 import static org.mockito.Mockito.when;
25
26 import java.time.LocalDateTime;
27 import org.apache.syncope.common.lib.to.AuditEventTO;
28 import org.apache.syncope.common.rest.api.service.AuditService;
29 import org.apache.syncope.wa.bootstrap.WARestClient;
30 import org.apache.syncope.wa.starter.AbstractTest;
31 import org.apereo.inspektr.audit.AuditActionContext;
32 import org.apereo.inspektr.common.web.ClientInfo;
33 import org.junit.jupiter.api.Test;
34
35 public class WAAuditTrailManagerTest extends AbstractTest {
36
37 private static AuditService AUDIT_SERVICE;
38
39 private static WARestClient getWaRestClient() {
40 AUDIT_SERVICE = mock(AuditService.class);
41
42 WARestClient waRestClient = mock(WARestClient.class);
43 when(waRestClient.isReady()).thenReturn(Boolean.TRUE);
44 when(waRestClient.getService(AuditService.class)).thenReturn(AUDIT_SERVICE);
45
46 return waRestClient;
47 }
48
49 @Test
50 public void saveAuditRecord() {
51 AuditActionContext audit = new AuditActionContext(
52 "principal", "resourceOperatedUpon", "actionPerformed", "applicationCode",
53 LocalDateTime.now(),
54 new ClientInfo("clientIpAddress", "serverIpAddress", "userAgent", null));
55 WAAuditTrailManager auditTrailManager = new WAAuditTrailManager(getWaRestClient());
56 auditTrailManager.saveAuditRecord(audit);
57 verify(AUDIT_SERVICE).create(any(AuditEventTO.class));
58 }
59 }