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.dao.cassandra.AuditCassandraDao;
34 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
35 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
36 import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
37 import org.openecomp.sdc.be.resources.data.auditing.CategoryEvent;
38 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
39 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
40 import org.openecomp.sdc.test.utils.TestConfigurationProvider;
42 import static org.assertj.core.api.Assertions.assertThat;
43 import static org.mockito.ArgumentMatchers.any;
44 import static org.mockito.Mockito.verify;
45 import static org.mockito.Mockito.when;
46 import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.CATEGORY;
47 import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.DESCRIPTION;
48 import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.EXPECTED_ADD_CATEGORY_LOG_STR;
49 import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.GROUPING_NAME;
50 import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.MODIFIER_UID;
51 import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.REQUEST_ID;
52 import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.RESOURCE_TYPE;
53 import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.SERVICE_INSTANCE_ID;
54 import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.STATUS_OK;
55 import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.SUB_CATEGORY;
56 import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.init;
57 import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.modifier;
59 @RunWith(MockitoJUnitRunner.class)
60 public class AuditCategoryEventFuncTest {
61 private AuditingManager auditingManager;
64 private static AuditCassandraDao cassandraDao;
67 private ArgumentCaptor<CategoryEvent> eventCaptor;
72 auditingManager = new AuditingManager(cassandraDao, new TestConfigurationProvider());
73 ThreadLocalsHolder.setUuid(REQUEST_ID);
77 public void testAddCategoryEvent() {
78 AuditEventFactory builder = new AuditCategoryEventFactory(
79 AuditingActionEnum.ADD_CATEGORY,
80 CommonAuditData.newBuilder()
81 .description(DESCRIPTION)
83 .requestId(REQUEST_ID)
84 .serviceInstanceId(SERVICE_INSTANCE_ID)
86 modifier, CATEGORY, SUB_CATEGORY, GROUPING_NAME, RESOURCE_TYPE);
88 when(cassandraDao.saveRecord(any(AuditingGenericEvent.class))).thenReturn(CassandraOperationStatus.OK);
90 assertThat(auditingManager.auditEvent(builder)).isEqualTo(EXPECTED_ADD_CATEGORY_LOG_STR);
91 verifyCategoryEvent(AuditingActionEnum.ADD_CATEGORY.getName());
94 private void verifyCategoryEvent(String action) {
95 verify(cassandraDao).saveRecord(eventCaptor.capture());
96 CategoryEvent storedEvent = eventCaptor.getValue();
97 assertThat(storedEvent.getModifier()).isEqualTo(MODIFIER_UID);
98 assertThat(storedEvent.getDesc()).isEqualTo(DESCRIPTION);
99 assertThat(storedEvent.getStatus()).isEqualTo(STATUS_OK);
100 assertThat(storedEvent.getRequestId()).isEqualTo(REQUEST_ID);
101 assertThat(storedEvent.getServiceInstanceId()).isEqualTo(SERVICE_INSTANCE_ID);
102 assertThat(storedEvent.getAction()).isEqualTo(action);
103 assertThat(storedEvent.getCategoryName()).isEqualTo(CATEGORY);
104 assertThat(storedEvent.getSubCategoryName()).isEqualTo(SUB_CATEGORY);
105 assertThat(storedEvent.getGroupingName()).isEqualTo(GROUPING_NAME);
106 assertThat(storedEvent.getResourceType()).isEqualTo(RESOURCE_TYPE);