2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.sdc.be.auditing.impl;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.Mock;
26 import org.mockito.Mockito;
27 import org.mockito.junit.MockitoJUnitRunner;
28 import org.openecomp.sdc.be.auditing.api.AuditEventFactory;
29 import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
30 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
31 import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
32 import org.openecomp.sdc.test.utils.TestConfigurationProvider;
34 import static org.hamcrest.CoreMatchers.is;
35 import static org.junit.Assert.assertThat;
37 @RunWith(MockitoJUnitRunner.class)
38 public class AuditingManagerTest {
40 private static final String MSG = "msg";
41 private String msg = "Any message";
42 private AuditingManager auditingManager;
45 private AuditingGenericEvent auditEvent;
47 private AuditCassandraDao cassandraDao;
49 private AuditEventFactory eventFactory;
52 public void setUp() throws Exception {
53 auditingManager = new AuditingManager(cassandraDao, new TestConfigurationProvider());
54 Mockito.when(eventFactory.getLogMessage()).thenReturn(msg);
55 Mockito.when(eventFactory.getDbEvent()).thenReturn(auditEvent);
56 Mockito.when(cassandraDao.saveRecord(auditEvent)).thenReturn(CassandraOperationStatus.OK);
60 public void testShouldAuditEvent() {
61 String result = auditingManager.auditEvent(eventFactory);
62 assertThat(result, is(msg));
63 Mockito.verify(cassandraDao).saveRecord(auditEvent);