3 * * ============LICENSE_START=======================================================
4 * * Copyright (C) 2019 Nordix Foundation.
5 * * ================================================================================
6 * * Licensed under the Apache License, Version 2.0 (the "License");
7 * * you may not use this file except in compliance with the License.
8 * * You may obtain a copy of the License at
10 * * http://www.apache.org/licenses/LICENSE-2.0
12 * * Unless required by applicable law or agreed to in writing, software
13 * * distributed under the License is distributed on an "AS IS" BASIS,
14 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * * See the License for the specific language governing permissions and
16 * * limitations under the License.
18 * * SPDX-License-Identifier: Apache-2.0
19 * * ============LICENSE_END=========================================================
23 package org.openecomp.sdc.be.components.impl;
25 import fj.data.Either;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.mockito.MockitoAnnotations;
31 import org.openecomp.sdc.be.components.validation.UserValidations;
32 import org.openecomp.sdc.be.dao.api.ActionStatus;
33 import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
34 import org.openecomp.sdc.be.impl.ComponentsUtils;
35 import org.openecomp.sdc.be.info.DistributionStatusListResponse;
36 import org.openecomp.sdc.be.model.User;
37 import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
38 import org.openecomp.sdc.be.resources.data.auditing.DistributionStatusEvent;
39 import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
40 import org.openecomp.sdc.exception.ResponseFormat;
42 import java.util.ArrayList;
43 import java.util.HashMap;
44 import java.util.List;
47 import static org.junit.Assert.assertEquals;
48 import static org.junit.Assert.assertTrue;
49 import static org.mockito.Mockito.when;
51 public class DistributionMonitoringBusinessLogicTest extends BaseBusinessLogicMock {
53 private String userId;
55 private String distributionId;
56 private String serviceId;
58 private DistributionMonitoringBusinessLogic businessLogic;
60 @Mock private AuditCassandraDao cassandraDao;
61 @Mock private UserValidations userValidations;
62 @Mock private ComponentsUtils componentsUtils;
66 MockitoAnnotations.openMocks(this);
67 businessLogic = new DistributionMonitoringBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
68 groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation,
69 cassandraDao, artifactToscaOperation);
70 businessLogic.setUserValidations(userValidations);
71 businessLogic.setComponentsUtils(componentsUtils);
75 distributionId = "did";
76 serviceId = "serviceId";
78 when(userValidations.validateUserExists(Mockito.eq(userId)))
83 public void testGetListOfDistribution_givenInvalidDistributionId_thenReturnsError() {
84 when(cassandraDao.getListOfDistributionStatuses(distributionId))
85 .thenReturn(Either.right(ActionStatus.DISTRIBUTION_NOT_FOUND));
87 assertTrue(businessLogic.getListOfDistributionStatus(distributionId, userId).isRight());
91 public void testGetListOfDistribution_givenValidDistributionId_thenReturnsSuccessful() {
93 List<DistributionStatusEvent> distributionEvents = new ArrayList<>();
94 DistributionStatusEvent event = new DistributionStatusEvent();
95 distributionEvents.add(event);
97 when(cassandraDao.getListOfDistributionStatuses(distributionId))
98 .thenReturn(Either.left(distributionEvents));
100 Either<DistributionStatusListResponse, ResponseFormat> result = businessLogic.getListOfDistributionStatus(distributionId, userId);
102 assertTrue(result.isLeft());
103 assertEquals(1, result.left().value().getDistributionStatusList().size());
107 public void testGetDistributionServiceStatus_givenInvalidServiceIdId_thenReturnsError() {
109 when(cassandraDao.getServiceDistributionStatusesList(serviceId))
110 .thenReturn(Either.right(ActionStatus.DISTRIBUTION_NOT_FOUND));
111 assertTrue(businessLogic.getListOfDistributionServiceStatus(serviceId, userId).isRight());
115 public void testGetDistributionServiceStatus_givenValidServiceId_thenReturnsSuccessful() {
117 List<AuditingGenericEvent> serviceEvents = new ArrayList<>();
118 AuditingGenericEvent event1 = new AuditingGenericEvent();
119 AuditingGenericEvent event2 = new AuditingGenericEvent();
121 Map<String, Object> event1Fields = new HashMap<>();
122 Map<String, Object> event2Fields = new HashMap<>();
124 event1Fields.put("DID", "event1");
125 event1Fields.put("ACTION", "DRequest");
126 event1Fields.put("STATUS", "200");
127 event1Fields.put("MODIFIER", userId);
129 event2Fields.put("DID", "event2");
130 event2Fields.put("ACTION", "DNotify");
131 event2Fields.put("STATUS", "200");
132 event2Fields.put("MODIFIER", userId);
134 event1.setFields(event1Fields);
135 event2.setFields(event2Fields);
137 serviceEvents.add(event1);
138 serviceEvents.add(event2);
140 when(cassandraDao.getServiceDistributionStatusesList(serviceId))
141 .thenReturn(Either.left(serviceEvents));
143 assertTrue(businessLogic.getListOfDistributionServiceStatus(serviceId, userId).isLeft());
147 public void testGetDistributionServiceStatus_givenLongTimeStamp_thenReturnsSuccessful() {
149 Map<String, Object> event1Fields = new HashMap<>();
150 event1Fields.put("DID", "event1");
151 event1Fields.put("ACTION", "DRequest");
152 event1Fields.put("STATUS", "200");
153 event1Fields.put("MODIFIER", userId);
154 event1Fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), "2024-04-05 07:29:10.735 UTC");
156 Map<String, Object> event2Fields = new HashMap<>();
157 event2Fields.put("DID", "event2");
158 event2Fields.put("ACTION", "DNotify");
159 event2Fields.put("STATUS", "200");
160 event2Fields.put("MODIFIER", userId);
161 event1Fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), 1712645750L);
163 List<AuditingGenericEvent> serviceEvents = new ArrayList<>();
164 AuditingGenericEvent event1 = new AuditingGenericEvent();
165 AuditingGenericEvent event2 = new AuditingGenericEvent();
166 event1.setFields(event1Fields);
167 event2.setFields(event2Fields);
169 serviceEvents.add(event1);
170 serviceEvents.add(event2);
172 when(cassandraDao.getServiceDistributionStatusesList(serviceId))
173 .thenReturn(Either.left(serviceEvents));
175 assertTrue(businessLogic.getListOfDistributionServiceStatus(serviceId, userId).isLeft());