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.*;
49 @RunWith(MockitoJUnitRunner.class)
50 public class ArchiveBusinessLogicTest {
52 private ComponentsUtils componentsUtils;
54 private ToscaOperationFacade toscaOperationFacade;
58 private ResponseFormat responseFormat;
60 private Component component;
63 private ArchiveBusinessLogic archiveBusinessLogic;
66 public void auditLastComponentVersionOnlyAndIgnorePreviousVersions() {
67 List<String> archivedCompIds = Arrays.asList("1", "2", "3", "4", "5");
68 when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class)))
69 .thenReturn(Either.left(component));
70 when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
71 when(component.getUUID())
78 archiveBusinessLogic.auditAction(ArchiveOperation.Action.ARCHIVE, archivedCompIds, user, ComponentTypeEnum.RESOURCE_PARAM_NAME);
79 verify(componentsUtils, times(3)).auditComponentAdmin(eq(responseFormat), eq(user), eq(component),
80 eq(AuditingActionEnum.ARCHIVE_COMPONENT), eq(ComponentTypeEnum.RESOURCE), any(String.class));
85 public void auditLastComponentVersionOnly() {
86 List<String> archivedCompIds = Arrays.asList("1", "2", "3", "4", "5");
87 when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class)))
88 .thenReturn(Either.left(component));
89 when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
90 when(component.getUUID())
97 archiveBusinessLogic.auditAction(ArchiveOperation.Action.RESTORE, archivedCompIds, user, ComponentTypeEnum.RESOURCE_PARAM_NAME);
98 verify(componentsUtils, times(5)).auditComponentAdmin(eq(responseFormat), eq(user), eq(component),
99 eq(AuditingActionEnum.RESTORE_COMPONENT), eq(ComponentTypeEnum.RESOURCE), any(String.class));
104 public void noAuditDoneForEmptyList() {
105 List<String> archivedCompIds = ImmutableList.of();
106 archiveBusinessLogic.auditAction(ArchiveOperation.Action.RESTORE, archivedCompIds, user, ComponentTypeEnum.RESOURCE_PARAM_NAME);
107 verify(componentsUtils, times(0)).auditComponentAdmin(any(ResponseFormat.class), any(User.class), any(Component.class),
108 any(AuditingActionEnum.class), any(ComponentTypeEnum.class), any(String.class));
113 public void noAuditOnErrorGetElementResponse() {
114 List<String> archivedCompIds = Arrays.asList("1", "2", "3", "4", "5");
115 when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class)))
116 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
117 archiveBusinessLogic.auditAction(ArchiveOperation.Action.RESTORE, archivedCompIds, user, ComponentTypeEnum.RESOURCE_PARAM_NAME);
118 verify(componentsUtils, times(0)).auditComponentAdmin(any(ResponseFormat.class), any(User.class), any(Component.class),
119 any(AuditingActionEnum.class), any(ComponentTypeEnum.class), any(String.class));