2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T 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=========================================================
19 * Modifications copyright (c) 2019 Nokia
20 * ================================================================================
22 package org.openecomp.sdc.be.auditing.impl.category;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.ArgumentCaptor;
28 import org.mockito.Captor;
29 import org.mockito.Mock;
30 import org.mockito.junit.MockitoJUnitRunner;
31 import org.openecomp.sdc.be.auditing.api.AuditEventFactory;
32 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
33 import org.openecomp.sdc.be.config.Configuration;
34 import org.openecomp.sdc.be.dao.api.ActionStatus;
35 import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
36 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
37 import org.openecomp.sdc.be.dao.impl.AuditingDao;
38 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
39 import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
40 import org.openecomp.sdc.be.resources.data.auditing.GetCategoryHierarchyEvent;
41 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
42 import org.openecomp.sdc.test.utils.TestConfigurationProvider;
44 import static org.assertj.core.api.Assertions.assertThat;
45 import static org.mockito.ArgumentMatchers.any;
46 import static org.mockito.ArgumentMatchers.eq;
47 import static org.mockito.Mockito.verify;
48 import static org.mockito.Mockito.when;
49 import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.*;
51 @RunWith(MockitoJUnitRunner.class)
52 public class AuditGetCategoryHierarchyEventTest {
54 private static AuditCassandraDao cassandraDao;
56 private ArgumentCaptor<GetCategoryHierarchyEvent> eventCaptor;
58 private static AuditingDao auditingDao;
60 private Configuration.ElasticSearchConfig esConfig;
62 private AuditingManager auditingManager;
67 auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
71 public void testNewGetCategoryHierarchyEvent() {
72 AuditEventFactory factory = new AuditGetCategoryHierarchyEventFactory(
73 CommonAuditData.newBuilder()
74 .description(DESCRIPTION)
76 .requestId(REQUEST_ID)
79 when(auditingDao.addRecord(any(AuditingGenericEvent.class), eq(AuditingActionEnum.GET_CATEGORY_HIERARCHY.getAuditingEsType())))
80 .thenReturn(ActionStatus.OK);
81 when(cassandraDao.saveRecord(any(AuditingGenericEvent.class))).thenReturn(CassandraOperationStatus.OK);
83 assertThat(auditingManager.auditEvent(factory)).isEqualTo(EXPECTED_GET_CATEGORY_HIERARCHY_LOG_STR);
87 private void verifyEvent() {
88 verify(cassandraDao).saveRecord(eventCaptor.capture());
89 GetCategoryHierarchyEvent storedEvent = eventCaptor.getValue();
90 assertThat(storedEvent.getModifier()).isEqualTo(USER_UID);
91 assertThat(storedEvent.getStatus()).isEqualTo(STATUS_OK);
92 assertThat(storedEvent.getDesc()).isEqualTo(DESCRIPTION);
93 assertThat(storedEvent.getDetails()).isEqualTo(USER_DETAILS);
94 assertThat(storedEvent.getRequestId()).isNotBlank();
95 assertThat(storedEvent.getServiceInstanceId()).isNull();
96 assertThat(storedEvent.getAction()).isEqualTo(AuditingActionEnum.GET_CATEGORY_HIERARCHY.getName());