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.InjectMocks;
29 import org.mockito.Mock;
30 import org.mockito.Mockito;
31 import org.mockito.MockitoAnnotations;
32 import org.openecomp.sdc.be.components.validation.UserValidations;
33 import org.openecomp.sdc.be.dao.api.ActionStatus;
34 import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
35 import org.openecomp.sdc.be.impl.ComponentsUtils;
36 import org.openecomp.sdc.be.info.DistributionStatusListResponse;
37 import org.openecomp.sdc.be.model.User;
38 import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
39 import org.openecomp.sdc.be.resources.data.auditing.DistributionStatusEvent;
40 import org.openecomp.sdc.exception.ResponseFormat;
41 import java.util.ArrayList;
42 import java.util.HashMap;
43 import java.util.List;
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.assertTrue;
48 import static org.mockito.ArgumentMatchers.anyBoolean;
49 import static org.mockito.ArgumentMatchers.eq;
50 import static org.mockito.Mockito.when;
52 public class DistributionMonitoringBusinessLogicTest {
56 private String ditributionId;
57 private String serviceId;
60 private DistributionMonitoringBusinessLogic businessLogic;
63 private AuditCassandraDao cassandraDao;
66 private UserValidations userValidations;
69 private ComponentsUtils componentsUtils;
73 businessLogic = new DistributionMonitoringBusinessLogic();
74 MockitoAnnotations.initMocks(this);
78 ditributionId = "did";
79 serviceId = "serviceId";
81 when(userValidations.validateUserExists(Mockito.eq(uId), eq(ditributionId), anyBoolean()))
86 public void testGetListOfDistribution_givenInvalidDistributionId_thenReturnsError() {
87 when(cassandraDao.getListOfDistributionStatuses(ditributionId))
88 .thenReturn(Either.right(ActionStatus.DISTRIBUTION_NOT_FOUND));
90 assertTrue(businessLogic.getListOfDistributionStatus(ditributionId, uId).isRight());
94 public void testGetListOfDistribution_givenValidDistributionId_thenReturnsSuccessful() {
96 List<DistributionStatusEvent> distributionEvents = new ArrayList<>();
97 DistributionStatusEvent event = new DistributionStatusEvent();
98 distributionEvents.add(event);
100 when(cassandraDao.getListOfDistributionStatuses(ditributionId))
101 .thenReturn(Either.left(distributionEvents));
103 Either<DistributionStatusListResponse, ResponseFormat> result = businessLogic.getListOfDistributionStatus(ditributionId, uId);
105 assertTrue(result.isLeft());
106 assertEquals(1, result.left().value().getDistributionStatusList().size());
110 public void testGetDistributionServiceStatus_givenInvalidServiceIdId_thenReturnsError() {
112 when(cassandraDao.getServiceDistributionStatusesList(serviceId))
113 .thenReturn(Either.right(ActionStatus.DISTRIBUTION_NOT_FOUND));
114 assertTrue(businessLogic.getListOfDistributionServiceStatus(serviceId, uId).isRight());
118 public void testGetDistributionServiceStatus_givenValidServiceId_thenReturnsSuccessful() {
120 List<AuditingGenericEvent> serviceEvents = new ArrayList<>();
121 AuditingGenericEvent event1 = new AuditingGenericEvent();
122 AuditingGenericEvent event2 = new AuditingGenericEvent();
124 Map<String, Object> event1Fields = new HashMap<>();
125 Map<String, Object> event2Fields = new HashMap<>();
127 event1Fields.put("DID", "event1");
128 event1Fields.put("ACTION", "DRequest");
129 event1Fields.put("STATUS", "200");
130 event1Fields.put("MODIFIER", uId);
132 event2Fields.put("DID", "event2");
133 event2Fields.put("ACTION", "DNotify");
134 event2Fields.put("STATUS", "200");
135 event2Fields.put("MODIFIER", uId);
137 event1.setFields(event1Fields);
138 event2.setFields(event2Fields);
140 serviceEvents.add(event1);
141 serviceEvents.add(event2);
143 when(cassandraDao.getServiceDistributionStatusesList(serviceId))
144 .thenReturn(Either.left(serviceEvents));
146 assertTrue(businessLogic.getListOfDistributionServiceStatus(serviceId, uId).isLeft());