Skip to content

Commit

Permalink
Updated TracingBatch and InteropService with some fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pasqualino.cristaudo committed Dec 5, 2023
1 parent 94e33a2 commit 35d4581
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Integer countBatchInErrorWithLastEventIdAndType(Long lastEventId, String
public Long getLastEventIdByTracingBatchAndType(String type) {
List<TracingBatchEntity> 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()){
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class TracingBatchMapperImplTest {
private Long batchId;
private Long lastEventId;
private String state;
private TracingBatchStateEnum state;
private TracingBatchMapperImpl tracingBatchMapper;

@BeforeEach
Expand All @@ -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);
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -41,15 +43,15 @@ void checkAndCreateTracingBatch() {

//state = ENDED
TracingBatchEntity tracingBatchEntity= new TracingBatchEntity();
tracingBatchEntity.setState(ENDED.name());
tracingBatchEntity.setState(ENDED);
tracingBatchEntity.setLastEventId(1L);
List<TracingBatchEntity> list= new ArrayList<>();
list.add(tracingBatchEntity);
Mockito.when(repository.findLatestByType(Const.ESERVICE_EVENT)).thenReturn(list);
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);
Expand Down

0 comments on commit 35d4581

Please sign in to comment.