diff --git a/src/main/java/it/pagopa/interop/signalhub/updater/service/impl/TracingBatchServiceImpl.java b/src/main/java/it/pagopa/interop/signalhub/updater/service/impl/TracingBatchServiceImpl.java index a60d0de..a834c93 100644 --- a/src/main/java/it/pagopa/interop/signalhub/updater/service/impl/TracingBatchServiceImpl.java +++ b/src/main/java/it/pagopa/interop/signalhub/updater/service/impl/TracingBatchServiceImpl.java @@ -37,7 +37,7 @@ public Integer countBatchInErrorWithLastEventIdAndType(Long lastEventId, String public Long getLastEventIdByTracingBatchAndType(String type) { List list = repository.findLatestByType(type); if (list.isEmpty()) return 0L; - if (list.get(0).getState().equals(TracingBatchStateEnum.ENDED.name())){ + if (list.get(0).getState() == TracingBatchStateEnum.ENDED){ return list.get(0).getLastEventId(); } if (list.size() >= props.getAttemptEvent()){ @@ -51,7 +51,7 @@ public TracingBatchDto terminateTracingBatch(TracingBatchStateEnum stateEnum, Lo TracingBatchEntity tracingBatchEntity = new TracingBatchEntity(); tracingBatchEntity.setTmstCreated(Timestamp.from(Instant.now())); tracingBatchEntity.setLastEventId(eventId-1); - tracingBatchEntity.setState(stateEnum.name()); + tracingBatchEntity.setState(stateEnum); tracingBatchEntity.setType(type); tracingBatchEntity = this.repository.saveAndFlush(tracingBatchEntity); log.debug("Create a tracing batch entity of type {} {}", type, tracingBatchEntity); diff --git a/src/test/java/it/pagopa/interop/signalhub/updater/mapper/TracingBatchMapperImplTest.java b/src/test/java/it/pagopa/interop/signalhub/updater/mapper/TracingBatchMapperImplTest.java index 3c609b7..0d946b2 100644 --- a/src/test/java/it/pagopa/interop/signalhub/updater/mapper/TracingBatchMapperImplTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/updater/mapper/TracingBatchMapperImplTest.java @@ -11,7 +11,7 @@ class TracingBatchMapperImplTest { private Long batchId; private Long lastEventId; - private String state; + private TracingBatchStateEnum state; private TracingBatchMapperImpl tracingBatchMapper; @BeforeEach @@ -26,7 +26,7 @@ void toDtoTest() { assertNotNull(tracingBatchDto); assertEquals(batchId, tracingBatchDto.getBatchId()); assertEquals(lastEventId, tracingBatchDto.getLastEventId()); - assertEquals(state, tracingBatchDto.getState().name()); + assertEquals(state, tracingBatchDto.getState()); tracingBatchEntity.setState(null); tracingBatchDto = tracingBatchMapper.toDto(tracingBatchEntity); @@ -52,7 +52,7 @@ private TracingBatchEntity getTracingBatchEntity() { private void setUp() { this.batchId = 0L; this.lastEventId = 100L; - this.state = TracingBatchStateEnum.ENDED.name(); + this.state = TracingBatchStateEnum.ENDED; this.tracingBatchMapper = new TracingBatchMapperImpl(); } } \ No newline at end of file diff --git a/src/test/java/it/pagopa/interop/signalhub/updater/service/impl/InteropServiceImplTest.java b/src/test/java/it/pagopa/interop/signalhub/updater/service/impl/InteropServiceImplTest.java index 20bea47..3e49440 100644 --- a/src/test/java/it/pagopa/interop/signalhub/updater/service/impl/InteropServiceImplTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/updater/service/impl/InteropServiceImplTest.java @@ -52,7 +52,7 @@ void getAgreementsAndEServices() { EventsDto eventsDto = interopService.getEventsByType(1L, Const.ESERVICE_EVENT); assertNotNull(eventsDto); assertEquals(responseMock.getLastEventId(), eventsDto.getLastEventId()); - assertEquals(3, eventsDto.getEvents().size()); + assertEquals(7, eventsDto.getEvents().size()); } @Test diff --git a/src/test/java/it/pagopa/interop/signalhub/updater/service/impl/TracingBatchServiceImplTest.java b/src/test/java/it/pagopa/interop/signalhub/updater/service/impl/TracingBatchServiceImplTest.java index 5a0a7dc..c72d4e3 100644 --- a/src/test/java/it/pagopa/interop/signalhub/updater/service/impl/TracingBatchServiceImplTest.java +++ b/src/test/java/it/pagopa/interop/signalhub/updater/service/impl/TracingBatchServiceImplTest.java @@ -4,6 +4,7 @@ import it.pagopa.interop.signalhub.updater.entity.TracingBatchEntity; import it.pagopa.interop.signalhub.updater.mapper.TracingBatchMapper; import it.pagopa.interop.signalhub.updater.model.TracingBatchDto; +import it.pagopa.interop.signalhub.updater.model.TracingBatchStateEnum; import it.pagopa.interop.signalhub.updater.repository.TracingBatchRepository; import it.pagopa.interop.signalhub.updater.utility.Const; import org.junit.jupiter.api.Test; @@ -17,6 +18,7 @@ import java.util.List; import static it.pagopa.interop.signalhub.updater.model.TracingBatchStateEnum.ENDED; +import static it.pagopa.interop.signalhub.updater.model.TracingBatchStateEnum.ENDED_WITH_ERROR; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -41,7 +43,7 @@ void checkAndCreateTracingBatch() { //state = ENDED TracingBatchEntity tracingBatchEntity= new TracingBatchEntity(); - tracingBatchEntity.setState(ENDED.name()); + tracingBatchEntity.setState(ENDED); tracingBatchEntity.setLastEventId(1L); List list= new ArrayList<>(); list.add(tracingBatchEntity); @@ -49,7 +51,7 @@ void checkAndCreateTracingBatch() { assertEquals(tracingBatchService.getLastEventIdByTracingBatchAndType(Const.ESERVICE_EVENT), tracingBatchEntity.getLastEventId()); //lastEventId==tracingBatchEntity.getLastEventId()+1 - tracingBatchEntity.setState("test"); + tracingBatchEntity.setState(ENDED_WITH_ERROR); list= new ArrayList<>(); list.add(tracingBatchEntity); Mockito.when(repository.findLatestByType(Const.ESERVICE_EVENT)).thenReturn(list);