Skip to content

Commit

Permalink
[SELC-5097] fix: modify createAggregateOnboardingRequest return value (
Browse files Browse the repository at this point in the history
  • Loading branch information
giulia-tremolada authored Jun 28, 2024
1 parent 7929e71 commit 932fe9a
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void sendMailCompletionAggregate(@DurableActivityTrigger(name = "onboardi
}

@FunctionName(CREATE_AGGREGATE_ONBOARDING_REQUEST_ACTIVITY)
public Onboarding createAggregateOnboardingRequest(@DurableActivityTrigger(name = "onboardingString") String onboardingAggregateOrchestratorInputString, final ExecutionContext context) {
public String createAggregateOnboardingRequest(@DurableActivityTrigger(name = "onboardingString") String onboardingAggregateOrchestratorInputString, final ExecutionContext context) {
context.getLogger().info(String.format(FORMAT_LOGGER_ONBOARDING_STRING, CREATE_AGGREGATE_ONBOARDING_REQUEST_ACTIVITY, onboardingAggregateOrchestratorInputString));
return completionService.createAggregateOnboardingRequest(readOnboardingAggregateOrchestratorInputValue(objectMapper, onboardingAggregateOrchestratorInputString));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface OnboardingMapper {
@Mapping(target = "institution", expression = "java(mapInstitution(input.getAggregate(), input.getInstitution()))")
@Mapping(target = "aggregator", source = "institution")
@Mapping(target = "id", expression = "java(java.util.UUID.randomUUID().toString())")
@Mapping(target = "activatedAt", ignore = true)
Onboarding mapToOnboarding(OnboardingAggregateOrchestratorInput input);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public interface CompletionService {

String createDelegation(Onboarding onboarding);

Onboarding createAggregateOnboardingRequest(OnboardingAggregateOrchestratorInput onboardingAggregateOrchestratorInput);
String createAggregateOnboardingRequest(OnboardingAggregateOrchestratorInput onboardingAggregateOrchestratorInput);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.common.OnboardingStatus;
import it.pagopa.selfcare.onboarding.common.Origin;
import it.pagopa.selfcare.onboarding.entity.*;
import it.pagopa.selfcare.onboarding.dto.OnboardingAggregateOrchestratorInput;
import it.pagopa.selfcare.onboarding.entity.Institution;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.Token;
import it.pagopa.selfcare.onboarding.entity.User;
import it.pagopa.selfcare.onboarding.entity.*;
import it.pagopa.selfcare.onboarding.exception.GenericOnboardingException;
import it.pagopa.selfcare.onboarding.mapper.InstitutionMapper;
import it.pagopa.selfcare.onboarding.mapper.OnboardingMapper;
Expand Down Expand Up @@ -335,11 +331,11 @@ public void sendCompletedEmailAggregate(Onboarding onboarding) {
}

@Override
public Onboarding createAggregateOnboardingRequest(OnboardingAggregateOrchestratorInput onboardingAggregateOrchestratorInput) {
public String createAggregateOnboardingRequest(OnboardingAggregateOrchestratorInput onboardingAggregateOrchestratorInput) {
Onboarding onboardingToUpdate = onboardingMapper.mapToOnboarding(onboardingAggregateOrchestratorInput);
onboardingToUpdate.setWorkflowType(CONFIRMATION_AGGREGATE);
onboardingToUpdate.setStatus(OnboardingStatus.PENDING);
onboardingRepository.persistOrUpdate(onboardingToUpdate);
return onboardingToUpdate;
return onboardingToUpdate.getId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ default String createInstitutionAndOnboarding(TaskOrchestrationContext ctx, Onbo
ctx.callActivity(CREATE_USERS_ACTIVITY, onboardingWithInstitutionIdString, optionsRetry(), String.class).await();
ctx.callActivity(STORE_ONBOARDING_ACTIVATEDAT, onboardingWithInstitutionIdString, optionsRetry(), String.class).await();

createTestEnvironmentsOnboarding(ctx, onboarding, onboardingWithInstitutionIdString);

return onboardingWithInstitutionIdString;
}

default void createTestEnvironmentsOnboarding(TaskOrchestrationContext ctx, Onboarding onboarding, String onboardingWithInstitutionIdString) {
// Create onboarding for test environments if exists (ex. prod-interop-coll)
if(Objects.nonNull(onboarding.getTestEnvProductIds()) && !onboarding.getTestEnvProductIds().isEmpty()) {
// Schedule each task to run in parallel
Expand All @@ -63,8 +69,6 @@ default String createInstitutionAndOnboarding(TaskOrchestrationContext ctx, Onbo
// Wait for all tasks to complete
ctx.allOf(parallelTasks).await();
}

return onboardingWithInstitutionIdString;
}

default Optional<OnboardingStatus> onboardingCompletionActivity(TaskOrchestrationContext ctx, Onboarding onboarding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public Optional<OnboardingStatus> executeToBeValidatedState(TaskOrchestrationCon
@Override
public Optional<OnboardingStatus> executePendingState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) {
Onboarding onboarding = onboardingWorkflow.getOnboarding();

String onboardingString = getOnboardingString(objectMapper, onboarding);
String institutionId = ctx.callActivity(CREATE_INSTITUTION_ACTIVITY, onboardingString, optionsRetry, String.class).await();
onboarding.getInstitution().setId(institutionId);
Expand All @@ -40,6 +41,10 @@ public Optional<OnboardingStatus> executePendingState(TaskOrchestrationContext c

final String onboardingWithDelegationIdString = getOnboardingString(objectMapper(), onboarding);
ctx.callActivity(CREATE_USERS_ACTIVITY, onboardingWithDelegationIdString, optionsRetry, String.class).await();
ctx.callActivity(STORE_ONBOARDING_ACTIVATEDAT, onboardingWithInstitutionIdString, optionsRetry(), String.class).await();

createTestEnvironmentsOnboarding(ctx, onboarding, onboardingWithInstitutionIdString);

ctx.callActivity(SEND_MAIL_COMPLETION_AGGREGATE_ACTIVITY, onboardingWithDelegationIdString, optionsRetry, String.class).await();
return Optional.of(OnboardingStatus.COMPLETED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,35 @@ void onboardingsOrchestratorConfirmationWithTestProductIds() {
.updateOnboardingStatus(onboarding.getId(), OnboardingStatus.COMPLETED);
}

@Test
void onboardingOrchestratorConfirmAggregate(){
Onboarding onboarding = new Onboarding();
onboarding.setId("onboardingId");
onboarding.setStatus(OnboardingStatus.PENDING);
onboarding.setWorkflowType(WorkflowType.CONFIRMATION_AGGREGATE);
Institution institution = new Institution();
institution.setId("id");
onboarding.setInstitution(institution);

TaskOrchestrationContext orchestrationContext = mockTaskOrchestrationContext(onboarding);
function.onboardingsOrchestrator(orchestrationContext, executionContext);

ArgumentCaptor<String> captorActivity = ArgumentCaptor.forClass(String.class);
Mockito.verify(orchestrationContext, times(6))
.callActivity(captorActivity.capture(), any(), any(),any());
assertEquals(CREATE_INSTITUTION_ACTIVITY, captorActivity.getAllValues().get(0));
assertEquals(CREATE_ONBOARDING_ACTIVITY, captorActivity.getAllValues().get(1));
assertEquals(CREATE_DELEGATION_ACTIVITY, captorActivity.getAllValues().get(2));
assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(3));
assertEquals(STORE_ONBOARDING_ACTIVATEDAT, captorActivity.getAllValues().get(4));
assertEquals(SEND_MAIL_COMPLETION_AGGREGATE_ACTIVITY, captorActivity.getAllValues().get(5));

Mockito.verify(service, times(1))
.updateOnboardingStatus(onboarding.getId(), OnboardingStatus.COMPLETED);

function.onboardingsOrchestrator(orchestrationContext, executionContext);
}

@Test
void onboardingsAggregateOrchestrator(){
Onboarding onboarding = new Onboarding();
Expand Down Expand Up @@ -670,15 +699,14 @@ void createUsersOnboarding() {
void createAggregateOnboardingRequest() {
final String onboardingAggregateOrchestratorInputString = "{\"productId\":\"prod-io\"}";

Onboarding onboarding = new Onboarding();
onboarding.setProductId("prod-io");
String onboardingId = "id";
when(executionContext.getLogger()).thenReturn(Logger.getGlobal());
when(completionService.createAggregateOnboardingRequest(any())).thenReturn(onboarding);
when(completionService.createAggregateOnboardingRequest(any())).thenReturn(onboardingId);

Onboarding response = function.createAggregateOnboardingRequest(onboardingAggregateOrchestratorInputString, executionContext);
String response = function.createAggregateOnboardingRequest(onboardingAggregateOrchestratorInputString, executionContext);

Assertions.assertEquals("prod-io", response.getProductId());
verify(completionService, times(1))
Assertions.assertEquals(onboardingId, response);
Mockito.verify(completionService, times(1))
.createAggregateOnboardingRequest(any());
}
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
import java.util.*;

import static it.pagopa.selfcare.onboarding.service.OnboardingService.USERS_FIELD_LIST;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

@QuarkusTest
Expand Down Expand Up @@ -609,12 +608,13 @@ void testCreateAggregateOnboardingRequest() throws JsonProcessingException {
Onboarding onboardingToUpdate = createSampleOnboarding();

// When
Onboarding onboarding = completionServiceDefault.createAggregateOnboardingRequest(input);
String onboardingId = completionServiceDefault.createAggregateOnboardingRequest(input);

onboardingToUpdate.setId(onboarding.getId());
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
assertEquals(objectMapper.writeValueAsString(onboardingToUpdate), objectMapper.writeValueAsString(onboarding));

assertNotEquals(onboardingToUpdate.getId(), onboardingId);
assertEquals(input.getAggregate().getTaxCode(), onboardingToUpdate.getInstitution().getTaxCode());
}

public static OnboardingAggregateOrchestratorInput createSampleOnboardingInput() {
Expand Down Expand Up @@ -683,7 +683,7 @@ public static Onboarding createSampleOnboarding() {
onboarding.setUpdatedAt(LocalDateTime.MAX);
onboarding.setActivatedAt(LocalDateTime.MAX);
onboarding.setDeletedAt(null);
onboarding.setReasonForReject(null);;
onboarding.setReasonForReject(null);

Aggregator aggregator = new Aggregator();
aggregator.setId("institutionId");
Expand Down

0 comments on commit 932fe9a

Please sign in to comment.