diff --git a/src/main/java/it/gov/pagopa/payhub/activities/activity/classifications/TransferClassificationActivity.java b/src/main/java/it/gov/pagopa/payhub/activities/activity/classifications/TransferClassificationActivity.java index fe727294..9fc8337c 100644 --- a/src/main/java/it/gov/pagopa/payhub/activities/activity/classifications/TransferClassificationActivity.java +++ b/src/main/java/it/gov/pagopa/payhub/activities/activity/classifications/TransferClassificationActivity.java @@ -9,14 +9,14 @@ @ActivityInterface public interface TransferClassificationActivity { - /** - * Processes Transfer classification based on the provided parameters. - * - * @param orgId the unique identifier of the organization - * @param iuv the unique identifier of the payment (IUV) - * @param iur the identifier of the receipt associated with the payment - * @param transferIndex the index of the transfer to be classified - */ - @ActivityMethod - void classify(Long orgId, String iuv, String iur, int transferIndex); + /** + * Processes Transfer classification based on the provided parameters. + * + * @param orgId the unique identifier of the organization + * @param iuv the unique identifier of the payment (IUV) + * @param iur the identifier of the receipt associated with the payment + * @param transferIndex the index of the transfer to be classified + */ + @ActivityMethod + void classify(Long orgId, String iuv, String iur, int transferIndex); } \ No newline at end of file diff --git a/src/main/java/it/gov/pagopa/payhub/activities/activity/classifications/TransferClassificationActivityImpl.java b/src/main/java/it/gov/pagopa/payhub/activities/activity/classifications/TransferClassificationActivityImpl.java index 588de427..eef9d153 100644 --- a/src/main/java/it/gov/pagopa/payhub/activities/activity/classifications/TransferClassificationActivityImpl.java +++ b/src/main/java/it/gov/pagopa/payhub/activities/activity/classifications/TransferClassificationActivityImpl.java @@ -1,6 +1,7 @@ package it.gov.pagopa.payhub.activities.activity.classifications; import it.gov.pagopa.payhub.activities.dao.ClassificationDao; +import it.gov.pagopa.payhub.activities.dao.TransferDao; import it.gov.pagopa.payhub.activities.exception.ClassificationException; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Lazy; @@ -11,9 +12,12 @@ @Component public class TransferClassificationActivityImpl implements TransferClassificationActivity { private final ClassificationDao classificationDao; + private final TransferDao transferDao; - public TransferClassificationActivityImpl(ClassificationDao classificationDao) { + public TransferClassificationActivityImpl(ClassificationDao classificationDao, + TransferDao transferDao) { this.classificationDao = classificationDao; + this.transferDao = transferDao; } @Override @@ -22,6 +26,6 @@ public void classify(Long orgId, String iuv, String iur, int transferIndex) { if (!classificationDao.deleteTransferClassification(orgId, iuv, iur, transferIndex)) { throw new ClassificationException("Error occurred while clean up current processing Requests due to failed deletion"); } + transferDao.findBySemanticKey(orgId, iuv, iur, transferIndex); } - } diff --git a/src/main/java/it/gov/pagopa/payhub/activities/dao/TransferDao.java b/src/main/java/it/gov/pagopa/payhub/activities/dao/TransferDao.java new file mode 100644 index 00000000..ce941707 --- /dev/null +++ b/src/main/java/it/gov/pagopa/payhub/activities/dao/TransferDao.java @@ -0,0 +1,16 @@ +package it.gov.pagopa.payhub.activities.dao; + +import it.gov.pagopa.payhub.activities.dto.TransferDTO; + +import java.util.List; + +/** + * Data Access Object (DAO) interface for handling operations related to + * `Transfer` objects. + * + * @see TransferDTO + */ +public interface TransferDao { + + TransferDTO findBySemanticKey(Long orgId, String iuv, String iur, int transferIndex); +} diff --git a/src/test/java/it/gov/pagopa/payhub/activities/activity/classifications/TransferClassificationActivityImplTest.java b/src/test/java/it/gov/pagopa/payhub/activities/activity/classifications/TransferClassificationActivityImplTest.java index f7322ff1..6644135a 100644 --- a/src/test/java/it/gov/pagopa/payhub/activities/activity/classifications/TransferClassificationActivityImplTest.java +++ b/src/test/java/it/gov/pagopa/payhub/activities/activity/classifications/TransferClassificationActivityImplTest.java @@ -1,6 +1,8 @@ package it.gov.pagopa.payhub.activities.activity.classifications; import it.gov.pagopa.payhub.activities.dao.ClassificationDao; +import it.gov.pagopa.payhub.activities.dao.TransferDao; +import it.gov.pagopa.payhub.activities.dto.TransferDTO; import it.gov.pagopa.payhub.activities.exception.ClassificationException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -8,6 +10,8 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import java.util.List; + import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; @@ -21,22 +25,33 @@ class TransferClassificationActivityImplTest { @Mock private ClassificationDao classificationDaoMock; + @Mock + private TransferDao transferDaoMock; + private TransferClassificationActivity activity; @BeforeEach void setUp() { - activity = new TransferClassificationActivityImpl(classificationDaoMock); + activity = new TransferClassificationActivityImpl(classificationDaoMock, transferDaoMock); } @Test void classificationSuccess() { when(classificationDaoMock.deleteTransferClassification(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(Boolean.TRUE); + when(transferDaoMock.findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(new TransferDTO()); assertDoesNotThrow(() -> activity.classify(ORGANIZATION, IUV, IUR, INDEX)); } @Test - void classificationFailed() { + void givenFailedDeletePreviousClassificationWhenClassifyThenClassificationFailed() { when(classificationDaoMock.deleteTransferClassification(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(Boolean.FALSE); assertThrows(ClassificationException.class, () -> activity.classify(ORGANIZATION, IUV, IUR, INDEX), "classification failed"); } + + @Test + void givenFailedFindTransferWhenClassifyThenClassificationFailed() { + when(classificationDaoMock.deleteTransferClassification(ORGANIZATION, IUV, IUR, INDEX)).thenReturn(Boolean.TRUE); + when(transferDaoMock.findBySemanticKey(ORGANIZATION, IUV, IUR, INDEX)).thenThrow(new ClassificationException("retrieving failed")); + assertThrows(ClassificationException.class, () -> activity.classify(ORGANIZATION, IUV, IUR, INDEX), "classification failed"); + } } diff --git a/version b/version index 815d5ca0..46ea34ec 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.19.0 +1.19.0-SNAPSHOT \ No newline at end of file