Skip to content

Commit

Permalink
setting business key for loan agreement
Browse files Browse the repository at this point in the history
  • Loading branch information
Luc Weinbrecht committed Jun 19, 2022
1 parent 48ee99e commit 5b5f81b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class ProcessConstants {
public static final String LOAN_AGREEMENT_NUMBER = "loanAgreementNumber";
public static final String RECOMMENDATION_START_EVENT_MESSAGE_REF = "crossSellingPotentialDiscoveredMessage";
public static final String RECOMMENDATION_CUSTOMER_NUMBER = "customerNumber";
public static final String BUSINESS_KEY = "businessKey";

public static final String LOAN_AGREEMENT_TASK = "approve-loan-agreement";
public static final String LOAN_REJECTION_TASK = "reject-loan-agreement";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import static de.weinbrecht.luc.bpm.architecture.loan.agreement.adapter.common.ProcessConstants.LOAN_AGREEMENT_NUMBER;
import static de.weinbrecht.luc.bpm.architecture.loan.agreement.adapter.common.ProcessConstants.SEND_CROSS_SELLING_RECOMMENDATION_TASK;
import static de.weinbrecht.luc.bpm.architecture.loan.agreement.adapter.common.ProcessConstants.*;

@RequiredArgsConstructor
@Component
Expand All @@ -24,9 +23,10 @@ public class SendCrossSellingRecommendation {
@ZeebeWorker(type = SEND_CROSS_SELLING_RECOMMENDATION_TASK, fetchVariables = LOAN_AGREEMENT_NUMBER)
public void handleJobFoo(final JobClient client, final ActivatedJob job) {
Long loanAgreementNumber = ((Number) job.getVariablesAsMap().get(LOAN_AGREEMENT_NUMBER)).longValue();
String businessKey = (String) job.getVariablesAsMap().get(BUSINESS_KEY);
LoanAgreement loanAgreement = loanAgreementQuery.loadByNumber(new LoanAgreementNumber(loanAgreementNumber));

recommendationTrigger.startLoanAgreement(new CaseId("11"), loanAgreement);
recommendationTrigger.startLoanAgreement(new CaseId(businessKey), loanAgreement);

client.newCompleteCommand(job.getKey())
.send()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import java.util.HashMap;
import java.util.Map;

import static de.weinbrecht.luc.bpm.architecture.loan.agreement.adapter.common.ProcessConstants.LOAN_AGREEMENT_NUMBER;
import static de.weinbrecht.luc.bpm.architecture.loan.agreement.adapter.common.ProcessConstants.LOAN_START_EVENT_MESSAGE_REF;
import static de.weinbrecht.luc.bpm.architecture.loan.agreement.adapter.common.ProcessConstants.*;

@RequiredArgsConstructor
@Component
Expand All @@ -23,6 +22,7 @@ class ProcessEngineClient implements WorkflowCommand {
public void startLoanAgreement(CaseId caseId, LoanAgreementNumber loanAgreementNumber) {
Map<String, Object> processVariables = new HashMap<>();
processVariables.put(LOAN_AGREEMENT_NUMBER, loanAgreementNumber.getValue());
processVariables.put(BUSINESS_KEY, caseId.getValue());
client.newPublishMessageCommand()
.messageName(LOAN_START_EVENT_MESSAGE_REF)
.correlationKey("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.HashMap;
import java.util.Map;

import static de.weinbrecht.luc.bpm.architecture.loan.agreement.adapter.common.ProcessConstants.BUSINESS_KEY;
import static de.weinbrecht.luc.bpm.architecture.loan.agreement.adapter.common.ProcessConstants.LOAN_AGREEMENT_NUMBER;
import static de.weinbrecht.luc.bpm.architecture.loan.agreement.domain.model.TestdataGenerator.createLoanAgreementWithNumber;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
Expand All @@ -34,11 +35,12 @@ class SendCrossSellingRecommendationTest {
@Test
void should_load_data_and_start_process_by_message() {
LoanAgreement loanAgreement = createLoanAgreementWithNumber();
String caseId = "11";
CaseId caseId = new CaseId("11");
JobClient client = mock(JobClient.class, RETURNS_DEEP_STUBS);
ActivatedJob job = mock(ActivatedJob.class);
Map<String, Object> variables = new HashMap<>();
variables.put(LOAN_AGREEMENT_NUMBER, loanAgreement.getLoanAgreementNumber().getValue().intValue());
variables.put(BUSINESS_KEY, caseId.getValue());
when(job.getVariablesAsMap()).thenReturn(variables);
when(job.getKey()).thenReturn(1L);
when(loanAgreementQuery.loadByNumber(loanAgreement.getLoanAgreementNumber())).thenReturn(loanAgreement);
Expand All @@ -47,6 +49,6 @@ void should_load_data_and_start_process_by_message() {

verify(client.newCompleteCommand(job.getKey())).send();

verify(recommendationTrigger).startLoanAgreement(new CaseId(caseId), loanAgreement);
verify(recommendationTrigger).startLoanAgreement(caseId, loanAgreement);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ProcessEngineClientTest {
void should_call_zeebe_to_start_reommendation() {
Map<String, Object> processVariables = new HashMap<>();
processVariables.put(LOAN_AGREEMENT_NUMBER, loanAgreementNumber.getValue());
processVariables.put(BUSINESS_KEY, caseId.getValue());

classUnderTest.startLoanAgreement(caseId, loanAgreementNumber);

Expand Down

0 comments on commit 5b5f81b

Please sign in to comment.