From a542f19d421229508c4408583e552c4c0eba84f1 Mon Sep 17 00:00:00 2001 From: Fiete Ostkamp Date: Tue, 9 Apr 2024 09:39:16 +0200 Subject: Listing distributions (/services/{distributionId}/distribution/) fails with ClassCastException - attempt to format AuditEvent timestamp when it's of long type - do not update gem package in docker builds since newer versions are incompatible with ruby 2.7.6 Issue-ID: SDC-4682 Signed-off-by: Fiete Ostkamp Change-Id: I6ff3ac6bfa3ce7985c69df3eb79f9711b753800f --- .../DistributionMonitoringBusinessLogicTest.java | 70 +++++++++++++++------- 1 file changed, 49 insertions(+), 21 deletions(-) (limited to 'catalog-be/src/test/java') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DistributionMonitoringBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DistributionMonitoringBusinessLogicTest.java index 7b111ba52f..4681a4d01b 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DistributionMonitoringBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DistributionMonitoringBusinessLogicTest.java @@ -36,6 +36,7 @@ import org.openecomp.sdc.be.info.DistributionStatusListResponse; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent; import org.openecomp.sdc.be.resources.data.auditing.DistributionStatusEvent; +import org.openecomp.sdc.common.datastructure.AuditingFieldsKey; import org.openecomp.sdc.exception.ResponseFormat; import java.util.ArrayList; @@ -49,21 +50,16 @@ import static org.mockito.Mockito.when; public class DistributionMonitoringBusinessLogicTest extends BaseBusinessLogicMock { - private String uId; + private String userId; private User user; - private String ditributionId; + private String distributionId; private String serviceId; private DistributionMonitoringBusinessLogic businessLogic; - @Mock - private AuditCassandraDao cassandraDao; - - @Mock - private UserValidations userValidations; - - @Mock - private ComponentsUtils componentsUtils; + @Mock private AuditCassandraDao cassandraDao; + @Mock private UserValidations userValidations; + @Mock private ComponentsUtils componentsUtils; @Before public void setUp() { @@ -75,20 +71,20 @@ public class DistributionMonitoringBusinessLogicTest extends BaseBusinessLogicMo businessLogic.setComponentsUtils(componentsUtils); user = new User(); - uId = "userId"; - ditributionId = "did"; + userId = "userId"; + distributionId = "did"; serviceId = "serviceId"; - when(userValidations.validateUserExists(Mockito.eq(uId))) + when(userValidations.validateUserExists(Mockito.eq(userId))) .thenReturn(user); } @Test public void testGetListOfDistribution_givenInvalidDistributionId_thenReturnsError() { - when(cassandraDao.getListOfDistributionStatuses(ditributionId)) + when(cassandraDao.getListOfDistributionStatuses(distributionId)) .thenReturn(Either.right(ActionStatus.DISTRIBUTION_NOT_FOUND)); - assertTrue(businessLogic.getListOfDistributionStatus(ditributionId, uId).isRight()); + assertTrue(businessLogic.getListOfDistributionStatus(distributionId, userId).isRight()); } @Test @@ -98,10 +94,10 @@ public class DistributionMonitoringBusinessLogicTest extends BaseBusinessLogicMo DistributionStatusEvent event = new DistributionStatusEvent(); distributionEvents.add(event); - when(cassandraDao.getListOfDistributionStatuses(ditributionId)) + when(cassandraDao.getListOfDistributionStatuses(distributionId)) .thenReturn(Either.left(distributionEvents)); - Either result = businessLogic.getListOfDistributionStatus(ditributionId, uId); + Either result = businessLogic.getListOfDistributionStatus(distributionId, userId); assertTrue(result.isLeft()); assertEquals(1, result.left().value().getDistributionStatusList().size()); @@ -112,7 +108,7 @@ public class DistributionMonitoringBusinessLogicTest extends BaseBusinessLogicMo when(cassandraDao.getServiceDistributionStatusesList(serviceId)) .thenReturn(Either.right(ActionStatus.DISTRIBUTION_NOT_FOUND)); - assertTrue(businessLogic.getListOfDistributionServiceStatus(serviceId, uId).isRight()); + assertTrue(businessLogic.getListOfDistributionServiceStatus(serviceId, userId).isRight()); } @Test @@ -128,13 +124,45 @@ public class DistributionMonitoringBusinessLogicTest extends BaseBusinessLogicMo event1Fields.put("DID", "event1"); event1Fields.put("ACTION", "DRequest"); event1Fields.put("STATUS", "200"); - event1Fields.put("MODIFIER", uId); + event1Fields.put("MODIFIER", userId); + + event2Fields.put("DID", "event2"); + event2Fields.put("ACTION", "DNotify"); + event2Fields.put("STATUS", "200"); + event2Fields.put("MODIFIER", userId); + + event1.setFields(event1Fields); + event2.setFields(event2Fields); + + serviceEvents.add(event1); + serviceEvents.add(event2); + + when(cassandraDao.getServiceDistributionStatusesList(serviceId)) + .thenReturn(Either.left(serviceEvents)); + + assertTrue(businessLogic.getListOfDistributionServiceStatus(serviceId, userId).isLeft()); + } + + @Test + public void testGetDistributionServiceStatus_givenLongTimeStamp_thenReturnsSuccessful() { + + Map event1Fields = new HashMap<>(); + event1Fields.put("DID", "event1"); + event1Fields.put("ACTION", "DRequest"); + event1Fields.put("STATUS", "200"); + event1Fields.put("MODIFIER", userId); + event1Fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), "2024-04-05 07:29:10.735 UTC"); + Map event2Fields = new HashMap<>(); event2Fields.put("DID", "event2"); event2Fields.put("ACTION", "DNotify"); event2Fields.put("STATUS", "200"); - event2Fields.put("MODIFIER", uId); + event2Fields.put("MODIFIER", userId); + event1Fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), 1712645750L); + List serviceEvents = new ArrayList<>(); + AuditingGenericEvent event1 = new AuditingGenericEvent(); + AuditingGenericEvent event2 = new AuditingGenericEvent(); event1.setFields(event1Fields); event2.setFields(event2Fields); @@ -144,6 +172,6 @@ public class DistributionMonitoringBusinessLogicTest extends BaseBusinessLogicMo when(cassandraDao.getServiceDistributionStatusesList(serviceId)) .thenReturn(Either.left(serviceEvents)); - assertTrue(businessLogic.getListOfDistributionServiceStatus(serviceId, uId).isLeft()); + assertTrue(businessLogic.getListOfDistributionServiceStatus(serviceId, userId).isLeft()); } } \ No newline at end of file -- cgit 1.2.3-korg