generated from pagopa/template-payments-java-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: P4ADEV-1678-add-wf-create-debt-position-sync (#7)
- Loading branch information
1 parent
4bfa024
commit bd8a174
Showing
16 changed files
with
253 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...n/java/it/gov/pagopa/pu/workflow/wf/debtposition/createdp/CreateDebtPositionWfClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package it.gov.pagopa.pu.workflow.wf.debtposition.createdp; | ||
|
||
import io.temporal.client.WorkflowClient; | ||
import it.gov.pagopa.payhub.activities.dto.debtposition.DebtPositionDTO; | ||
import it.gov.pagopa.pu.workflow.service.WorkflowService; | ||
import it.gov.pagopa.pu.workflow.wf.debtposition.createdp.wfsync.CreateDebtPositionSyncWF; | ||
import it.gov.pagopa.pu.workflow.wf.debtposition.createdp.wfsync.CreateDebtPositionSyncWFImpl; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class CreateDebtPositionWfClient { | ||
private final WorkflowService workflowService; | ||
|
||
public CreateDebtPositionWfClient(WorkflowService workflowService) { | ||
this.workflowService = workflowService; | ||
} | ||
|
||
public String createDPSync(DebtPositionDTO debtPosition) { | ||
String workflowId = String.valueOf(debtPosition.getDebtPositionId()); | ||
CreateDebtPositionSyncWF workflow = workflowService.buildWorkflowStub( | ||
CreateDebtPositionSyncWF.class, | ||
CreateDebtPositionSyncWFImpl.TASK_QUEUE, | ||
workflowId); | ||
WorkflowClient.start(workflow::createDPSync, debtPosition); | ||
return workflowId; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...it/gov/pagopa/pu/workflow/wf/debtposition/createdp/config/CreateDebtPositionWfConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package it.gov.pagopa.pu.workflow.wf.debtposition.createdp.config; | ||
|
||
import io.temporal.workflow.Workflow; | ||
import it.gov.pagopa.payhub.activities.activity.debtposition.ionotification.SendDebtPositionIONotificationActivity; | ||
import it.gov.pagopa.pu.workflow.config.BaseWfConfig; | ||
import it.gov.pagopa.pu.workflow.config.TemporalWFImplementationCustomizer; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ConfigurationProperties(prefix = "workflow.debt-position-creation") | ||
public class CreateDebtPositionWfConfig extends BaseWfConfig { | ||
|
||
public SendDebtPositionIONotificationActivity buildSendDebtPositionIONotificationActivityStub() { | ||
return Workflow.newActivityStub(SendDebtPositionIONotificationActivity.class, TemporalWFImplementationCustomizer.baseWfConfig2ActivityOptions(this)); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...a/it/gov/pagopa/pu/workflow/wf/debtposition/createdp/wfsync/CreateDebtPositionSyncWF.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package it.gov.pagopa.pu.workflow.wf.debtposition.createdp.wfsync; | ||
|
||
import io.temporal.workflow.WorkflowInterface; | ||
import io.temporal.workflow.WorkflowMethod; | ||
import it.gov.pagopa.payhub.activities.dto.debtposition.DebtPositionDTO; | ||
|
||
/** | ||
* Workflow interface for creating a Sync Debt Position Workflow | ||
* */ | ||
@WorkflowInterface | ||
public interface CreateDebtPositionSyncWF { | ||
|
||
/** | ||
* Workflow method for the Sync Debt Position Workflow | ||
* @param debtPosition the debt position to be created | ||
* */ | ||
@WorkflowMethod | ||
void createDPSync(DebtPositionDTO debtPosition); | ||
} |
41 changes: 41 additions & 0 deletions
41
.../gov/pagopa/pu/workflow/wf/debtposition/createdp/wfsync/CreateDebtPositionSyncWFImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package it.gov.pagopa.pu.workflow.wf.debtposition.createdp.wfsync; | ||
|
||
import io.temporal.spring.boot.WorkflowImpl; | ||
import it.gov.pagopa.payhub.activities.activity.debtposition.ionotification.SendDebtPositionIONotificationActivity; | ||
import it.gov.pagopa.payhub.activities.dto.debtposition.DebtPositionDTO; | ||
import it.gov.pagopa.pu.workflow.wf.debtposition.createdp.config.CreateDebtPositionWfConfig; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.BeansException; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
|
||
import static it.gov.pagopa.pu.workflow.wf.debtposition.createdp.wfsync.CreateDebtPositionSyncWFImpl.TASK_QUEUE; | ||
|
||
|
||
@Slf4j | ||
@WorkflowImpl(taskQueues = TASK_QUEUE) | ||
public class CreateDebtPositionSyncWFImpl implements CreateDebtPositionSyncWF, ApplicationContextAware { | ||
|
||
public static final String TASK_QUEUE = "CreateDebtPositionWf"; | ||
|
||
private SendDebtPositionIONotificationActivity sendDebtPositionIONotificationActivity; | ||
|
||
/** | ||
* Temporal workflow will not allow to use injection in order to avoid <a href="https://docs.temporal.io/workflows#non-deterministic-change">non-deterministic changes</a> due to dynamic reconfiguration.<BR /> | ||
* Anyway it allows to override ActivityOptions, but actually it's not supporting the override based on the particular workflow.<BR /> | ||
* In {@link it.gov.pagopa.pu.workflow.config.TemporalWFImplementationCustomizer} we are already setting defaults to all workflows.<BR /> | ||
* Use this as an example to override based on the particular workflow. | ||
*/ | ||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
CreateDebtPositionWfConfig wfConfig = applicationContext.getBean(CreateDebtPositionWfConfig.class); | ||
sendDebtPositionIONotificationActivity = wfConfig.buildSendDebtPositionIONotificationActivityStub(); | ||
} | ||
|
||
@Override | ||
public void createDPSync(DebtPositionDTO debtPosition) { | ||
log.info("Starting workflow for ingesting DebtPosition with ID: {}", debtPosition.getDebtPositionId()); | ||
sendDebtPositionIONotificationActivity.sendMessage(debtPosition); | ||
log.info("Message to IO sent with payload {}", debtPosition); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ing/def/PaymentsReportingIngestionWF.java → ...gestion/PaymentsReportingIngestionWF.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/test/java/it/gov/pagopa/pu/workflow/utilities/faker/DebtPositionFaker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package it.gov.pagopa.pu.workflow.utilities.faker; | ||
|
||
import it.gov.pagopa.payhub.activities.dto.debtposition.DebtPositionDTO; | ||
|
||
public class DebtPositionFaker { | ||
|
||
public static DebtPositionDTO buildDebtPositionDTO(){ | ||
return DebtPositionDTO.builder() | ||
.debtPositionId(1L) | ||
.iupdOrg("codeIud") | ||
.iupdPagopa("gpdIupd") | ||
.status("statusCode") | ||
.ingestionFlowFileLineNumber(1L) | ||
.gpdStatus('G') | ||
.build(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...va/it/gov/pagopa/pu/workflow/wf/debtposition/createdp/CreateDebtPositionWfClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package it.gov.pagopa.pu.workflow.wf.debtposition.createdp; | ||
|
||
import it.gov.pagopa.payhub.activities.dto.debtposition.DebtPositionDTO; | ||
import it.gov.pagopa.pu.workflow.service.WorkflowService; | ||
import it.gov.pagopa.pu.workflow.wf.debtposition.createdp.wfsync.CreateDebtPositionSyncWF; | ||
import it.gov.pagopa.pu.workflow.wf.debtposition.createdp.wfsync.CreateDebtPositionSyncWFImpl; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static it.gov.pagopa.pu.workflow.utilities.faker.DebtPositionFaker.buildDebtPositionDTO; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class CreateDebtPositionWfClientTest { | ||
|
||
@Mock | ||
private WorkflowService workflowServiceMock; | ||
@Mock | ||
private CreateDebtPositionSyncWF wfMock; | ||
|
||
private CreateDebtPositionWfClient client; | ||
|
||
@BeforeEach | ||
void init(){ | ||
client = new CreateDebtPositionWfClient(workflowServiceMock); | ||
} | ||
|
||
@AfterEach | ||
void verifyNoMoreInteractions(){ | ||
Mockito.verifyNoMoreInteractions(workflowServiceMock); | ||
} | ||
|
||
@Test | ||
void whenCreateDPSyncThenSuccess(){ | ||
// Given | ||
long id = 1L; | ||
String expectedWorkflowId = String.valueOf(id); | ||
DebtPositionDTO debtPosition = buildDebtPositionDTO(); | ||
|
||
Mockito.when(workflowServiceMock.buildWorkflowStub(CreateDebtPositionSyncWF.class, CreateDebtPositionSyncWFImpl.TASK_QUEUE, expectedWorkflowId)) | ||
.thenReturn(wfMock); | ||
|
||
// When | ||
String workflowId = client.createDPSync(debtPosition); | ||
|
||
// Then | ||
Assertions.assertEquals(expectedWorkflowId, workflowId); | ||
Mockito.verify(wfMock).createDPSync(debtPosition); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
.../gov/pagopa/pu/workflow/wf/debtposition/createdp/wfsync/CreateDebtPositionSyncWFTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package it.gov.pagopa.pu.workflow.wf.debtposition.createdp.wfsync; | ||
|
||
import it.gov.pagopa.payhub.activities.activity.debtposition.ionotification.SendDebtPositionIONotificationActivity; | ||
import it.gov.pagopa.payhub.activities.dto.debtposition.DebtPositionDTO; | ||
import it.gov.pagopa.pu.workflow.wf.debtposition.createdp.config.CreateDebtPositionWfConfig; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.context.ApplicationContext; | ||
|
||
import static it.gov.pagopa.pu.workflow.utilities.faker.DebtPositionFaker.buildDebtPositionDTO; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class CreateDebtPositionSyncWFTest { | ||
|
||
@Mock | ||
private SendDebtPositionIONotificationActivity sendDebtPositionIONotificationActivityMock; | ||
|
||
private CreateDebtPositionSyncWFImpl wf; | ||
|
||
@BeforeEach | ||
void init() { | ||
CreateDebtPositionWfConfig createDebtPositionWfConfigMock = Mockito.mock(CreateDebtPositionWfConfig.class); | ||
ApplicationContext applicationContextMock = Mockito.mock(ApplicationContext.class); | ||
|
||
Mockito.when(createDebtPositionWfConfigMock.buildSendDebtPositionIONotificationActivityStub()) | ||
.thenReturn(sendDebtPositionIONotificationActivityMock); | ||
|
||
Mockito.when(applicationContextMock.getBean(CreateDebtPositionWfConfig.class)) | ||
.thenReturn(createDebtPositionWfConfigMock); | ||
|
||
wf = new CreateDebtPositionSyncWFImpl(); | ||
wf.setApplicationContext(applicationContextMock); | ||
} | ||
|
||
@AfterEach | ||
void verifyNoMoreInteractions() { | ||
Mockito.verifyNoMoreInteractions(sendDebtPositionIONotificationActivityMock); | ||
} | ||
|
||
@Test | ||
void givenCreateDPSyncThenSuccess() { | ||
// Given | ||
DebtPositionDTO debtPosition = buildDebtPositionDTO(); | ||
|
||
Mockito.doNothing().when(sendDebtPositionIONotificationActivityMock) | ||
.sendMessage(debtPosition); | ||
|
||
// When | ||
wf.createDPSync(debtPosition); | ||
|
||
// Then | ||
Mockito.verify(sendDebtPositionIONotificationActivityMock).sendMessage(debtPosition); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...u/workflow/wf/ingestionflow/paymentsreporting/PaymentsReportingIngestionWFClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...def/PaymentsReportingIngestionWFTest.java → ...ion/PaymentsReportingIngestionWFTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters