2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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=========================================================
21 package org.openecomp.sdc.be.components.impl;
23 import com.google.common.collect.ImmutableList;
24 import fj.data.Either;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.junit.MockitoJUnitRunner;
30 import org.openecomp.sdc.be.dao.api.ActionStatus;
31 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
32 import org.openecomp.sdc.be.impl.ComponentsUtils;
33 import org.openecomp.sdc.be.model.Component;
34 import org.openecomp.sdc.be.model.ComponentParametersView;
35 import org.openecomp.sdc.be.model.User;
36 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArchiveOperation;
37 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
38 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
39 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
40 import org.openecomp.sdc.exception.ResponseFormat;
42 import java.util.Arrays;
43 import java.util.List;
45 import static org.mockito.ArgumentMatchers.any;
46 import static org.mockito.ArgumentMatchers.eq;
47 import static org.mockito.Mockito.times;
48 import static org.mockito.Mockito.verify;
49 import static org.mockito.Mockito.when;
51 @RunWith(MockitoJUnitRunner.class)
52 public class ArchiveBusinessLogicTest {
54 private ComponentsUtils componentsUtils;
56 private ToscaOperationFacade toscaOperationFacade;
60 private ResponseFormat responseFormat;
62 private Component component;
65 private ArchiveBusinessLogic archiveBusinessLogic;
68 public void auditLastComponentVersionOnlyAndIgnorePreviousVersions() {
69 List<String> archivedCompIds = Arrays.asList("1", "2", "3", "4", "5");
70 when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class)))
71 .thenReturn(Either.left(component));
72 when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
73 when(component.getUUID())
80 archiveBusinessLogic.auditAction(ArchiveOperation.Action.ARCHIVE, archivedCompIds, user, ComponentTypeEnum.RESOURCE_PARAM_NAME);
81 verify(componentsUtils, times(3)).auditComponentAdmin(eq(responseFormat), eq(user), eq(component),
82 eq(AuditingActionEnum.ARCHIVE_COMPONENT), eq(ComponentTypeEnum.RESOURCE), any(String.class));
87 public void auditLastComponentVersionOnly() {
88 List<String> archivedCompIds = Arrays.asList("1", "2", "3", "4", "5");
89 when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class)))
90 .thenReturn(Either.left(component));
91 when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
92 when(component.getUUID())
99 archiveBusinessLogic.auditAction(ArchiveOperation.Action.RESTORE, archivedCompIds, user, ComponentTypeEnum.RESOURCE_PARAM_NAME);
100 verify(componentsUtils, times(5)).auditComponentAdmin(eq(responseFormat), eq(user), eq(component),
101 eq(AuditingActionEnum.RESTORE_COMPONENT), eq(ComponentTypeEnum.RESOURCE), any(String.class));
106 public void noAuditDoneForEmptyList() {
107 List<String> archivedCompIds = ImmutableList.of();
108 archiveBusinessLogic.auditAction(ArchiveOperation.Action.RESTORE, archivedCompIds, user, ComponentTypeEnum.RESOURCE_PARAM_NAME);
109 verify(componentsUtils, times(0)).auditComponentAdmin(any(ResponseFormat.class), any(User.class), any(Component.class),
110 any(AuditingActionEnum.class), any(ComponentTypeEnum.class), any(String.class));
115 public void noAuditOnErrorGetElementResponse() {
116 List<String> archivedCompIds = Arrays.asList("1", "2", "3", "4", "5");
117 when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class)))
118 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
119 archiveBusinessLogic.auditAction(ArchiveOperation.Action.RESTORE, archivedCompIds, user, ComponentTypeEnum.RESOURCE_PARAM_NAME);
120 verify(componentsUtils, times(0)).auditComponentAdmin(any(ResponseFormat.class), any(User.class), any(Component.class),
121 any(AuditingActionEnum.class), any(ComponentTypeEnum.class), any(String.class));