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.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.Mockito.when;
50 public class DistributionMonitoringBusinessLogicTest extends BaseBusinessLogicMock {
54 private String ditributionId;
55 private String serviceId;
57 private DistributionMonitoringBusinessLogic businessLogic;
60 private AuditCassandraDao cassandraDao;
63 private UserValidations userValidations;
66 private ComponentsUtils componentsUtils;
70 MockitoAnnotations.openMocks(this);
71 businessLogic = new DistributionMonitoringBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
72 groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation,
73 cassandraDao, artifactToscaOperation);
74 businessLogic.setUserValidations(userValidations);
75 businessLogic.setComponentsUtils(componentsUtils);
79 ditributionId = "did";
80 serviceId = "serviceId";
82 when(userValidations.validateUserExists(Mockito.eq(uId)))
87 public void testGetListOfDistribution_givenInvalidDistributionId_thenReturnsError() {
88 when(cassandraDao.getListOfDistributionStatuses(ditributionId))
89 .thenReturn(Either.right(ActionStatus.DISTRIBUTION_NOT_FOUND));
91 assertTrue(businessLogic.getListOfDistributionStatus(ditributionId, uId).isRight());
95 public void testGetListOfDistribution_givenValidDistributionId_thenReturnsSuccessful() {
97 List<DistributionStatusEvent> distributionEvents = new ArrayList<>();
98 DistributionStatusEvent event = new DistributionStatusEvent();
99 distributionEvents.add(event);
101 when(cassandraDao.getListOfDistributionStatuses(ditributionId))
102 .thenReturn(Either.left(distributionEvents));
104 Either<DistributionStatusListResponse, ResponseFormat> result = businessLogic.getListOfDistributionStatus(ditributionId, uId);
106 assertTrue(result.isLeft());
107 assertEquals(1, result.left().value().getDistributionStatusList().size());
111 public void testGetDistributionServiceStatus_givenInvalidServiceIdId_thenReturnsError() {
113 when(cassandraDao.getServiceDistributionStatusesList(serviceId))
114 .thenReturn(Either.right(ActionStatus.DISTRIBUTION_NOT_FOUND));
115 assertTrue(businessLogic.getListOfDistributionServiceStatus(serviceId, uId).isRight());
119 public void testGetDistributionServiceStatus_givenValidServiceId_thenReturnsSuccessful() {
121 List<AuditingGenericEvent> serviceEvents = new ArrayList<>();
122 AuditingGenericEvent event1 = new AuditingGenericEvent();
123 AuditingGenericEvent event2 = new AuditingGenericEvent();
125 Map<String, Object> event1Fields = new HashMap<>();
126 Map<String, Object> event2Fields = new HashMap<>();
128 event1Fields.put("DID", "event1");
129 event1Fields.put("ACTION", "DRequest");
130 event1Fields.put("STATUS", "200");
131 event1Fields.put("MODIFIER", uId);
133 event2Fields.put("DID", "event2");
134 event2Fields.put("ACTION", "DNotify");
135 event2Fields.put("STATUS", "200");
136 event2Fields.put("MODIFIER", uId);
138 event1.setFields(event1Fields);
139 event2.setFields(event2Fields);
141 serviceEvents.add(event1);
142 serviceEvents.add(event2);
144 when(cassandraDao.getServiceDistributionStatusesList(serviceId))
145 .thenReturn(Either.left(serviceEvents));
147 assertTrue(businessLogic.getListOfDistributionServiceStatus(serviceId, uId).isLeft());