From dd4e642f2141d5c56294207e20978945abd0af73 Mon Sep 17 00:00:00 2001 From: AayVerma Date: Sun, 8 Jun 2025 20:42:43 +0530 Subject: [PATCH 1/7] Added New Test --- pom.xml | 8 - .../eclipse/ecsp/ro/RoDAOMongoImplTest.java | 45 ++++++ .../ro/queue/AbstractQueueHandlerTest.java | 145 ++++++++++++++++++ .../ro/queue/RequestQueueHandlerTest.java | 103 +++++++++++++ .../ecsp/ro/utils/CachedKeyUtilTest.java | 52 +++++++ .../ecsp/ro/utils/NotificationUtilTest.java | 119 ++++++++++++++ .../ecsp/ro/utils/OutboundUtilTest.java | 102 ++++++++++++ .../ro/utils/StockingRuleConfigUtilTest.java | 35 +++++ .../ecsp/ro/utils/TimeZoneUtilsTest.java | 53 +++++++ .../org/eclipse/ecsp/ro/utils/UtilsTest.java | 16 ++ 10 files changed, 670 insertions(+), 8 deletions(-) create mode 100644 ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java create mode 100644 ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java create mode 100644 ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java create mode 100644 ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java create mode 100644 ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java create mode 100644 ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java diff --git a/pom.xml b/pom.xml index 48bd091..b55017b 100644 --- a/pom.xml +++ b/pom.xml @@ -124,17 +124,9 @@ **/org/eclipse/ecsp/platform/services/ro/constant/*.java, **/org/eclipse/ecsp/platform/services/ro/service/*.java, **/org/eclipse/ecsp/platform/services/ro/configure/*.java, - **/org/eclipse/ecsp/ro/utils/NotificationUtil.java, - **/org/eclipse/ecsp/ro/queue/AbstractQueueHandler.java, - **/org/eclipse/ecsp/ro/queue/RequestQueueHandler.java, **/org/eclipse/ecsp/ro/RoScheduleV2DAOMongoImpl.java, **/org/eclipse/ecsp/ro/utils/CacheUtil.java, - **/org/eclipse/ecsp/ro/utils/CachedKeyUtil.java, - **/org/eclipse/ecsp/ro/utils/OutboundUtil.java, - **/org/eclipse/ecsp/ro/queue/DeviceMessageFailureQueueHandler.java, **/org/eclipse/ecsp/ro/utils/Utils.java, - **/org/eclipse/ecsp/ro/utils/TimeZoneUtils.java, - **/org/eclipse/ecsp/ro/RoDAOMongoImpl.java, **/org/eclipse/ecsp/platform/services/ro/rest/RCPDController.java, **/org/eclipse/ecsp/platform/services/ro/rest/ROHoodTrunkLiftgateController.java, **/org/eclipse/ecsp/ro/notification/StockingRuleNotificationResolver.java, diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/RoDAOMongoImplTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/RoDAOMongoImplTest.java index e57fa20..15b1907 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/RoDAOMongoImplTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/RoDAOMongoImplTest.java @@ -38,6 +38,8 @@ package org.eclipse.ecsp.ro; import io.prometheus.client.CollectorRegistry; +import org.eclipse.ecsp.domain.ro.Ro; +import org.eclipse.ecsp.nosqldao.IgniteQuery; import org.eclipse.ecsp.testutils.CommonTestBase; import org.junit.Test; import org.junit.jupiter.api.AfterEach; @@ -52,6 +54,8 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; +import java.util.Optional; + /** * Tests for {@link RoDAOMongoImpl}. */ @@ -81,4 +85,45 @@ public void getLatesRIEntityForNotification() { Assertions.assertNull(roDAOMongo.getLatesRIEntityForNotification("sessionId", "vehicleId")); } + @Test + public void testGetRIEntityByFieldName_ReturnsEmpty() { + Optional result = roDAOMongo.getRIEntityByFieldName("someRequestID", "someVehicleId"); + Assertions.assertTrue(result.isEmpty()); + } + + @Test + public void testPrepareIgniteQueryForRoRequest() { + IgniteQuery query = roDAOMongo.prepareIgniteQueryForRoRequest("roReqId", "vehicleId"); + Assertions.assertNotNull(query); + } + + @Test + public void testPrepareIgniteQueryBySessionIdANDMsgId() { + IgniteQuery query = roDAOMongo.prepareIgniteQueryBySessionIdANDMsgId("vehicleId", "sessionId", "msgId"); + Assertions.assertNotNull(query); + } + + @Test + public void testPrepareIgniteQueryForRIRequestWithSessionId() { + IgniteQuery query = roDAOMongo.prepareIgniteQueryForRIRequestWithSessionId("sessionId", "vehicleid"); + Assertions.assertNotNull(query); + } + + @Test + public void testGetROEntityByFieldNameByRoReqIdExceptACV_ReturnsEmpty() { + Optional result = roDAOMongo.getROEntityByFieldNameByRoReqIdExceptACV("vehicleId", "roRequestId"); + Assertions.assertTrue(result.isEmpty()); + } + + @Test + public void testGetROEntityByFieldNameByRoReqId_ReturnsEmpty() { + Optional result = roDAOMongo.getROEntityByFieldNameByRoReqId("vehicleId", "roRequestId"); + Assertions.assertTrue(result.isEmpty()); + } + + @Test + public void testGetROEntityByFieldNameByBizIdExceptACV_ReturnsEmpty() { + Optional result = roDAOMongo.getROEntityByFieldNameByBizIdExceptACV("vehicleId", "sessionId"); + Assertions.assertTrue(result.isEmpty()); + } } \ No newline at end of file diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java new file mode 100644 index 0000000..52cddba --- /dev/null +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java @@ -0,0 +1,145 @@ +package org.eclipse.ecsp.ro.queue; + +import org.apache.kafka.streams.processor.api.Record; +import org.bson.types.ObjectId; +import org.eclipse.ecsp.analytics.stream.base.StreamProcessingContext; +import org.eclipse.ecsp.domain.ro.ROStatus; +import org.eclipse.ecsp.domain.ro.Ro; +import org.eclipse.ecsp.entities.AbstractIgniteEvent; +import org.eclipse.ecsp.entities.IgniteEvent; +import org.eclipse.ecsp.key.IgniteKey; +import org.eclipse.ecsp.key.IgniteStringKey; +import org.eclipse.ecsp.nosqldao.Updates; +import org.eclipse.ecsp.ro.RoDAOMongoImpl; +import org.eclipse.ecsp.services.utils.ServiceUtil; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.*; +import org.redisson.api.RQueue; +import org.redisson.api.RedissonClient; + +import java.time.Instant; +import java.util.*; + +import static org.mockito.Mockito.*; + +class AbstractQueueHandlerTest { + + static class TestQueueHandler extends AbstractQueueHandler { + @Override + public void process(IgniteKey key, IgniteEvent event, StreamProcessingContext context) { + // No-op for test + } + } + + @InjectMocks + private TestQueueHandler queueHandler; + + @Mock + private RoDAOMongoImpl roDAOMongoImpl; + + @Mock + private RedissonClient redissonClient; + + @Mock + private ServiceUtil serviceUtil; + + @Mock + private StreamProcessingContext ctxt; + + @Mock + private RQueue queue; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + queueHandler = new TestQueueHandler(); + queueHandler.roDAOMongoImpl = roDAOMongoImpl; + queueHandler.redissonClient = redissonClient; + queueHandler.serviceUtil = serviceUtil; + queueHandler.roForeachTTL = 180000; + } + + @Test + void testUpdateEntityByROStatus_updatesWhenRoPresent() { + IgniteEvent event = mock(IgniteEvent.class); + when(event.getVehicleId()).thenReturn("VIN123"); + when(event.getRequestId()).thenReturn("REQ123"); + + Ro ro = new Ro(); + ObjectId id = new ObjectId(); + ro.setId(id); + + when(roDAOMongoImpl.getROEntityByFieldNameByRoReqIdExceptACV("VIN123", "REQ123")) + .thenReturn(Optional.of(ro)); + + queueHandler.updateEntityByROStatus(event, ROStatus.TTL_EXPIRED); + + verify(roDAOMongoImpl).update(eq(id), any(Updates.class)); + } + + @Test + void testUpdateEntityByROStatusWithVinAndRoRequestID_updatesWhenRoPresent() { + Ro ro = new Ro(); + ObjectId id = new ObjectId(); + ro.setId(id); + + when(roDAOMongoImpl.getROEntityByFieldNameByRoReqIdExceptACV("VIN999", "REQ999")) + .thenReturn(Optional.of(ro)); + + queueHandler.updateEntityByROStatusWithVinAndRoRequestID("REQ999", "VIN999", ROStatus.TTL_EXPIRED); + + verify(roDAOMongoImpl).update(eq(id), any(Updates.class)); + } + + @Test + void testSendToDevice_forwardsToKafkaStream() { + AbstractIgniteEvent event = mock(AbstractIgniteEvent.class); + when(event.getRequestId()).thenReturn("REQ001"); + when(event.getVehicleId()).thenReturn("VIN001"); + + queueHandler.sendToDevice(event, ctxt); + + verify(event).setResponseExpected(true); + verify(event).setDeviceRoutable(true); + verify(event).setShoulderTapEnabled(true); + verify(ctxt).forward(any(Record.class)); + } + + @Test + void testCheckTTLExpireANDForwad_sendsEventIfNotExpired() { + AbstractIgniteEvent event = mock(AbstractIgniteEvent.class); + when(event.getTimestamp()).thenReturn(Instant.now().toEpochMilli()); + when(event.getVehicleId()).thenReturn("VIN001"); + + when(queue.iterator()).thenReturn(List.of(event).iterator()); + + queueHandler.checkTTLExpireANDForwad(queue, ctxt); + + verify(ctxt).forward(any(Record.class)); + verify(queue, never()).poll(); + } + + @Test + void testCheckTTLExpireANDForwad_expiresEventIfOld() { + AbstractIgniteEvent event = mock(AbstractIgniteEvent.class); + long oldTimestamp = Instant.now().minusMillis(200000).toEpochMilli(); + when(event.getTimestamp()).thenReturn(oldTimestamp); + when(event.getVehicleId()).thenReturn("VIN123"); + when(event.getRequestId()).thenReturn("REQ123"); + + Ro ro = new Ro(); + ObjectId id = new ObjectId(); + ro.setId(id); + + when(roDAOMongoImpl.getROEntityByFieldNameByRoReqIdExceptACV("VIN123", "REQ123")) + .thenReturn(Optional.of(ro)); + + when(queue.iterator()).thenReturn(List.of(event).iterator()); + + queueHandler.checkTTLExpireANDForwad(queue, ctxt); + + verify(roDAOMongoImpl).update(eq(id), any(Updates.class)); + verify(queue).poll(); + } +} \ No newline at end of file diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java new file mode 100644 index 0000000..1e32e28 --- /dev/null +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java @@ -0,0 +1,103 @@ +package org.eclipse.ecsp.ro.queue; + +import org.eclipse.ecsp.analytics.stream.base.StreamProcessingContext; +import org.eclipse.ecsp.domain.ro.ROStatus; +import org.eclipse.ecsp.entities.AbstractIgniteEvent; +import org.eclipse.ecsp.entities.IgniteEvent; +import org.eclipse.ecsp.key.IgniteKey; +import org.eclipse.ecsp.key.IgniteStringKey; +import org.eclipse.ecsp.nosqldao.Updates; +import org.eclipse.ecsp.ro.RoDAOMongoImpl; +import org.eclipse.ecsp.services.utils.ServiceUtil; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.*; +import org.redisson.api.RQueue; +import org.redisson.api.RedissonClient; + +import java.time.Instant; +import java.util.*; + +import static org.mockito.Mockito.*; + +class RequestQueueHandlerTest { + + @InjectMocks + private RequestQueueHandler requestQueueHandler; + + @Mock + private RoDAOMongoImpl roDAOMongoImpl; + + @Mock + private RedissonClient redissonClient; + + @Mock + private RQueue queue; + + @Mock + private ServiceUtil serviceUtil; + + @Mock + private StreamProcessingContext context; + + @Mock + private IgniteKey igniteKey; + + private IgniteEvent igniteEvent; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + + igniteEvent = mock(AbstractIgniteEvent.class); + when(igniteEvent.getVehicleId()).thenReturn("VIN1234"); + when(igniteEvent.getRequestId()).thenReturn("REQ-1"); + queue = mock(RQueue.class); + when(redissonClient.getQueue(anyString())).thenReturn((RQueue)queue); + } + + @Test + void testProcess_withNonExpiredEvent_shouldSendToDevice() { + AbstractIgniteEvent event = mock(AbstractIgniteEvent.class); + long currentTime = Instant.now().toEpochMilli(); + when(event.getTimestamp()).thenReturn(currentTime); + when(event.getVehicleId()).thenReturn("VIN1234"); + when(event.getRequestId()).thenReturn("REQ-1"); + + when(redissonClient.getQueue(anyString())).thenReturn((RQueue)queue); + when(queue.iterator()).thenReturn(Collections.singletonList(event).iterator()); + when(queue.size()).thenReturn(1); + + requestQueueHandler.roForeachTTL = 180000L; + + requestQueueHandler.process(igniteKey, igniteEvent, context); + + // Should send to device, TTL not expired + verify(queue).offer((AbstractIgniteEvent) igniteEvent); + } + + @Test + void testProcess_withExpiredEvent_shouldUpdateStatusAndRemove() { + AbstractIgniteEvent expiredEvent = mock(AbstractIgniteEvent.class); + long oldTimestamp = Instant.now().minusMillis(999999).toEpochMilli(); + + when(expiredEvent.getTimestamp()).thenReturn(oldTimestamp); + when(expiredEvent.getVehicleId()).thenReturn("VIN1234"); + when(expiredEvent.getRequestId()).thenReturn("REQ-2"); + + Iterator iterator = mock(Iterator.class); + when(iterator.hasNext()).thenReturn(true, false); + when(iterator.next()).thenReturn(expiredEvent); + + when(redissonClient.getQueue(anyString())).thenReturn((RQueue)queue); + when(queue.iterator()).thenReturn(iterator); + when(queue.size()).thenReturn(1); + + requestQueueHandler.roForeachTTL = 180000L; + + requestQueueHandler.process(igniteKey, igniteEvent, context); + + // Should call updateEntityByROStatus + verify(roDAOMongoImpl, atLeastOnce()).getROEntityByFieldNameByRoReqIdExceptACV(eq("VIN1234"), eq("REQ-2")); + } +} \ No newline at end of file diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java new file mode 100644 index 0000000..508d2f2 --- /dev/null +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java @@ -0,0 +1,52 @@ +package org.eclipse.ecsp.ro.utils; + +import org.eclipse.ecsp.entities.IgniteEvent; +import org.eclipse.ecsp.ro.constants.Constants; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.*; + +class CachedKeyUtilTest { + + /*@Test + void testPrivateConstructor_shouldThrowException() throws Exception { + var constructor = CachedKeyUtil.class.getDeclaredConstructor(); + constructor.setAccessible(true); + assertThrows(UnsupportedOperationException.class, constructor::newInstance); + }*/ + + @Test + void getEngineStatusKey_shouldReturnCorrectKey() { + IgniteEvent event = mock(IgniteEvent.class); + when(event.getVehicleId()).thenReturn("VH001"); + + String expected = Constants.RO_ENGINE_STATUS_PREFIX + "VH001"; + String result = CachedKeyUtil.getEngineStatusKey(event); + + assertEquals(expected, result); + } + + @Test + void getROQueueKey_shouldReturnCorrectKey() { + IgniteEvent event = mock(IgniteEvent.class); + when(event.getVehicleId()).thenReturn("VH002"); + + String expected = Constants.RO_QUEUE_PREFIX + "VH002"; + String result = CachedKeyUtil.getROQueueKey(event); + + assertEquals(expected, result); + } + + @Test + void getRONotificationMappingKey_shouldReturnCorrectKey() { + IgniteEvent event = mock(IgniteEvent.class); + when(event.getVehicleId()).thenReturn("VH003"); + + String expected = Constants.NOTIFICATION_MAPPING + Constants.UNDER_SCORE + "VH003"; + String result = CachedKeyUtil.getRONotificationMappingKey(event); + + assertEquals(expected, result); + } +} \ No newline at end of file diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java new file mode 100644 index 0000000..b77441a --- /dev/null +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java @@ -0,0 +1,119 @@ +package org.eclipse.ecsp.ro.utils; + +import org.eclipse.ecsp.analytics.stream.base.StreamProcessingContext; +import org.eclipse.ecsp.domain.GenericCustomExtension; +import org.eclipse.ecsp.domain.ro.RemoteOperationResponseV1_1; +import org.eclipse.ecsp.domain.ro.RemoteOperationResponseV1_1.Response; +import org.eclipse.ecsp.entities.IgniteEvent; +import org.eclipse.ecsp.entities.IgniteEventImpl; +import org.eclipse.ecsp.key.IgniteKey; +import org.eclipse.ecsp.ro.domains.ROGenericNotificationEventDataV1_1; +import org.eclipse.ecsp.ro.notification.NotificationResolver; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.*; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import static org.mockito.Mockito.*; + +public class NotificationUtilTest { + + @InjectMocks + private NotificationUtil notificationUtil; + + @Mock + private NotificationResolver notificationResolver; + + @Mock + private StreamProcessingContext context; + + @Mock + private IgniteKey igniteKey; + + @Mock + private IgniteEvent igniteEvent; + + @Mock + private RemoteOperationResponseV1_1 response; + + @Mock + private GenericCustomExtension customExtension; + + @BeforeEach + public void setUp() throws Exception { + MockitoAnnotations.openMocks(this); + + notificationUtil = new NotificationUtil(); + + // Inject private fields using reflection directly + setField(notificationUtil, "notificationStatusMapping", Map.of("notif-1", "SUCCESS")); + setField(notificationUtil, "notificationIdMapping", Map.of("RESPONSE_OK", "notif-1")); + setField(notificationUtil, "whitelistedDffOrigins", new String[]{"THIRDPARTY2"}); + setField(notificationUtil, "sinkTopics", new String[]{"sink-topic"}); + setField(notificationUtil, "sourceTopics", new String[]{"source-topic"}); + setField(notificationUtil, "notificationResolver", notificationResolver); + } + + // Inline reflection helper inside the test class + private void setField(Object target, String fieldName, Object value) throws Exception { + var field = target.getClass().getDeclaredField(fieldName); + field.setAccessible(true); + field.set(target, value); + } + + @Test + public void testSendRONotification_withValidInput_shouldForwardEvent() { + when(igniteEvent.getVehicleId()).thenReturn("veh123"); + when(igniteEvent.getBizTransactionId()).thenReturn("biz123"); + + when(response.getRoRequestId()).thenReturn("ro-req-1"); + when(response.getResponse()).thenReturn(Response.SUCCESS); + + when(response.getCustomExtension()).thenReturn(Optional.of(customExtension)); + when(customExtension.getCustomData()).thenReturn(Map.of("response", "SUCCESS")); + + notificationUtil.sendRONotification( + igniteKey, + igniteEvent, + context, + "THIRDPARTY2", + "notif-1", + response + ); + + verify(context).forwardDirectly(any(IgniteKey.class), any(IgniteEvent.class), eq("sink-topic")); + } + + @Test + public void testSendRONotification_withNonWhitelistedOrigin_shouldNotSend() { + notificationUtil.sendRONotification( + igniteKey, + igniteEvent, + context, + "UNKNOWN_ORIGIN", + "notif-1", + response + ); + + verifyNoInteractions(context); + } + + @Test + public void testSendRONotification_withEmptyNotificationId_shouldSkip() { + when(response.getRoRequestId()).thenReturn("ro-req-1"); + + notificationUtil.sendRONotification( + igniteKey, + igniteEvent, + context, + "THIRDPARTY2", + "", + response + ); + + verifyNoInteractions(context); + } +} \ No newline at end of file diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java new file mode 100644 index 0000000..1bf30b9 --- /dev/null +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java @@ -0,0 +1,102 @@ +package org.eclipse.ecsp.ro.utils; + +import org.eclipse.ecsp.analytics.stream.base.StreamProcessingContext; +import org.eclipse.ecsp.domain.ro.RemoteOperationResponseV1_1; +import org.eclipse.ecsp.entities.IgniteEvent; +import org.eclipse.ecsp.key.IgniteKey; +import org.eclipse.ecsp.entities.IgniteEventImpl; +import org.eclipse.ecsp.entities.UserContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +class OutboundUtilTest { + + private OutboundUtil outboundUtil; + private StreamProcessingContext mockContext; + private IgniteKey mockKey; + + @BeforeEach + void setUp() { + outboundUtil = new OutboundUtil(); + mockContext = mock(StreamProcessingContext.class); + mockKey = mock(IgniteKey.class); + } + + @Test + void testSendROResponseOutbound_shouldForwardEvent() { + // Given + String eventId = "RO_EVENT"; + String vehicleId = "VH001"; + String requestId = "REQ123"; + String bizTransactionId = "BTID456"; + String origin = "THIRDPARTY"; + String userId = "user-abc"; + RemoteOperationResponseV1_1 response = new RemoteOperationResponseV1_1(); + response.setRoRequestId(requestId); + response.setUserId(userId); + + // When + outboundUtil.sendROResponseOutbound( + mockKey, + mockContext, + eventId, + vehicleId, + requestId, + bizTransactionId, + origin, + userId, + response + ); + + // Then + ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(IgniteEvent.class); + verify(mockContext).forward(any()); + } + + @Test + void testCreateRemoteOperationResponseV1_1_shouldPopulateAllFields() { + // Given + String requestId = "REQ123"; + String userId = "user-xyz"; + String partnerId = "partner-321"; + RemoteOperationResponseV1_1.Response responseEnum = RemoteOperationResponseV1_1.Response.SUCCESS; + + // When + RemoteOperationResponseV1_1 result = outboundUtil.createRemoteOperationResponseV1_1( + requestId, userId, partnerId, responseEnum + ); + + // Then + assertNotNull(result); + assertEquals(requestId, result.getRoRequestId()); + assertEquals(userId, result.getUserId()); + assertEquals(partnerId, result.getPartnerId()); + assertEquals(responseEnum, result.getResponse()); + } + + @Test + void testCreateRemoteOperationResponseV1_1_shouldSkipEmptyPartnerId() { + // Given + String requestId = "REQ789"; + String userId = "user-000"; + String partnerId = null; + RemoteOperationResponseV1_1.Response responseEnum = RemoteOperationResponseV1_1.Response.FAIL; + + // When + RemoteOperationResponseV1_1 result = outboundUtil.createRemoteOperationResponseV1_1( + requestId, userId, partnerId, responseEnum + ); + + // Then + assertEquals(requestId, result.getRoRequestId()); + assertEquals(userId, result.getUserId()); + assertNull(result.getPartnerId()); + assertEquals(responseEnum, result.getResponse()); + } +} \ No newline at end of file diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/StockingRuleConfigUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/StockingRuleConfigUtilTest.java index ec0b5c1..0c98f43 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/StockingRuleConfigUtilTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/StockingRuleConfigUtilTest.java @@ -57,4 +57,39 @@ public void getStockingRuleConfig() { Map resultMap = StockingRuleConfigUtil.getStockingRuleConfig(input); Assertions.assertEquals("vehicle_archType1_precondition", resultMap.get("mappingName")); } + + @Test + public void getStockingRuleConfig_withMissingKey() { + // Missing STOCKING_RULE_CONFIGURATIONOBJECT key + Map input = new HashMap<>(); + Map resultMap = StockingRuleConfigUtil.getStockingRuleConfig(input); + Assertions.assertTrue(resultMap == null || resultMap.isEmpty(), "Expected empty map when key is missing"); + } + + @Test + public void getStockingRuleConfig_withNullInput() { + // Null input + Map resultMap = StockingRuleConfigUtil.getStockingRuleConfig(null); + Assertions.assertTrue(resultMap == null || resultMap.isEmpty(), "Expected empty map when input is null"); + } + + @Test + public void getStockingRuleConfig_withInvalidValue() { + // Value that can't be converted to string + Map input = new HashMap<>(); + input.put(Constants.STOCKING_RULE_CONFIGURATIONOBJECT, new Object()); + Map resultMap = StockingRuleConfigUtil.getStockingRuleConfig(input); + Assertions.assertTrue(resultMap == null || resultMap.isEmpty(), "Expected empty map on parse error"); + } + + @Test + public void getStockingRuleConfig_withMalformedJsonString() { + // Manually passing malformed JSON string + Map input = new HashMap<>(); + input.put(Constants.STOCKING_RULE_CONFIGURATIONOBJECT, "{invalidJson: }"); + Map resultMap = StockingRuleConfigUtil.getStockingRuleConfig(input); + Assertions.assertTrue(resultMap == null || resultMap.isEmpty(), "Expected empty map for invalid JSON string"); + } + + } \ No newline at end of file diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java new file mode 100644 index 0000000..9dd5f4e --- /dev/null +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java @@ -0,0 +1,53 @@ +package org.eclipse.ecsp.ro.utils; + +import org.junit.jupiter.api.Test; + +import java.time.ZoneId; + +import static org.junit.jupiter.api.Assertions.*; + +public class TimeZoneUtilsTest { + + @Test + public void testGetZoneIdByLocation_validCoordinates() { + // Sample coordinates for New York City + double latitude = 40.7128; + double longitude = -74.0060; + + ZoneId zoneId = TimeZoneUtils.getZoneIdByLocation(latitude, longitude); + + assertNotNull(zoneId, "ZoneId should not be null for valid coordinates"); + System.out.println("Zone ID for NYC: " + zoneId); + } + + @Test + public void testGetZoneIdByLocation_invalidCoordinates() { + // Invalid coordinates in the middle of the ocean + double latitude = -90.0; + double longitude = -180.0; + + ZoneId zoneId = TimeZoneUtils.getZoneIdByLocation(latitude, longitude); + + assertNull(zoneId, "ZoneId should be null for invalid coordinates"); + } + + @Test + public void testGetUTCTimestamp_validInput() { + ZoneId zoneId = ZoneId.of("Asia/Kolkata"); + String timeStr = "2025/06/08 10:30:00"; + String pattern = "yyyy/MM/dd HH:mm:ss"; + + long utcTimestamp = TimeZoneUtils.getUTCTimestamp(zoneId, timeStr, pattern); + + assertTrue(utcTimestamp > 0, "UTC timestamp should be greater than zero"); + System.out.println("UTC Timestamp: " + utcTimestamp); + } + + @Test + public void testGetCurrentUTCTimestamp() { + long currentUtc = TimeZoneUtils.getCurrentUTCTimestamp(); + + assertTrue(currentUtc > 0, "Current UTC timestamp should be greater than zero"); + System.out.println("Current UTC Timestamp: " + currentUtc); + } +} \ No newline at end of file diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/UtilsTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/UtilsTest.java index 95c8fe8..35a3245 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/UtilsTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/UtilsTest.java @@ -50,6 +50,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.Assertions; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; @@ -154,4 +155,19 @@ public void testUTCConvert3() { LOGGER.debug("firstScheduleTs: {}", firstScheduleTs); Assert.assertNotNull(zoneId); } + + @Test + public void testLogForging_withInput() { + String input = "Hello\nWorld\rTab\tEnd"; + String expected = "Hello_World_Tab_End"; + + String result = Utils.logForging(input); + Assertions.assertEquals(expected, result); + } + + @Test + public void testLogForging_withNull() { + String result = Utils.logForging(null); + Assertions.assertNull(result); + } } \ No newline at end of file From d823ffe74953298cda70b5b9b479ce3dc6cee337 Mon Sep 17 00:00:00 2001 From: AayVerma Date: Tue, 10 Jun 2025 10:43:47 +0530 Subject: [PATCH 2/7] Added New Test --- .../ro/queue/AbstractQueueHandlerTest.java | 16 +++++++++---- .../ro/queue/RequestQueueHandlerTest.java | 23 +++++++++++-------- .../ecsp/ro/utils/CachedKeyUtilTest.java | 4 +++- .../ecsp/ro/utils/NotificationUtilTest.java | 11 +++++++-- .../ecsp/ro/utils/OutboundUtilTest.java | 5 +++- .../ecsp/ro/utils/TimeZoneUtilsTest.java | 4 +++- 6 files changed, 45 insertions(+), 18 deletions(-) diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java index 52cddba..ab1bfc3 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java @@ -14,14 +14,22 @@ import org.eclipse.ecsp.services.utils.ServiceUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.*; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.redisson.api.RQueue; import org.redisson.api.RedissonClient; import java.time.Instant; -import java.util.*; - -import static org.mockito.Mockito.*; +import java.util.List; +import java.util.Optional; + +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.never; class AbstractQueueHandlerTest { diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java index 1e32e28..eff84b4 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java @@ -1,24 +1,32 @@ package org.eclipse.ecsp.ro.queue; import org.eclipse.ecsp.analytics.stream.base.StreamProcessingContext; -import org.eclipse.ecsp.domain.ro.ROStatus; import org.eclipse.ecsp.entities.AbstractIgniteEvent; import org.eclipse.ecsp.entities.IgniteEvent; import org.eclipse.ecsp.key.IgniteKey; -import org.eclipse.ecsp.key.IgniteStringKey; -import org.eclipse.ecsp.nosqldao.Updates; import org.eclipse.ecsp.ro.RoDAOMongoImpl; import org.eclipse.ecsp.services.utils.ServiceUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.*; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.redisson.api.RQueue; import org.redisson.api.RedissonClient; import java.time.Instant; -import java.util.*; +import java.util.Collections; +import java.util.Iterator; + + +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.eq; + -import static org.mockito.Mockito.*; class RequestQueueHandlerTest { @@ -34,9 +42,6 @@ class RequestQueueHandlerTest { @Mock private RQueue queue; - @Mock - private ServiceUtil serviceUtil; - @Mock private StreamProcessingContext context; diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java index 508d2f2..a6a8aea 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java @@ -6,7 +6,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + class CachedKeyUtilTest { diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java index b77441a..81c88cd 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java @@ -11,13 +11,20 @@ import org.eclipse.ecsp.ro.notification.NotificationResolver; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.*; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + import java.util.HashMap; import java.util.Map; import java.util.Optional; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.any; public class NotificationUtilTest { diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java index 1bf30b9..642d138 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java @@ -13,7 +13,10 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + class OutboundUtilTest { diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java index 9dd5f4e..fac8b8b 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java @@ -4,7 +4,9 @@ import java.time.ZoneId; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TimeZoneUtilsTest { From 08a5ddb12843866df66f2f791af60644c2bdeb4c Mon Sep 17 00:00:00 2001 From: AayVerma Date: Tue, 10 Jun 2025 12:19:32 +0530 Subject: [PATCH 3/7] Added New Test --- .../ro/queue/AbstractQueueHandlerTest.java | 17 +++++++------ .../ro/queue/RequestQueueHandlerTest.java | 25 ++++++++++--------- .../ecsp/ro/utils/CachedKeyUtilTest.java | 1 - .../ecsp/ro/utils/NotificationUtilTest.java | 18 ++++++++----- .../ecsp/ro/utils/OutboundUtilTest.java | 10 +++----- .../ecsp/ro/utils/TimeZoneUtilsTest.java | 23 +++++++++++++---- 6 files changed, 57 insertions(+), 37 deletions(-) diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java index ab1bfc3..7644a23 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java @@ -8,7 +8,6 @@ import org.eclipse.ecsp.entities.AbstractIgniteEvent; import org.eclipse.ecsp.entities.IgniteEvent; import org.eclipse.ecsp.key.IgniteKey; -import org.eclipse.ecsp.key.IgniteStringKey; import org.eclipse.ecsp.nosqldao.Updates; import org.eclipse.ecsp.ro.RoDAOMongoImpl; import org.eclipse.ecsp.services.utils.ServiceUtil; @@ -24,12 +23,12 @@ import java.util.List; import java.util.Optional; +import static org.mockito.Mockito.any; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; class AbstractQueueHandlerTest { @@ -58,6 +57,10 @@ public void process(IgniteKey key, IgniteEvent event, StreamProcessingContext co @Mock private RQueue queue; + private static final int DEFAULT_RO_FOREACH_TTL = 180000; + + private static final int TTL_SUBTRACTION_MILLIS = 200000; + @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); @@ -65,7 +68,7 @@ void setUp() { queueHandler.roDAOMongoImpl = roDAOMongoImpl; queueHandler.redissonClient = redissonClient; queueHandler.serviceUtil = serviceUtil; - queueHandler.roForeachTTL = 180000; + queueHandler.roForeachTTL = DEFAULT_RO_FOREACH_TTL; } @Test @@ -129,9 +132,9 @@ void testCheckTTLExpireANDForwad_sendsEventIfNotExpired() { } @Test - void testCheckTTLExpireANDForwad_expiresEventIfOld() { + void testCheckTTLExpireANDForward_expiresEventIfOld() { AbstractIgniteEvent event = mock(AbstractIgniteEvent.class); - long oldTimestamp = Instant.now().minusMillis(200000).toEpochMilli(); + long oldTimestamp = Instant.now().minusMillis(TTL_SUBTRACTION_MILLIS).toEpochMilli(); when(event.getTimestamp()).thenReturn(oldTimestamp); when(event.getVehicleId()).thenReturn("VIN123"); when(event.getRequestId()).thenReturn("REQ123"); diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java index eff84b4..52b777f 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java @@ -5,7 +5,6 @@ import org.eclipse.ecsp.entities.IgniteEvent; import org.eclipse.ecsp.key.IgniteKey; import org.eclipse.ecsp.ro.RoDAOMongoImpl; -import org.eclipse.ecsp.services.utils.ServiceUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; @@ -20,13 +19,11 @@ import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.eq; - - +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; class RequestQueueHandlerTest { @@ -50,6 +47,10 @@ class RequestQueueHandlerTest { private IgniteEvent igniteEvent; + private static final int DEFAULT_RO_FOREACH_TTL = 180000; + + private static final int TTL_SUBTRACTION_MILLIS = 200000; + @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); @@ -58,7 +59,7 @@ void setUp() { when(igniteEvent.getVehicleId()).thenReturn("VIN1234"); when(igniteEvent.getRequestId()).thenReturn("REQ-1"); queue = mock(RQueue.class); - when(redissonClient.getQueue(anyString())).thenReturn((RQueue)queue); + when(redissonClient.getQueue(anyString())).thenReturn((RQueue) queue); } @Test @@ -69,11 +70,11 @@ void testProcess_withNonExpiredEvent_shouldSendToDevice() { when(event.getVehicleId()).thenReturn("VIN1234"); when(event.getRequestId()).thenReturn("REQ-1"); - when(redissonClient.getQueue(anyString())).thenReturn((RQueue)queue); + when(redissonClient.getQueue(anyString())).thenReturn((RQueue) queue); when(queue.iterator()).thenReturn(Collections.singletonList(event).iterator()); when(queue.size()).thenReturn(1); - requestQueueHandler.roForeachTTL = 180000L; + requestQueueHandler.roForeachTTL = DEFAULT_RO_FOREACH_TTL; requestQueueHandler.process(igniteKey, igniteEvent, context); @@ -84,7 +85,7 @@ void testProcess_withNonExpiredEvent_shouldSendToDevice() { @Test void testProcess_withExpiredEvent_shouldUpdateStatusAndRemove() { AbstractIgniteEvent expiredEvent = mock(AbstractIgniteEvent.class); - long oldTimestamp = Instant.now().minusMillis(999999).toEpochMilli(); + long oldTimestamp = Instant.now().minusMillis(TTL_SUBTRACTION_MILLIS).toEpochMilli(); when(expiredEvent.getTimestamp()).thenReturn(oldTimestamp); when(expiredEvent.getVehicleId()).thenReturn("VIN1234"); @@ -94,11 +95,11 @@ void testProcess_withExpiredEvent_shouldUpdateStatusAndRemove() { when(iterator.hasNext()).thenReturn(true, false); when(iterator.next()).thenReturn(expiredEvent); - when(redissonClient.getQueue(anyString())).thenReturn((RQueue)queue); + when(redissonClient.getQueue(anyString())).thenReturn((RQueue) queue); when(queue.iterator()).thenReturn(iterator); when(queue.size()).thenReturn(1); - requestQueueHandler.roForeachTTL = 180000L; + requestQueueHandler.roForeachTTL = DEFAULT_RO_FOREACH_TTL; requestQueueHandler.process(igniteKey, igniteEvent, context); diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java index a6a8aea..7c8100b 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java @@ -5,7 +5,6 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java index 81c88cd..0b37913 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java @@ -5,9 +5,7 @@ import org.eclipse.ecsp.domain.ro.RemoteOperationResponseV1_1; import org.eclipse.ecsp.domain.ro.RemoteOperationResponseV1_1.Response; import org.eclipse.ecsp.entities.IgniteEvent; -import org.eclipse.ecsp.entities.IgniteEventImpl; import org.eclipse.ecsp.key.IgniteKey; -import org.eclipse.ecsp.ro.domains.ROGenericNotificationEventDataV1_1; import org.eclipse.ecsp.ro.notification.NotificationResolver; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -16,15 +14,20 @@ import org.mockito.MockitoAnnotations; +import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; import java.util.Optional; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.any; import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; -import static org.mockito.Mockito.any; +import static org.mockito.Mockito.when; + +/** + * Test for {@link NotificationUtil} class. + */ public class NotificationUtilTest { @@ -49,6 +52,9 @@ public class NotificationUtilTest { @Mock private GenericCustomExtension customExtension; + /** + * Initializes mocks and sets up the test environment before each test case. + */ @BeforeEach public void setUp() throws Exception { MockitoAnnotations.openMocks(this); @@ -66,7 +72,7 @@ public void setUp() throws Exception { // Inline reflection helper inside the test class private void setField(Object target, String fieldName, Object value) throws Exception { - var field = target.getClass().getDeclaredField(fieldName); + Field field = target.getClass().getDeclaredField(fieldName); field.setAccessible(true); field.set(target, value); } diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java index 642d138..ef6d16f 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java @@ -4,20 +4,18 @@ import org.eclipse.ecsp.domain.ro.RemoteOperationResponseV1_1; import org.eclipse.ecsp.entities.IgniteEvent; import org.eclipse.ecsp.key.IgniteKey; -import org.eclipse.ecsp.entities.IgniteEventImpl; -import org.eclipse.ecsp.entities.UserContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; -import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; - class OutboundUtilTest { private OutboundUtil outboundUtil; @@ -58,7 +56,7 @@ void testSendROResponseOutbound_shouldForwardEvent() { ); // Then - ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(IgniteEvent.class); + ArgumentCaptor.forClass(IgniteEvent.class); verify(mockContext).forward(any()); } diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java index fac8b8b..d781e7e 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java @@ -1,5 +1,6 @@ package org.eclipse.ecsp.ro.utils; +import org.eclipse.ecsp.ro.queue.DeviceMessageFailureQueueHandler; import org.junit.jupiter.api.Test; import java.time.ZoneId; @@ -8,13 +9,21 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; +/** + * Test for {@link TimeZoneUtils} class. + */ + public class TimeZoneUtilsTest { + private static final double NYlat = 40.7128; + + private static final double NYlongi = -74.0060; + @Test public void testGetZoneIdByLocation_validCoordinates() { // Sample coordinates for New York City - double latitude = 40.7128; - double longitude = -74.0060; + double latitude = NYlat; + double longitude = NYlongi; ZoneId zoneId = TimeZoneUtils.getZoneIdByLocation(latitude, longitude); @@ -22,13 +31,17 @@ public void testGetZoneIdByLocation_validCoordinates() { System.out.println("Zone ID for NYC: " + zoneId); } + private static final double INVlat = -90.0; + + private static final double INVlongi = -180.0; + @Test public void testGetZoneIdByLocation_invalidCoordinates() { // Invalid coordinates in the middle of the ocean - double latitude = -90.0; - double longitude = -180.0; + double invlatitude = INVlat; + double invlongitude = INVlongi; - ZoneId zoneId = TimeZoneUtils.getZoneIdByLocation(latitude, longitude); + ZoneId zoneId = TimeZoneUtils.getZoneIdByLocation(invlatitude, invlongitude); assertNull(zoneId, "ZoneId should be null for invalid coordinates"); } From 1b3f6685e1c85f9719c043fcb95dd97ec8a4e29b Mon Sep 17 00:00:00 2001 From: AayVerma Date: Tue, 10 Jun 2025 12:30:59 +0530 Subject: [PATCH 4/7] Added New Test --- .../org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java | 10 +++------- .../org/eclipse/ecsp/ro/utils/OutboundUtilTest.java | 4 ++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java index 7c8100b..e4e2256 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java @@ -8,16 +8,12 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +/** + * Test for {@link CachedKeyUtil} class. + */ class CachedKeyUtilTest { - /*@Test - void testPrivateConstructor_shouldThrowException() throws Exception { - var constructor = CachedKeyUtil.class.getDeclaredConstructor(); - constructor.setAccessible(true); - assertThrows(UnsupportedOperationException.class, constructor::newInstance); - }*/ - @Test void getEngineStatusKey_shouldReturnCorrectKey() { IgniteEvent event = mock(IgniteEvent.class); diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java index ef6d16f..735f339 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java @@ -16,6 +16,10 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +/** + * Test for {@link OutboundUtil} class. + */ + class OutboundUtilTest { private OutboundUtil outboundUtil; From b090db05e3a31eaedb6bb3ae14a51b3860c2d47e Mon Sep 17 00:00:00 2001 From: AayVerma Date: Tue, 10 Jun 2025 12:46:40 +0530 Subject: [PATCH 5/7] Added New Test --- .../test/java/org/eclipse/ecsp/ro/RoDAOMongoImplTest.java | 1 - .../eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java | 6 ++++-- .../org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java | 7 ++++--- .../java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java | 2 -- .../org/eclipse/ecsp/ro/utils/NotificationUtilTest.java | 5 ----- .../java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java | 3 --- .../java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java | 3 --- 7 files changed, 8 insertions(+), 19 deletions(-) diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/RoDAOMongoImplTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/RoDAOMongoImplTest.java index 15b1907..c141a75 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/RoDAOMongoImplTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/RoDAOMongoImplTest.java @@ -53,7 +53,6 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; - import java.util.Optional; /** diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java index 7644a23..07a9e17 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java @@ -10,6 +10,7 @@ import org.eclipse.ecsp.key.IgniteKey; import org.eclipse.ecsp.nosqldao.Updates; import org.eclipse.ecsp.ro.RoDAOMongoImpl; +import org.eclipse.ecsp.ro.utils.TimeZoneUtils; import org.eclipse.ecsp.services.utils.ServiceUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -18,11 +19,9 @@ import org.mockito.MockitoAnnotations; import org.redisson.api.RQueue; import org.redisson.api.RedissonClient; - import java.time.Instant; import java.util.List; import java.util.Optional; - import static org.mockito.Mockito.any; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; @@ -30,6 +29,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +/** + * Test for {@link AbstractQueueHandler} class. + */ class AbstractQueueHandlerTest { static class TestQueueHandler extends AbstractQueueHandler { diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java index 52b777f..d37398b 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java @@ -5,6 +5,7 @@ import org.eclipse.ecsp.entities.IgniteEvent; import org.eclipse.ecsp.key.IgniteKey; import org.eclipse.ecsp.ro.RoDAOMongoImpl; +import org.eclipse.ecsp.ro.utils.TimeZoneUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; @@ -12,12 +13,9 @@ import org.mockito.MockitoAnnotations; import org.redisson.api.RQueue; import org.redisson.api.RedissonClient; - import java.time.Instant; import java.util.Collections; import java.util.Iterator; - - import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.eq; @@ -25,6 +23,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +/** + * Test for {@link RequestQueueHandler} class. + */ class RequestQueueHandlerTest { @InjectMocks diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java index e4e2256..eacc68d 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/CachedKeyUtilTest.java @@ -3,7 +3,6 @@ import org.eclipse.ecsp.entities.IgniteEvent; import org.eclipse.ecsp.ro.constants.Constants; import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -11,7 +10,6 @@ /** * Test for {@link CachedKeyUtil} class. */ - class CachedKeyUtilTest { @Test diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java index 0b37913..592d0ae 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java @@ -12,13 +12,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; - - import java.lang.reflect.Field; -import java.util.HashMap; import java.util.Map; import java.util.Optional; - import static org.mockito.Mockito.any; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.verify; @@ -28,7 +24,6 @@ /** * Test for {@link NotificationUtil} class. */ - public class NotificationUtilTest { @InjectMocks diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java index 735f339..c262fcc 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/OutboundUtilTest.java @@ -7,11 +7,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; - import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -19,7 +17,6 @@ /** * Test for {@link OutboundUtil} class. */ - class OutboundUtilTest { private OutboundUtil outboundUtil; diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java index d781e7e..d155e8c 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java @@ -2,9 +2,7 @@ import org.eclipse.ecsp.ro.queue.DeviceMessageFailureQueueHandler; import org.junit.jupiter.api.Test; - import java.time.ZoneId; - import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -12,7 +10,6 @@ /** * Test for {@link TimeZoneUtils} class. */ - public class TimeZoneUtilsTest { private static final double NYlat = 40.7128; From 89b105b9aff378090ccdbb34575eaac5d9f38b41 Mon Sep 17 00:00:00 2001 From: AayVerma Date: Wed, 11 Jun 2025 14:23:20 +0530 Subject: [PATCH 6/7] Added New Test --- pom.xml | 3 - .../DefaultDMAShoulderTapResolverTest.java | 47 +++++++++ .../impl/rcpd/RCPDRequestProcessorTest.java | 96 +++++++++++++++++++ 3 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 ro-sp/src/test/java/org/eclipse/ecsp/ro/dma/DefaultDMAShoulderTapResolverTest.java create mode 100644 ro-sp/src/test/java/org/eclipse/ecsp/ro/processor/strategy/impl/rcpd/RCPDRequestProcessorTest.java diff --git a/pom.xml b/pom.xml index b55017b..ede3e33 100644 --- a/pom.xml +++ b/pom.xml @@ -126,15 +126,12 @@ **/org/eclipse/ecsp/platform/services/ro/configure/*.java, **/org/eclipse/ecsp/ro/RoScheduleV2DAOMongoImpl.java, **/org/eclipse/ecsp/ro/utils/CacheUtil.java, - **/org/eclipse/ecsp/ro/utils/Utils.java, **/org/eclipse/ecsp/platform/services/ro/rest/RCPDController.java, **/org/eclipse/ecsp/platform/services/ro/rest/ROHoodTrunkLiftgateController.java, - **/org/eclipse/ecsp/ro/notification/StockingRuleNotificationResolver.java, **/org/eclipse/ecsp/platform/services/ro/rest/ROHornLightsAlarmController.java, **/org/eclipse/ecsp/platform/services/ro/rest/ROStatusHistoryController.java, **/org/eclipse/ecsp/ro/queue/ResponseQueueHandler.java, **/org/eclipse/ecsp/platform/services/ro/handler/ApiRequestHandler.java, - **/org/eclipse/ecsp/ro/notification/identifier/NotificationArchAndECUTypeResolver.java diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/dma/DefaultDMAShoulderTapResolverTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/dma/DefaultDMAShoulderTapResolverTest.java new file mode 100644 index 0000000..28a9199 --- /dev/null +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/dma/DefaultDMAShoulderTapResolverTest.java @@ -0,0 +1,47 @@ +package org.eclipse.ecsp.ro.dma; + +import org.eclipse.ecsp.entities.IgniteEvent; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Field; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; + +class DefaultDMAShoulderTapResolverTest { + + private DefaultDMAShoulderTapResolver resolver; + + @BeforeEach + void setUp() throws Exception { + resolver = new DefaultDMAShoulderTapResolver(); + } + + private void injectShoulderTapValue(boolean value) throws Exception { + Field field = DefaultDMAShoulderTapResolver.class.getDeclaredField("shoulderTap"); + field.setAccessible(true); + field.set(resolver, value); + } + + @Test + void testIsShoulderTap_WhenTrue() throws Exception { + injectShoulderTapValue(true); + + IgniteEvent mockEvent = mock(IgniteEvent.class); + boolean result = resolver.isShoulderTap(mockEvent); + + assertTrue(result, "Expected shoulderTap to be true"); + } + + @Test + void testIsShoulderTap_WhenFalse() throws Exception { + injectShoulderTapValue(false); + + IgniteEvent mockEvent = mock(IgniteEvent.class); + boolean result = resolver.isShoulderTap(mockEvent); + + assertFalse(result, "Expected shoulderTap to be false"); + } +} \ No newline at end of file diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/processor/strategy/impl/rcpd/RCPDRequestProcessorTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/processor/strategy/impl/rcpd/RCPDRequestProcessorTest.java new file mode 100644 index 0000000..9e93e75 --- /dev/null +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/processor/strategy/impl/rcpd/RCPDRequestProcessorTest.java @@ -0,0 +1,96 @@ +package org.eclipse.ecsp.ro.processor.strategy.impl.rcpd; + +import org.apache.kafka.streams.processor.api.Record; +import org.eclipse.ecsp.analytics.stream.base.StreamProcessingContext; +import org.eclipse.ecsp.entities.IgniteEvent; +import org.eclipse.ecsp.entities.IgniteEventImpl; +import org.eclipse.ecsp.key.IgniteKey; +import org.eclipse.ecsp.ro.processor.RCPDHandler; +import org.eclipse.ecsp.services.utils.ServiceUtil; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.test.util.ReflectionTestUtils; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * RCPDRequestProcessorTest - This class contains unit tests for the RCPDRequestProcessor. + */ +@ExtendWith(MockitoExtension.class) +public class RCPDRequestProcessorTest { + + // Mock dependencies using @Mock + @Mock + private RCPDHandler rcpdEventHandler; + + @Mock + private ServiceUtil serviceUtil; + + @InjectMocks + private RCPDRequestProcessor rcpdRequestProcessor; + + // Define a value for the rcpdMqttTopic, which would normally be injected by Spring + private static final String MOCK_MQTT_TOPIC = "mock/rcpd/topic"; + + /** + * Set up method executed before each test. + * Used to inject the mocked @Value property using ReflectionTestUtils. + */ + @BeforeEach + void setUp() { + // Use ReflectionTestUtils to set the private field 'rcpdMqttTopic' + // This simulates how @Value would inject the property in a real Spring context. + ReflectionTestUtils.setField(rcpdRequestProcessor, "rcpdMqttTopic", MOCK_MQTT_TOPIC); + } + + /** + * Test case for the process method. + * Verifies that: + * 1. rcpdEventHandler.processRCPDRequest is called with correct arguments. + * 2. The returned IgniteEventImpl has the correct devMsgTopicSuffix set. + * 3. ctxt.forward is called with the correctly constructed Kafka Record. + */ + @Test + void testProcess() { + IgniteKey mockKey = mock(IgniteKey.class); + IgniteEvent mockValue = mock(IgniteEvent.class); + Record, IgniteEvent> kafkaRecordIn = new Record<>(mockKey, mockValue, System.currentTimeMillis()); + + StreamProcessingContext mockCtxt = mock(StreamProcessingContext.class); + + IgniteEventImpl mockRcpdReqImpl = mock(IgniteEventImpl.class); + + when(rcpdEventHandler.processRCPDRequest( + eq(mockKey), + eq(mockValue), + eq(serviceUtil) + )).thenReturn(mockRcpdReqImpl); + + // Act + rcpdRequestProcessor.process(kafkaRecordIn, mockCtxt); + + // Assert + verify(rcpdEventHandler).processRCPDRequest(mockKey, mockValue, serviceUtil); + + verify(mockRcpdReqImpl).setDevMsgTopicSuffix(MOCK_MQTT_TOPIC); + + ArgumentCaptor, IgniteEvent>> recordCaptor = ArgumentCaptor.forClass(Record.class); + verify(mockCtxt).forward(recordCaptor.capture()); + + Record, IgniteEvent> forwardedRecord = recordCaptor.getValue(); + + // Assertions on the forwarded record + // Verify the key of the forwarded record is the same as the input key + assertEquals(mockKey, forwardedRecord.key()); + // Verify the value of the forwarded record is the mockRcpdReqImpl (after topic suffix is set) + assertEquals(mockRcpdReqImpl, forwardedRecord.value()); + } +} \ No newline at end of file From d0b8dd505f47009d04e7caf5f22c5e1728b8b4f4 Mon Sep 17 00:00:00 2001 From: AayVerma Date: Fri, 13 Jun 2025 14:26:47 +0530 Subject: [PATCH 7/7] Sonar issue fix and OSSRH migration --- pom.xml | 47 ++++--------------- ro-api/pom.xml | 4 +- ro-entities/pom.xml | 4 +- ro-sp/pom.xml | 4 +- .../DefaultDMAShoulderTapResolverTest.java | 2 +- .../impl/rcpd/RCPDRequestProcessorTest.java | 9 ++-- .../ro/queue/AbstractQueueHandlerTest.java | 1 - .../ro/queue/RequestQueueHandlerTest.java | 4 +- .../ecsp/ro/utils/NotificationUtilTest.java | 10 ++-- .../ro/utils/StockingRuleConfigUtilTest.java | 8 ++-- .../ecsp/ro/utils/TimeZoneUtilsTest.java | 27 +++++------ 11 files changed, 47 insertions(+), 73 deletions(-) diff --git a/pom.xml b/pom.xml index ede3e33..1318a2b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.eclipse.ecsp - 1.0.0 + 1.0.1 ro ro RO library for ECSP project @@ -181,6 +181,7 @@ ${project.basedir}/checkstyle.xml ${project.build.directory}/checkstyle-result.xml + 0.7.0 @@ -621,16 +622,6 @@ - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - @@ -660,27 +651,19 @@ true - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.13 + org.sonatype.central + central-publishing-maven-plugin + ${central-publishing-maven-plugin.version} true - ossrh - https://oss.sonatype.org/ - true + central + true + published + https://central.sonatype.com/repository/maven-snapshots/ + false @@ -730,16 +713,6 @@ true - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - diff --git a/ro-api/pom.xml b/ro-api/pom.xml index 9c31d8b..c77cc11 100644 --- a/ro-api/pom.xml +++ b/ro-api/pom.xml @@ -6,10 +6,12 @@ org.eclipse.ecsp ro - 1.0.0 + 1.0.1 ro-api ro-api + ro library for ECSP project + https://github.com/eclipse-ecsp/ro UTF-8 org.eclipse.ecsp.platform.services.ro.Application diff --git a/ro-entities/pom.xml b/ro-entities/pom.xml index 7153cdb..e445a6b 100644 --- a/ro-entities/pom.xml +++ b/ro-entities/pom.xml @@ -5,10 +5,12 @@ org.eclipse.ecsp ro - 1.0.0 + 1.0.1 ro-entities ro-entities + ro library for ECSP project + https://github.com/eclipse-ecsp/ro UTF-8 diff --git a/ro-sp/pom.xml b/ro-sp/pom.xml index 3619cad..f192690 100644 --- a/ro-sp/pom.xml +++ b/ro-sp/pom.xml @@ -5,10 +5,12 @@ org.eclipse.ecsp ro - 1.0.0 + 1.0.1 ro-sp ro-sp + ro library for ECSP project + https://github.com/eclipse-ecsp/ro jar UTF-8 diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/dma/DefaultDMAShoulderTapResolverTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/dma/DefaultDMAShoulderTapResolverTest.java index 28a9199..966d296 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/dma/DefaultDMAShoulderTapResolverTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/dma/DefaultDMAShoulderTapResolverTest.java @@ -15,7 +15,7 @@ class DefaultDMAShoulderTapResolverTest { private DefaultDMAShoulderTapResolver resolver; @BeforeEach - void setUp() throws Exception { + void setUp() { resolver = new DefaultDMAShoulderTapResolver(); } diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/processor/strategy/impl/rcpd/RCPDRequestProcessorTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/processor/strategy/impl/rcpd/RCPDRequestProcessorTest.java index 9e93e75..c8ad84b 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/processor/strategy/impl/rcpd/RCPDRequestProcessorTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/processor/strategy/impl/rcpd/RCPDRequestProcessorTest.java @@ -16,7 +16,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.test.util.ReflectionTestUtils; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -25,7 +24,7 @@ * RCPDRequestProcessorTest - This class contains unit tests for the RCPDRequestProcessor. */ @ExtendWith(MockitoExtension.class) -public class RCPDRequestProcessorTest { +class RCPDRequestProcessorTest { // Mock dependencies using @Mock @Mock @@ -69,9 +68,9 @@ void testProcess() { IgniteEventImpl mockRcpdReqImpl = mock(IgniteEventImpl.class); when(rcpdEventHandler.processRCPDRequest( - eq(mockKey), - eq(mockValue), - eq(serviceUtil) + mockKey, + mockValue, + serviceUtil )).thenReturn(mockRcpdReqImpl); // Act diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java index 07a9e17..8c1fcff 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/AbstractQueueHandlerTest.java @@ -10,7 +10,6 @@ import org.eclipse.ecsp.key.IgniteKey; import org.eclipse.ecsp.nosqldao.Updates; import org.eclipse.ecsp.ro.RoDAOMongoImpl; -import org.eclipse.ecsp.ro.utils.TimeZoneUtils; import org.eclipse.ecsp.services.utils.ServiceUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java index d37398b..dcd9fb7 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/queue/RequestQueueHandlerTest.java @@ -5,7 +5,6 @@ import org.eclipse.ecsp.entities.IgniteEvent; import org.eclipse.ecsp.key.IgniteKey; import org.eclipse.ecsp.ro.RoDAOMongoImpl; -import org.eclipse.ecsp.ro.utils.TimeZoneUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; @@ -18,7 +17,6 @@ import java.util.Iterator; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -105,6 +103,6 @@ void testProcess_withExpiredEvent_shouldUpdateStatusAndRemove() { requestQueueHandler.process(igniteKey, igniteEvent, context); // Should call updateEntityByROStatus - verify(roDAOMongoImpl, atLeastOnce()).getROEntityByFieldNameByRoReqIdExceptACV(eq("VIN1234"), eq("REQ-2")); + verify(roDAOMongoImpl, atLeastOnce()).getROEntityByFieldNameByRoReqIdExceptACV("VIN1234", "REQ-2"); } } \ No newline at end of file diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java index 592d0ae..fb87cb9 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/NotificationUtilTest.java @@ -24,7 +24,7 @@ /** * Test for {@link NotificationUtil} class. */ -public class NotificationUtilTest { +class NotificationUtilTest { @InjectMocks private NotificationUtil notificationUtil; @@ -51,7 +51,7 @@ public class NotificationUtilTest { * Initializes mocks and sets up the test environment before each test case. */ @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { MockitoAnnotations.openMocks(this); notificationUtil = new NotificationUtil(); @@ -73,7 +73,7 @@ private void setField(Object target, String fieldName, Object value) throws Exce } @Test - public void testSendRONotification_withValidInput_shouldForwardEvent() { + void testSendRONotification_withValidInput_shouldForwardEvent() { when(igniteEvent.getVehicleId()).thenReturn("veh123"); when(igniteEvent.getBizTransactionId()).thenReturn("biz123"); @@ -96,7 +96,7 @@ public void testSendRONotification_withValidInput_shouldForwardEvent() { } @Test - public void testSendRONotification_withNonWhitelistedOrigin_shouldNotSend() { + void testSendRONotification_withNonWhitelistedOrigin_shouldNotSend() { notificationUtil.sendRONotification( igniteKey, igniteEvent, @@ -110,7 +110,7 @@ public void testSendRONotification_withNonWhitelistedOrigin_shouldNotSend() { } @Test - public void testSendRONotification_withEmptyNotificationId_shouldSkip() { + void testSendRONotification_withEmptyNotificationId_shouldSkip() { when(response.getRoRequestId()).thenReturn("ro-req-1"); notificationUtil.sendRONotification( diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/StockingRuleConfigUtilTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/StockingRuleConfigUtilTest.java index 0c98f43..976db4e 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/StockingRuleConfigUtilTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/StockingRuleConfigUtilTest.java @@ -59,7 +59,7 @@ public void getStockingRuleConfig() { } @Test - public void getStockingRuleConfig_withMissingKey() { + void getStockingRuleConfig_withMissingKey() { // Missing STOCKING_RULE_CONFIGURATIONOBJECT key Map input = new HashMap<>(); Map resultMap = StockingRuleConfigUtil.getStockingRuleConfig(input); @@ -67,14 +67,14 @@ public void getStockingRuleConfig_withMissingKey() { } @Test - public void getStockingRuleConfig_withNullInput() { + void getStockingRuleConfig_withNullInput() { // Null input Map resultMap = StockingRuleConfigUtil.getStockingRuleConfig(null); Assertions.assertTrue(resultMap == null || resultMap.isEmpty(), "Expected empty map when input is null"); } @Test - public void getStockingRuleConfig_withInvalidValue() { + void getStockingRuleConfig_withInvalidValue() { // Value that can't be converted to string Map input = new HashMap<>(); input.put(Constants.STOCKING_RULE_CONFIGURATIONOBJECT, new Object()); @@ -83,7 +83,7 @@ public void getStockingRuleConfig_withInvalidValue() { } @Test - public void getStockingRuleConfig_withMalformedJsonString() { + void getStockingRuleConfig_withMalformedJsonString() { // Manually passing malformed JSON string Map input = new HashMap<>(); input.put(Constants.STOCKING_RULE_CONFIGURATIONOBJECT, "{invalidJson: }"); diff --git a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java index d155e8c..34fbd23 100644 --- a/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java +++ b/ro-sp/src/test/java/org/eclipse/ecsp/ro/utils/TimeZoneUtilsTest.java @@ -1,6 +1,5 @@ package org.eclipse.ecsp.ro.utils; -import org.eclipse.ecsp.ro.queue.DeviceMessageFailureQueueHandler; import org.junit.jupiter.api.Test; import java.time.ZoneId; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -10,17 +9,17 @@ /** * Test for {@link TimeZoneUtils} class. */ -public class TimeZoneUtilsTest { +class TimeZoneUtilsTest { - private static final double NYlat = 40.7128; + private static final double NY_LAT = 40.7128; - private static final double NYlongi = -74.0060; + private static final double NY_LONG = -74.0060; @Test - public void testGetZoneIdByLocation_validCoordinates() { + void testGetZoneIdByLocation_validCoordinates() { // Sample coordinates for New York City - double latitude = NYlat; - double longitude = NYlongi; + double latitude = NY_LAT; + double longitude = NY_LONG; ZoneId zoneId = TimeZoneUtils.getZoneIdByLocation(latitude, longitude); @@ -28,15 +27,15 @@ public void testGetZoneIdByLocation_validCoordinates() { System.out.println("Zone ID for NYC: " + zoneId); } - private static final double INVlat = -90.0; + private static final double INV_LAT = -90.0; - private static final double INVlongi = -180.0; + private static final double INV_LONG = -180.0; @Test - public void testGetZoneIdByLocation_invalidCoordinates() { + void testGetZoneIdByLocation_invalidCoordinates() { // Invalid coordinates in the middle of the ocean - double invlatitude = INVlat; - double invlongitude = INVlongi; + double invlatitude = INV_LAT; + double invlongitude = INV_LONG; ZoneId zoneId = TimeZoneUtils.getZoneIdByLocation(invlatitude, invlongitude); @@ -44,7 +43,7 @@ public void testGetZoneIdByLocation_invalidCoordinates() { } @Test - public void testGetUTCTimestamp_validInput() { + void testGetUTCTimestamp_validInput() { ZoneId zoneId = ZoneId.of("Asia/Kolkata"); String timeStr = "2025/06/08 10:30:00"; String pattern = "yyyy/MM/dd HH:mm:ss"; @@ -56,7 +55,7 @@ public void testGetUTCTimestamp_validInput() { } @Test - public void testGetCurrentUTCTimestamp() { + void testGetCurrentUTCTimestamp() { long currentUtc = TimeZoneUtils.getCurrentUTCTimestamp(); assertTrue(currentUtc > 0, "Current UTC timestamp should be greater than zero");