Catalog alignment
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / auditing / impl / AuditingManagerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.openecomp.sdc.be.auditing.impl;
21
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;
33
34 import static org.hamcrest.CoreMatchers.is;
35 import static org.junit.Assert.assertThat;
36
37 @RunWith(MockitoJUnitRunner.class)
38 public class AuditingManagerTest {
39
40     private static final String MSG = "msg";
41     private String msg = "Any message";
42     private AuditingManager auditingManager;
43
44     @Mock
45     private AuditingGenericEvent auditEvent;
46     @Mock
47     private AuditCassandraDao cassandraDao;
48     @Mock
49     private AuditEventFactory eventFactory;
50
51     @Before
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);
57     }
58
59     @Test
60     public void testShouldAuditEvent() {
61         String result = auditingManager.auditEvent(eventFactory);
62         assertThat(result, is(msg));
63         Mockito.verify(cassandraDao).saveRecord(auditEvent);
64     }
65
66
67 }