View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.wa.starter.events;
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.util.Map;
27  import org.apache.syncope.common.lib.audit.AuditEntry;
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.cas.support.events.CasEventRepositoryFilter;
32  import org.apereo.cas.support.events.dao.CasEvent;
33  import org.junit.jupiter.api.Test;
34  
35  public class WAEventRepositoryTest 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 saveInternal() {
51          CasEvent event = new CasEvent(1L, "Auth", "principalId", "creationTime", Map.of("timestamp", "1"));
52          WAEventRepository eventRepository =
53                  new WAEventRepository(CasEventRepositoryFilter.noOp(), getWaRestClient());
54          eventRepository.saveInternal(event);
55          verify(AUDIT_SERVICE).create(any(AuditEntry.class));
56      }
57  }