Skip to content

Commit

Permalink
fix UpdateIngestionFlowStatusActivity error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioT90 committed Jan 31, 2025
1 parent 3de6344 commit e1806b8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public interface UpdateIngestionFlowStatusActivity {
*
* @param id the unique identifier of the record to update.
* @param newStatus the new status to set.
* @return true if the update was successful, false otherwise.
*/
@ActivityMethod
boolean updateStatus(Long id, IngestionFlowFile.StatusEnum newStatus, String codError, String discardFileName);
void updateStatus(Long id, IngestionFlowFile.StatusEnum newStatus, String codError, String discardFileName);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.gov.pagopa.payhub.activities.activity.ingestionflow;

import it.gov.pagopa.payhub.activities.connector.processexecutions.IngestionFlowFileService;
import it.gov.pagopa.payhub.activities.exception.ingestionflow.IngestionFlowFileNotFoundException;
import it.gov.pagopa.pu.processexecutions.dto.generated.IngestionFlowFile;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
Expand All @@ -21,14 +22,10 @@ public UpdateIngestionFlowStatusActivityImpl(IngestionFlowFileService ingestionF
}

@Override
public boolean updateStatus(Long id, IngestionFlowFile.StatusEnum newStatus, String codError, String discardFileName) {
public void updateStatus(Long id, IngestionFlowFile.StatusEnum newStatus, String codError, String discardFileName) {
log.info("Updating IngestionFlowFile {} to new status {}", id, newStatus);
if(id==null){
throw new IllegalArgumentException("A null IngestionFlowFile was provided when updating its status to " + newStatus);
if(ingestionFlowFileService.updateStatus(id, newStatus, codError, discardFileName) != 1){
throw new IngestionFlowFileNotFoundException("Cannot update ingestionFlowFile having id " + ingestionFlowFileService + " to status " + newStatus);
}
if(newStatus == null){
throw new IllegalArgumentException("A null IngestionFlowFile status was provided when updating the id " + id);
}
return ingestionFlowFileService.updateStatus(id, newStatus, codError, discardFileName) == 1;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.gov.pagopa.payhub.activities.activity.ingestionflow;

import it.gov.pagopa.payhub.activities.connector.processexecutions.IngestionFlowFileService;
import it.gov.pagopa.payhub.activities.exception.ingestionflow.IngestionFlowFileNotFoundException;
import it.gov.pagopa.pu.processexecutions.dto.generated.IngestionFlowFile;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -30,9 +31,8 @@ void givenValidIdAndNewStatusWhenUpdateStatusThenTrue(){
//given
Mockito.when(ingestionFlowFileServiceMock.updateStatus(VALID_ID, VALID_STATUS, COD_ERROR,DISCARD_FILE_NAME)).thenReturn(1);
//when
boolean result = updateIngestionFlowStatusActivity.updateStatus(VALID_ID, VALID_STATUS, COD_ERROR,DISCARD_FILE_NAME);
updateIngestionFlowStatusActivity.updateStatus(VALID_ID, VALID_STATUS, COD_ERROR,DISCARD_FILE_NAME);
//verify
Assertions.assertTrue(result);
Mockito.verify(ingestionFlowFileServiceMock, Mockito.times(1)).updateStatus(VALID_ID, VALID_STATUS, COD_ERROR, DISCARD_FILE_NAME);
}

Expand All @@ -41,28 +41,7 @@ void givenInvalidIdAndNewStatusWhenUpdateStatusThenFalse(){
//given
Mockito.when(ingestionFlowFileServiceMock.updateStatus(INVALID_ID, VALID_STATUS, COD_ERROR, DISCARD_FILE_NAME)).thenReturn(0);
//when
boolean result = updateIngestionFlowStatusActivity.updateStatus(INVALID_ID, VALID_STATUS, COD_ERROR, DISCARD_FILE_NAME);
//verify
Assertions.assertFalse(result);
Mockito.verify(ingestionFlowFileServiceMock, Mockito.times(1)).updateStatus(INVALID_ID, VALID_STATUS, COD_ERROR, DISCARD_FILE_NAME);
}

@Test
void givenNullIdAndNewStatusWhenUpdateStatusThenException(){
String expectedError = "A null IngestionFlowFile was provided when updating its status to " + VALID_STATUS;
//verify
IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> updateIngestionFlowStatusActivity.updateStatus(null, VALID_STATUS, COD_ERROR, DISCARD_FILE_NAME));
Assertions.assertEquals(expectedError, exception.getMessage());
}

@Test
void givenIdAndNullNewStatusWhenUpdateStatusThenException(){
String expectedError = "A null IngestionFlowFile status was provided when updating the id " + VALID_ID;
//verify
IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class,
() -> updateIngestionFlowStatusActivity.updateStatus(VALID_ID, null, COD_ERROR, DISCARD_FILE_NAME));
Assertions.assertEquals(expectedError, exception.getMessage());
Assertions.assertThrows(IngestionFlowFileNotFoundException.class, () -> updateIngestionFlowStatusActivity.updateStatus(INVALID_ID, VALID_STATUS, COD_ERROR, DISCARD_FILE_NAME));
}

}

0 comments on commit e1806b8

Please sign in to comment.