diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/ScanService.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/ScanService.java index 3fe6c76c..5ce50e18 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/ScanService.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/ScanService.java @@ -12,10 +12,12 @@ import com.solace.maas.ep.event.management.agent.repository.model.scan.ScanEntity; import com.solace.maas.ep.event.management.agent.repository.model.scan.ScanRecipientEntity; import com.solace.maas.ep.event.management.agent.repository.model.scan.ScanRecipientHierarchyEntity; +import com.solace.maas.ep.event.management.agent.repository.model.scan.ScanStatusEntity; import com.solace.maas.ep.event.management.agent.repository.model.scan.ScanTypeEntity; import com.solace.maas.ep.event.management.agent.repository.scan.ScanRecipientHierarchyRepository; import com.solace.maas.ep.event.management.agent.repository.scan.ScanRepository; import com.solace.maas.ep.event.management.agent.repository.scan.ScanTypeRepository; +import com.solace.maas.ep.event.management.agent.repository.scan.ScanStatusRepository; import com.solace.maas.ep.event.management.agent.scanManager.model.ScanItemBO; import com.solace.maas.ep.event.management.agent.scanManager.model.ScanTypeBO; import com.solace.maas.ep.event.management.agent.util.IDGenerator; @@ -50,6 +52,8 @@ public class ScanService { private final ScanTypeRepository scanTypeRepository; + private final ScanStatusRepository scanStatusRepository; + private final ScanRouteService scanRouteService; private final RouteService routeService; @@ -60,12 +64,13 @@ public class ScanService { public ScanService(ScanRepository repository, ScanRecipientHierarchyRepository scanRecipientHierarchyRepository, - ScanTypeRepository scanTypeRepository, ScanRouteService scanRouteService, + ScanTypeRepository scanTypeRepository, ScanStatusRepository scanStatusRepository, ScanRouteService scanRouteService, RouteService routeService, ProducerTemplate producerTemplate, IDGenerator idGenerator) { this.repository = repository; this.scanRecipientHierarchyRepository = scanRecipientHierarchyRepository; this.scanTypeRepository = scanTypeRepository; + this.scanStatusRepository = scanStatusRepository; this.scanRouteService = scanRouteService; this.routeService = routeService; this.producerTemplate = producerTemplate; @@ -219,6 +224,8 @@ private ScanEntity saveScanEntity(String scanId, String traceId, MessagingServic } private void setScanType(RouteBundle routeBundle, ScanEntity scanEntity) { + + ScanTypeEntity scanType = ScanTypeEntity.builder() .id(idGenerator.generateRandomUniqueId()) .name(routeBundle.getScanType()) @@ -226,8 +233,20 @@ private void setScanType(RouteBundle routeBundle, ScanEntity scanEntity) { .build(); scanTypeRepository.save(scanType); + + setScanStatus(scanType); } + private void setScanStatus(ScanTypeEntity scanType) { + ScanStatusEntity scanStatus = ScanStatusEntity.builder() + .id(idGenerator.generateRandomUniqueId()) + .status(ScanStatus.INITIATED.name()) + .scanType(scanType) + .build(); + + scanStatusRepository.save(scanStatus); + + } protected void setupRecipientsForScan(ScanEntity scanEntity, RouteBundle routeBundle) { for (RouteBundle recipient : routeBundle.getRecipients()) { diff --git a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/service/ScanServiceTests.java b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/service/ScanServiceTests.java index cb76cad6..d2844f56 100644 --- a/service/application/src/test/java/com/solace/maas/ep/event/management/agent/service/ScanServiceTests.java +++ b/service/application/src/test/java/com/solace/maas/ep/event/management/agent/service/ScanServiceTests.java @@ -14,6 +14,7 @@ import com.solace.maas.ep.event.management.agent.repository.model.scan.ScanTypeEntity; import com.solace.maas.ep.event.management.agent.repository.scan.ScanRecipientHierarchyRepository; import com.solace.maas.ep.event.management.agent.repository.scan.ScanRepository; +import com.solace.maas.ep.event.management.agent.repository.scan.ScanStatusRepository; import com.solace.maas.ep.event.management.agent.repository.scan.ScanTypeRepository; import com.solace.maas.ep.event.management.agent.service.logging.LoggingService; import com.solace.maas.ep.event.management.agent.util.IDGenerator; @@ -23,6 +24,7 @@ import org.apache.camel.ProducerTemplate; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; @@ -41,9 +43,12 @@ import java.util.concurrent.CompletableFuture; import static org.assertj.core.api.Assertions.assertThatNoException; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.when; +import static org.mockito.Mockito.verify; @ActiveProfiles("TEST") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestConfig.class) @@ -63,6 +68,9 @@ public class ScanServiceTests { @Mock private ScanTypeRepository scanTypeRepository; + @Mock + private ScanStatusRepository scanStatusRepository; + @Mock private ScanRecipientHierarchyRepository scanRecipientHierarchyRepository; @@ -115,6 +123,7 @@ public void testSingleScanWithRouteBundle() { RouteEntity returnedEntity = scanServiceHelper.buildRouteEntity(routeId, "", true); ScanEntity scanEntity = scanServiceHelper.buildScanEntity("123", "emaId1", List.of(returnedEntity), null); ScanTypeEntity scanType = scanServiceHelper.buildScanTypeEntity("scan1", "scanType", scanEntity, null); + ScanStatusEntity scanStatus = scanServiceHelper.buildScanStatusEntity("scanstatus1", "dummyStatus"); when(idGenerator.generateRandomUniqueId()) .thenReturn("abc123"); @@ -132,6 +141,9 @@ public void testSingleScanWithRouteBundle() { .thenReturn(scanEntity); when(scanTypeRepository.save(scanType)) .thenReturn(scanType); + when(scanStatusRepository.save(scanStatus)) + .thenReturn(scanStatus); + when(scanRecipientHierarchyRepository.save(any(ScanRecipientHierarchyEntity.class))) .thenReturn(mock(ScanRecipientHierarchyEntity.class)); @@ -142,6 +154,12 @@ public void testSingleScanWithRouteBundle() { mock(MessagingServiceEntity.class), "runtimeAgent1"); + ArgumentCaptor scanCaptor = ArgumentCaptor.forClass(ScanStatusEntity.class); + verify(scanStatusRepository, times(8)).save(scanCaptor.capture()); + + // Assert that the scanStatus is initialized to "INITIATED" for all scan types + scanCaptor.getAllValues().stream().forEach(entity -> assertThat(entity.getStatus().equals(ScanStatus.INITIATED.name()))); + assertThatNoException(); } @@ -293,7 +311,7 @@ public void testParseRouteRecipients() { public void testSendScanStatus() { ScanService service = new ScanService(mock(ScanRepository.class), mock(ScanRecipientHierarchyRepository.class), mock(ScanTypeRepository.class), - mock(ScanRouteService.class), mock(RouteService.class), template, idGenerator); + mock(ScanStatusRepository.class), mock(ScanRouteService.class), mock(RouteService.class), template, idGenerator); service.sendScanStatus("scanId", "groupId", "messagingServiceId", "traceId", "queueListing", ScanStatus.IN_PROGRESS);